| 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 | |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 19 | #include "arch/x86/jni_frame_x86.h" |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 20 | #include "art_method-inl.h" |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 21 | #include "class_table.h" |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 22 | #include "code_generator_utils.h" |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 23 | #include "compiled_method.h" |
| Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 24 | #include "entrypoints/quick/quick_entrypoints.h" |
| Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 25 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
| Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 26 | #include "gc/accounting/card_table.h" |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 27 | #include "gc/space/image_space.h" |
| Andreas Gampe | 09659c2 | 2017-09-18 18:23:32 -0700 | [diff] [blame] | 28 | #include "heap_poisoning.h" |
| Nicolas Geoffray | 8b8d93d | 2020-09-17 14:30:01 +0100 | [diff] [blame] | 29 | #include "interpreter/mterp/nterp.h" |
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 30 | #include "intrinsics.h" |
| 31 | #include "intrinsics_x86.h" |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 32 | #include "jit/profiling_info.h" |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 33 | #include "linker/linker_patch.h" |
| Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 34 | #include "lock_word.h" |
| Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 35 | #include "mirror/array-inl.h" |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 36 | #include "mirror/class-inl.h" |
| Andra Danciu | 52d2c0c | 2020-09-15 14:27:21 +0000 | [diff] [blame] | 37 | #include "mirror/var_handle.h" |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 38 | #include "scoped_thread_state_change-inl.h" |
| Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 39 | #include "thread.h" |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 40 | #include "utils/assembler.h" |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 41 | #include "utils/stack_checks.h" |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 42 | #include "utils/x86/assembler_x86.h" |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 43 | #include "utils/x86/managed_register_x86.h" |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 44 | |
| Vladimir Marko | 0a51605 | 2019-10-14 13:00:44 +0000 | [diff] [blame] | 45 | namespace art { |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 46 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 47 | template<class MirrorType> |
| 48 | class GcRoot; |
| 49 | |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 50 | namespace x86 { |
| 51 | |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 52 | static constexpr int kCurrentMethodStackOffset = 0; |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 53 | static constexpr Register kMethodRegisterArgument = EAX; |
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 54 | static constexpr Register kCoreCalleeSaves[] = { EBP, ESI, EDI }; |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 55 | |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 56 | static constexpr int kC2ConditionMask = 0x400; |
| 57 | |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 58 | static constexpr int kFakeReturnRegister = Register(8); |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 59 | |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 60 | static constexpr int64_t kDoubleNaN = INT64_C(0x7FF8000000000000); |
| 61 | static constexpr int32_t kFloatNaN = INT32_C(0x7FC00000); |
| 62 | |
| Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 63 | static RegisterSet OneRegInReferenceOutSaveEverythingCallerSaves() { |
| 64 | InvokeRuntimeCallingConvention calling_convention; |
| 65 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 66 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 67 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 68 | // that the the kPrimNot result register is the same as the first argument register. |
| 69 | return caller_saves; |
| 70 | } |
| 71 | |
| Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 72 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 73 | #define __ down_cast<X86Assembler*>(codegen->GetAssembler())-> // NOLINT |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 74 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86PointerSize, x).Int32Value() |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 75 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 76 | class NullCheckSlowPathX86 : public SlowPathCode { |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 77 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 78 | explicit NullCheckSlowPathX86(HNullCheck* instruction) : SlowPathCode(instruction) {} |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 79 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 80 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 81 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 82 | __ Bind(GetEntryLabel()); |
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 83 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 84 | // Live registers will be restored in the catch block if caught. |
| 85 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 86 | } |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 87 | x86_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 88 | instruction_, |
| 89 | instruction_->GetDexPc(), |
| 90 | this); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 91 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 92 | } |
| 93 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 94 | bool IsFatal() const override { return true; } |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 95 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 96 | const char* GetDescription() const override { return "NullCheckSlowPathX86"; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 97 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 98 | private: |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 99 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86); |
| 100 | }; |
| 101 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 102 | class DivZeroCheckSlowPathX86 : 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 | explicit DivZeroCheckSlowPathX86(HDivZeroCheck* instruction) : SlowPathCode(instruction) {} |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 105 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 106 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 107 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 108 | __ Bind(GetEntryLabel()); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 109 | x86_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 110 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 111 | } |
| 112 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 113 | bool IsFatal() const override { return true; } |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 114 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 115 | const char* GetDescription() const override { return "DivZeroCheckSlowPathX86"; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 116 | |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 117 | private: |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 118 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86); |
| 119 | }; |
| 120 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 121 | class DivRemMinusOneSlowPathX86 : public SlowPathCode { |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 122 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 123 | DivRemMinusOneSlowPathX86(HInstruction* instruction, Register reg, bool is_div) |
| 124 | : SlowPathCode(instruction), reg_(reg), is_div_(is_div) {} |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 125 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 126 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 127 | __ Bind(GetEntryLabel()); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 128 | if (is_div_) { |
| 129 | __ negl(reg_); |
| 130 | } else { |
| 131 | __ movl(reg_, Immediate(0)); |
| 132 | } |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 133 | __ jmp(GetExitLabel()); |
| 134 | } |
| 135 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 136 | const char* GetDescription() const override { return "DivRemMinusOneSlowPathX86"; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 137 | |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 138 | private: |
| 139 | Register reg_; |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 140 | bool is_div_; |
| 141 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 142 | }; |
| 143 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 144 | class BoundsCheckSlowPathX86 : public SlowPathCode { |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 145 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 146 | explicit BoundsCheckSlowPathX86(HBoundsCheck* instruction) : SlowPathCode(instruction) {} |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 147 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 148 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 149 | LocationSummary* locations = instruction_->GetLocations(); |
| Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 150 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 151 | __ Bind(GetEntryLabel()); |
| Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 152 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 153 | // move resolver. |
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 154 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 155 | // Live registers will be restored in the catch block if caught. |
| 156 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 157 | } |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 158 | |
| 159 | // Are we using an array length from memory? |
| 160 | HInstruction* array_length = instruction_->InputAt(1); |
| 161 | Location length_loc = locations->InAt(1); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 162 | InvokeRuntimeCallingConvention calling_convention; |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 163 | if (array_length->IsArrayLength() && array_length->IsEmittedAtUseSite()) { |
| 164 | // Load the array length into our temporary. |
| Nicolas Geoffray | 0aff3a8 | 2017-10-13 13:12:36 +0100 | [diff] [blame] | 165 | HArrayLength* length = array_length->AsArrayLength(); |
| 166 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(length); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 167 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 168 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
| 169 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(1)); |
| 170 | // Check for conflicts with index. |
| 171 | if (length_loc.Equals(locations->InAt(0))) { |
| 172 | // We know we aren't using parameter 2. |
| 173 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(2)); |
| 174 | } |
| 175 | __ movl(length_loc.AsRegister<Register>(), array_len); |
| Nicolas Geoffray | 0aff3a8 | 2017-10-13 13:12:36 +0100 | [diff] [blame] | 176 | if (mirror::kUseStringCompression && length->IsStringLength()) { |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 177 | __ shrl(length_loc.AsRegister<Register>(), Immediate(1)); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 178 | } |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 179 | } |
| Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 180 | x86_codegen->EmitParallelMoves( |
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 181 | locations->InAt(0), |
| Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 182 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 183 | DataType::Type::kInt32, |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 184 | length_loc, |
| Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 185 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 186 | DataType::Type::kInt32); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 187 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 188 | ? kQuickThrowStringBounds |
| 189 | : kQuickThrowArrayBounds; |
| 190 | x86_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 191 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 192 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 193 | } |
| 194 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 195 | bool IsFatal() const override { return true; } |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 196 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 197 | const char* GetDescription() const override { return "BoundsCheckSlowPathX86"; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 198 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 199 | private: |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 200 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86); |
| 201 | }; |
| 202 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 203 | class SuspendCheckSlowPathX86 : public SlowPathCode { |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 204 | public: |
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 205 | SuspendCheckSlowPathX86(HSuspendCheck* instruction, HBasicBlock* successor) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 206 | : SlowPathCode(instruction), successor_(successor) {} |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 207 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 208 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 209 | LocationSummary* locations = instruction_->GetLocations(); |
| Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 210 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 211 | __ Bind(GetEntryLabel()); |
| Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 212 | SaveLiveRegisters(codegen, locations); // Only saves full width XMM for SIMD. |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 213 | x86_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 214 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
| Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 215 | RestoreLiveRegisters(codegen, locations); // Only restores full width XMM for SIMD. |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 216 | if (successor_ == nullptr) { |
| 217 | __ jmp(GetReturnLabel()); |
| 218 | } else { |
| Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 219 | __ jmp(x86_codegen->GetLabelOf(successor_)); |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 220 | } |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 221 | } |
| 222 | |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 223 | Label* GetReturnLabel() { |
| 224 | DCHECK(successor_ == nullptr); |
| 225 | return &return_label_; |
| 226 | } |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 227 | |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 228 | HBasicBlock* GetSuccessor() const { |
| 229 | return successor_; |
| 230 | } |
| 231 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 232 | const char* GetDescription() const override { return "SuspendCheckSlowPathX86"; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 233 | |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 234 | private: |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 235 | HBasicBlock* const successor_; |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 236 | Label return_label_; |
| 237 | |
| 238 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86); |
| 239 | }; |
| 240 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 241 | class LoadStringSlowPathX86 : public SlowPathCode { |
| 242 | public: |
| 243 | explicit LoadStringSlowPathX86(HLoadString* instruction): SlowPathCode(instruction) {} |
| 244 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 245 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 246 | LocationSummary* locations = instruction_->GetLocations(); |
| 247 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 248 | |
| 249 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 250 | __ Bind(GetEntryLabel()); |
| 251 | SaveLiveRegisters(codegen, locations); |
| 252 | |
| 253 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 254 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 255 | __ movl(calling_convention.GetRegisterAt(0), Immediate(string_index.index_)); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 256 | x86_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 257 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 258 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 259 | RestoreLiveRegisters(codegen, locations); |
| 260 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 261 | __ jmp(GetExitLabel()); |
| 262 | } |
| 263 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 264 | const char* GetDescription() const override { return "LoadStringSlowPathX86"; } |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 265 | |
| 266 | private: |
| 267 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86); |
| 268 | }; |
| 269 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 270 | class LoadClassSlowPathX86 : public SlowPathCode { |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 271 | public: |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 272 | LoadClassSlowPathX86(HLoadClass* cls, HInstruction* at) |
| 273 | : SlowPathCode(at), cls_(cls) { |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 274 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 275 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 276 | } |
| 277 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 278 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 279 | LocationSummary* locations = instruction_->GetLocations(); |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 280 | Location out = locations->Out(); |
| 281 | const uint32_t dex_pc = instruction_->GetDexPc(); |
| 282 | bool must_resolve_type = instruction_->IsLoadClass() && cls_->MustResolveTypeOnSlowPath(); |
| 283 | bool must_do_clinit = instruction_->IsClinitCheck() || cls_->MustGenerateClinitCheck(); |
| 284 | |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 285 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 286 | __ Bind(GetEntryLabel()); |
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 287 | SaveLiveRegisters(codegen, locations); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 288 | |
| 289 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 290 | if (must_resolve_type) { |
| 291 | DCHECK(IsSameDexFile(cls_->GetDexFile(), x86_codegen->GetGraph()->GetDexFile())); |
| 292 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 293 | __ movl(calling_convention.GetRegisterAt(0), Immediate(type_index.index_)); |
| Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 294 | if (cls_->NeedsAccessCheck()) { |
| 295 | CheckEntrypointTypes<kQuickResolveTypeAndVerifyAccess, void*, uint32_t>(); |
| 296 | x86_codegen->InvokeRuntime(kQuickResolveTypeAndVerifyAccess, instruction_, dex_pc, this); |
| 297 | } else { |
| 298 | CheckEntrypointTypes<kQuickResolveType, void*, uint32_t>(); |
| 299 | x86_codegen->InvokeRuntime(kQuickResolveType, instruction_, dex_pc, this); |
| 300 | } |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 301 | // If we also must_do_clinit, the resolved type is now in the correct register. |
| 302 | } else { |
| 303 | DCHECK(must_do_clinit); |
| 304 | Location source = instruction_->IsLoadClass() ? out : locations->InAt(0); |
| 305 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), source); |
| 306 | } |
| 307 | if (must_do_clinit) { |
| 308 | x86_codegen->InvokeRuntime(kQuickInitializeStaticStorage, instruction_, dex_pc, this); |
| 309 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, mirror::Class*>(); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 310 | } |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 311 | |
| 312 | // Move the class to the desired location. |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 313 | if (out.IsValid()) { |
| 314 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 315 | x86_codegen->Move32(out, Location::RegisterLocation(EAX)); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 316 | } |
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 317 | RestoreLiveRegisters(codegen, locations); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 318 | __ jmp(GetExitLabel()); |
| 319 | } |
| 320 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 321 | const char* GetDescription() const override { return "LoadClassSlowPathX86"; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 322 | |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 323 | private: |
| 324 | // The class this slow path will load. |
| 325 | HLoadClass* const cls_; |
| 326 | |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 327 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86); |
| 328 | }; |
| 329 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 330 | class TypeCheckSlowPathX86 : public SlowPathCode { |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 331 | public: |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 332 | TypeCheckSlowPathX86(HInstruction* instruction, bool is_fatal) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 333 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 334 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 335 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 336 | LocationSummary* locations = instruction_->GetLocations(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 337 | DCHECK(instruction_->IsCheckCast() |
| 338 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 339 | |
| 340 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 341 | __ Bind(GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 342 | |
| Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 343 | if (kPoisonHeapReferences && |
| 344 | instruction_->IsCheckCast() && |
| 345 | instruction_->AsCheckCast()->GetTypeCheckKind() == TypeCheckKind::kInterfaceCheck) { |
| 346 | // First, unpoison the `cls` reference that was poisoned for direct memory comparison. |
| 347 | __ UnpoisonHeapReference(locations->InAt(1).AsRegister<Register>()); |
| 348 | } |
| 349 | |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 350 | if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 351 | SaveLiveRegisters(codegen, locations); |
| 352 | } |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 353 | |
| 354 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 355 | // move resolver. |
| 356 | InvokeRuntimeCallingConvention calling_convention; |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 357 | x86_codegen->EmitParallelMoves(locations->InAt(0), |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 358 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 359 | DataType::Type::kReference, |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 360 | locations->InAt(1), |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 361 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 362 | DataType::Type::kReference); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 363 | if (instruction_->IsInstanceOf()) { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 364 | x86_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 365 | instruction_, |
| 366 | instruction_->GetDexPc(), |
| 367 | this); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 368 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 369 | } else { |
| 370 | DCHECK(instruction_->IsCheckCast()); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 371 | x86_codegen->InvokeRuntime(kQuickCheckInstanceOf, |
| 372 | instruction_, |
| 373 | instruction_->GetDexPc(), |
| 374 | this); |
| 375 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 376 | } |
| 377 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 378 | if (!is_fatal_) { |
| 379 | if (instruction_->IsInstanceOf()) { |
| 380 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 381 | } |
| 382 | RestoreLiveRegisters(codegen, locations); |
| Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 383 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 384 | __ jmp(GetExitLabel()); |
| 385 | } |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 386 | } |
| 387 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 388 | const char* GetDescription() const override { return "TypeCheckSlowPathX86"; } |
| 389 | bool IsFatal() const override { return is_fatal_; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 390 | |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 391 | private: |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 392 | const bool is_fatal_; |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 393 | |
| 394 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86); |
| 395 | }; |
| 396 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 397 | class DeoptimizationSlowPathX86 : public SlowPathCode { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 398 | public: |
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 399 | explicit DeoptimizationSlowPathX86(HDeoptimize* instruction) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 400 | : SlowPathCode(instruction) {} |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 401 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 402 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 403 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 404 | __ Bind(GetEntryLabel()); |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 405 | LocationSummary* locations = instruction_->GetLocations(); |
| 406 | SaveLiveRegisters(codegen, locations); |
| 407 | InvokeRuntimeCallingConvention calling_convention; |
| 408 | x86_codegen->Load32BitValue( |
| 409 | calling_convention.GetRegisterAt(0), |
| 410 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 411 | x86_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 412 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 413 | } |
| 414 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 415 | const char* GetDescription() const override { return "DeoptimizationSlowPathX86"; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 416 | |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 417 | private: |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 418 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86); |
| 419 | }; |
| 420 | |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 421 | class ArraySetSlowPathX86 : public SlowPathCode { |
| 422 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 423 | explicit ArraySetSlowPathX86(HInstruction* instruction) : SlowPathCode(instruction) {} |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 424 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 425 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 426 | LocationSummary* locations = instruction_->GetLocations(); |
| 427 | __ Bind(GetEntryLabel()); |
| 428 | SaveLiveRegisters(codegen, locations); |
| 429 | |
| 430 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 431 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 432 | parallel_move.AddMove( |
| 433 | locations->InAt(0), |
| 434 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 435 | DataType::Type::kReference, |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 436 | nullptr); |
| 437 | parallel_move.AddMove( |
| 438 | locations->InAt(1), |
| 439 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 440 | DataType::Type::kInt32, |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 441 | nullptr); |
| 442 | parallel_move.AddMove( |
| 443 | locations->InAt(2), |
| 444 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 445 | DataType::Type::kReference, |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 446 | nullptr); |
| 447 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 448 | |
| 449 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 450 | x86_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 451 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 452 | RestoreLiveRegisters(codegen, locations); |
| 453 | __ jmp(GetExitLabel()); |
| 454 | } |
| 455 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 456 | const char* GetDescription() const override { return "ArraySetSlowPathX86"; } |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 457 | |
| 458 | private: |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 459 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86); |
| 460 | }; |
| 461 | |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 462 | // Slow path marking an object reference `ref` during a read |
| 463 | // barrier. The field `obj.field` in the object `obj` holding this |
| 464 | // reference does not get updated by this slow path after marking (see |
| 465 | // ReadBarrierMarkAndUpdateFieldSlowPathX86 below for that). |
| 466 | // |
| 467 | // This means that after the execution of this slow path, `ref` will |
| 468 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 469 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 470 | // probably still be a from-space reference (unless it gets updated by |
| 471 | // another thread, or if another thread installed another object |
| 472 | // reference (different from `ref`) in `obj.field`). |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 473 | class ReadBarrierMarkSlowPathX86 : public SlowPathCode { |
| 474 | public: |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 475 | ReadBarrierMarkSlowPathX86(HInstruction* instruction, |
| 476 | Location ref, |
| 477 | bool unpoison_ref_before_marking) |
| 478 | : SlowPathCode(instruction), |
| 479 | ref_(ref), |
| 480 | unpoison_ref_before_marking_(unpoison_ref_before_marking) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 481 | DCHECK(kEmitCompilerReadBarrier); |
| 482 | } |
| 483 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 484 | const char* GetDescription() const override { return "ReadBarrierMarkSlowPathX86"; } |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 485 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 486 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 487 | LocationSummary* locations = instruction_->GetLocations(); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 488 | Register ref_reg = ref_.AsRegister<Register>(); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 489 | DCHECK(locations->CanCall()); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 490 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 491 | DCHECK(instruction_->IsInstanceFieldGet() || |
| Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 492 | instruction_->IsPredicatedInstanceFieldGet() || |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 493 | instruction_->IsStaticFieldGet() || |
| 494 | instruction_->IsArrayGet() || |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 495 | instruction_->IsArraySet() || |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 496 | instruction_->IsLoadClass() || |
| 497 | instruction_->IsLoadString() || |
| 498 | instruction_->IsInstanceOf() || |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 499 | instruction_->IsCheckCast() || |
| Andra Danciu | 1ca6f32 | 2020-08-12 08:58:07 +0000 | [diff] [blame] | 500 | (instruction_->IsInvoke() && instruction_->GetLocations()->Intrinsified())) |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 501 | << "Unexpected instruction in read barrier marking slow path: " |
| 502 | << instruction_->DebugName(); |
| 503 | |
| 504 | __ Bind(GetEntryLabel()); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 505 | if (unpoison_ref_before_marking_) { |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 506 | // Object* ref = ref_addr->AsMirrorPtr() |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 507 | __ MaybeUnpoisonHeapReference(ref_reg); |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 508 | } |
| Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 509 | // No need to save live registers; it's taken care of by the |
| 510 | // entrypoint. Also, there is no need to update the stack mask, |
| 511 | // as this runtime call will not trigger a garbage collection. |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 512 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 513 | DCHECK_NE(ref_reg, ESP); |
| 514 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 515 | // "Compact" slow path, saving two moves. |
| 516 | // |
| 517 | // Instead of using the standard runtime calling convention (input |
| 518 | // and output in EAX): |
| 519 | // |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 520 | // EAX <- ref |
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 521 | // EAX <- ReadBarrierMark(EAX) |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 522 | // ref <- EAX |
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 523 | // |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 524 | // we just use rX (the register containing `ref`) as input and output |
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 525 | // of a dedicated entrypoint: |
| 526 | // |
| 527 | // rX <- ReadBarrierMarkRegX(rX) |
| 528 | // |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 529 | int32_t entry_point_offset = Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(ref_reg); |
| Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 530 | // This runtime call does not require a stack map. |
| 531 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 532 | __ jmp(GetExitLabel()); |
| 533 | } |
| 534 | |
| 535 | private: |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 536 | // The location (register) of the marked object reference. |
| 537 | const Location ref_; |
| 538 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 539 | const bool unpoison_ref_before_marking_; |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 540 | |
| 541 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86); |
| 542 | }; |
| 543 | |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 544 | // Slow path marking an object reference `ref` during a read barrier, |
| 545 | // and if needed, atomically updating the field `obj.field` in the |
| 546 | // object `obj` holding this reference after marking (contrary to |
| 547 | // ReadBarrierMarkSlowPathX86 above, which never tries to update |
| 548 | // `obj.field`). |
| 549 | // |
| 550 | // This means that after the execution of this slow path, both `ref` |
| 551 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 552 | // hold the same to-space reference (unless another thread installed |
| 553 | // another object reference (different from `ref`) in `obj.field`). |
| 554 | class ReadBarrierMarkAndUpdateFieldSlowPathX86 : public SlowPathCode { |
| 555 | public: |
| 556 | ReadBarrierMarkAndUpdateFieldSlowPathX86(HInstruction* instruction, |
| 557 | Location ref, |
| 558 | Register obj, |
| 559 | const Address& field_addr, |
| 560 | bool unpoison_ref_before_marking, |
| 561 | Register temp) |
| 562 | : SlowPathCode(instruction), |
| 563 | ref_(ref), |
| 564 | obj_(obj), |
| 565 | field_addr_(field_addr), |
| 566 | unpoison_ref_before_marking_(unpoison_ref_before_marking), |
| 567 | temp_(temp) { |
| 568 | DCHECK(kEmitCompilerReadBarrier); |
| 569 | } |
| 570 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 571 | const char* GetDescription() const override { return "ReadBarrierMarkAndUpdateFieldSlowPathX86"; } |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 572 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 573 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 574 | LocationSummary* locations = instruction_->GetLocations(); |
| 575 | Register ref_reg = ref_.AsRegister<Register>(); |
| 576 | DCHECK(locations->CanCall()); |
| 577 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 578 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| Andra Danciu | 5e13d45 | 2020-09-08 14:35:09 +0000 | [diff] [blame] | 579 | DCHECK((instruction_->IsInvoke() && instruction_->GetLocations()->Intrinsified())) |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 580 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 581 | << instruction_->DebugName(); |
| 582 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| Andra Danciu | 52d2c0c | 2020-09-15 14:27:21 +0000 | [diff] [blame] | 583 | Intrinsics intrinsic = instruction_->AsInvoke()->GetIntrinsic(); |
| 584 | static constexpr auto kVarHandleCAS = mirror::VarHandle::AccessModeTemplate::kCompareAndSet; |
| Andra Danciu | 9dfb1a9 | 2020-09-22 13:27:18 +0000 | [diff] [blame] | 585 | static constexpr auto kVarHandleGetAndSet = |
| 586 | mirror::VarHandle::AccessModeTemplate::kGetAndUpdate; |
| Andra Danciu | 370948e | 2020-09-23 08:07:25 +0000 | [diff] [blame] | 587 | static constexpr auto kVarHandleCAX = |
| 588 | mirror::VarHandle::AccessModeTemplate::kCompareAndExchange; |
| Andra Danciu | 52d2c0c | 2020-09-15 14:27:21 +0000 | [diff] [blame] | 589 | DCHECK(intrinsic == Intrinsics::kUnsafeCASObject || |
| Sorin Basca | 2f01e8e | 2021-06-18 06:44:07 +0000 | [diff] [blame] | 590 | intrinsic == Intrinsics::kJdkUnsafeCASObject || |
| Andra Danciu | 9dfb1a9 | 2020-09-22 13:27:18 +0000 | [diff] [blame] | 591 | mirror::VarHandle::GetAccessModeTemplateByIntrinsic(intrinsic) == kVarHandleCAS || |
| Andra Danciu | 370948e | 2020-09-23 08:07:25 +0000 | [diff] [blame] | 592 | mirror::VarHandle::GetAccessModeTemplateByIntrinsic(intrinsic) == kVarHandleGetAndSet || |
| 593 | mirror::VarHandle::GetAccessModeTemplateByIntrinsic(intrinsic) == kVarHandleCAX); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 594 | |
| 595 | __ Bind(GetEntryLabel()); |
| 596 | if (unpoison_ref_before_marking_) { |
| 597 | // Object* ref = ref_addr->AsMirrorPtr() |
| 598 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 599 | } |
| 600 | |
| 601 | // Save the old (unpoisoned) reference. |
| 602 | __ movl(temp_, ref_reg); |
| 603 | |
| 604 | // No need to save live registers; it's taken care of by the |
| 605 | // entrypoint. Also, there is no need to update the stack mask, |
| 606 | // as this runtime call will not trigger a garbage collection. |
| 607 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 608 | DCHECK_NE(ref_reg, ESP); |
| 609 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
| 610 | // "Compact" slow path, saving two moves. |
| 611 | // |
| 612 | // Instead of using the standard runtime calling convention (input |
| 613 | // and output in EAX): |
| 614 | // |
| 615 | // EAX <- ref |
| 616 | // EAX <- ReadBarrierMark(EAX) |
| 617 | // ref <- EAX |
| 618 | // |
| 619 | // we just use rX (the register containing `ref`) as input and output |
| 620 | // of a dedicated entrypoint: |
| 621 | // |
| 622 | // rX <- ReadBarrierMarkRegX(rX) |
| 623 | // |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 624 | int32_t entry_point_offset = Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(ref_reg); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 625 | // This runtime call does not require a stack map. |
| 626 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 627 | |
| 628 | // If the new reference is different from the old reference, |
| 629 | // update the field in the holder (`*field_addr`). |
| 630 | // |
| 631 | // Note that this field could also hold a different object, if |
| 632 | // another thread had concurrently changed it. In that case, the |
| 633 | // LOCK CMPXCHGL instruction in the compare-and-set (CAS) |
| 634 | // operation below would abort the CAS, leaving the field as-is. |
| 635 | NearLabel done; |
| 636 | __ cmpl(temp_, ref_reg); |
| 637 | __ j(kEqual, &done); |
| 638 | |
| 639 | // Update the the holder's field atomically. This may fail if |
| 640 | // mutator updates before us, but it's OK. This is achieved |
| 641 | // using a strong compare-and-set (CAS) operation with relaxed |
| 642 | // memory synchronization ordering, where the expected value is |
| 643 | // the old reference and the desired value is the new reference. |
| 644 | // This operation is implemented with a 32-bit LOCK CMPXLCHG |
| 645 | // instruction, which requires the expected value (the old |
| 646 | // reference) to be in EAX. Save EAX beforehand, and move the |
| 647 | // expected value (stored in `temp_`) into EAX. |
| 648 | __ pushl(EAX); |
| 649 | __ movl(EAX, temp_); |
| 650 | |
| 651 | // Convenience aliases. |
| 652 | Register base = obj_; |
| 653 | Register expected = EAX; |
| 654 | Register value = ref_reg; |
| 655 | |
| 656 | bool base_equals_value = (base == value); |
| 657 | if (kPoisonHeapReferences) { |
| 658 | if (base_equals_value) { |
| 659 | // If `base` and `value` are the same register location, move |
| 660 | // `value` to a temporary register. This way, poisoning |
| 661 | // `value` won't invalidate `base`. |
| 662 | value = temp_; |
| 663 | __ movl(value, base); |
| 664 | } |
| 665 | |
| 666 | // Check that the register allocator did not assign the location |
| 667 | // of `expected` (EAX) to `value` nor to `base`, so that heap |
| 668 | // poisoning (when enabled) works as intended below. |
| 669 | // - If `value` were equal to `expected`, both references would |
| 670 | // be poisoned twice, meaning they would not be poisoned at |
| 671 | // all, as heap poisoning uses address negation. |
| 672 | // - If `base` were equal to `expected`, poisoning `expected` |
| 673 | // would invalidate `base`. |
| 674 | DCHECK_NE(value, expected); |
| 675 | DCHECK_NE(base, expected); |
| 676 | |
| 677 | __ PoisonHeapReference(expected); |
| 678 | __ PoisonHeapReference(value); |
| 679 | } |
| 680 | |
| 681 | __ LockCmpxchgl(field_addr_, value); |
| 682 | |
| 683 | // If heap poisoning is enabled, we need to unpoison the values |
| 684 | // that were poisoned earlier. |
| 685 | if (kPoisonHeapReferences) { |
| 686 | if (base_equals_value) { |
| 687 | // `value` has been moved to a temporary register, no need |
| 688 | // to unpoison it. |
| 689 | } else { |
| 690 | __ UnpoisonHeapReference(value); |
| 691 | } |
| 692 | // No need to unpoison `expected` (EAX), as it is be overwritten below. |
| 693 | } |
| 694 | |
| 695 | // Restore EAX. |
| 696 | __ popl(EAX); |
| 697 | |
| 698 | __ Bind(&done); |
| 699 | __ jmp(GetExitLabel()); |
| 700 | } |
| 701 | |
| 702 | private: |
| 703 | // The location (register) of the marked object reference. |
| 704 | const Location ref_; |
| 705 | // The register containing the object holding the marked object reference field. |
| 706 | const Register obj_; |
| 707 | // The address of the marked reference field. The base of this address must be `obj_`. |
| 708 | const Address field_addr_; |
| 709 | |
| 710 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 711 | const bool unpoison_ref_before_marking_; |
| 712 | |
| 713 | const Register temp_; |
| 714 | |
| 715 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathX86); |
| 716 | }; |
| 717 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 718 | // Slow path generating a read barrier for a heap reference. |
| 719 | class ReadBarrierForHeapReferenceSlowPathX86 : public SlowPathCode { |
| 720 | public: |
| 721 | ReadBarrierForHeapReferenceSlowPathX86(HInstruction* instruction, |
| 722 | Location out, |
| 723 | Location ref, |
| 724 | Location obj, |
| 725 | uint32_t offset, |
| 726 | Location index) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 727 | : SlowPathCode(instruction), |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 728 | out_(out), |
| 729 | ref_(ref), |
| 730 | obj_(obj), |
| 731 | offset_(offset), |
| 732 | index_(index) { |
| 733 | DCHECK(kEmitCompilerReadBarrier); |
| 734 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 735 | // has been overwritten by (or after) the heap object reference load |
| 736 | // to be instrumented, e.g.: |
| 737 | // |
| 738 | // __ movl(out, Address(out, offset)); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 739 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 740 | // |
| 741 | // In that case, we have lost the information about the original |
| 742 | // object, and the emitted read barrier cannot work properly. |
| 743 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 744 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 745 | } |
| 746 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 747 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 748 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 749 | LocationSummary* locations = instruction_->GetLocations(); |
| 750 | Register reg_out = out_.AsRegister<Register>(); |
| 751 | DCHECK(locations->CanCall()); |
| 752 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 753 | DCHECK(instruction_->IsInstanceFieldGet() || |
| Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 754 | instruction_->IsPredicatedInstanceFieldGet() || |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 755 | instruction_->IsStaticFieldGet() || |
| 756 | instruction_->IsArrayGet() || |
| 757 | instruction_->IsInstanceOf() || |
| 758 | instruction_->IsCheckCast() || |
| Vladimir Marko | 94d2c81 | 2020-11-05 10:04:45 +0000 | [diff] [blame] | 759 | (instruction_->IsInvoke() && instruction_->GetLocations()->Intrinsified())) |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 760 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 761 | << instruction_->DebugName(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 762 | |
| 763 | __ Bind(GetEntryLabel()); |
| 764 | SaveLiveRegisters(codegen, locations); |
| 765 | |
| 766 | // We may have to change the index's value, but as `index_` is a |
| 767 | // constant member (like other "inputs" of this slow path), |
| 768 | // introduce a copy of it, `index`. |
| 769 | Location index = index_; |
| 770 | if (index_.IsValid()) { |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 771 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 772 | if (instruction_->IsArrayGet()) { |
| 773 | // Compute the actual memory offset and store it in `index`. |
| 774 | Register index_reg = index_.AsRegister<Register>(); |
| 775 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 776 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 777 | // We are about to change the value of `index_reg` (see the |
| 778 | // calls to art::x86::X86Assembler::shll and |
| 779 | // art::x86::X86Assembler::AddImmediate below), but it has |
| 780 | // not been saved by the previous call to |
| 781 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 782 | // callee-save register -- |
| 783 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 784 | // callee-save registers, as it has been designed with the |
| 785 | // assumption that callee-save registers are supposed to be |
| 786 | // handled by the called function. So, as a callee-save |
| 787 | // register, `index_reg` _would_ eventually be saved onto |
| 788 | // the stack, but it would be too late: we would have |
| 789 | // changed its value earlier. Therefore, we manually save |
| 790 | // it here into another freely available register, |
| 791 | // `free_reg`, chosen of course among the caller-save |
| 792 | // registers (as a callee-save `free_reg` register would |
| 793 | // exhibit the same problem). |
| 794 | // |
| 795 | // Note we could have requested a temporary register from |
| 796 | // the register allocator instead; but we prefer not to, as |
| 797 | // this is a slow path, and we know we can find a |
| 798 | // caller-save register that is available. |
| 799 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 800 | __ movl(free_reg, index_reg); |
| 801 | index_reg = free_reg; |
| 802 | index = Location::RegisterLocation(index_reg); |
| 803 | } else { |
| 804 | // The initial register stored in `index_` has already been |
| 805 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 806 | // (as it is not a callee-save register), so we can freely |
| 807 | // use it. |
| 808 | } |
| 809 | // Shifting the index value contained in `index_reg` by the scale |
| 810 | // factor (2) cannot overflow in practice, as the runtime is |
| 811 | // unable to allocate object arrays with a size larger than |
| 812 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 813 | __ shll(index_reg, Immediate(TIMES_4)); |
| 814 | static_assert( |
| 815 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 816 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 817 | __ AddImmediate(index_reg, Immediate(offset_)); |
| 818 | } else { |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 819 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 820 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 821 | // (as in the case of ArrayGet), as it is actually an offset |
| 822 | // to an object field within an object. |
| 823 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 824 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 825 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| Sorin Basca | 2f01e8e | 2021-06-18 06:44:07 +0000 | [diff] [blame] | 826 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile) || |
| 827 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kJdkUnsafeGetObject) || |
| Sorin Basca | 4a4696a | 2021-10-09 07:14:40 +0000 | [diff] [blame] | 828 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kJdkUnsafeGetObjectVolatile) || |
| 829 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kJdkUnsafeGetObjectAcquire)) |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 830 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 831 | DCHECK_EQ(offset_, 0U); |
| 832 | DCHECK(index_.IsRegisterPair()); |
| 833 | // UnsafeGet's offset location is a register pair, the low |
| 834 | // part contains the correct offset. |
| 835 | index = index_.ToLow(); |
| 836 | } |
| 837 | } |
| 838 | |
| 839 | // We're moving two or three locations to locations that could |
| 840 | // overlap, so we need a parallel move resolver. |
| 841 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 842 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 843 | parallel_move.AddMove(ref_, |
| 844 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 845 | DataType::Type::kReference, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 846 | nullptr); |
| 847 | parallel_move.AddMove(obj_, |
| 848 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 849 | DataType::Type::kReference, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 850 | nullptr); |
| 851 | if (index.IsValid()) { |
| 852 | parallel_move.AddMove(index, |
| 853 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 854 | DataType::Type::kInt32, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 855 | nullptr); |
| 856 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 857 | } else { |
| 858 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 859 | __ movl(calling_convention.GetRegisterAt(2), Immediate(offset_)); |
| 860 | } |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 861 | x86_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 862 | CheckEntrypointTypes< |
| 863 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 864 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 865 | |
| 866 | RestoreLiveRegisters(codegen, locations); |
| 867 | __ jmp(GetExitLabel()); |
| 868 | } |
| 869 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 870 | const char* GetDescription() const override { return "ReadBarrierForHeapReferenceSlowPathX86"; } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 871 | |
| 872 | private: |
| 873 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 874 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 875 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 876 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 877 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 878 | return static_cast<Register>(i); |
| 879 | } |
| 880 | } |
| 881 | // We shall never fail to find a free caller-save register, as |
| 882 | // there are more than two core caller-save registers on x86 |
| 883 | // (meaning it is possible to find one which is different from |
| 884 | // `ref` and `obj`). |
| 885 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 886 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 887 | UNREACHABLE(); |
| 888 | } |
| 889 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 890 | const Location out_; |
| 891 | const Location ref_; |
| 892 | const Location obj_; |
| 893 | const uint32_t offset_; |
| 894 | // An additional location containing an index to an array. |
| 895 | // Only used for HArrayGet and the UnsafeGetObject & |
| 896 | // UnsafeGetObjectVolatile intrinsics. |
| 897 | const Location index_; |
| 898 | |
| 899 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86); |
| 900 | }; |
| 901 | |
| 902 | // Slow path generating a read barrier for a GC root. |
| 903 | class ReadBarrierForRootSlowPathX86 : public SlowPathCode { |
| 904 | public: |
| 905 | ReadBarrierForRootSlowPathX86(HInstruction* instruction, Location out, Location root) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 906 | : SlowPathCode(instruction), out_(out), root_(root) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 907 | DCHECK(kEmitCompilerReadBarrier); |
| 908 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 909 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 910 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 911 | LocationSummary* locations = instruction_->GetLocations(); |
| 912 | Register reg_out = out_.AsRegister<Register>(); |
| 913 | DCHECK(locations->CanCall()); |
| 914 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 915 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 916 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 917 | << instruction_->DebugName(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 918 | |
| 919 | __ Bind(GetEntryLabel()); |
| 920 | SaveLiveRegisters(codegen, locations); |
| 921 | |
| 922 | InvokeRuntimeCallingConvention calling_convention; |
| 923 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 924 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 925 | x86_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 926 | instruction_, |
| 927 | instruction_->GetDexPc(), |
| 928 | this); |
| 929 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 930 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 931 | |
| 932 | RestoreLiveRegisters(codegen, locations); |
| 933 | __ jmp(GetExitLabel()); |
| 934 | } |
| 935 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 936 | const char* GetDescription() const override { return "ReadBarrierForRootSlowPathX86"; } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 937 | |
| 938 | private: |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 939 | const Location out_; |
| 940 | const Location root_; |
| 941 | |
| 942 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86); |
| 943 | }; |
| 944 | |
| Mythri Alle | 2d4feeb | 2021-10-13 15:39:37 +0000 | [diff] [blame^] | 945 | class MethodEntryExitHooksSlowPathX86 : public SlowPathCode { |
| 946 | public: |
| 947 | explicit MethodEntryExitHooksSlowPathX86(HInstruction* instruction) : SlowPathCode(instruction) {} |
| 948 | |
| 949 | void EmitNativeCode(CodeGenerator* codegen) override { |
| 950 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 951 | LocationSummary* locations = instruction_->GetLocations(); |
| 952 | QuickEntrypointEnum entry_point = |
| 953 | (instruction_->IsMethodEntryHook()) ? kQuickMethodEntryHook : kQuickMethodExitHook; |
| 954 | __ Bind(GetEntryLabel()); |
| 955 | SaveLiveRegisters(codegen, locations); |
| 956 | x86_codegen->InvokeRuntime(entry_point, instruction_, instruction_->GetDexPc(), this); |
| 957 | RestoreLiveRegisters(codegen, locations); |
| 958 | __ jmp(GetExitLabel()); |
| 959 | } |
| 960 | |
| 961 | const char* GetDescription() const override { |
| 962 | return "MethodEntryExitHooksSlowPath"; |
| 963 | } |
| 964 | |
| 965 | private: |
| 966 | DISALLOW_COPY_AND_ASSIGN(MethodEntryExitHooksSlowPathX86); |
| 967 | }; |
| 968 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 969 | #undef __ |
| Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 970 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 971 | #define __ down_cast<X86Assembler*>(GetAssembler())-> // NOLINT |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 972 | |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 973 | inline Condition X86Condition(IfCondition cond) { |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 974 | switch (cond) { |
| 975 | case kCondEQ: return kEqual; |
| 976 | case kCondNE: return kNotEqual; |
| 977 | case kCondLT: return kLess; |
| 978 | case kCondLE: return kLessEqual; |
| 979 | case kCondGT: return kGreater; |
| 980 | case kCondGE: return kGreaterEqual; |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 981 | case kCondB: return kBelow; |
| 982 | case kCondBE: return kBelowEqual; |
| 983 | case kCondA: return kAbove; |
| 984 | case kCondAE: return kAboveEqual; |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 985 | } |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 986 | LOG(FATAL) << "Unreachable"; |
| 987 | UNREACHABLE(); |
| 988 | } |
| 989 | |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 990 | // Maps signed condition to unsigned condition and FP condition to x86 name. |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 991 | inline Condition X86UnsignedOrFPCondition(IfCondition cond) { |
| 992 | switch (cond) { |
| 993 | case kCondEQ: return kEqual; |
| 994 | case kCondNE: return kNotEqual; |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 995 | // Signed to unsigned, and FP to x86 name. |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 996 | case kCondLT: return kBelow; |
| 997 | case kCondLE: return kBelowEqual; |
| 998 | case kCondGT: return kAbove; |
| 999 | case kCondGE: return kAboveEqual; |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1000 | // Unsigned remain unchanged. |
| 1001 | case kCondB: return kBelow; |
| 1002 | case kCondBE: return kBelowEqual; |
| 1003 | case kCondA: return kAbove; |
| 1004 | case kCondAE: return kAboveEqual; |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1005 | } |
| 1006 | LOG(FATAL) << "Unreachable"; |
| 1007 | UNREACHABLE(); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1008 | } |
| 1009 | |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1010 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1011 | stream << Register(reg); |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1015 | stream << XmmRegister(reg); |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1016 | } |
| 1017 | |
| Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 1018 | const X86InstructionSetFeatures& CodeGeneratorX86::GetInstructionSetFeatures() const { |
| 1019 | return *GetCompilerOptions().GetInstructionSetFeatures()->AsX86InstructionSetFeatures(); |
| 1020 | } |
| 1021 | |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1022 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1023 | __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); |
| 1024 | return kX86WordSize; |
| Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1025 | } |
| 1026 | |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1027 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1028 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); |
| 1029 | return kX86WordSize; |
| Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1030 | } |
| 1031 | |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1032 | size_t CodeGeneratorX86::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1033 | if (GetGraph()->HasSIMD()) { |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 1034 | __ movups(Address(ESP, stack_index), XmmRegister(reg_id)); |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1035 | } else { |
| 1036 | __ movsd(Address(ESP, stack_index), XmmRegister(reg_id)); |
| 1037 | } |
| Artem Serov | 6a0b657 | 2019-07-26 20:38:37 +0100 | [diff] [blame] | 1038 | return GetSlowPathFPWidth(); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1039 | } |
| 1040 | |
| 1041 | size_t CodeGeneratorX86::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1042 | if (GetGraph()->HasSIMD()) { |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 1043 | __ movups(XmmRegister(reg_id), Address(ESP, stack_index)); |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1044 | } else { |
| 1045 | __ movsd(XmmRegister(reg_id), Address(ESP, stack_index)); |
| 1046 | } |
| Artem Serov | 6a0b657 | 2019-07-26 20:38:37 +0100 | [diff] [blame] | 1047 | return GetSlowPathFPWidth(); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1048 | } |
| 1049 | |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1050 | void CodeGeneratorX86::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1051 | HInstruction* instruction, |
| 1052 | uint32_t dex_pc, |
| 1053 | SlowPathCode* slow_path) { |
| Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1054 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1055 | GenerateInvokeRuntime(GetThreadOffset<kX86PointerSize>(entrypoint).Int32Value()); |
| 1056 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1057 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1058 | } |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 1059 | } |
| 1060 | |
| Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1061 | void CodeGeneratorX86::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1062 | HInstruction* instruction, |
| 1063 | SlowPathCode* slow_path) { |
| 1064 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1065 | GenerateInvokeRuntime(entry_point_offset); |
| 1066 | } |
| 1067 | |
| 1068 | void CodeGeneratorX86::GenerateInvokeRuntime(int32_t entry_point_offset) { |
| Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1069 | __ fs()->call(Address::Absolute(entry_point_offset)); |
| 1070 | } |
| 1071 | |
| Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1072 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1073 | const CompilerOptions& compiler_options, |
| 1074 | OptimizingCompilerStats* stats) |
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1075 | : CodeGenerator(graph, |
| 1076 | kNumberOfCpuRegisters, |
| 1077 | kNumberOfXmmRegisters, |
| 1078 | kNumberOfRegisterPairs, |
| 1079 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1080 | arraysize(kCoreCalleeSaves)) |
| 1081 | | (1 << kFakeReturnRegister), |
| Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1082 | 0, |
| 1083 | compiler_options, |
| 1084 | stats), |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1085 | block_labels_(nullptr), |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1086 | location_builder_(graph, this), |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1087 | instruction_visitor_(graph, this), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1088 | move_resolver_(graph->GetAllocator(), this), |
| 1089 | assembler_(graph->GetAllocator()), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1090 | boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1091 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1092 | boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1093 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 1094 | public_type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1095 | package_type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1096 | boot_image_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1097 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 1098 | boot_image_jni_entrypoint_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 1099 | boot_image_other_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1100 | jit_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1101 | jit_class_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1102 | constant_area_start_(-1), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1103 | fixups_to_jump_tables_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1104 | method_address_offset_(std::less<uint32_t>(), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1105 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1106 | // Use a fake return address register to mimic Quick. |
| 1107 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1108 | } |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1109 | |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1110 | void CodeGeneratorX86::SetupBlockedRegisters() const { |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1111 | // Stack register is always reserved. |
| Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1112 | blocked_core_registers_[ESP] = true; |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1113 | } |
| 1114 | |
| Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1115 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1116 | : InstructionCodeGenerator(graph, codegen), |
| Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1117 | assembler_(codegen->GetAssembler()), |
| 1118 | codegen_(codegen) {} |
| 1119 | |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1120 | static dwarf::Reg DWARFReg(Register reg) { |
| David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1121 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1122 | } |
| 1123 | |
| Mythri Alle | 2d4feeb | 2021-10-13 15:39:37 +0000 | [diff] [blame^] | 1124 | void SetInForReturnValue(HInstruction* ret, LocationSummary* locations) { |
| 1125 | switch (ret->InputAt(0)->GetType()) { |
| 1126 | case DataType::Type::kReference: |
| 1127 | case DataType::Type::kBool: |
| 1128 | case DataType::Type::kUint8: |
| 1129 | case DataType::Type::kInt8: |
| 1130 | case DataType::Type::kUint16: |
| 1131 | case DataType::Type::kInt16: |
| 1132 | case DataType::Type::kInt32: |
| 1133 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 1134 | break; |
| 1135 | |
| 1136 | case DataType::Type::kInt64: |
| 1137 | locations->SetInAt(0, Location::RegisterPairLocation(EAX, EDX)); |
| 1138 | break; |
| 1139 | |
| 1140 | case DataType::Type::kFloat32: |
| 1141 | case DataType::Type::kFloat64: |
| 1142 | locations->SetInAt(0, Location::FpuRegisterLocation(XMM0)); |
| 1143 | break; |
| 1144 | |
| 1145 | case DataType::Type::kVoid: |
| 1146 | locations->SetInAt(0, Location::NoLocation()); |
| 1147 | break; |
| 1148 | |
| 1149 | default: |
| 1150 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
| 1151 | } |
| 1152 | } |
| 1153 | |
| 1154 | void LocationsBuilderX86::VisitMethodExitHook(HMethodExitHook* method_hook) { |
| 1155 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
| 1156 | LocationSummary(method_hook, LocationSummary::kCallOnSlowPath); |
| 1157 | SetInForReturnValue(method_hook, locations); |
| 1158 | } |
| 1159 | |
| 1160 | void InstructionCodeGeneratorX86::GenerateMethodEntryExitHook(HInstruction* instruction) { |
| 1161 | SlowPathCode* slow_path = |
| 1162 | new (codegen_->GetScopedAllocator()) MethodEntryExitHooksSlowPathX86(instruction); |
| 1163 | codegen_->AddSlowPath(slow_path); |
| 1164 | |
| 1165 | uint64_t address = reinterpret_cast64<uint64_t>(Runtime::Current()->GetInstrumentation()); |
| 1166 | int offset = instrumentation::Instrumentation::NeedsEntryExitHooksOffset().Int32Value(); |
| 1167 | __ cmpw(Address::Absolute(address + offset), Immediate(0)); |
| 1168 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 1169 | __ Bind(slow_path->GetExitLabel()); |
| 1170 | } |
| 1171 | |
| 1172 | void InstructionCodeGeneratorX86::VisitMethodExitHook(HMethodExitHook* instruction) { |
| 1173 | DCHECK(codegen_->GetCompilerOptions().IsJitCompiler() && GetGraph()->IsDebuggable()); |
| 1174 | DCHECK(codegen_->RequiresCurrentMethod()); |
| 1175 | GenerateMethodEntryExitHook(instruction); |
| 1176 | } |
| 1177 | |
| 1178 | void LocationsBuilderX86::VisitMethodEntryHook(HMethodEntryHook* method_hook) { |
| 1179 | new (GetGraph()->GetAllocator()) LocationSummary(method_hook, LocationSummary::kCallOnSlowPath); |
| 1180 | } |
| 1181 | |
| 1182 | void InstructionCodeGeneratorX86::VisitMethodEntryHook(HMethodEntryHook* instruction) { |
| 1183 | DCHECK(codegen_->GetCompilerOptions().IsJitCompiler() && GetGraph()->IsDebuggable()); |
| 1184 | DCHECK(codegen_->RequiresCurrentMethod()); |
| 1185 | GenerateMethodEntryExitHook(instruction); |
| 1186 | } |
| 1187 | |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1188 | void CodeGeneratorX86::MaybeIncrementHotness(bool is_frame_entry) { |
| 1189 | if (GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 1190 | Register reg = EAX; |
| 1191 | if (is_frame_entry) { |
| 1192 | reg = kMethodRegisterArgument; |
| 1193 | } else { |
| 1194 | __ pushl(EAX); |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1195 | __ cfi().AdjustCFAOffset(4); |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1196 | __ movl(EAX, Address(ESP, kX86WordSize)); |
| 1197 | } |
| 1198 | NearLabel overflow; |
| 1199 | __ cmpw(Address(reg, ArtMethod::HotnessCountOffset().Int32Value()), |
| Vladimir Marko | ce131fe | 2021-10-26 20:03:35 +0000 | [diff] [blame] | 1200 | Immediate(ArtMethod::MaxCounter())); |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1201 | __ j(kEqual, &overflow); |
| Vladimir Marko | ce131fe | 2021-10-26 20:03:35 +0000 | [diff] [blame] | 1202 | __ addw(Address(reg, ArtMethod::HotnessCountOffset().Int32Value()), |
| 1203 | Immediate(1)); |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1204 | __ Bind(&overflow); |
| 1205 | if (!is_frame_entry) { |
| 1206 | __ popl(EAX); |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1207 | __ cfi().AdjustCFAOffset(-4); |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1208 | } |
| 1209 | } |
| 1210 | |
| 1211 | if (GetGraph()->IsCompilingBaseline() && !Runtime::Current()->IsAotCompiler()) { |
| Nicolas Geoffray | 095dc46 | 2020-08-17 16:40:28 +0100 | [diff] [blame] | 1212 | ScopedProfilingInfoUse spiu( |
| 1213 | Runtime::Current()->GetJit(), GetGraph()->GetArtMethod(), Thread::Current()); |
| 1214 | ProfilingInfo* info = spiu.GetProfilingInfo(); |
| Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1215 | if (info != nullptr) { |
| 1216 | uint32_t address = reinterpret_cast32<uint32_t>(info); |
| 1217 | NearLabel done; |
| 1218 | if (HasEmptyFrame()) { |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1219 | CHECK(is_frame_entry); |
| Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1220 | // Alignment |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1221 | IncreaseFrame(8); |
| Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1222 | // We need a temporary. The stub also expects the method at bottom of stack. |
| 1223 | __ pushl(EAX); |
| 1224 | __ cfi().AdjustCFAOffset(4); |
| 1225 | __ movl(EAX, Immediate(address)); |
| 1226 | __ addw(Address(EAX, ProfilingInfo::BaselineHotnessCountOffset().Int32Value()), |
| 1227 | Immediate(1)); |
| Nicolas Geoffray | 8b8d93d | 2020-09-17 14:30:01 +0100 | [diff] [blame] | 1228 | __ andw(Address(EAX, ProfilingInfo::BaselineHotnessCountOffset().Int32Value()), |
| 1229 | Immediate(interpreter::kTieredHotnessMask)); |
| 1230 | __ j(kNotZero, &done); |
| Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1231 | GenerateInvokeRuntime( |
| 1232 | GetThreadOffset<kX86PointerSize>(kQuickCompileOptimized).Int32Value()); |
| 1233 | __ Bind(&done); |
| 1234 | // We don't strictly require to restore EAX, but this makes the generated |
| 1235 | // code easier to reason about. |
| 1236 | __ popl(EAX); |
| 1237 | __ cfi().AdjustCFAOffset(-4); |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1238 | DecreaseFrame(8); |
| Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1239 | } else { |
| 1240 | if (!RequiresCurrentMethod()) { |
| 1241 | CHECK(is_frame_entry); |
| 1242 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
| 1243 | } |
| 1244 | // We need a temporary. |
| 1245 | __ pushl(EAX); |
| 1246 | __ cfi().AdjustCFAOffset(4); |
| 1247 | __ movl(EAX, Immediate(address)); |
| 1248 | __ addw(Address(EAX, ProfilingInfo::BaselineHotnessCountOffset().Int32Value()), |
| 1249 | Immediate(1)); |
| 1250 | __ popl(EAX); // Put stack as expected before exiting or calling stub. |
| 1251 | __ cfi().AdjustCFAOffset(-4); |
| 1252 | __ j(kCarryClear, &done); |
| 1253 | GenerateInvokeRuntime( |
| 1254 | GetThreadOffset<kX86PointerSize>(kQuickCompileOptimized).Int32Value()); |
| 1255 | __ Bind(&done); |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1256 | } |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1257 | } |
| 1258 | } |
| 1259 | } |
| 1260 | |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1261 | void CodeGeneratorX86::GenerateFrameEntry() { |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1262 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
| Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1263 | __ Bind(&frame_entry_label_); |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1264 | bool skip_overflow_check = |
| 1265 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1266 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
| Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 1267 | |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1268 | if (!skip_overflow_check) { |
| Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1269 | size_t reserved_bytes = GetStackOverflowReservedBytes(InstructionSet::kX86); |
| 1270 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(reserved_bytes))); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1271 | RecordPcInfo(nullptr, 0); |
| Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 1272 | } |
| 1273 | |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1274 | if (!HasEmptyFrame()) { |
| 1275 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 1276 | Register reg = kCoreCalleeSaves[i]; |
| 1277 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1278 | __ pushl(reg); |
| 1279 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 1280 | __ cfi().RelOffset(DWARFReg(reg), 0); |
| 1281 | } |
| 1282 | } |
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1283 | |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1284 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1285 | IncreaseFrame(adjust); |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1286 | // Save the current method if we need it. Note that we do not |
| 1287 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1288 | // in the SSA graph. |
| 1289 | if (RequiresCurrentMethod()) { |
| 1290 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
| 1291 | } |
| 1292 | |
| 1293 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1294 | // Initialize should_deoptimize flag to 0. |
| 1295 | __ movl(Address(ESP, GetStackOffsetOfShouldDeoptimizeFlag()), Immediate(0)); |
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1296 | } |
| 1297 | } |
| 1298 | |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1299 | MaybeIncrementHotness(/* is_frame_entry= */ true); |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1300 | } |
| 1301 | |
| 1302 | void CodeGeneratorX86::GenerateFrameExit() { |
| David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1303 | __ cfi().RememberState(); |
| 1304 | if (!HasEmptyFrame()) { |
| 1305 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1306 | DecreaseFrame(adjust); |
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1307 | |
| David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1308 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1309 | Register reg = kCoreCalleeSaves[i]; |
| 1310 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1311 | __ popl(reg); |
| 1312 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 1313 | __ cfi().Restore(DWARFReg(reg)); |
| 1314 | } |
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1315 | } |
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1316 | } |
| David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1317 | __ ret(); |
| 1318 | __ cfi().RestoreState(); |
| 1319 | __ cfi().DefCFAOffset(GetFrameSize()); |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1320 | } |
| 1321 | |
| Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1322 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 1323 | __ Bind(GetLabelOf(block)); |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1324 | } |
| 1325 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1326 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(DataType::Type type) const { |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1327 | switch (type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1328 | case DataType::Type::kReference: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1329 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1330 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1331 | case DataType::Type::kInt8: |
| 1332 | case DataType::Type::kUint16: |
| 1333 | case DataType::Type::kInt16: |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1334 | case DataType::Type::kUint32: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1335 | case DataType::Type::kInt32: |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1336 | return Location::RegisterLocation(EAX); |
| 1337 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1338 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1339 | case DataType::Type::kInt64: |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1340 | return Location::RegisterPairLocation(EAX, EDX); |
| 1341 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1342 | case DataType::Type::kVoid: |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1343 | return Location::NoLocation(); |
| 1344 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1345 | case DataType::Type::kFloat64: |
| 1346 | case DataType::Type::kFloat32: |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1347 | return Location::FpuRegisterLocation(XMM0); |
| 1348 | } |
| Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1349 | |
| 1350 | UNREACHABLE(); |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1351 | } |
| 1352 | |
| 1353 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 1354 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1355 | } |
| 1356 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1357 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(DataType::Type type) { |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1358 | switch (type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1359 | case DataType::Type::kReference: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1360 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1361 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1362 | case DataType::Type::kInt8: |
| 1363 | case DataType::Type::kUint16: |
| 1364 | case DataType::Type::kInt16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1365 | case DataType::Type::kInt32: { |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1366 | uint32_t index = gp_index_++; |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1367 | stack_index_++; |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1368 | if (index < calling_convention.GetNumberOfRegisters()) { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1369 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1370 | } else { |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1371 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1372 | } |
| Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1373 | } |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1374 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1375 | case DataType::Type::kInt64: { |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1376 | uint32_t index = gp_index_; |
| 1377 | gp_index_ += 2; |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1378 | stack_index_ += 2; |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1379 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1380 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 1381 | calling_convention.GetRegisterPairAt(index)); |
| 1382 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1383 | } else { |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1384 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1385 | } |
| 1386 | } |
| 1387 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1388 | case DataType::Type::kFloat32: { |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1389 | uint32_t index = float_index_++; |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1390 | stack_index_++; |
| 1391 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1392 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1393 | } else { |
| 1394 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1395 | } |
| 1396 | } |
| 1397 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1398 | case DataType::Type::kFloat64: { |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1399 | uint32_t index = float_index_++; |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1400 | stack_index_ += 2; |
| 1401 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1402 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1403 | } else { |
| 1404 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1405 | } |
| 1406 | } |
| 1407 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1408 | case DataType::Type::kUint32: |
| 1409 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1410 | case DataType::Type::kVoid: |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1411 | LOG(FATAL) << "Unexpected parameter type " << type; |
| Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 1412 | UNREACHABLE(); |
| Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1413 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1414 | return Location::NoLocation(); |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1415 | } |
| Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1416 | |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 1417 | Location CriticalNativeCallingConventionVisitorX86::GetNextLocation(DataType::Type type) { |
| 1418 | DCHECK_NE(type, DataType::Type::kReference); |
| 1419 | |
| 1420 | Location location; |
| 1421 | if (DataType::Is64BitType(type)) { |
| 1422 | location = Location::DoubleStackSlot(stack_offset_); |
| 1423 | stack_offset_ += 2 * kFramePointerSize; |
| 1424 | } else { |
| 1425 | location = Location::StackSlot(stack_offset_); |
| 1426 | stack_offset_ += kFramePointerSize; |
| 1427 | } |
| 1428 | if (for_register_allocation_) { |
| 1429 | location = Location::Any(); |
| 1430 | } |
| 1431 | return location; |
| 1432 | } |
| 1433 | |
| 1434 | Location CriticalNativeCallingConventionVisitorX86::GetReturnLocation(DataType::Type type) const { |
| 1435 | // We perform conversion to the managed ABI return register after the call if needed. |
| 1436 | InvokeDexCallingConventionVisitorX86 dex_calling_convention; |
| 1437 | return dex_calling_convention.GetReturnLocation(type); |
| 1438 | } |
| 1439 | |
| 1440 | Location CriticalNativeCallingConventionVisitorX86::GetMethodLocation() const { |
| 1441 | // Pass the method in the hidden argument EAX. |
| 1442 | return Location::RegisterLocation(EAX); |
| 1443 | } |
| 1444 | |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1445 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 1446 | if (source.Equals(destination)) { |
| 1447 | return; |
| 1448 | } |
| 1449 | if (destination.IsRegister()) { |
| 1450 | if (source.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1451 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1452 | } else if (source.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1453 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
| Andra Danciu | 5e13d45 | 2020-09-08 14:35:09 +0000 | [diff] [blame] | 1454 | } else if (source.IsConstant()) { |
| 1455 | int32_t value = GetInt32ValueOf(source.GetConstant()); |
| 1456 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1457 | } else { |
| 1458 | DCHECK(source.IsStackSlot()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1459 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1460 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1461 | } else if (destination.IsFpuRegister()) { |
| 1462 | if (source.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1463 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1464 | } else if (source.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1465 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1466 | } else { |
| 1467 | DCHECK(source.IsStackSlot()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1468 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1469 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1470 | } else { |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1471 | DCHECK(destination.IsStackSlot()) << destination; |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1472 | if (source.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1473 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1474 | } else if (source.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1475 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1476 | } else if (source.IsConstant()) { |
| 1477 | HConstant* constant = source.GetConstant(); |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1478 | int32_t value = GetInt32ValueOf(constant); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1479 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1480 | } else { |
| 1481 | DCHECK(source.IsStackSlot()); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1482 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 1483 | __ popl(Address(ESP, destination.GetStackIndex())); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1484 | } |
| 1485 | } |
| 1486 | } |
| 1487 | |
| 1488 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 1489 | if (source.Equals(destination)) { |
| 1490 | return; |
| 1491 | } |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1492 | if (destination.IsRegisterPair()) { |
| 1493 | if (source.IsRegisterPair()) { |
| Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1494 | EmitParallelMoves( |
| 1495 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1496 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1497 | DataType::Type::kInt32, |
| Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1498 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
| Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1499 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1500 | DataType::Type::kInt32); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1501 | } else if (source.IsFpuRegister()) { |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1502 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 1503 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 1504 | __ psrlq(src_reg, Immediate(32)); |
| 1505 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1506 | } else { |
| Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1507 | // No conflict possible, so just do the moves. |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1508 | DCHECK(source.IsDoubleStackSlot()); |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1509 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 1510 | __ movl(destination.AsRegisterPairHigh<Register>(), |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1511 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 1512 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1513 | } else if (destination.IsFpuRegister()) { |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1514 | if (source.IsFpuRegister()) { |
| 1515 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 1516 | } else if (source.IsDoubleStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1517 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1518 | } else if (source.IsRegisterPair()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1519 | size_t elem_size = DataType::Size(DataType::Type::kInt32); |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1520 | // Push the 2 source registers to the stack. |
| 1521 | __ pushl(source.AsRegisterPairHigh<Register>()); |
| 1522 | __ cfi().AdjustCFAOffset(elem_size); |
| 1523 | __ pushl(source.AsRegisterPairLow<Register>()); |
| 1524 | __ cfi().AdjustCFAOffset(elem_size); |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1525 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 1526 | // And remove the temporary stack space we allocated. |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1527 | DecreaseFrame(2 * elem_size); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1528 | } else { |
| 1529 | LOG(FATAL) << "Unimplemented"; |
| 1530 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1531 | } else { |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1532 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1533 | if (source.IsRegisterPair()) { |
| Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1534 | // No conflict possible, so just do the moves. |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1535 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1536 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1537 | source.AsRegisterPairHigh<Register>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1538 | } else if (source.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1539 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1540 | } else if (source.IsConstant()) { |
| 1541 | HConstant* constant = source.GetConstant(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1542 | DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant()); |
| 1543 | int64_t value = GetInt64ValueOf(constant); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1544 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1545 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
| 1546 | Immediate(High32Bits(value))); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1547 | } else { |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1548 | DCHECK(source.IsDoubleStackSlot()) << source; |
| Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1549 | EmitParallelMoves( |
| 1550 | Location::StackSlot(source.GetStackIndex()), |
| 1551 | Location::StackSlot(destination.GetStackIndex()), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1552 | DataType::Type::kInt32, |
| Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1553 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
| Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1554 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1555 | DataType::Type::kInt32); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1556 | } |
| 1557 | } |
| 1558 | } |
| 1559 | |
| Andra Danciu | 1ca6f32 | 2020-08-12 08:58:07 +0000 | [diff] [blame] | 1560 | static Address CreateAddress(Register base, |
| 1561 | Register index = Register::kNoRegister, |
| 1562 | ScaleFactor scale = TIMES_1, |
| 1563 | int32_t disp = 0) { |
| 1564 | if (index == Register::kNoRegister) { |
| 1565 | return Address(base, disp); |
| 1566 | } |
| 1567 | |
| 1568 | return Address(base, index, scale, disp); |
| 1569 | } |
| 1570 | |
| Andra Danciu | d0f71f2 | 2020-09-17 09:00:15 +0000 | [diff] [blame] | 1571 | void CodeGeneratorX86::LoadFromMemoryNoBarrier(DataType::Type dst_type, |
| 1572 | Location dst, |
| 1573 | Address src, |
| Ulya Trafimovich | 322eced | 2021-06-02 15:39:36 +0100 | [diff] [blame] | 1574 | HInstruction* instr, |
| Andra Danciu | d0f71f2 | 2020-09-17 09:00:15 +0000 | [diff] [blame] | 1575 | XmmRegister temp, |
| 1576 | bool is_atomic_load) { |
| Andra Danciu | 1ca6f32 | 2020-08-12 08:58:07 +0000 | [diff] [blame] | 1577 | switch (dst_type) { |
| 1578 | case DataType::Type::kBool: |
| 1579 | case DataType::Type::kUint8: |
| 1580 | __ movzxb(dst.AsRegister<Register>(), src); |
| 1581 | break; |
| 1582 | case DataType::Type::kInt8: |
| 1583 | __ movsxb(dst.AsRegister<Register>(), src); |
| 1584 | break; |
| 1585 | case DataType::Type::kInt16: |
| 1586 | __ movsxw(dst.AsRegister<Register>(), src); |
| 1587 | break; |
| 1588 | case DataType::Type::kUint16: |
| 1589 | __ movzxw(dst.AsRegister<Register>(), src); |
| 1590 | break; |
| 1591 | case DataType::Type::kInt32: |
| Andra Danciu | 1ca6f32 | 2020-08-12 08:58:07 +0000 | [diff] [blame] | 1592 | __ movl(dst.AsRegister<Register>(), src); |
| 1593 | break; |
| Andra Danciu | d0f71f2 | 2020-09-17 09:00:15 +0000 | [diff] [blame] | 1594 | case DataType::Type::kInt64: { |
| 1595 | if (is_atomic_load) { |
| 1596 | __ movsd(temp, src); |
| Ulya Trafimovich | 322eced | 2021-06-02 15:39:36 +0100 | [diff] [blame] | 1597 | if (instr != nullptr) { |
| 1598 | MaybeRecordImplicitNullCheck(instr); |
| 1599 | } |
| Andra Danciu | d0f71f2 | 2020-09-17 09:00:15 +0000 | [diff] [blame] | 1600 | __ movd(dst.AsRegisterPairLow<Register>(), temp); |
| 1601 | __ psrlq(temp, Immediate(32)); |
| 1602 | __ movd(dst.AsRegisterPairHigh<Register>(), temp); |
| 1603 | } else { |
| 1604 | DCHECK_NE(src.GetBaseRegister(), dst.AsRegisterPairLow<Register>()); |
| Ulya Trafimovich | 893e2ed | 2021-06-10 16:18:12 +0100 | [diff] [blame] | 1605 | Address src_high = Address::displace(src, kX86WordSize); |
| Andra Danciu | d0f71f2 | 2020-09-17 09:00:15 +0000 | [diff] [blame] | 1606 | __ movl(dst.AsRegisterPairLow<Register>(), src); |
| Ulya Trafimovich | 322eced | 2021-06-02 15:39:36 +0100 | [diff] [blame] | 1607 | if (instr != nullptr) { |
| 1608 | MaybeRecordImplicitNullCheck(instr); |
| 1609 | } |
| Andra Danciu | d0f71f2 | 2020-09-17 09:00:15 +0000 | [diff] [blame] | 1610 | __ movl(dst.AsRegisterPairHigh<Register>(), src_high); |
| 1611 | } |
| Andra Danciu | 1ca6f32 | 2020-08-12 08:58:07 +0000 | [diff] [blame] | 1612 | break; |
| 1613 | } |
| 1614 | case DataType::Type::kFloat32: |
| 1615 | __ movss(dst.AsFpuRegister<XmmRegister>(), src); |
| 1616 | break; |
| 1617 | case DataType::Type::kFloat64: |
| 1618 | __ movsd(dst.AsFpuRegister<XmmRegister>(), src); |
| 1619 | break; |
| Andra Danciu | 1ca6f32 | 2020-08-12 08:58:07 +0000 | [diff] [blame] | 1620 | case DataType::Type::kReference: |
| Ulya Trafimovich | 322eced | 2021-06-02 15:39:36 +0100 | [diff] [blame] | 1621 | DCHECK(!kEmitCompilerReadBarrier); |
| Andra Danciu | d0f71f2 | 2020-09-17 09:00:15 +0000 | [diff] [blame] | 1622 | __ movl(dst.AsRegister<Register>(), src); |
| 1623 | __ MaybeUnpoisonHeapReference(dst.AsRegister<Register>()); |
| 1624 | break; |
| 1625 | default: |
| Andra Danciu | 1ca6f32 | 2020-08-12 08:58:07 +0000 | [diff] [blame] | 1626 | LOG(FATAL) << "Unreachable type " << dst_type; |
| 1627 | } |
| Ulya Trafimovich | 322eced | 2021-06-02 15:39:36 +0100 | [diff] [blame] | 1628 | if (instr != nullptr && dst_type != DataType::Type::kInt64) { |
| 1629 | // kInt64 needs special handling that is done in the above switch. |
| 1630 | MaybeRecordImplicitNullCheck(instr); |
| 1631 | } |
| Andra Danciu | 1ca6f32 | 2020-08-12 08:58:07 +0000 | [diff] [blame] | 1632 | } |
| 1633 | |
| Andra Danciu | 73c3180 | 2020-09-01 13:17:05 +0000 | [diff] [blame] | 1634 | void CodeGeneratorX86::MoveToMemory(DataType::Type src_type, |
| 1635 | Location src, |
| 1636 | Register dst_base, |
| 1637 | Register dst_index, |
| 1638 | ScaleFactor dst_scale, |
| 1639 | int32_t dst_disp) { |
| 1640 | DCHECK(dst_base != Register::kNoRegister); |
| 1641 | Address dst = CreateAddress(dst_base, dst_index, dst_scale, dst_disp); |
| 1642 | |
| 1643 | switch (src_type) { |
| 1644 | case DataType::Type::kBool: |
| 1645 | case DataType::Type::kUint8: |
| 1646 | case DataType::Type::kInt8: { |
| 1647 | if (src.IsConstant()) { |
| 1648 | __ movb(dst, Immediate(CodeGenerator::GetInt8ValueOf(src.GetConstant()))); |
| 1649 | } else { |
| 1650 | __ movb(dst, src.AsRegister<ByteRegister>()); |
| 1651 | } |
| 1652 | break; |
| 1653 | } |
| 1654 | case DataType::Type::kUint16: |
| 1655 | case DataType::Type::kInt16: { |
| 1656 | if (src.IsConstant()) { |
| 1657 | __ movw(dst, Immediate(CodeGenerator::GetInt16ValueOf(src.GetConstant()))); |
| 1658 | } else { |
| 1659 | __ movw(dst, src.AsRegister<Register>()); |
| 1660 | } |
| 1661 | break; |
| 1662 | } |
| 1663 | case DataType::Type::kUint32: |
| 1664 | case DataType::Type::kInt32: { |
| 1665 | if (src.IsConstant()) { |
| 1666 | int32_t v = CodeGenerator::GetInt32ValueOf(src.GetConstant()); |
| 1667 | __ movl(dst, Immediate(v)); |
| 1668 | } else { |
| 1669 | __ movl(dst, src.AsRegister<Register>()); |
| 1670 | } |
| 1671 | break; |
| 1672 | } |
| 1673 | case DataType::Type::kUint64: |
| 1674 | case DataType::Type::kInt64: { |
| 1675 | Address dst_next_4_bytes = CreateAddress(dst_base, dst_index, dst_scale, dst_disp + 4); |
| 1676 | if (src.IsConstant()) { |
| 1677 | int64_t v = CodeGenerator::GetInt64ValueOf(src.GetConstant()); |
| 1678 | __ movl(dst, Immediate(Low32Bits(v))); |
| 1679 | __ movl(dst_next_4_bytes, Immediate(High32Bits(v))); |
| 1680 | } else { |
| 1681 | __ movl(dst, src.AsRegisterPairLow<Register>()); |
| 1682 | __ movl(dst_next_4_bytes, src.AsRegisterPairHigh<Register>()); |
| 1683 | } |
| 1684 | break; |
| 1685 | } |
| 1686 | case DataType::Type::kFloat32: { |
| 1687 | if (src.IsConstant()) { |
| 1688 | int32_t v = CodeGenerator::GetInt32ValueOf(src.GetConstant()); |
| 1689 | __ movl(dst, Immediate(v)); |
| 1690 | } else { |
| 1691 | __ movss(dst, src.AsFpuRegister<XmmRegister>()); |
| 1692 | } |
| 1693 | break; |
| 1694 | } |
| 1695 | case DataType::Type::kFloat64: { |
| 1696 | Address dst_next_4_bytes = CreateAddress(dst_base, dst_index, dst_scale, dst_disp + 4); |
| 1697 | if (src.IsConstant()) { |
| 1698 | int64_t v = CodeGenerator::GetInt64ValueOf(src.GetConstant()); |
| 1699 | __ movl(dst, Immediate(Low32Bits(v))); |
| 1700 | __ movl(dst_next_4_bytes, Immediate(High32Bits(v))); |
| 1701 | } else { |
| 1702 | __ movsd(dst, src.AsFpuRegister<XmmRegister>()); |
| 1703 | } |
| 1704 | break; |
| 1705 | } |
| 1706 | case DataType::Type::kVoid: |
| 1707 | case DataType::Type::kReference: |
| 1708 | LOG(FATAL) << "Unreachable type " << src_type; |
| 1709 | } |
| 1710 | } |
| 1711 | |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1712 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { |
| 1713 | DCHECK(location.IsRegister()); |
| 1714 | __ movl(location.AsRegister<Register>(), Immediate(value)); |
| 1715 | } |
| 1716 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1717 | void CodeGeneratorX86::MoveLocation(Location dst, Location src, DataType::Type dst_type) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1718 | HParallelMove move(GetGraph()->GetAllocator()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1719 | if (dst_type == DataType::Type::kInt64 && !src.IsConstant() && !src.IsFpuRegister()) { |
| 1720 | move.AddMove(src.ToLow(), dst.ToLow(), DataType::Type::kInt32, nullptr); |
| 1721 | move.AddMove(src.ToHigh(), dst.ToHigh(), DataType::Type::kInt32, nullptr); |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1722 | } else { |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1723 | move.AddMove(src, dst, dst_type, nullptr); |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1724 | } |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1725 | GetMoveResolver()->EmitNativeCode(&move); |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1726 | } |
| 1727 | |
| 1728 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1729 | if (location.IsRegister()) { |
| 1730 | locations->AddTemp(location); |
| 1731 | } else if (location.IsRegisterPair()) { |
| 1732 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1733 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1734 | } else { |
| 1735 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1736 | } |
| 1737 | } |
| 1738 | |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1739 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
| Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 1740 | if (successor->IsExitBlock()) { |
| 1741 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 1742 | return; // no code needed |
| 1743 | } |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1744 | |
| 1745 | HBasicBlock* block = got->GetBlock(); |
| 1746 | HInstruction* previous = got->GetPrevious(); |
| 1747 | |
| 1748 | HLoopInformation* info = block->GetLoopInformation(); |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1749 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1750 | codegen_->MaybeIncrementHotness(/* is_frame_entry= */ false); |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1751 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1752 | return; |
| 1753 | } |
| 1754 | |
| 1755 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1756 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1757 | } |
| 1758 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1759 | __ jmp(codegen_->GetLabelOf(successor)); |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1760 | } |
| 1761 | } |
| 1762 | |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1763 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 1764 | got->SetLocations(nullptr); |
| 1765 | } |
| 1766 | |
| 1767 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 1768 | HandleGoto(got, got->GetSuccessor()); |
| 1769 | } |
| 1770 | |
| 1771 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1772 | try_boundary->SetLocations(nullptr); |
| 1773 | } |
| 1774 | |
| 1775 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1776 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1777 | if (!successor->IsExitBlock()) { |
| 1778 | HandleGoto(try_boundary, successor); |
| 1779 | } |
| 1780 | } |
| 1781 | |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1782 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1783 | exit->SetLocations(nullptr); |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1784 | } |
| 1785 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1786 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1787 | } |
| 1788 | |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1789 | template<class LabelType> |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1790 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1791 | LabelType* true_label, |
| 1792 | LabelType* false_label) { |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1793 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1794 | __ j(kUnordered, true_label); |
| 1795 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1796 | __ j(kUnordered, false_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1797 | } |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1798 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1799 | } |
| 1800 | |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1801 | template<class LabelType> |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1802 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1803 | LabelType* true_label, |
| 1804 | LabelType* false_label) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1805 | LocationSummary* locations = cond->GetLocations(); |
| 1806 | Location left = locations->InAt(0); |
| 1807 | Location right = locations->InAt(1); |
| 1808 | IfCondition if_cond = cond->GetCondition(); |
| 1809 | |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1810 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1811 | Register left_low = left.AsRegisterPairLow<Register>(); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1812 | IfCondition true_high_cond = if_cond; |
| 1813 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1814 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); // unsigned on lower part |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1815 | |
| 1816 | // Set the conditions for the test, remembering that == needs to be |
| 1817 | // decided using the low words. |
| 1818 | switch (if_cond) { |
| 1819 | case kCondEQ: |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1820 | case kCondNE: |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1821 | // Nothing to do. |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1822 | break; |
| 1823 | case kCondLT: |
| 1824 | false_high_cond = kCondGT; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1825 | break; |
| 1826 | case kCondLE: |
| 1827 | true_high_cond = kCondLT; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1828 | break; |
| 1829 | case kCondGT: |
| 1830 | false_high_cond = kCondLT; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1831 | break; |
| 1832 | case kCondGE: |
| 1833 | true_high_cond = kCondGT; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1834 | break; |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1835 | case kCondB: |
| 1836 | false_high_cond = kCondA; |
| 1837 | break; |
| 1838 | case kCondBE: |
| 1839 | true_high_cond = kCondB; |
| 1840 | break; |
| 1841 | case kCondA: |
| 1842 | false_high_cond = kCondB; |
| 1843 | break; |
| 1844 | case kCondAE: |
| 1845 | true_high_cond = kCondA; |
| 1846 | break; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1847 | } |
| 1848 | |
| 1849 | if (right.IsConstant()) { |
| 1850 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1851 | int32_t val_high = High32Bits(value); |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1852 | int32_t val_low = Low32Bits(value); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1853 | |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1854 | codegen_->Compare32BitValue(left_high, val_high); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1855 | if (if_cond == kCondNE) { |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1856 | __ j(X86Condition(true_high_cond), true_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1857 | } else if (if_cond == kCondEQ) { |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1858 | __ j(X86Condition(false_high_cond), false_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1859 | } else { |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1860 | __ j(X86Condition(true_high_cond), true_label); |
| 1861 | __ j(X86Condition(false_high_cond), false_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1862 | } |
| 1863 | // Must be equal high, so compare the lows. |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1864 | codegen_->Compare32BitValue(left_low, val_low); |
| Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1865 | } else if (right.IsRegisterPair()) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1866 | Register right_high = right.AsRegisterPairHigh<Register>(); |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1867 | Register right_low = right.AsRegisterPairLow<Register>(); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1868 | |
| 1869 | __ cmpl(left_high, right_high); |
| 1870 | if (if_cond == kCondNE) { |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1871 | __ j(X86Condition(true_high_cond), true_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1872 | } else if (if_cond == kCondEQ) { |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1873 | __ j(X86Condition(false_high_cond), false_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1874 | } else { |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1875 | __ j(X86Condition(true_high_cond), true_label); |
| 1876 | __ j(X86Condition(false_high_cond), false_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1877 | } |
| 1878 | // Must be equal high, so compare the lows. |
| 1879 | __ cmpl(left_low, right_low); |
| Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1880 | } else { |
| 1881 | DCHECK(right.IsDoubleStackSlot()); |
| 1882 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
| 1883 | if (if_cond == kCondNE) { |
| 1884 | __ j(X86Condition(true_high_cond), true_label); |
| 1885 | } else if (if_cond == kCondEQ) { |
| 1886 | __ j(X86Condition(false_high_cond), false_label); |
| 1887 | } else { |
| 1888 | __ j(X86Condition(true_high_cond), true_label); |
| 1889 | __ j(X86Condition(false_high_cond), false_label); |
| 1890 | } |
| 1891 | // Must be equal high, so compare the lows. |
| 1892 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1893 | } |
| 1894 | // The last comparison might be unsigned. |
| 1895 | __ j(final_condition, true_label); |
| 1896 | } |
| 1897 | |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1898 | void InstructionCodeGeneratorX86::GenerateFPCompare(Location lhs, |
| 1899 | Location rhs, |
| 1900 | HInstruction* insn, |
| 1901 | bool is_double) { |
| 1902 | HX86LoadFromConstantTable* const_area = insn->InputAt(1)->AsX86LoadFromConstantTable(); |
| 1903 | if (is_double) { |
| 1904 | if (rhs.IsFpuRegister()) { |
| 1905 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1906 | } else if (const_area != nullptr) { |
| 1907 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1908 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), |
| 1909 | codegen_->LiteralDoubleAddress( |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1910 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 1911 | const_area->GetBaseMethodAddress(), |
| 1912 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1913 | } else { |
| 1914 | DCHECK(rhs.IsDoubleStackSlot()); |
| 1915 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1916 | } |
| 1917 | } else { |
| 1918 | if (rhs.IsFpuRegister()) { |
| 1919 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1920 | } else if (const_area != nullptr) { |
| 1921 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1922 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), |
| 1923 | codegen_->LiteralFloatAddress( |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1924 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 1925 | const_area->GetBaseMethodAddress(), |
| 1926 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1927 | } else { |
| 1928 | DCHECK(rhs.IsStackSlot()); |
| 1929 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1930 | } |
| 1931 | } |
| 1932 | } |
| 1933 | |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1934 | template<class LabelType> |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1935 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1936 | LabelType* true_target_in, |
| 1937 | LabelType* false_target_in) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1938 | // Generated branching requires both targets to be explicit. If either of the |
| 1939 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1940 | LabelType fallthrough_target; |
| 1941 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1942 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1943 | |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1944 | LocationSummary* locations = condition->GetLocations(); |
| 1945 | Location left = locations->InAt(0); |
| 1946 | Location right = locations->InAt(1); |
| 1947 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1948 | DataType::Type type = condition->InputAt(0)->GetType(); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1949 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1950 | case DataType::Type::kInt64: |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1951 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1952 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1953 | case DataType::Type::kFloat32: |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1954 | GenerateFPCompare(left, right, condition, false); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1955 | GenerateFPJumps(condition, true_target, false_target); |
| 1956 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1957 | case DataType::Type::kFloat64: |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1958 | GenerateFPCompare(left, right, condition, true); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1959 | GenerateFPJumps(condition, true_target, false_target); |
| 1960 | break; |
| 1961 | default: |
| 1962 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1963 | } |
| 1964 | |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1965 | if (false_target != &fallthrough_target) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1966 | __ jmp(false_target); |
| 1967 | } |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1968 | |
| 1969 | if (fallthrough_target.IsLinked()) { |
| 1970 | __ Bind(&fallthrough_target); |
| 1971 | } |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1972 | } |
| 1973 | |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1974 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1975 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1976 | // are set only strictly before `branch`. We can't use the eflags on long/FP |
| 1977 | // conditions if they are materialized due to the complex branching. |
| 1978 | return cond->IsCondition() && |
| 1979 | cond->GetNext() == branch && |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1980 | cond->InputAt(0)->GetType() != DataType::Type::kInt64 && |
| 1981 | !DataType::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1982 | } |
| 1983 | |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1984 | template<class LabelType> |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1985 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1986 | size_t condition_input_index, |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1987 | LabelType* true_target, |
| 1988 | LabelType* false_target) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1989 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1990 | |
| 1991 | if (true_target == nullptr && false_target == nullptr) { |
| 1992 | // Nothing to do. The code always falls through. |
| 1993 | return; |
| 1994 | } else if (cond->IsIntConstant()) { |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1995 | // Constant condition, statically compared against "true" (integer value 1). |
| 1996 | if (cond->AsIntConstant()->IsTrue()) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1997 | if (true_target != nullptr) { |
| 1998 | __ jmp(true_target); |
| Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1999 | } |
| Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2000 | } else { |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2001 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2002 | if (false_target != nullptr) { |
| 2003 | __ jmp(false_target); |
| 2004 | } |
| 2005 | } |
| 2006 | return; |
| 2007 | } |
| 2008 | |
| 2009 | // The following code generates these patterns: |
| 2010 | // (1) true_target == nullptr && false_target != nullptr |
| 2011 | // - opposite condition true => branch to false_target |
| 2012 | // (2) true_target != nullptr && false_target == nullptr |
| 2013 | // - condition true => branch to true_target |
| 2014 | // (3) true_target != nullptr && false_target != nullptr |
| 2015 | // - condition true => branch to true_target |
| 2016 | // - branch to false_target |
| 2017 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 2018 | if (AreEflagsSetFrom(cond, instruction)) { |
| 2019 | if (true_target == nullptr) { |
| 2020 | __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 2021 | } else { |
| 2022 | __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); |
| 2023 | } |
| 2024 | } else { |
| 2025 | // Materialized condition, compare against 0. |
| 2026 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 2027 | if (lhs.IsRegister()) { |
| 2028 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 2029 | } else { |
| 2030 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 2031 | } |
| 2032 | if (true_target == nullptr) { |
| 2033 | __ j(kEqual, false_target); |
| 2034 | } else { |
| 2035 | __ j(kNotEqual, true_target); |
| 2036 | } |
| Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2037 | } |
| 2038 | } else { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2039 | // Condition has not been materialized, use its inputs as the comparison and |
| 2040 | // its condition as the branch condition. |
| Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 2041 | HCondition* condition = cond->AsCondition(); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2042 | |
| 2043 | // If this is a long or FP comparison that has been folded into |
| 2044 | // the HCondition, generate the comparison directly. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2045 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 2046 | if (type == DataType::Type::kInt64 || DataType::IsFloatingPointType(type)) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2047 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 2048 | return; |
| 2049 | } |
| 2050 | |
| 2051 | Location lhs = condition->GetLocations()->InAt(0); |
| 2052 | Location rhs = condition->GetLocations()->InAt(1); |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2053 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition). |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 2054 | codegen_->GenerateIntCompare(lhs, rhs); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2055 | if (true_target == nullptr) { |
| 2056 | __ j(X86Condition(condition->GetOppositeCondition()), false_target); |
| 2057 | } else { |
| Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 2058 | __ j(X86Condition(condition->GetCondition()), true_target); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2059 | } |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2060 | } |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2061 | |
| 2062 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 2063 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 2064 | if (true_target != nullptr && false_target != nullptr) { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2065 | __ jmp(false_target); |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2066 | } |
| 2067 | } |
| 2068 | |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2069 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2070 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2071 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2072 | locations->SetInAt(0, Location::Any()); |
| 2073 | } |
| 2074 | } |
| 2075 | |
| 2076 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2077 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 2078 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 2079 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 2080 | nullptr : codegen_->GetLabelOf(true_successor); |
| 2081 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 2082 | nullptr : codegen_->GetLabelOf(false_successor); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2083 | GenerateTestAndBranch(if_instr, /* condition_input_index= */ 0, true_target, false_target); |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2084 | } |
| 2085 | |
| 2086 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2087 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2088 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 2089 | InvokeRuntimeCallingConvention calling_convention; |
| 2090 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 2091 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2092 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2093 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2094 | locations->SetInAt(0, Location::Any()); |
| 2095 | } |
| 2096 | } |
| 2097 | |
| 2098 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 2099 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86>(deoptimize); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2100 | GenerateTestAndBranch<Label>(deoptimize, |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2101 | /* condition_input_index= */ 0, |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2102 | slow_path->GetEntryLabel(), |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2103 | /* false_target= */ nullptr); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2104 | } |
| 2105 | |
| Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 2106 | void LocationsBuilderX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2107 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
| Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 2108 | LocationSummary(flag, LocationSummary::kNoCall); |
| 2109 | locations->SetOut(Location::RequiresRegister()); |
| 2110 | } |
| 2111 | |
| 2112 | void InstructionCodeGeneratorX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 2113 | __ movl(flag->GetLocations()->Out().AsRegister<Register>(), |
| 2114 | Address(ESP, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 2115 | } |
| 2116 | |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2117 | static bool SelectCanUseCMOV(HSelect* select) { |
| 2118 | // There are no conditional move instructions for XMMs. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2119 | if (DataType::IsFloatingPointType(select->GetType())) { |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2120 | return false; |
| 2121 | } |
| 2122 | |
| 2123 | // A FP condition doesn't generate the single CC that we need. |
| 2124 | // In 32 bit mode, a long condition doesn't generate a single CC either. |
| 2125 | HInstruction* condition = select->GetCondition(); |
| 2126 | if (condition->IsCondition()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2127 | DataType::Type compare_type = condition->InputAt(0)->GetType(); |
| 2128 | if (compare_type == DataType::Type::kInt64 || |
| 2129 | DataType::IsFloatingPointType(compare_type)) { |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2130 | return false; |
| 2131 | } |
| 2132 | } |
| 2133 | |
| 2134 | // We can generate a CMOV for this Select. |
| 2135 | return true; |
| 2136 | } |
| 2137 | |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2138 | void LocationsBuilderX86::VisitSelect(HSelect* select) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2139 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2140 | if (DataType::IsFloatingPointType(select->GetType())) { |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2141 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2142 | locations->SetInAt(1, Location::Any()); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2143 | } else { |
| 2144 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2145 | if (SelectCanUseCMOV(select)) { |
| 2146 | if (select->InputAt(1)->IsConstant()) { |
| 2147 | // Cmov can't handle a constant value. |
| 2148 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2149 | } else { |
| 2150 | locations->SetInAt(1, Location::Any()); |
| 2151 | } |
| 2152 | } else { |
| 2153 | locations->SetInAt(1, Location::Any()); |
| 2154 | } |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2155 | } |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2156 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 2157 | locations->SetInAt(2, Location::RequiresRegister()); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2158 | } |
| 2159 | locations->SetOut(Location::SameAsFirstInput()); |
| 2160 | } |
| 2161 | |
| 2162 | void InstructionCodeGeneratorX86::VisitSelect(HSelect* select) { |
| 2163 | LocationSummary* locations = select->GetLocations(); |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2164 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 2165 | if (SelectCanUseCMOV(select)) { |
| 2166 | // If both the condition and the source types are integer, we can generate |
| 2167 | // a CMOV to implement Select. |
| 2168 | |
| 2169 | HInstruction* select_condition = select->GetCondition(); |
| 2170 | Condition cond = kNotEqual; |
| 2171 | |
| 2172 | // Figure out how to test the 'condition'. |
| 2173 | if (select_condition->IsCondition()) { |
| 2174 | HCondition* condition = select_condition->AsCondition(); |
| 2175 | if (!condition->IsEmittedAtUseSite()) { |
| 2176 | // This was a previously materialized condition. |
| 2177 | // Can we use the existing condition code? |
| 2178 | if (AreEflagsSetFrom(condition, select)) { |
| 2179 | // Materialization was the previous instruction. Condition codes are right. |
| 2180 | cond = X86Condition(condition->GetCondition()); |
| 2181 | } else { |
| 2182 | // No, we have to recreate the condition code. |
| 2183 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 2184 | __ testl(cond_reg, cond_reg); |
| 2185 | } |
| 2186 | } else { |
| 2187 | // We can't handle FP or long here. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2188 | DCHECK_NE(condition->InputAt(0)->GetType(), DataType::Type::kInt64); |
| 2189 | DCHECK(!DataType::IsFloatingPointType(condition->InputAt(0)->GetType())); |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2190 | LocationSummary* cond_locations = condition->GetLocations(); |
| Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2191 | codegen_->GenerateIntCompare(cond_locations->InAt(0), cond_locations->InAt(1)); |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2192 | cond = X86Condition(condition->GetCondition()); |
| 2193 | } |
| 2194 | } else { |
| Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 2195 | // Must be a Boolean condition, which needs to be compared to 0. |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2196 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 2197 | __ testl(cond_reg, cond_reg); |
| 2198 | } |
| 2199 | |
| 2200 | // If the condition is true, overwrite the output, which already contains false. |
| 2201 | Location false_loc = locations->InAt(0); |
| 2202 | Location true_loc = locations->InAt(1); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2203 | if (select->GetType() == DataType::Type::kInt64) { |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2204 | // 64 bit conditional move. |
| 2205 | Register false_high = false_loc.AsRegisterPairHigh<Register>(); |
| 2206 | Register false_low = false_loc.AsRegisterPairLow<Register>(); |
| 2207 | if (true_loc.IsRegisterPair()) { |
| 2208 | __ cmovl(cond, false_high, true_loc.AsRegisterPairHigh<Register>()); |
| 2209 | __ cmovl(cond, false_low, true_loc.AsRegisterPairLow<Register>()); |
| 2210 | } else { |
| 2211 | __ cmovl(cond, false_high, Address(ESP, true_loc.GetHighStackIndex(kX86WordSize))); |
| 2212 | __ cmovl(cond, false_low, Address(ESP, true_loc.GetStackIndex())); |
| 2213 | } |
| 2214 | } else { |
| 2215 | // 32 bit conditional move. |
| 2216 | Register false_reg = false_loc.AsRegister<Register>(); |
| 2217 | if (true_loc.IsRegister()) { |
| 2218 | __ cmovl(cond, false_reg, true_loc.AsRegister<Register>()); |
| 2219 | } else { |
| 2220 | __ cmovl(cond, false_reg, Address(ESP, true_loc.GetStackIndex())); |
| 2221 | } |
| 2222 | } |
| 2223 | } else { |
| 2224 | NearLabel false_target; |
| 2225 | GenerateTestAndBranch<NearLabel>( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2226 | select, /* condition_input_index= */ 2, /* true_target= */ nullptr, &false_target); |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2227 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 2228 | __ Bind(&false_target); |
| 2229 | } |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2230 | } |
| 2231 | |
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 2232 | void LocationsBuilderX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2233 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 2234 | } |
| 2235 | |
| David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 2236 | void InstructionCodeGeneratorX86::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 2237 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
| David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 2238 | } |
| 2239 | |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 2240 | void CodeGeneratorX86::IncreaseFrame(size_t adjustment) { |
| 2241 | __ subl(ESP, Immediate(adjustment)); |
| 2242 | __ cfi().AdjustCFAOffset(adjustment); |
| 2243 | } |
| 2244 | |
| 2245 | void CodeGeneratorX86::DecreaseFrame(size_t adjustment) { |
| 2246 | __ addl(ESP, Immediate(adjustment)); |
| 2247 | __ cfi().AdjustCFAOffset(-adjustment); |
| 2248 | } |
| 2249 | |
| David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 2250 | void CodeGeneratorX86::GenerateNop() { |
| 2251 | __ nop(); |
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 2252 | } |
| 2253 | |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2254 | void LocationsBuilderX86::HandleCondition(HCondition* cond) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2255 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2256 | new (GetGraph()->GetAllocator()) LocationSummary(cond, LocationSummary::kNoCall); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2257 | // Handle the long/FP comparisons made in instruction simplification. |
| 2258 | switch (cond->InputAt(0)->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2259 | case DataType::Type::kInt64: { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2260 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 2261 | locations->SetInAt(1, Location::Any()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2262 | if (!cond->IsEmittedAtUseSite()) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2263 | locations->SetOut(Location::RequiresRegister()); |
| 2264 | } |
| 2265 | break; |
| 2266 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2267 | case DataType::Type::kFloat32: |
| 2268 | case DataType::Type::kFloat64: { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2269 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2270 | if (cond->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2271 | DCHECK(cond->InputAt(1)->IsEmittedAtUseSite()); |
| 2272 | } else if (cond->InputAt(1)->IsConstant()) { |
| 2273 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2274 | } else { |
| 2275 | locations->SetInAt(1, Location::Any()); |
| 2276 | } |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2277 | if (!cond->IsEmittedAtUseSite()) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2278 | locations->SetOut(Location::RequiresRegister()); |
| 2279 | } |
| 2280 | break; |
| 2281 | } |
| 2282 | default: |
| 2283 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2284 | locations->SetInAt(1, Location::Any()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2285 | if (!cond->IsEmittedAtUseSite()) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2286 | // We need a byte register. |
| 2287 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 2288 | } |
| 2289 | break; |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2290 | } |
| Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2291 | } |
| 2292 | |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2293 | void InstructionCodeGeneratorX86::HandleCondition(HCondition* cond) { |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2294 | if (cond->IsEmittedAtUseSite()) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2295 | return; |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2296 | } |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2297 | |
| 2298 | LocationSummary* locations = cond->GetLocations(); |
| 2299 | Location lhs = locations->InAt(0); |
| 2300 | Location rhs = locations->InAt(1); |
| 2301 | Register reg = locations->Out().AsRegister<Register>(); |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 2302 | NearLabel true_label, false_label; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2303 | |
| 2304 | switch (cond->InputAt(0)->GetType()) { |
| 2305 | default: { |
| 2306 | // Integer case. |
| 2307 | |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 2308 | // Clear output register: setb only sets the low byte. |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2309 | __ xorl(reg, reg); |
| Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2310 | codegen_->GenerateIntCompare(lhs, rhs); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2311 | __ setb(X86Condition(cond->GetCondition()), reg); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2312 | return; |
| 2313 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2314 | case DataType::Type::kInt64: |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2315 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 2316 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2317 | case DataType::Type::kFloat32: |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2318 | GenerateFPCompare(lhs, rhs, cond, false); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2319 | GenerateFPJumps(cond, &true_label, &false_label); |
| 2320 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2321 | case DataType::Type::kFloat64: |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2322 | GenerateFPCompare(lhs, rhs, cond, true); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2323 | GenerateFPJumps(cond, &true_label, &false_label); |
| 2324 | break; |
| 2325 | } |
| 2326 | |
| 2327 | // Convert the jumps into the result. |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2328 | NearLabel done_label; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2329 | |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2330 | // False case: result = 0. |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2331 | __ Bind(&false_label); |
| 2332 | __ xorl(reg, reg); |
| 2333 | __ jmp(&done_label); |
| 2334 | |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2335 | // True case: result = 1. |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2336 | __ Bind(&true_label); |
| 2337 | __ movl(reg, Immediate(1)); |
| 2338 | __ Bind(&done_label); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2339 | } |
| 2340 | |
| 2341 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2342 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2343 | } |
| 2344 | |
| 2345 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2346 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2347 | } |
| 2348 | |
| 2349 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2350 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2351 | } |
| 2352 | |
| 2353 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2354 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2355 | } |
| 2356 | |
| 2357 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2358 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2359 | } |
| 2360 | |
| 2361 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2362 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2363 | } |
| 2364 | |
| 2365 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2366 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2367 | } |
| 2368 | |
| 2369 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2370 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2371 | } |
| 2372 | |
| 2373 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2374 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2375 | } |
| 2376 | |
| 2377 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2378 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2379 | } |
| 2380 | |
| 2381 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2382 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2383 | } |
| 2384 | |
| 2385 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2386 | HandleCondition(comp); |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2387 | } |
| 2388 | |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2389 | void LocationsBuilderX86::VisitBelow(HBelow* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2390 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2391 | } |
| 2392 | |
| 2393 | void InstructionCodeGeneratorX86::VisitBelow(HBelow* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2394 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2395 | } |
| 2396 | |
| 2397 | void LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2398 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2399 | } |
| 2400 | |
| 2401 | void InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2402 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2403 | } |
| 2404 | |
| 2405 | void LocationsBuilderX86::VisitAbove(HAbove* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2406 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2407 | } |
| 2408 | |
| 2409 | void InstructionCodeGeneratorX86::VisitAbove(HAbove* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2410 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2411 | } |
| 2412 | |
| 2413 | void LocationsBuilderX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2414 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2415 | } |
| 2416 | |
| 2417 | void InstructionCodeGeneratorX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2418 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2419 | } |
| 2420 | |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2421 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2422 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2423 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2424 | locations->SetOut(Location::ConstantLocation(constant)); |
| Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2425 | } |
| 2426 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2427 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2428 | // Will be generated at use site. |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2429 | } |
| 2430 | |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2431 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 2432 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2433 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2434 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2435 | } |
| 2436 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2437 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2438 | // Will be generated at use site. |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2439 | } |
| 2440 | |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2441 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2442 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2443 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2444 | locations->SetOut(Location::ConstantLocation(constant)); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2445 | } |
| 2446 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2447 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2448 | // Will be generated at use site. |
| 2449 | } |
| 2450 | |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2451 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 2452 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2453 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2454 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2455 | } |
| 2456 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2457 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2458 | // Will be generated at use site. |
| 2459 | } |
| 2460 | |
| 2461 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2462 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2463 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2464 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2465 | } |
| 2466 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2467 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2468 | // Will be generated at use site. |
| 2469 | } |
| 2470 | |
| Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2471 | void LocationsBuilderX86::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 2472 | constructor_fence->SetLocations(nullptr); |
| 2473 | } |
| 2474 | |
| 2475 | void InstructionCodeGeneratorX86::VisitConstructorFence( |
| 2476 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 2477 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 2478 | } |
| 2479 | |
| Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2480 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2481 | memory_barrier->SetLocations(nullptr); |
| 2482 | } |
| 2483 | |
| 2484 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 2485 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2486 | } |
| 2487 | |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2488 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2489 | ret->SetLocations(nullptr); |
| Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2490 | } |
| 2491 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2492 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2493 | codegen_->GenerateFrameExit(); |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2494 | } |
| 2495 | |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2496 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2497 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2498 | new (GetGraph()->GetAllocator()) LocationSummary(ret, LocationSummary::kNoCall); |
| Mythri Alle | 2d4feeb | 2021-10-13 15:39:37 +0000 | [diff] [blame^] | 2499 | SetInForReturnValue(ret, locations); |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2500 | } |
| 2501 | |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2502 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
| Nicolas Geoffray | 57cacb7 | 2019-12-08 22:07:08 +0000 | [diff] [blame] | 2503 | switch (ret->InputAt(0)->GetType()) { |
| 2504 | case DataType::Type::kReference: |
| 2505 | case DataType::Type::kBool: |
| 2506 | case DataType::Type::kUint8: |
| 2507 | case DataType::Type::kInt8: |
| 2508 | case DataType::Type::kUint16: |
| 2509 | case DataType::Type::kInt16: |
| 2510 | case DataType::Type::kInt32: |
| 2511 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
| 2512 | break; |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2513 | |
| Nicolas Geoffray | 57cacb7 | 2019-12-08 22:07:08 +0000 | [diff] [blame] | 2514 | case DataType::Type::kInt64: |
| 2515 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 2516 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
| 2517 | break; |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2518 | |
| Nicolas Geoffray | 57cacb7 | 2019-12-08 22:07:08 +0000 | [diff] [blame] | 2519 | case DataType::Type::kFloat32: |
| 2520 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
| 2521 | if (GetGraph()->IsCompilingOsr()) { |
| 2522 | // To simplify callers of an OSR method, we put the return value in both |
| 2523 | // floating point and core registers. |
| 2524 | __ movd(EAX, XMM0); |
| 2525 | } |
| 2526 | break; |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2527 | |
| Nicolas Geoffray | 57cacb7 | 2019-12-08 22:07:08 +0000 | [diff] [blame] | 2528 | case DataType::Type::kFloat64: |
| 2529 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
| 2530 | if (GetGraph()->IsCompilingOsr()) { |
| 2531 | // To simplify callers of an OSR method, we put the return value in both |
| 2532 | // floating point and core registers. |
| 2533 | __ movd(EAX, XMM0); |
| 2534 | // Use XMM1 as temporary register to not clobber XMM0. |
| 2535 | __ movaps(XMM1, XMM0); |
| 2536 | __ psrlq(XMM1, Immediate(32)); |
| 2537 | __ movd(EDX, XMM1); |
| 2538 | } |
| 2539 | break; |
| 2540 | |
| 2541 | default: |
| 2542 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2543 | } |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2544 | codegen_->GenerateFrameExit(); |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2545 | } |
| 2546 | |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2547 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2548 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2549 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2550 | // the method_idx. |
| 2551 | HandleInvoke(invoke); |
| 2552 | } |
| 2553 | |
| 2554 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2555 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2556 | } |
| 2557 | |
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2558 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2559 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2560 | // art::PrepareForRegisterAllocation. |
| 2561 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2562 | |
| Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2563 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2564 | if (intrinsic.TryDispatch(invoke)) { |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 2565 | if (invoke->GetLocations()->CanCall() && |
| 2566 | invoke->HasPcRelativeMethodLoadKind() && |
| 2567 | invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()).IsInvalid()) { |
| Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 2568 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2569 | } |
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2570 | return; |
| 2571 | } |
| 2572 | |
| Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 2573 | if (invoke->GetCodePtrLocation() == CodePtrLocation::kCallCriticalNative) { |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 2574 | CriticalNativeCallingConventionVisitorX86 calling_convention_visitor( |
| 2575 | /*for_register_allocation=*/ true); |
| 2576 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 2577 | } else { |
| 2578 | HandleInvoke(invoke); |
| 2579 | } |
| Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2580 | |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 2581 | // For PC-relative load kinds the invoke has an extra input, the PC-relative address base. |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 2582 | if (invoke->HasPcRelativeMethodLoadKind()) { |
| Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2583 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2584 | } |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2585 | } |
| 2586 | |
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2587 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 2588 | if (invoke->GetLocations()->Intrinsified()) { |
| 2589 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 2590 | intrinsic.Dispatch(invoke); |
| 2591 | return true; |
| 2592 | } |
| 2593 | return false; |
| 2594 | } |
| 2595 | |
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2596 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2597 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2598 | // art::PrepareForRegisterAllocation. |
| 2599 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2600 | |
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2601 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2602 | return; |
| Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2603 | } |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2604 | |
| Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2605 | LocationSummary* locations = invoke->GetLocations(); |
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2606 | codegen_->GenerateStaticOrDirectCall( |
| Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2607 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2608 | } |
| 2609 | |
| 2610 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 2611 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 2612 | if (intrinsic.TryDispatch(invoke)) { |
| 2613 | return; |
| 2614 | } |
| 2615 | |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2616 | HandleInvoke(invoke); |
| Nicolas Geoffray | 9b5271e | 2019-12-04 14:39:46 +0000 | [diff] [blame] | 2617 | |
| 2618 | if (GetGraph()->IsCompilingBaseline() && !Runtime::Current()->IsAotCompiler()) { |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2619 | // Add one temporary for inline cache update. |
| 2620 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(EBP)); |
| 2621 | } |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2622 | } |
| 2623 | |
| 2624 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2625 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2626 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2627 | } |
| 2628 | |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2629 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2630 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2631 | return; |
| 2632 | } |
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2633 | |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2634 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2635 | DCHECK(!codegen_->IsLeafMethod()); |
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2636 | } |
| 2637 | |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2638 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2639 | // This call to HandleInvoke allocates a temporary (core) register |
| 2640 | // which is also used to transfer the hidden argument from FP to |
| 2641 | // core register. |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2642 | HandleInvoke(invoke); |
| 2643 | // Add the hidden argument. |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2644 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2645 | |
| Nicolas Geoffray | 9b5271e | 2019-12-04 14:39:46 +0000 | [diff] [blame] | 2646 | if (GetGraph()->IsCompilingBaseline() && !Runtime::Current()->IsAotCompiler()) { |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2647 | // Add one temporary for inline cache update. |
| 2648 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(EBP)); |
| 2649 | } |
| Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 2650 | |
| 2651 | // For PC-relative load kinds the invoke has an extra input, the PC-relative address base. |
| 2652 | if (IsPcRelativeMethodLoadKind(invoke->GetHiddenArgumentLoadKind())) { |
| 2653 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| 2654 | } |
| 2655 | |
| 2656 | if (invoke->GetHiddenArgumentLoadKind() == MethodLoadKind::kRecursive) { |
| 2657 | invoke->GetLocations()->SetInAt(invoke->GetNumberOfArguments() - 1, |
| 2658 | Location::RequiresRegister()); |
| 2659 | } |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2660 | } |
| 2661 | |
| 2662 | void CodeGeneratorX86::MaybeGenerateInlineCacheCheck(HInstruction* instruction, Register klass) { |
| 2663 | DCHECK_EQ(EAX, klass); |
| Nicolas Geoffray | 17a39ba | 2019-11-27 20:57:48 +0000 | [diff] [blame] | 2664 | // We know the destination of an intrinsic, so no need to record inline |
| 2665 | // caches (also the intrinsic location builder doesn't request an additional |
| 2666 | // temporary). |
| 2667 | if (!instruction->GetLocations()->Intrinsified() && |
| Nicolas Geoffray | 9b5271e | 2019-12-04 14:39:46 +0000 | [diff] [blame] | 2668 | GetGraph()->IsCompilingBaseline() && |
| Nicolas Geoffray | 17a39ba | 2019-11-27 20:57:48 +0000 | [diff] [blame] | 2669 | !Runtime::Current()->IsAotCompiler()) { |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2670 | DCHECK(!instruction->GetEnvironment()->IsFromInlinedInvoke()); |
| Nicolas Geoffray | 095dc46 | 2020-08-17 16:40:28 +0100 | [diff] [blame] | 2671 | ScopedProfilingInfoUse spiu( |
| 2672 | Runtime::Current()->GetJit(), GetGraph()->GetArtMethod(), Thread::Current()); |
| 2673 | ProfilingInfo* info = spiu.GetProfilingInfo(); |
| Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 2674 | if (info != nullptr) { |
| 2675 | InlineCache* cache = info->GetInlineCache(instruction->GetDexPc()); |
| 2676 | uint32_t address = reinterpret_cast32<uint32_t>(cache); |
| 2677 | if (kIsDebugBuild) { |
| 2678 | uint32_t temp_index = instruction->GetLocations()->GetTempCount() - 1u; |
| 2679 | CHECK_EQ(EBP, instruction->GetLocations()->GetTemp(temp_index).AsRegister<Register>()); |
| 2680 | } |
| 2681 | Register temp = EBP; |
| 2682 | NearLabel done; |
| 2683 | __ movl(temp, Immediate(address)); |
| 2684 | // Fast path for a monomorphic cache. |
| 2685 | __ cmpl(klass, Address(temp, InlineCache::ClassesOffset().Int32Value())); |
| 2686 | __ j(kEqual, &done); |
| 2687 | GenerateInvokeRuntime(GetThreadOffset<kX86PointerSize>(kQuickUpdateInlineCache).Int32Value()); |
| 2688 | __ Bind(&done); |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2689 | } |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2690 | } |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2691 | } |
| 2692 | |
| 2693 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2694 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2695 | LocationSummary* locations = invoke->GetLocations(); |
| 2696 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2697 | XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2698 | Location receiver = locations->InAt(0); |
| 2699 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2700 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2701 | // Set the hidden argument. This is safe to do this here, as XMM7 |
| 2702 | // won't be modified thereafter, before the `call` instruction. |
| 2703 | DCHECK_EQ(XMM7, hidden_reg); |
| Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 2704 | if (invoke->GetHiddenArgumentLoadKind() == MethodLoadKind::kRecursive) { |
| 2705 | __ movd(hidden_reg, locations->InAt(invoke->GetNumberOfArguments() - 1).AsRegister<Register>()); |
| Nicolas Geoffray | d6bd107 | 2020-11-30 18:42:01 +0000 | [diff] [blame] | 2706 | } else if (invoke->GetHiddenArgumentLoadKind() != MethodLoadKind::kRuntimeCall) { |
| Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 2707 | codegen_->LoadMethod(invoke->GetHiddenArgumentLoadKind(), locations->GetTemp(0), invoke); |
| 2708 | __ movd(hidden_reg, temp); |
| 2709 | } |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2710 | |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2711 | if (receiver.IsStackSlot()) { |
| 2712 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2713 | // /* HeapReference<Class> */ temp = temp->klass_ |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2714 | __ movl(temp, Address(temp, class_offset)); |
| 2715 | } else { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2716 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2717 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2718 | } |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2719 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2720 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2721 | // emit a read barrier for the previous class reference load. |
| 2722 | // However this is not required in practice, as this is an |
| 2723 | // intermediate/temporary reference and because the current |
| 2724 | // concurrent copying collector keeps the from-space memory |
| 2725 | // intact/accessible until the end of the marking phase (the |
| 2726 | // concurrent copying collector may not in the future). |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2727 | __ MaybeUnpoisonHeapReference(temp); |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2728 | |
| 2729 | codegen_->MaybeGenerateInlineCacheCheck(invoke, temp); |
| 2730 | |
| Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2731 | // temp = temp->GetAddressOfIMT() |
| 2732 | __ movl(temp, |
| 2733 | Address(temp, mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2734 | // temp = temp->GetImtEntryAt(method_offset); |
| Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2735 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2736 | invoke->GetImtIndex(), kX86PointerSize)); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2737 | __ movl(temp, Address(temp, method_offset)); |
| Nicolas Geoffray | d6bd107 | 2020-11-30 18:42:01 +0000 | [diff] [blame] | 2738 | if (invoke->GetHiddenArgumentLoadKind() == MethodLoadKind::kRuntimeCall) { |
| 2739 | // We pass the method from the IMT in case of a conflict. This will ensure |
| 2740 | // we go into the runtime to resolve the actual method. |
| 2741 | __ movd(hidden_reg, temp); |
| 2742 | } |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2743 | // call temp->GetEntryPoint(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2744 | __ call(Address(temp, |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2745 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2746 | |
| 2747 | DCHECK(!codegen_->IsLeafMethod()); |
| 2748 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2749 | } |
| 2750 | |
| Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2751 | void LocationsBuilderX86::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 2752 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 2753 | if (intrinsic.TryDispatch(invoke)) { |
| 2754 | return; |
| 2755 | } |
| Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2756 | HandleInvoke(invoke); |
| 2757 | } |
| 2758 | |
| 2759 | void InstructionCodeGeneratorX86::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 2760 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2761 | return; |
| 2762 | } |
| Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2763 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 2764 | } |
| 2765 | |
| Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 2766 | void LocationsBuilderX86::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 2767 | HandleInvoke(invoke); |
| 2768 | } |
| 2769 | |
| 2770 | void InstructionCodeGeneratorX86::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 2771 | codegen_->GenerateInvokeCustomCall(invoke); |
| 2772 | } |
| 2773 | |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2774 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 2775 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2776 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2777 | switch (neg->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2778 | case DataType::Type::kInt32: |
| 2779 | case DataType::Type::kInt64: |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2780 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2781 | locations->SetOut(Location::SameAsFirstInput()); |
| 2782 | break; |
| 2783 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2784 | case DataType::Type::kFloat32: |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2785 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2786 | locations->SetOut(Location::SameAsFirstInput()); |
| 2787 | locations->AddTemp(Location::RequiresRegister()); |
| 2788 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2789 | break; |
| 2790 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2791 | case DataType::Type::kFloat64: |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2792 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2793 | locations->SetOut(Location::SameAsFirstInput()); |
| 2794 | locations->AddTemp(Location::RequiresFpuRegister()); |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2795 | break; |
| 2796 | |
| 2797 | default: |
| 2798 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2799 | } |
| 2800 | } |
| 2801 | |
| 2802 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 2803 | LocationSummary* locations = neg->GetLocations(); |
| 2804 | Location out = locations->Out(); |
| 2805 | Location in = locations->InAt(0); |
| 2806 | switch (neg->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2807 | case DataType::Type::kInt32: |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2808 | DCHECK(in.IsRegister()); |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2809 | DCHECK(in.Equals(out)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2810 | __ negl(out.AsRegister<Register>()); |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2811 | break; |
| 2812 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2813 | case DataType::Type::kInt64: |
| Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2814 | DCHECK(in.IsRegisterPair()); |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2815 | DCHECK(in.Equals(out)); |
| Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2816 | __ negl(out.AsRegisterPairLow<Register>()); |
| 2817 | // Negation is similar to subtraction from zero. The least |
| 2818 | // significant byte triggers a borrow when it is different from |
| 2819 | // zero; to take it into account, add 1 to the most significant |
| 2820 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 2821 | // operation. |
| 2822 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2823 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 2824 | break; |
| 2825 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2826 | case DataType::Type::kFloat32: { |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2827 | DCHECK(in.Equals(out)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2828 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 2829 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2830 | // Implement float negation with an exclusive or with value |
| 2831 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2832 | // single-precision floating-point number). |
| 2833 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 2834 | __ movd(mask, constant); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2835 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2836 | break; |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2837 | } |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2838 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2839 | case DataType::Type::kFloat64: { |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2840 | DCHECK(in.Equals(out)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2841 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2842 | // Implement double negation with an exclusive or with value |
| 2843 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 2844 | // a double-precision floating-point number). |
| 2845 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2846 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2847 | break; |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2848 | } |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2849 | |
| 2850 | default: |
| 2851 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2852 | } |
| 2853 | } |
| 2854 | |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2855 | void LocationsBuilderX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2856 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2857 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2858 | DCHECK(DataType::IsFloatingPointType(neg->GetType())); |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2859 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2860 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2861 | locations->SetOut(Location::SameAsFirstInput()); |
| 2862 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2863 | } |
| 2864 | |
| 2865 | void InstructionCodeGeneratorX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2866 | LocationSummary* locations = neg->GetLocations(); |
| 2867 | Location out = locations->Out(); |
| 2868 | DCHECK(locations->InAt(0).Equals(out)); |
| 2869 | |
| 2870 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 2871 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2872 | if (neg->GetType() == DataType::Type::kFloat32) { |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 2873 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x80000000), |
| 2874 | neg->GetBaseMethodAddress(), |
| 2875 | constant_area)); |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2876 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| 2877 | } else { |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 2878 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000), |
| 2879 | neg->GetBaseMethodAddress(), |
| 2880 | constant_area)); |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2881 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| 2882 | } |
| 2883 | } |
| 2884 | |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2885 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2886 | DataType::Type result_type = conversion->GetResultType(); |
| 2887 | DataType::Type input_type = conversion->GetInputType(); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2888 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 2889 | << input_type << " -> " << result_type; |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2890 | |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2891 | // The float-to-long and double-to-long type conversions rely on a |
| 2892 | // call to the runtime. |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2893 | LocationSummary::CallKind call_kind = |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2894 | ((input_type == DataType::Type::kFloat32 || input_type == DataType::Type::kFloat64) |
| 2895 | && result_type == DataType::Type::kInt64) |
| Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2896 | ? LocationSummary::kCallOnMainOnly |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2897 | : LocationSummary::kNoCall; |
| 2898 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2899 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, call_kind); |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2900 | |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2901 | switch (result_type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2902 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2903 | case DataType::Type::kInt8: |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2904 | switch (input_type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2905 | case DataType::Type::kUint8: |
| 2906 | case DataType::Type::kInt8: |
| 2907 | case DataType::Type::kUint16: |
| 2908 | case DataType::Type::kInt16: |
| 2909 | case DataType::Type::kInt32: |
| 2910 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 2911 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2912 | // the validation of the linear scan implementation |
| 2913 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2914 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2915 | case DataType::Type::kInt64: { |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2916 | HInstruction* input = conversion->InputAt(0); |
| 2917 | Location input_location = input->IsConstant() |
| 2918 | ? Location::ConstantLocation(input->AsConstant()) |
| 2919 | : Location::RegisterPairLocation(EAX, EDX); |
| 2920 | locations->SetInAt(0, input_location); |
| 2921 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2922 | // the validation of the linear scan implementation |
| 2923 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2924 | break; |
| 2925 | } |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2926 | |
| 2927 | default: |
| 2928 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2929 | << " to " << result_type; |
| 2930 | } |
| 2931 | break; |
| 2932 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2933 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2934 | case DataType::Type::kInt16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2935 | DCHECK(DataType::IsIntegralType(input_type)) << input_type; |
| 2936 | locations->SetInAt(0, Location::Any()); |
| 2937 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2938 | break; |
| 2939 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2940 | case DataType::Type::kInt32: |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2941 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2942 | case DataType::Type::kInt64: |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2943 | locations->SetInAt(0, Location::Any()); |
| 2944 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2945 | break; |
| 2946 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2947 | case DataType::Type::kFloat32: |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2948 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2949 | locations->SetOut(Location::RequiresRegister()); |
| 2950 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2951 | break; |
| 2952 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2953 | case DataType::Type::kFloat64: |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2954 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2955 | locations->SetOut(Location::RequiresRegister()); |
| 2956 | locations->AddTemp(Location::RequiresFpuRegister()); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2957 | break; |
| 2958 | |
| 2959 | default: |
| 2960 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2961 | << " to " << result_type; |
| 2962 | } |
| 2963 | break; |
| 2964 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2965 | case DataType::Type::kInt64: |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2966 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2967 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2968 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2969 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2970 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2971 | case DataType::Type::kInt16: |
| 2972 | case DataType::Type::kInt32: |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2973 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 2974 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2975 | break; |
| 2976 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2977 | case DataType::Type::kFloat32: |
| 2978 | case DataType::Type::kFloat64: { |
| Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2979 | InvokeRuntimeCallingConvention calling_convention; |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2980 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 2981 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 2982 | |
| Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2983 | // The runtime helper puts the result in EAX, EDX. |
| 2984 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2985 | } |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2986 | break; |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2987 | |
| 2988 | default: |
| 2989 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2990 | << " to " << result_type; |
| 2991 | } |
| 2992 | break; |
| 2993 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2994 | case DataType::Type::kFloat32: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2995 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2996 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2997 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2998 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2999 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3000 | case DataType::Type::kInt16: |
| 3001 | case DataType::Type::kInt32: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3002 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3003 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3004 | break; |
| 3005 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3006 | case DataType::Type::kInt64: |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3007 | locations->SetInAt(0, Location::Any()); |
| 3008 | locations->SetOut(Location::Any()); |
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3009 | break; |
| 3010 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3011 | case DataType::Type::kFloat64: |
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3012 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3013 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3014 | break; |
| 3015 | |
| 3016 | default: |
| 3017 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3018 | << " to " << result_type; |
| Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3019 | } |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3020 | break; |
| 3021 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3022 | case DataType::Type::kFloat64: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3023 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3024 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3025 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3026 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3027 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3028 | case DataType::Type::kInt16: |
| 3029 | case DataType::Type::kInt32: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3030 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3031 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3032 | break; |
| 3033 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3034 | case DataType::Type::kInt64: |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3035 | locations->SetInAt(0, Location::Any()); |
| 3036 | locations->SetOut(Location::Any()); |
| Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3037 | break; |
| 3038 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3039 | case DataType::Type::kFloat32: |
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3040 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3041 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3042 | break; |
| 3043 | |
| 3044 | default: |
| 3045 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3046 | << " to " << result_type; |
| 3047 | } |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3048 | break; |
| 3049 | |
| 3050 | default: |
| 3051 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3052 | << " to " << result_type; |
| 3053 | } |
| 3054 | } |
| 3055 | |
| 3056 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 3057 | LocationSummary* locations = conversion->GetLocations(); |
| 3058 | Location out = locations->Out(); |
| 3059 | Location in = locations->InAt(0); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3060 | DataType::Type result_type = conversion->GetResultType(); |
| 3061 | DataType::Type input_type = conversion->GetInputType(); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3062 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 3063 | << input_type << " -> " << result_type; |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3064 | switch (result_type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3065 | case DataType::Type::kUint8: |
| 3066 | switch (input_type) { |
| 3067 | case DataType::Type::kInt8: |
| 3068 | case DataType::Type::kUint16: |
| 3069 | case DataType::Type::kInt16: |
| 3070 | case DataType::Type::kInt32: |
| 3071 | if (in.IsRegister()) { |
| 3072 | __ movzxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
| 3073 | } else { |
| 3074 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 3075 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 3076 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint8_t>(value))); |
| 3077 | } |
| 3078 | break; |
| 3079 | case DataType::Type::kInt64: |
| 3080 | if (in.IsRegisterPair()) { |
| 3081 | __ movzxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 3082 | } else { |
| 3083 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 3084 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3085 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint8_t>(value))); |
| 3086 | } |
| 3087 | break; |
| 3088 | |
| 3089 | default: |
| 3090 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3091 | << " to " << result_type; |
| 3092 | } |
| 3093 | break; |
| 3094 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3095 | case DataType::Type::kInt8: |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3096 | switch (input_type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3097 | case DataType::Type::kUint8: |
| 3098 | case DataType::Type::kUint16: |
| 3099 | case DataType::Type::kInt16: |
| 3100 | case DataType::Type::kInt32: |
| 3101 | if (in.IsRegister()) { |
| 3102 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
| 3103 | } else { |
| 3104 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 3105 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 3106 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 3107 | } |
| 3108 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3109 | case DataType::Type::kInt64: |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3110 | if (in.IsRegisterPair()) { |
| 3111 | __ movsxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 3112 | } else { |
| 3113 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 3114 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3115 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 3116 | } |
| 3117 | break; |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3118 | |
| 3119 | default: |
| 3120 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3121 | << " to " << result_type; |
| 3122 | } |
| 3123 | break; |
| 3124 | |
| 3125 | case DataType::Type::kUint16: |
| 3126 | switch (input_type) { |
| 3127 | case DataType::Type::kInt8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3128 | case DataType::Type::kInt16: |
| 3129 | case DataType::Type::kInt32: |
| Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 3130 | if (in.IsRegister()) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3131 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
| 3132 | } else if (in.IsStackSlot()) { |
| 3133 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 3134 | } else { |
| 3135 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 3136 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3137 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
| 3138 | } |
| 3139 | break; |
| 3140 | case DataType::Type::kInt64: |
| 3141 | if (in.IsRegisterPair()) { |
| 3142 | __ movzxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 3143 | } else if (in.IsDoubleStackSlot()) { |
| 3144 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 3145 | } else { |
| 3146 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 3147 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3148 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
| Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 3149 | } |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3150 | break; |
| 3151 | |
| 3152 | default: |
| 3153 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3154 | << " to " << result_type; |
| 3155 | } |
| 3156 | break; |
| 3157 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3158 | case DataType::Type::kInt16: |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3159 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3160 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3161 | case DataType::Type::kInt32: |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3162 | if (in.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3163 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3164 | } else if (in.IsStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3165 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3166 | } else { |
| 3167 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 3168 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3169 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3170 | } |
| 3171 | break; |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3172 | case DataType::Type::kInt64: |
| 3173 | if (in.IsRegisterPair()) { |
| 3174 | __ movsxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 3175 | } else if (in.IsDoubleStackSlot()) { |
| 3176 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 3177 | } else { |
| 3178 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 3179 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3180 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
| 3181 | } |
| 3182 | break; |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3183 | |
| 3184 | default: |
| 3185 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3186 | << " to " << result_type; |
| 3187 | } |
| 3188 | break; |
| 3189 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3190 | case DataType::Type::kInt32: |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3191 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3192 | case DataType::Type::kInt64: |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3193 | if (in.IsRegisterPair()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3194 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3195 | } else if (in.IsDoubleStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3196 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3197 | } else { |
| 3198 | DCHECK(in.IsConstant()); |
| 3199 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 3200 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3201 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3202 | } |
| 3203 | break; |
| 3204 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3205 | case DataType::Type::kFloat32: { |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 3206 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 3207 | Register output = out.AsRegister<Register>(); |
| 3208 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3209 | NearLabel done, nan; |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 3210 | |
| 3211 | __ movl(output, Immediate(kPrimIntMax)); |
| 3212 | // temp = int-to-float(output) |
| 3213 | __ cvtsi2ss(temp, output); |
| 3214 | // if input >= temp goto done |
| 3215 | __ comiss(input, temp); |
| 3216 | __ j(kAboveEqual, &done); |
| 3217 | // if input == NaN goto nan |
| 3218 | __ j(kUnordered, &nan); |
| 3219 | // output = float-to-int-truncate(input) |
| 3220 | __ cvttss2si(output, input); |
| 3221 | __ jmp(&done); |
| 3222 | __ Bind(&nan); |
| 3223 | // output = 0 |
| 3224 | __ xorl(output, output); |
| 3225 | __ Bind(&done); |
| 3226 | break; |
| 3227 | } |
| 3228 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3229 | case DataType::Type::kFloat64: { |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3230 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 3231 | Register output = out.AsRegister<Register>(); |
| 3232 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3233 | NearLabel done, nan; |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3234 | |
| 3235 | __ movl(output, Immediate(kPrimIntMax)); |
| 3236 | // temp = int-to-double(output) |
| 3237 | __ cvtsi2sd(temp, output); |
| 3238 | // if input >= temp goto done |
| 3239 | __ comisd(input, temp); |
| 3240 | __ j(kAboveEqual, &done); |
| 3241 | // if input == NaN goto nan |
| 3242 | __ j(kUnordered, &nan); |
| 3243 | // output = double-to-int-truncate(input) |
| 3244 | __ cvttsd2si(output, input); |
| 3245 | __ jmp(&done); |
| 3246 | __ Bind(&nan); |
| 3247 | // output = 0 |
| 3248 | __ xorl(output, output); |
| 3249 | __ Bind(&done); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3250 | break; |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3251 | } |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3252 | |
| 3253 | default: |
| 3254 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3255 | << " to " << result_type; |
| 3256 | } |
| 3257 | break; |
| 3258 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3259 | case DataType::Type::kInt64: |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3260 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3261 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3262 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3263 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3264 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3265 | case DataType::Type::kInt16: |
| 3266 | case DataType::Type::kInt32: |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3267 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 3268 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3269 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3270 | __ cdq(); |
| 3271 | break; |
| 3272 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3273 | case DataType::Type::kFloat32: |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3274 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3275 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3276 | break; |
| 3277 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3278 | case DataType::Type::kFloat64: |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3279 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3280 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3281 | break; |
| 3282 | |
| 3283 | default: |
| 3284 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3285 | << " to " << result_type; |
| 3286 | } |
| 3287 | break; |
| 3288 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3289 | case DataType::Type::kFloat32: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3290 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3291 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3292 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3293 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3294 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3295 | case DataType::Type::kInt16: |
| 3296 | case DataType::Type::kInt32: |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3297 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3298 | break; |
| 3299 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3300 | case DataType::Type::kInt64: { |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3301 | size_t adjustment = 0; |
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3302 | |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3303 | // Create stack space for the call to |
| 3304 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 3305 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3306 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3307 | adjustment = DataType::Size(DataType::Type::kInt64); |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 3308 | codegen_->IncreaseFrame(adjustment); |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3309 | } |
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3310 | |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3311 | // Load the value to the FP stack, using temporaries if needed. |
| 3312 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 3313 | |
| 3314 | if (out.IsStackSlot()) { |
| 3315 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 3316 | } else { |
| 3317 | __ fstps(Address(ESP, 0)); |
| 3318 | Location stack_temp = Location::StackSlot(0); |
| 3319 | codegen_->Move32(out, stack_temp); |
| 3320 | } |
| 3321 | |
| 3322 | // Remove the temporary stack space we allocated. |
| 3323 | if (adjustment != 0) { |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 3324 | codegen_->DecreaseFrame(adjustment); |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3325 | } |
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3326 | break; |
| 3327 | } |
| 3328 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3329 | case DataType::Type::kFloat64: |
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3330 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3331 | break; |
| 3332 | |
| 3333 | default: |
| 3334 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3335 | << " to " << result_type; |
| Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3336 | } |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3337 | break; |
| 3338 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3339 | case DataType::Type::kFloat64: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3340 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3341 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3342 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3343 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3344 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3345 | case DataType::Type::kInt16: |
| 3346 | case DataType::Type::kInt32: |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3347 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3348 | break; |
| 3349 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3350 | case DataType::Type::kInt64: { |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3351 | size_t adjustment = 0; |
| Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3352 | |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3353 | // Create stack space for the call to |
| 3354 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 3355 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3356 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3357 | adjustment = DataType::Size(DataType::Type::kInt64); |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 3358 | codegen_->IncreaseFrame(adjustment); |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3359 | } |
| 3360 | |
| 3361 | // Load the value to the FP stack, using temporaries if needed. |
| 3362 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 3363 | |
| 3364 | if (out.IsDoubleStackSlot()) { |
| 3365 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 3366 | } else { |
| 3367 | __ fstpl(Address(ESP, 0)); |
| 3368 | Location stack_temp = Location::DoubleStackSlot(0); |
| 3369 | codegen_->Move64(out, stack_temp); |
| 3370 | } |
| 3371 | |
| 3372 | // Remove the temporary stack space we allocated. |
| 3373 | if (adjustment != 0) { |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 3374 | codegen_->DecreaseFrame(adjustment); |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3375 | } |
| Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3376 | break; |
| 3377 | } |
| 3378 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3379 | case DataType::Type::kFloat32: |
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3380 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3381 | break; |
| 3382 | |
| 3383 | default: |
| 3384 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3385 | << " to " << result_type; |
| Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3386 | } |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3387 | break; |
| 3388 | |
| 3389 | default: |
| 3390 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3391 | << " to " << result_type; |
| 3392 | } |
| 3393 | } |
| 3394 | |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3395 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3396 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3397 | new (GetGraph()->GetAllocator()) LocationSummary(add, LocationSummary::kNoCall); |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3398 | switch (add->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3399 | case DataType::Type::kInt32: { |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3400 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3401 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 3402 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3403 | break; |
| 3404 | } |
| 3405 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3406 | case DataType::Type::kInt64: { |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3407 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3408 | locations->SetInAt(1, Location::Any()); |
| 3409 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3410 | break; |
| 3411 | } |
| 3412 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3413 | case DataType::Type::kFloat32: |
| 3414 | case DataType::Type::kFloat64: { |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3415 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3416 | if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3417 | DCHECK(add->InputAt(1)->IsEmittedAtUseSite()); |
| Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3418 | } else if (add->InputAt(1)->IsConstant()) { |
| 3419 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3420 | } else { |
| 3421 | locations->SetInAt(1, Location::Any()); |
| 3422 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3423 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3424 | break; |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3425 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3426 | |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3427 | default: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3428 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 3429 | UNREACHABLE(); |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3430 | } |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3431 | } |
| 3432 | |
| 3433 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 3434 | LocationSummary* locations = add->GetLocations(); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3435 | Location first = locations->InAt(0); |
| 3436 | Location second = locations->InAt(1); |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3437 | Location out = locations->Out(); |
| 3438 | |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3439 | switch (add->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3440 | case DataType::Type::kInt32: { |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3441 | if (second.IsRegister()) { |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3442 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3443 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
| Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 3444 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 3445 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3446 | } else { |
| 3447 | __ leal(out.AsRegister<Register>(), Address( |
| 3448 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 3449 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3450 | } else if (second.IsConstant()) { |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3451 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3452 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3453 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 3454 | } else { |
| 3455 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 3456 | } |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3457 | } else { |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3458 | DCHECK(first.Equals(locations->Out())); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3459 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3460 | } |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3461 | break; |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3462 | } |
| 3463 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3464 | case DataType::Type::kInt64: { |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3465 | if (second.IsRegisterPair()) { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3466 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3467 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3468 | } else if (second.IsDoubleStackSlot()) { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3469 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 3470 | __ adcl(first.AsRegisterPairHigh<Register>(), |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3471 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3472 | } else { |
| 3473 | DCHECK(second.IsConstant()) << second; |
| 3474 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3475 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 3476 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3477 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3478 | break; |
| 3479 | } |
| 3480 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3481 | case DataType::Type::kFloat32: { |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3482 | if (second.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3483 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3484 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3485 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3486 | DCHECK(const_area->IsEmittedAtUseSite()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3487 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 3488 | codegen_->LiteralFloatAddress( |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3489 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3490 | const_area->GetBaseMethodAddress(), |
| 3491 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3492 | } else { |
| 3493 | DCHECK(second.IsStackSlot()); |
| 3494 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3495 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3496 | break; |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3497 | } |
| 3498 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3499 | case DataType::Type::kFloat64: { |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3500 | if (second.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3501 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3502 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3503 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3504 | DCHECK(const_area->IsEmittedAtUseSite()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3505 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 3506 | codegen_->LiteralDoubleAddress( |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3507 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3508 | const_area->GetBaseMethodAddress(), |
| 3509 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3510 | } else { |
| 3511 | DCHECK(second.IsDoubleStackSlot()); |
| 3512 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3513 | } |
| 3514 | break; |
| 3515 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3516 | |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3517 | default: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3518 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3519 | } |
| 3520 | } |
| 3521 | |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3522 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3523 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3524 | new (GetGraph()->GetAllocator()) LocationSummary(sub, LocationSummary::kNoCall); |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3525 | switch (sub->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3526 | case DataType::Type::kInt32: |
| 3527 | case DataType::Type::kInt64: { |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3528 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3529 | locations->SetInAt(1, Location::Any()); |
| 3530 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3531 | break; |
| 3532 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3533 | case DataType::Type::kFloat32: |
| 3534 | case DataType::Type::kFloat64: { |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3535 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3536 | if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3537 | DCHECK(sub->InputAt(1)->IsEmittedAtUseSite()); |
| Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3538 | } else if (sub->InputAt(1)->IsConstant()) { |
| 3539 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3540 | } else { |
| 3541 | locations->SetInAt(1, Location::Any()); |
| 3542 | } |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3543 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3544 | break; |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3545 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3546 | |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3547 | default: |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3548 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3549 | } |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3550 | } |
| 3551 | |
| 3552 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 3553 | LocationSummary* locations = sub->GetLocations(); |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3554 | Location first = locations->InAt(0); |
| 3555 | Location second = locations->InAt(1); |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3556 | DCHECK(first.Equals(locations->Out())); |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3557 | switch (sub->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3558 | case DataType::Type::kInt32: { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3559 | if (second.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3560 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3561 | } else if (second.IsConstant()) { |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3562 | __ subl(first.AsRegister<Register>(), |
| 3563 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3564 | } else { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3565 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3566 | } |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3567 | break; |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3568 | } |
| 3569 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3570 | case DataType::Type::kInt64: { |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3571 | if (second.IsRegisterPair()) { |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3572 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3573 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3574 | } else if (second.IsDoubleStackSlot()) { |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3575 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3576 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 3577 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3578 | } else { |
| 3579 | DCHECK(second.IsConstant()) << second; |
| 3580 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3581 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 3582 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3583 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3584 | break; |
| 3585 | } |
| 3586 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3587 | case DataType::Type::kFloat32: { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3588 | if (second.IsFpuRegister()) { |
| 3589 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3590 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3591 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3592 | DCHECK(const_area->IsEmittedAtUseSite()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3593 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3594 | codegen_->LiteralFloatAddress( |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3595 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3596 | const_area->GetBaseMethodAddress(), |
| 3597 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3598 | } else { |
| 3599 | DCHECK(second.IsStackSlot()); |
| 3600 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3601 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3602 | break; |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3603 | } |
| 3604 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3605 | case DataType::Type::kFloat64: { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3606 | if (second.IsFpuRegister()) { |
| 3607 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3608 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3609 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3610 | DCHECK(const_area->IsEmittedAtUseSite()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3611 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3612 | codegen_->LiteralDoubleAddress( |
| 3613 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3614 | const_area->GetBaseMethodAddress(), |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3615 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3616 | } else { |
| 3617 | DCHECK(second.IsDoubleStackSlot()); |
| 3618 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3619 | } |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3620 | break; |
| 3621 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3622 | |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3623 | default: |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3624 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3625 | } |
| 3626 | } |
| 3627 | |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3628 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 3629 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3630 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3631 | switch (mul->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3632 | case DataType::Type::kInt32: |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3633 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3634 | locations->SetInAt(1, Location::Any()); |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3635 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3636 | // Can use 3 operand multiply. |
| 3637 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3638 | } else { |
| 3639 | locations->SetOut(Location::SameAsFirstInput()); |
| 3640 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3641 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3642 | case DataType::Type::kInt64: { |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3643 | locations->SetInAt(0, Location::RequiresRegister()); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3644 | locations->SetInAt(1, Location::Any()); |
| 3645 | locations->SetOut(Location::SameAsFirstInput()); |
| 3646 | // Needed for imul on 32bits with 64bits output. |
| 3647 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 3648 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 3649 | break; |
| 3650 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3651 | case DataType::Type::kFloat32: |
| 3652 | case DataType::Type::kFloat64: { |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3653 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3654 | if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3655 | DCHECK(mul->InputAt(1)->IsEmittedAtUseSite()); |
| Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3656 | } else if (mul->InputAt(1)->IsConstant()) { |
| 3657 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3658 | } else { |
| 3659 | locations->SetInAt(1, Location::Any()); |
| 3660 | } |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3661 | locations->SetOut(Location::SameAsFirstInput()); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3662 | break; |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3663 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3664 | |
| 3665 | default: |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3666 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3667 | } |
| 3668 | } |
| 3669 | |
| 3670 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 3671 | LocationSummary* locations = mul->GetLocations(); |
| 3672 | Location first = locations->InAt(0); |
| 3673 | Location second = locations->InAt(1); |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3674 | Location out = locations->Out(); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3675 | |
| 3676 | switch (mul->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3677 | case DataType::Type::kInt32: |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3678 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3679 | // problems where the output may not be the same as the first operand. |
| 3680 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3681 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3682 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 3683 | } else if (second.IsRegister()) { |
| 3684 | DCHECK(first.Equals(out)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3685 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3686 | } else { |
| 3687 | DCHECK(second.IsStackSlot()); |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3688 | DCHECK(first.Equals(out)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3689 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3690 | } |
| 3691 | break; |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3692 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3693 | case DataType::Type::kInt64: { |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3694 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 3695 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3696 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 3697 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3698 | |
| 3699 | DCHECK_EQ(EAX, eax); |
| 3700 | DCHECK_EQ(EDX, edx); |
| 3701 | |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3702 | // input: in1 - 64 bits, in2 - 64 bits. |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3703 | // output: in1 |
| 3704 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3705 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3706 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3707 | if (second.IsConstant()) { |
| 3708 | DCHECK(second.GetConstant()->IsLongConstant()); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3709 | |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3710 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3711 | int32_t low_value = Low32Bits(value); |
| 3712 | int32_t high_value = High32Bits(value); |
| 3713 | Immediate low(low_value); |
| 3714 | Immediate high(high_value); |
| 3715 | |
| 3716 | __ movl(eax, high); |
| 3717 | // eax <- in1.lo * in2.hi |
| 3718 | __ imull(eax, in1_lo); |
| 3719 | // in1.hi <- in1.hi * in2.lo |
| 3720 | __ imull(in1_hi, low); |
| 3721 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3722 | __ addl(in1_hi, eax); |
| 3723 | // move in2_lo to eax to prepare for double precision |
| 3724 | __ movl(eax, low); |
| 3725 | // edx:eax <- in1.lo * in2.lo |
| 3726 | __ mull(in1_lo); |
| 3727 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3728 | __ addl(in1_hi, edx); |
| 3729 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3730 | __ movl(in1_lo, eax); |
| 3731 | } else if (second.IsRegisterPair()) { |
| 3732 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3733 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3734 | |
| 3735 | __ movl(eax, in2_hi); |
| 3736 | // eax <- in1.lo * in2.hi |
| 3737 | __ imull(eax, in1_lo); |
| 3738 | // in1.hi <- in1.hi * in2.lo |
| 3739 | __ imull(in1_hi, in2_lo); |
| 3740 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3741 | __ addl(in1_hi, eax); |
| 3742 | // move in1_lo to eax to prepare for double precision |
| 3743 | __ movl(eax, in1_lo); |
| 3744 | // edx:eax <- in1.lo * in2.lo |
| 3745 | __ mull(in2_lo); |
| 3746 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3747 | __ addl(in1_hi, edx); |
| 3748 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3749 | __ movl(in1_lo, eax); |
| 3750 | } else { |
| 3751 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 3752 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 3753 | Address in2_lo(ESP, second.GetStackIndex()); |
| 3754 | |
| 3755 | __ movl(eax, in2_hi); |
| 3756 | // eax <- in1.lo * in2.hi |
| 3757 | __ imull(eax, in1_lo); |
| 3758 | // in1.hi <- in1.hi * in2.lo |
| 3759 | __ imull(in1_hi, in2_lo); |
| 3760 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3761 | __ addl(in1_hi, eax); |
| 3762 | // move in1_lo to eax to prepare for double precision |
| 3763 | __ movl(eax, in1_lo); |
| 3764 | // edx:eax <- in1.lo * in2.lo |
| 3765 | __ mull(in2_lo); |
| 3766 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3767 | __ addl(in1_hi, edx); |
| 3768 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3769 | __ movl(in1_lo, eax); |
| 3770 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3771 | |
| 3772 | break; |
| 3773 | } |
| 3774 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3775 | case DataType::Type::kFloat32: { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3776 | DCHECK(first.Equals(locations->Out())); |
| 3777 | if (second.IsFpuRegister()) { |
| 3778 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3779 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3780 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3781 | DCHECK(const_area->IsEmittedAtUseSite()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3782 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3783 | codegen_->LiteralFloatAddress( |
| 3784 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3785 | const_area->GetBaseMethodAddress(), |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3786 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3787 | } else { |
| 3788 | DCHECK(second.IsStackSlot()); |
| 3789 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3790 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3791 | break; |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3792 | } |
| 3793 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3794 | case DataType::Type::kFloat64: { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3795 | DCHECK(first.Equals(locations->Out())); |
| 3796 | if (second.IsFpuRegister()) { |
| 3797 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3798 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3799 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3800 | DCHECK(const_area->IsEmittedAtUseSite()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3801 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3802 | codegen_->LiteralDoubleAddress( |
| 3803 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3804 | const_area->GetBaseMethodAddress(), |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3805 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3806 | } else { |
| 3807 | DCHECK(second.IsDoubleStackSlot()); |
| 3808 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3809 | } |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3810 | break; |
| 3811 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3812 | |
| 3813 | default: |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3814 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3815 | } |
| 3816 | } |
| 3817 | |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3818 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 3819 | uint32_t temp_offset, |
| 3820 | uint32_t stack_adjustment, |
| 3821 | bool is_fp, |
| 3822 | bool is_wide) { |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3823 | if (source.IsStackSlot()) { |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3824 | DCHECK(!is_wide); |
| 3825 | if (is_fp) { |
| 3826 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3827 | } else { |
| 3828 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3829 | } |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3830 | } else if (source.IsDoubleStackSlot()) { |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3831 | DCHECK(is_wide); |
| 3832 | if (is_fp) { |
| 3833 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3834 | } else { |
| 3835 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3836 | } |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3837 | } else { |
| 3838 | // 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] | 3839 | if (!is_wide) { |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3840 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3841 | codegen_->Move32(stack_temp, source); |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3842 | if (is_fp) { |
| 3843 | __ flds(Address(ESP, temp_offset)); |
| 3844 | } else { |
| 3845 | __ filds(Address(ESP, temp_offset)); |
| 3846 | } |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3847 | } else { |
| 3848 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3849 | codegen_->Move64(stack_temp, source); |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3850 | if (is_fp) { |
| 3851 | __ fldl(Address(ESP, temp_offset)); |
| 3852 | } else { |
| 3853 | __ fildl(Address(ESP, temp_offset)); |
| 3854 | } |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3855 | } |
| 3856 | } |
| 3857 | } |
| 3858 | |
| 3859 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3860 | DataType::Type type = rem->GetResultType(); |
| 3861 | bool is_float = type == DataType::Type::kFloat32; |
| 3862 | size_t elem_size = DataType::Size(type); |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3863 | LocationSummary* locations = rem->GetLocations(); |
| 3864 | Location first = locations->InAt(0); |
| 3865 | Location second = locations->InAt(1); |
| 3866 | Location out = locations->Out(); |
| 3867 | |
| 3868 | // Create stack space for 2 elements. |
| 3869 | // TODO: enhance register allocator to ask for stack temporaries. |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 3870 | codegen_->IncreaseFrame(2 * elem_size); |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3871 | |
| 3872 | // 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] | 3873 | const bool is_wide = !is_float; |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3874 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp= */ true, is_wide); |
| 3875 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp= */ true, is_wide); |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3876 | |
| 3877 | // Loop doing FPREM until we stabilize. |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3878 | NearLabel retry; |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3879 | __ Bind(&retry); |
| 3880 | __ fprem(); |
| 3881 | |
| 3882 | // Move FP status to AX. |
| 3883 | __ fstsw(); |
| 3884 | |
| 3885 | // And see if the argument reduction is complete. This is signaled by the |
| 3886 | // C2 FPU flag bit set to 0. |
| 3887 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 3888 | __ j(kNotEqual, &retry); |
| 3889 | |
| 3890 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3891 | // Store FP top of stack to real stack. |
| 3892 | if (is_float) { |
| 3893 | __ fsts(Address(ESP, 0)); |
| 3894 | } else { |
| 3895 | __ fstl(Address(ESP, 0)); |
| 3896 | } |
| 3897 | |
| 3898 | // Pop the 2 items from the FP stack. |
| 3899 | __ fucompp(); |
| 3900 | |
| 3901 | // Load the value from the stack into an XMM register. |
| 3902 | DCHECK(out.IsFpuRegister()) << out; |
| 3903 | if (is_float) { |
| 3904 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3905 | } else { |
| 3906 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3907 | } |
| 3908 | |
| 3909 | // And remove the temporary stack space we allocated. |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 3910 | codegen_->DecreaseFrame(2 * elem_size); |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3911 | } |
| 3912 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3913 | |
| 3914 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3915 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3916 | |
| 3917 | LocationSummary* locations = instruction->GetLocations(); |
| 3918 | DCHECK(locations->InAt(1).IsConstant()); |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3919 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3920 | |
| 3921 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3922 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3923 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3924 | |
| 3925 | DCHECK(imm == 1 || imm == -1); |
| 3926 | |
| 3927 | if (instruction->IsRem()) { |
| 3928 | __ xorl(out_register, out_register); |
| 3929 | } else { |
| 3930 | __ movl(out_register, input_register); |
| 3931 | if (imm == -1) { |
| 3932 | __ negl(out_register); |
| 3933 | } |
| 3934 | } |
| 3935 | } |
| 3936 | |
| Shalini Salomi Bodapati | a66784b | 2018-11-06 13:05:44 +0530 | [diff] [blame] | 3937 | void InstructionCodeGeneratorX86::RemByPowerOfTwo(HRem* instruction) { |
| 3938 | LocationSummary* locations = instruction->GetLocations(); |
| 3939 | Location second = locations->InAt(1); |
| 3940 | |
| 3941 | Register out = locations->Out().AsRegister<Register>(); |
| 3942 | Register numerator = locations->InAt(0).AsRegister<Register>(); |
| 3943 | |
| 3944 | int32_t imm = Int64FromConstant(second.GetConstant()); |
| 3945 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3946 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
| 3947 | |
| 3948 | Register tmp = locations->GetTemp(0).AsRegister<Register>(); |
| 3949 | NearLabel done; |
| 3950 | __ movl(out, numerator); |
| 3951 | __ andl(out, Immediate(abs_imm-1)); |
| 3952 | __ j(Condition::kZero, &done); |
| 3953 | __ leal(tmp, Address(out, static_cast<int32_t>(~(abs_imm-1)))); |
| 3954 | __ testl(numerator, numerator); |
| 3955 | __ cmovl(Condition::kLess, out, tmp); |
| 3956 | __ Bind(&done); |
| 3957 | } |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3958 | |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3959 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3960 | LocationSummary* locations = instruction->GetLocations(); |
| 3961 | |
| 3962 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3963 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3964 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3965 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3966 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3967 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3968 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 3969 | |
| Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3970 | __ leal(num, Address(input_register, abs_imm - 1)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3971 | __ testl(input_register, input_register); |
| 3972 | __ cmovl(kGreaterEqual, num, input_register); |
| 3973 | int shift = CTZ(imm); |
| 3974 | __ sarl(num, Immediate(shift)); |
| 3975 | |
| 3976 | if (imm < 0) { |
| 3977 | __ negl(num); |
| 3978 | } |
| 3979 | |
| 3980 | __ movl(out_register, num); |
| 3981 | } |
| 3982 | |
| 3983 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3984 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3985 | |
| 3986 | LocationSummary* locations = instruction->GetLocations(); |
| 3987 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 3988 | |
| 3989 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 3990 | Register out = locations->Out().AsRegister<Register>(); |
| 3991 | Register num; |
| 3992 | Register edx; |
| 3993 | |
| 3994 | if (instruction->IsDiv()) { |
| 3995 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 3996 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 3997 | } else { |
| 3998 | edx = locations->Out().AsRegister<Register>(); |
| 3999 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 4000 | } |
| 4001 | |
| 4002 | DCHECK_EQ(EAX, eax); |
| 4003 | DCHECK_EQ(EDX, edx); |
| 4004 | if (instruction->IsDiv()) { |
| 4005 | DCHECK_EQ(EAX, out); |
| 4006 | } else { |
| 4007 | DCHECK_EQ(EDX, out); |
| 4008 | } |
| 4009 | |
| 4010 | int64_t magic; |
| 4011 | int shift; |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4012 | CalculateMagicAndShiftForDivRem(imm, /* is_long= */ false, &magic, &shift); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4013 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4014 | // Save the numerator. |
| 4015 | __ movl(num, eax); |
| 4016 | |
| 4017 | // EAX = magic |
| 4018 | __ movl(eax, Immediate(magic)); |
| 4019 | |
| 4020 | // EDX:EAX = magic * numerator |
| 4021 | __ imull(num); |
| 4022 | |
| 4023 | if (imm > 0 && magic < 0) { |
| 4024 | // EDX += num |
| 4025 | __ addl(edx, num); |
| 4026 | } else if (imm < 0 && magic > 0) { |
| 4027 | __ subl(edx, num); |
| 4028 | } |
| 4029 | |
| 4030 | // Shift if needed. |
| 4031 | if (shift != 0) { |
| 4032 | __ sarl(edx, Immediate(shift)); |
| 4033 | } |
| 4034 | |
| 4035 | // EDX += 1 if EDX < 0 |
| 4036 | __ movl(eax, edx); |
| 4037 | __ shrl(edx, Immediate(31)); |
| 4038 | __ addl(edx, eax); |
| 4039 | |
| 4040 | if (instruction->IsRem()) { |
| 4041 | __ movl(eax, num); |
| 4042 | __ imull(edx, Immediate(imm)); |
| 4043 | __ subl(eax, edx); |
| 4044 | __ movl(edx, eax); |
| 4045 | } else { |
| 4046 | __ movl(eax, edx); |
| 4047 | } |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4048 | } |
| 4049 | |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4050 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 4051 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 4052 | |
| 4053 | LocationSummary* locations = instruction->GetLocations(); |
| 4054 | Location out = locations->Out(); |
| 4055 | Location first = locations->InAt(0); |
| 4056 | Location second = locations->InAt(1); |
| 4057 | bool is_div = instruction->IsDiv(); |
| 4058 | |
| 4059 | switch (instruction->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4060 | case DataType::Type::kInt32: { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4061 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 4062 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4063 | |
| Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 4064 | if (second.IsConstant()) { |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 4065 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4066 | |
| 4067 | if (imm == 0) { |
| 4068 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 4069 | } else if (imm == 1 || imm == -1) { |
| 4070 | DivRemOneOrMinusOne(instruction); |
| Shalini Salomi Bodapati | a66784b | 2018-11-06 13:05:44 +0530 | [diff] [blame] | 4071 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 4072 | if (is_div) { |
| 4073 | DivByPowerOfTwo(instruction->AsDiv()); |
| 4074 | } else { |
| 4075 | RemByPowerOfTwo(instruction->AsRem()); |
| 4076 | } |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4077 | } else { |
| 4078 | DCHECK(imm <= -2 || imm >= 2); |
| 4079 | GenerateDivRemWithAnyConstant(instruction); |
| 4080 | } |
| 4081 | } else { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4082 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) DivRemMinusOneSlowPathX86( |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 4083 | instruction, out.AsRegister<Register>(), is_div); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4084 | codegen_->AddSlowPath(slow_path); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4085 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4086 | Register second_reg = second.AsRegister<Register>(); |
| 4087 | // 0x80000000/-1 triggers an arithmetic exception! |
| 4088 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 4089 | // it's safe to just use negl instead of more complex comparisons. |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4090 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4091 | __ cmpl(second_reg, Immediate(-1)); |
| 4092 | __ j(kEqual, slow_path->GetEntryLabel()); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4093 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4094 | // edx:eax <- sign-extended of eax |
| 4095 | __ cdq(); |
| 4096 | // eax = quotient, edx = remainder |
| 4097 | __ idivl(second_reg); |
| 4098 | __ Bind(slow_path->GetExitLabel()); |
| 4099 | } |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4100 | break; |
| 4101 | } |
| 4102 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4103 | case DataType::Type::kInt64: { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4104 | InvokeRuntimeCallingConvention calling_convention; |
| 4105 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 4106 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 4107 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 4108 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 4109 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 4110 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 4111 | |
| 4112 | if (is_div) { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 4113 | codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4114 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4115 | } else { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 4116 | codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4117 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4118 | } |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4119 | break; |
| 4120 | } |
| 4121 | |
| 4122 | default: |
| 4123 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 4124 | } |
| 4125 | } |
| 4126 | |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4127 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4128 | LocationSummary::CallKind call_kind = (div->GetResultType() == DataType::Type::kInt64) |
| Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4129 | ? LocationSummary::kCallOnMainOnly |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4130 | : LocationSummary::kNoCall; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4131 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(div, call_kind); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4132 | |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4133 | switch (div->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4134 | case DataType::Type::kInt32: { |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4135 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4136 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4137 | locations->SetOut(Location::SameAsFirstInput()); |
| 4138 | // Intel uses edx:eax as the dividend. |
| 4139 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4140 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 4141 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 4142 | // output and request another temp. |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 4143 | if (div->InputAt(1)->IsIntConstant()) { |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4144 | locations->AddTemp(Location::RequiresRegister()); |
| 4145 | } |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4146 | break; |
| 4147 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4148 | case DataType::Type::kInt64: { |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4149 | InvokeRuntimeCallingConvention calling_convention; |
| 4150 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 4151 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4152 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 4153 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4154 | // Runtime helper puts the result in EAX, EDX. |
| 4155 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4156 | break; |
| 4157 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4158 | case DataType::Type::kFloat32: |
| 4159 | case DataType::Type::kFloat64: { |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4160 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 4161 | if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4162 | DCHECK(div->InputAt(1)->IsEmittedAtUseSite()); |
| Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 4163 | } else if (div->InputAt(1)->IsConstant()) { |
| 4164 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 4165 | } else { |
| 4166 | locations->SetInAt(1, Location::Any()); |
| 4167 | } |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4168 | locations->SetOut(Location::SameAsFirstInput()); |
| 4169 | break; |
| 4170 | } |
| 4171 | |
| 4172 | default: |
| 4173 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4174 | } |
| 4175 | } |
| 4176 | |
| 4177 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 4178 | LocationSummary* locations = div->GetLocations(); |
| 4179 | Location first = locations->InAt(0); |
| 4180 | Location second = locations->InAt(1); |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4181 | |
| 4182 | switch (div->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4183 | case DataType::Type::kInt32: |
| 4184 | case DataType::Type::kInt64: { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4185 | GenerateDivRemIntegral(div); |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4186 | break; |
| 4187 | } |
| 4188 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4189 | case DataType::Type::kFloat32: { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 4190 | if (second.IsFpuRegister()) { |
| 4191 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 4192 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4193 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 4194 | DCHECK(const_area->IsEmittedAtUseSite()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 4195 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 4196 | codegen_->LiteralFloatAddress( |
| 4197 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4198 | const_area->GetBaseMethodAddress(), |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 4199 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 4200 | } else { |
| 4201 | DCHECK(second.IsStackSlot()); |
| 4202 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 4203 | } |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4204 | break; |
| 4205 | } |
| 4206 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4207 | case DataType::Type::kFloat64: { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 4208 | if (second.IsFpuRegister()) { |
| 4209 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 4210 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4211 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 4212 | DCHECK(const_area->IsEmittedAtUseSite()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 4213 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 4214 | codegen_->LiteralDoubleAddress( |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4215 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 4216 | const_area->GetBaseMethodAddress(), |
| 4217 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 4218 | } else { |
| 4219 | DCHECK(second.IsDoubleStackSlot()); |
| 4220 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 4221 | } |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4222 | break; |
| 4223 | } |
| 4224 | |
| 4225 | default: |
| 4226 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4227 | } |
| 4228 | } |
| 4229 | |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4230 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4231 | DataType::Type type = rem->GetResultType(); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4232 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4233 | LocationSummary::CallKind call_kind = (rem->GetResultType() == DataType::Type::kInt64) |
| Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4234 | ? LocationSummary::kCallOnMainOnly |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4235 | : LocationSummary::kNoCall; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4236 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4237 | |
| Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4238 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4239 | case DataType::Type::kInt32: { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4240 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4241 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4242 | locations->SetOut(Location::RegisterLocation(EDX)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4243 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 4244 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 4245 | // output and request another temp. |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 4246 | if (rem->InputAt(1)->IsIntConstant()) { |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4247 | locations->AddTemp(Location::RequiresRegister()); |
| 4248 | } |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4249 | break; |
| 4250 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4251 | case DataType::Type::kInt64: { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4252 | InvokeRuntimeCallingConvention calling_convention; |
| 4253 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 4254 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4255 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 4256 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4257 | // Runtime helper puts the result in EAX, EDX. |
| 4258 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 4259 | break; |
| 4260 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4261 | case DataType::Type::kFloat64: |
| 4262 | case DataType::Type::kFloat32: { |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 4263 | locations->SetInAt(0, Location::Any()); |
| 4264 | locations->SetInAt(1, Location::Any()); |
| 4265 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4266 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4267 | break; |
| 4268 | } |
| 4269 | |
| 4270 | default: |
| Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4271 | LOG(FATAL) << "Unexpected rem type " << type; |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4272 | } |
| 4273 | } |
| 4274 | |
| 4275 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4276 | DataType::Type type = rem->GetResultType(); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4277 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4278 | case DataType::Type::kInt32: |
| 4279 | case DataType::Type::kInt64: { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4280 | GenerateDivRemIntegral(rem); |
| 4281 | break; |
| 4282 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4283 | case DataType::Type::kFloat32: |
| 4284 | case DataType::Type::kFloat64: { |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 4285 | GenerateRemFP(rem); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4286 | break; |
| 4287 | } |
| 4288 | default: |
| 4289 | LOG(FATAL) << "Unexpected rem type " << type; |
| 4290 | } |
| 4291 | } |
| 4292 | |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4293 | static void CreateMinMaxLocations(ArenaAllocator* allocator, HBinaryOperation* minmax) { |
| 4294 | LocationSummary* locations = new (allocator) LocationSummary(minmax); |
| 4295 | switch (minmax->GetResultType()) { |
| 4296 | case DataType::Type::kInt32: |
| 4297 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4298 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4299 | locations->SetOut(Location::SameAsFirstInput()); |
| 4300 | break; |
| 4301 | case DataType::Type::kInt64: |
| 4302 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4303 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4304 | locations->SetOut(Location::SameAsFirstInput()); |
| 4305 | // Register to use to perform a long subtract to set cc. |
| 4306 | locations->AddTemp(Location::RequiresRegister()); |
| 4307 | break; |
| 4308 | case DataType::Type::kFloat32: |
| 4309 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4310 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4311 | locations->SetOut(Location::SameAsFirstInput()); |
| 4312 | locations->AddTemp(Location::RequiresRegister()); |
| 4313 | break; |
| 4314 | case DataType::Type::kFloat64: |
| 4315 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4316 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4317 | locations->SetOut(Location::SameAsFirstInput()); |
| 4318 | break; |
| 4319 | default: |
| 4320 | LOG(FATAL) << "Unexpected type for HMinMax " << minmax->GetResultType(); |
| 4321 | } |
| 4322 | } |
| 4323 | |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4324 | void InstructionCodeGeneratorX86::GenerateMinMaxInt(LocationSummary* locations, |
| 4325 | bool is_min, |
| 4326 | DataType::Type type) { |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4327 | Location op1_loc = locations->InAt(0); |
| 4328 | Location op2_loc = locations->InAt(1); |
| 4329 | |
| 4330 | // Shortcut for same input locations. |
| 4331 | if (op1_loc.Equals(op2_loc)) { |
| 4332 | // Can return immediately, as op1_loc == out_loc. |
| 4333 | // Note: if we ever support separate registers, e.g., output into memory, we need to check for |
| 4334 | // a copy here. |
| 4335 | DCHECK(locations->Out().Equals(op1_loc)); |
| 4336 | return; |
| 4337 | } |
| 4338 | |
| 4339 | if (type == DataType::Type::kInt64) { |
| 4340 | // Need to perform a subtract to get the sign right. |
| 4341 | // op1 is already in the same location as the output. |
| 4342 | Location output = locations->Out(); |
| 4343 | Register output_lo = output.AsRegisterPairLow<Register>(); |
| 4344 | Register output_hi = output.AsRegisterPairHigh<Register>(); |
| 4345 | |
| 4346 | Register op2_lo = op2_loc.AsRegisterPairLow<Register>(); |
| 4347 | Register op2_hi = op2_loc.AsRegisterPairHigh<Register>(); |
| 4348 | |
| 4349 | // The comparison is performed by subtracting the second operand from |
| 4350 | // the first operand and then setting the status flags in the same |
| 4351 | // manner as the SUB instruction." |
| 4352 | __ cmpl(output_lo, op2_lo); |
| 4353 | |
| 4354 | // Now use a temp and the borrow to finish the subtraction of op2_hi. |
| 4355 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4356 | __ movl(temp, output_hi); |
| 4357 | __ sbbl(temp, op2_hi); |
| 4358 | |
| 4359 | // Now the condition code is correct. |
| 4360 | Condition cond = is_min ? Condition::kGreaterEqual : Condition::kLess; |
| 4361 | __ cmovl(cond, output_lo, op2_lo); |
| 4362 | __ cmovl(cond, output_hi, op2_hi); |
| 4363 | } else { |
| 4364 | DCHECK_EQ(type, DataType::Type::kInt32); |
| 4365 | Register out = locations->Out().AsRegister<Register>(); |
| 4366 | Register op2 = op2_loc.AsRegister<Register>(); |
| 4367 | |
| 4368 | // (out := op1) |
| 4369 | // out <=? op2 |
| 4370 | // if out is min jmp done |
| 4371 | // out := op2 |
| 4372 | // done: |
| 4373 | |
| 4374 | __ cmpl(out, op2); |
| 4375 | Condition cond = is_min ? Condition::kGreater : Condition::kLess; |
| 4376 | __ cmovl(cond, out, op2); |
| 4377 | } |
| 4378 | } |
| 4379 | |
| 4380 | void InstructionCodeGeneratorX86::GenerateMinMaxFP(LocationSummary* locations, |
| 4381 | bool is_min, |
| 4382 | DataType::Type type) { |
| 4383 | Location op1_loc = locations->InAt(0); |
| 4384 | Location op2_loc = locations->InAt(1); |
| 4385 | Location out_loc = locations->Out(); |
| 4386 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
| 4387 | |
| 4388 | // Shortcut for same input locations. |
| 4389 | if (op1_loc.Equals(op2_loc)) { |
| 4390 | DCHECK(out_loc.Equals(op1_loc)); |
| 4391 | return; |
| 4392 | } |
| 4393 | |
| 4394 | // (out := op1) |
| 4395 | // out <=? op2 |
| 4396 | // if Nan jmp Nan_label |
| 4397 | // if out is min jmp done |
| 4398 | // if op2 is min jmp op2_label |
| 4399 | // handle -0/+0 |
| 4400 | // jmp done |
| 4401 | // Nan_label: |
| 4402 | // out := NaN |
| 4403 | // op2_label: |
| 4404 | // out := op2 |
| 4405 | // done: |
| 4406 | // |
| 4407 | // This removes one jmp, but needs to copy one input (op1) to out. |
| 4408 | // |
| 4409 | // TODO: This is straight from Quick (except literal pool). Make NaN an out-of-line slowpath? |
| 4410 | |
| 4411 | XmmRegister op2 = op2_loc.AsFpuRegister<XmmRegister>(); |
| 4412 | |
| 4413 | NearLabel nan, done, op2_label; |
| 4414 | if (type == DataType::Type::kFloat64) { |
| 4415 | __ ucomisd(out, op2); |
| 4416 | } else { |
| 4417 | DCHECK_EQ(type, DataType::Type::kFloat32); |
| 4418 | __ ucomiss(out, op2); |
| 4419 | } |
| 4420 | |
| 4421 | __ j(Condition::kParityEven, &nan); |
| 4422 | |
| 4423 | __ j(is_min ? Condition::kAbove : Condition::kBelow, &op2_label); |
| 4424 | __ j(is_min ? Condition::kBelow : Condition::kAbove, &done); |
| 4425 | |
| 4426 | // Handle 0.0/-0.0. |
| 4427 | if (is_min) { |
| 4428 | if (type == DataType::Type::kFloat64) { |
| 4429 | __ orpd(out, op2); |
| 4430 | } else { |
| 4431 | __ orps(out, op2); |
| 4432 | } |
| 4433 | } else { |
| 4434 | if (type == DataType::Type::kFloat64) { |
| 4435 | __ andpd(out, op2); |
| 4436 | } else { |
| 4437 | __ andps(out, op2); |
| 4438 | } |
| 4439 | } |
| 4440 | __ jmp(&done); |
| 4441 | |
| 4442 | // NaN handling. |
| 4443 | __ Bind(&nan); |
| 4444 | if (type == DataType::Type::kFloat64) { |
| 4445 | // TODO: Use a constant from the constant table (requires extra input). |
| 4446 | __ LoadLongConstant(out, kDoubleNaN); |
| 4447 | } else { |
| 4448 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 4449 | __ movl(constant, Immediate(kFloatNaN)); |
| 4450 | __ movd(out, constant); |
| 4451 | } |
| 4452 | __ jmp(&done); |
| 4453 | |
| 4454 | // out := op2; |
| 4455 | __ Bind(&op2_label); |
| 4456 | if (type == DataType::Type::kFloat64) { |
| 4457 | __ movsd(out, op2); |
| 4458 | } else { |
| 4459 | __ movss(out, op2); |
| 4460 | } |
| 4461 | |
| 4462 | // Done. |
| 4463 | __ Bind(&done); |
| 4464 | } |
| 4465 | |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4466 | void InstructionCodeGeneratorX86::GenerateMinMax(HBinaryOperation* minmax, bool is_min) { |
| 4467 | DataType::Type type = minmax->GetResultType(); |
| 4468 | switch (type) { |
| 4469 | case DataType::Type::kInt32: |
| 4470 | case DataType::Type::kInt64: |
| 4471 | GenerateMinMaxInt(minmax->GetLocations(), is_min, type); |
| 4472 | break; |
| 4473 | case DataType::Type::kFloat32: |
| 4474 | case DataType::Type::kFloat64: |
| 4475 | GenerateMinMaxFP(minmax->GetLocations(), is_min, type); |
| 4476 | break; |
| 4477 | default: |
| 4478 | LOG(FATAL) << "Unexpected type for HMinMax " << type; |
| 4479 | } |
| 4480 | } |
| 4481 | |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4482 | void LocationsBuilderX86::VisitMin(HMin* min) { |
| 4483 | CreateMinMaxLocations(GetGraph()->GetAllocator(), min); |
| 4484 | } |
| 4485 | |
| 4486 | void InstructionCodeGeneratorX86::VisitMin(HMin* min) { |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4487 | GenerateMinMax(min, /*is_min*/ true); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4488 | } |
| 4489 | |
| 4490 | void LocationsBuilderX86::VisitMax(HMax* max) { |
| 4491 | CreateMinMaxLocations(GetGraph()->GetAllocator(), max); |
| 4492 | } |
| 4493 | |
| 4494 | void InstructionCodeGeneratorX86::VisitMax(HMax* max) { |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4495 | GenerateMinMax(max, /*is_min*/ false); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4496 | } |
| 4497 | |
| Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 4498 | void LocationsBuilderX86::VisitAbs(HAbs* abs) { |
| 4499 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 4500 | switch (abs->GetResultType()) { |
| 4501 | case DataType::Type::kInt32: |
| 4502 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 4503 | locations->SetOut(Location::SameAsFirstInput()); |
| 4504 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 4505 | break; |
| 4506 | case DataType::Type::kInt64: |
| 4507 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4508 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4509 | locations->AddTemp(Location::RequiresRegister()); |
| 4510 | break; |
| 4511 | case DataType::Type::kFloat32: |
| 4512 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4513 | locations->SetOut(Location::SameAsFirstInput()); |
| 4514 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4515 | locations->AddTemp(Location::RequiresRegister()); |
| 4516 | break; |
| 4517 | case DataType::Type::kFloat64: |
| 4518 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4519 | locations->SetOut(Location::SameAsFirstInput()); |
| 4520 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4521 | break; |
| 4522 | default: |
| 4523 | LOG(FATAL) << "Unexpected type for HAbs " << abs->GetResultType(); |
| 4524 | } |
| 4525 | } |
| 4526 | |
| 4527 | void InstructionCodeGeneratorX86::VisitAbs(HAbs* abs) { |
| 4528 | LocationSummary* locations = abs->GetLocations(); |
| 4529 | switch (abs->GetResultType()) { |
| 4530 | case DataType::Type::kInt32: { |
| 4531 | Register out = locations->Out().AsRegister<Register>(); |
| 4532 | DCHECK_EQ(out, EAX); |
| 4533 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4534 | DCHECK_EQ(temp, EDX); |
| 4535 | // Sign extend EAX into EDX. |
| 4536 | __ cdq(); |
| 4537 | // XOR EAX with sign. |
| 4538 | __ xorl(EAX, EDX); |
| 4539 | // Subtract out sign to correct. |
| 4540 | __ subl(EAX, EDX); |
| 4541 | // The result is in EAX. |
| 4542 | break; |
| 4543 | } |
| 4544 | case DataType::Type::kInt64: { |
| 4545 | Location input = locations->InAt(0); |
| 4546 | Register input_lo = input.AsRegisterPairLow<Register>(); |
| 4547 | Register input_hi = input.AsRegisterPairHigh<Register>(); |
| 4548 | Location output = locations->Out(); |
| 4549 | Register output_lo = output.AsRegisterPairLow<Register>(); |
| 4550 | Register output_hi = output.AsRegisterPairHigh<Register>(); |
| 4551 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4552 | // Compute the sign into the temporary. |
| 4553 | __ movl(temp, input_hi); |
| 4554 | __ sarl(temp, Immediate(31)); |
| 4555 | // Store the sign into the output. |
| 4556 | __ movl(output_lo, temp); |
| 4557 | __ movl(output_hi, temp); |
| 4558 | // XOR the input to the output. |
| 4559 | __ xorl(output_lo, input_lo); |
| 4560 | __ xorl(output_hi, input_hi); |
| 4561 | // Subtract the sign. |
| 4562 | __ subl(output_lo, temp); |
| 4563 | __ sbbl(output_hi, temp); |
| 4564 | break; |
| 4565 | } |
| 4566 | case DataType::Type::kFloat32: { |
| 4567 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4568 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4569 | Register constant = locations->GetTemp(1).AsRegister<Register>(); |
| 4570 | __ movl(constant, Immediate(INT32_C(0x7FFFFFFF))); |
| 4571 | __ movd(temp, constant); |
| 4572 | __ andps(out, temp); |
| 4573 | break; |
| 4574 | } |
| 4575 | case DataType::Type::kFloat64: { |
| 4576 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4577 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4578 | // TODO: Use a constant from the constant table (requires extra input). |
| 4579 | __ LoadLongConstant(temp, INT64_C(0x7FFFFFFFFFFFFFFF)); |
| 4580 | __ andpd(out, temp); |
| 4581 | break; |
| 4582 | } |
| 4583 | default: |
| 4584 | LOG(FATAL) << "Unexpected type for HAbs " << abs->GetResultType(); |
| 4585 | } |
| 4586 | } |
| 4587 | |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4588 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4589 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4590 | switch (instruction->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4591 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4592 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4593 | case DataType::Type::kInt8: |
| 4594 | case DataType::Type::kUint16: |
| 4595 | case DataType::Type::kInt16: |
| 4596 | case DataType::Type::kInt32: { |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4597 | locations->SetInAt(0, Location::Any()); |
| 4598 | break; |
| 4599 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4600 | case DataType::Type::kInt64: { |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4601 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 4602 | if (!instruction->IsConstant()) { |
| 4603 | locations->AddTemp(Location::RequiresRegister()); |
| 4604 | } |
| 4605 | break; |
| 4606 | } |
| 4607 | default: |
| 4608 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 4609 | } |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4610 | } |
| 4611 | |
| 4612 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4613 | SlowPathCode* slow_path = |
| 4614 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathX86(instruction); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4615 | codegen_->AddSlowPath(slow_path); |
| 4616 | |
| 4617 | LocationSummary* locations = instruction->GetLocations(); |
| 4618 | Location value = locations->InAt(0); |
| 4619 | |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4620 | switch (instruction->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4621 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4622 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4623 | case DataType::Type::kInt8: |
| 4624 | case DataType::Type::kUint16: |
| 4625 | case DataType::Type::kInt16: |
| 4626 | case DataType::Type::kInt32: { |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4627 | if (value.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4628 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4629 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4630 | } else if (value.IsStackSlot()) { |
| 4631 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 4632 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4633 | } else { |
| 4634 | DCHECK(value.IsConstant()) << value; |
| 4635 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4636 | __ jmp(slow_path->GetEntryLabel()); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4637 | } |
| 4638 | } |
| 4639 | break; |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4640 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4641 | case DataType::Type::kInt64: { |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4642 | if (value.IsRegisterPair()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4643 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4644 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 4645 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 4646 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4647 | } else { |
| 4648 | DCHECK(value.IsConstant()) << value; |
| 4649 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 4650 | __ jmp(slow_path->GetEntryLabel()); |
| 4651 | } |
| 4652 | } |
| 4653 | break; |
| 4654 | } |
| 4655 | default: |
| 4656 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4657 | } |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4658 | } |
| 4659 | |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4660 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 4661 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4662 | |
| 4663 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4664 | new (GetGraph()->GetAllocator()) LocationSummary(op, LocationSummary::kNoCall); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4665 | |
| 4666 | switch (op->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4667 | case DataType::Type::kInt32: |
| 4668 | case DataType::Type::kInt64: { |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4669 | // Can't have Location::Any() and output SameAsFirstInput() |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4670 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4671 | // The shift count needs to be in CL or a constant. |
| 4672 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4673 | locations->SetOut(Location::SameAsFirstInput()); |
| 4674 | break; |
| 4675 | } |
| 4676 | default: |
| 4677 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 4678 | } |
| 4679 | } |
| 4680 | |
| 4681 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 4682 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4683 | |
| 4684 | LocationSummary* locations = op->GetLocations(); |
| 4685 | Location first = locations->InAt(0); |
| 4686 | Location second = locations->InAt(1); |
| 4687 | DCHECK(first.Equals(locations->Out())); |
| 4688 | |
| 4689 | switch (op->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4690 | case DataType::Type::kInt32: { |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4691 | DCHECK(first.IsRegister()); |
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4692 | Register first_reg = first.AsRegister<Register>(); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4693 | if (second.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4694 | Register second_reg = second.AsRegister<Register>(); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4695 | DCHECK_EQ(ECX, second_reg); |
| 4696 | if (op->IsShl()) { |
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4697 | __ shll(first_reg, second_reg); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4698 | } else if (op->IsShr()) { |
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4699 | __ sarl(first_reg, second_reg); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4700 | } else { |
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4701 | __ shrl(first_reg, second_reg); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4702 | } |
| 4703 | } else { |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4704 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance; |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4705 | if (shift == 0) { |
| 4706 | return; |
| 4707 | } |
| 4708 | Immediate imm(shift); |
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4709 | if (op->IsShl()) { |
| 4710 | __ shll(first_reg, imm); |
| 4711 | } else if (op->IsShr()) { |
| 4712 | __ sarl(first_reg, imm); |
| 4713 | } else { |
| 4714 | __ shrl(first_reg, imm); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4715 | } |
| 4716 | } |
| 4717 | break; |
| 4718 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4719 | case DataType::Type::kInt64: { |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4720 | if (second.IsRegister()) { |
| 4721 | Register second_reg = second.AsRegister<Register>(); |
| 4722 | DCHECK_EQ(ECX, second_reg); |
| 4723 | if (op->IsShl()) { |
| 4724 | GenerateShlLong(first, second_reg); |
| 4725 | } else if (op->IsShr()) { |
| 4726 | GenerateShrLong(first, second_reg); |
| 4727 | } else { |
| 4728 | GenerateUShrLong(first, second_reg); |
| 4729 | } |
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4730 | } else { |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4731 | // Shift by a constant. |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4732 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4733 | // Nothing to do if the shift is 0, as the input is already the output. |
| 4734 | if (shift != 0) { |
| 4735 | if (op->IsShl()) { |
| 4736 | GenerateShlLong(first, shift); |
| 4737 | } else if (op->IsShr()) { |
| 4738 | GenerateShrLong(first, shift); |
| 4739 | } else { |
| 4740 | GenerateUShrLong(first, shift); |
| 4741 | } |
| 4742 | } |
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4743 | } |
| 4744 | break; |
| 4745 | } |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4746 | default: |
| 4747 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 4748 | } |
| 4749 | } |
| 4750 | |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4751 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 4752 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4753 | Register high = loc.AsRegisterPairHigh<Register>(); |
| Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 4754 | if (shift == 1) { |
| 4755 | // This is just an addition. |
| 4756 | __ addl(low, low); |
| 4757 | __ adcl(high, high); |
| 4758 | } else if (shift == 32) { |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4759 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 4760 | codegen_->EmitParallelMoves( |
| 4761 | loc.ToLow(), |
| 4762 | loc.ToHigh(), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4763 | DataType::Type::kInt32, |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4764 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 4765 | loc.ToLow(), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4766 | DataType::Type::kInt32); |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4767 | } else if (shift > 32) { |
| 4768 | // Low part becomes 0. High part is low part << (shift-32). |
| 4769 | __ movl(high, low); |
| 4770 | __ shll(high, Immediate(shift - 32)); |
| 4771 | __ xorl(low, low); |
| 4772 | } else { |
| 4773 | // Between 1 and 31. |
| 4774 | __ shld(high, low, Immediate(shift)); |
| 4775 | __ shll(low, Immediate(shift)); |
| 4776 | } |
| 4777 | } |
| 4778 | |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4779 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4780 | NearLabel done; |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4781 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 4782 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 4783 | __ testl(shifter, Immediate(32)); |
| 4784 | __ j(kEqual, &done); |
| 4785 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 4786 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 4787 | __ Bind(&done); |
| 4788 | } |
| 4789 | |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4790 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 4791 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4792 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 4793 | if (shift == 32) { |
| 4794 | // Need to copy the sign. |
| 4795 | DCHECK_NE(low, high); |
| 4796 | __ movl(low, high); |
| 4797 | __ sarl(high, Immediate(31)); |
| 4798 | } else if (shift > 32) { |
| 4799 | DCHECK_NE(low, high); |
| 4800 | // High part becomes sign. Low part is shifted by shift - 32. |
| 4801 | __ movl(low, high); |
| 4802 | __ sarl(high, Immediate(31)); |
| 4803 | __ sarl(low, Immediate(shift - 32)); |
| 4804 | } else { |
| 4805 | // Between 1 and 31. |
| 4806 | __ shrd(low, high, Immediate(shift)); |
| 4807 | __ sarl(high, Immediate(shift)); |
| 4808 | } |
| 4809 | } |
| 4810 | |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4811 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4812 | NearLabel done; |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4813 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4814 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4815 | __ testl(shifter, Immediate(32)); |
| 4816 | __ j(kEqual, &done); |
| 4817 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4818 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 4819 | __ Bind(&done); |
| 4820 | } |
| 4821 | |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4822 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 4823 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4824 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 4825 | if (shift == 32) { |
| 4826 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 4827 | codegen_->EmitParallelMoves( |
| 4828 | loc.ToHigh(), |
| 4829 | loc.ToLow(), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4830 | DataType::Type::kInt32, |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4831 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 4832 | loc.ToHigh(), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4833 | DataType::Type::kInt32); |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4834 | } else if (shift > 32) { |
| 4835 | // Low part is high >> (shift - 32). High part becomes 0. |
| 4836 | __ movl(low, high); |
| 4837 | __ shrl(low, Immediate(shift - 32)); |
| 4838 | __ xorl(high, high); |
| 4839 | } else { |
| 4840 | // Between 1 and 31. |
| 4841 | __ shrd(low, high, Immediate(shift)); |
| 4842 | __ shrl(high, Immediate(shift)); |
| 4843 | } |
| 4844 | } |
| 4845 | |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4846 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4847 | NearLabel done; |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4848 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4849 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4850 | __ testl(shifter, Immediate(32)); |
| 4851 | __ j(kEqual, &done); |
| 4852 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4853 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 4854 | __ Bind(&done); |
| 4855 | } |
| 4856 | |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4857 | void LocationsBuilderX86::VisitRor(HRor* ror) { |
| 4858 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4859 | new (GetGraph()->GetAllocator()) LocationSummary(ror, LocationSummary::kNoCall); |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4860 | |
| 4861 | switch (ror->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4862 | case DataType::Type::kInt64: |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4863 | // Add the temporary needed. |
| 4864 | locations->AddTemp(Location::RequiresRegister()); |
| 4865 | FALLTHROUGH_INTENDED; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4866 | case DataType::Type::kInt32: |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4867 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4868 | // The shift count needs to be in CL (unless it is a constant). |
| 4869 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); |
| 4870 | locations->SetOut(Location::SameAsFirstInput()); |
| 4871 | break; |
| 4872 | default: |
| 4873 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4874 | UNREACHABLE(); |
| 4875 | } |
| 4876 | } |
| 4877 | |
| 4878 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { |
| 4879 | LocationSummary* locations = ror->GetLocations(); |
| 4880 | Location first = locations->InAt(0); |
| 4881 | Location second = locations->InAt(1); |
| 4882 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4883 | if (ror->GetResultType() == DataType::Type::kInt32) { |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4884 | Register first_reg = first.AsRegister<Register>(); |
| 4885 | if (second.IsRegister()) { |
| 4886 | Register second_reg = second.AsRegister<Register>(); |
| 4887 | __ rorl(first_reg, second_reg); |
| 4888 | } else { |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4889 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4890 | __ rorl(first_reg, imm); |
| 4891 | } |
| 4892 | return; |
| 4893 | } |
| 4894 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4895 | DCHECK_EQ(ror->GetResultType(), DataType::Type::kInt64); |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4896 | Register first_reg_lo = first.AsRegisterPairLow<Register>(); |
| 4897 | Register first_reg_hi = first.AsRegisterPairHigh<Register>(); |
| 4898 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 4899 | if (second.IsRegister()) { |
| 4900 | Register second_reg = second.AsRegister<Register>(); |
| 4901 | DCHECK_EQ(second_reg, ECX); |
| 4902 | __ movl(temp_reg, first_reg_hi); |
| 4903 | __ shrd(first_reg_hi, first_reg_lo, second_reg); |
| 4904 | __ shrd(first_reg_lo, temp_reg, second_reg); |
| 4905 | __ movl(temp_reg, first_reg_hi); |
| 4906 | __ testl(second_reg, Immediate(32)); |
| 4907 | __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); |
| 4908 | __ cmovl(kNotEqual, first_reg_lo, temp_reg); |
| 4909 | } else { |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4910 | int32_t shift_amt = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4911 | if (shift_amt == 0) { |
| 4912 | // Already fine. |
| 4913 | return; |
| 4914 | } |
| 4915 | if (shift_amt == 32) { |
| 4916 | // Just swap. |
| 4917 | __ movl(temp_reg, first_reg_lo); |
| 4918 | __ movl(first_reg_lo, first_reg_hi); |
| 4919 | __ movl(first_reg_hi, temp_reg); |
| 4920 | return; |
| 4921 | } |
| 4922 | |
| 4923 | Immediate imm(shift_amt); |
| 4924 | // Save the constents of the low value. |
| 4925 | __ movl(temp_reg, first_reg_lo); |
| 4926 | |
| 4927 | // Shift right into low, feeding bits from high. |
| 4928 | __ shrd(first_reg_lo, first_reg_hi, imm); |
| 4929 | |
| 4930 | // Shift right into high, feeding bits from the original low. |
| 4931 | __ shrd(first_reg_hi, temp_reg, imm); |
| 4932 | |
| 4933 | // Swap if needed. |
| 4934 | if (shift_amt > 32) { |
| 4935 | __ movl(temp_reg, first_reg_lo); |
| 4936 | __ movl(first_reg_lo, first_reg_hi); |
| 4937 | __ movl(first_reg_hi, temp_reg); |
| 4938 | } |
| 4939 | } |
| 4940 | } |
| 4941 | |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4942 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 4943 | HandleShift(shl); |
| 4944 | } |
| 4945 | |
| 4946 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 4947 | HandleShift(shl); |
| 4948 | } |
| 4949 | |
| 4950 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 4951 | HandleShift(shr); |
| 4952 | } |
| 4953 | |
| 4954 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 4955 | HandleShift(shr); |
| 4956 | } |
| 4957 | |
| 4958 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 4959 | HandleShift(ushr); |
| 4960 | } |
| 4961 | |
| 4962 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 4963 | HandleShift(ushr); |
| 4964 | } |
| 4965 | |
| Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4966 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4967 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4968 | instruction, LocationSummary::kCallOnMainOnly); |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4969 | locations->SetOut(Location::RegisterLocation(EAX)); |
| Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 4970 | InvokeRuntimeCallingConvention calling_convention; |
| 4971 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4972 | } |
| 4973 | |
| 4974 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
| Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 4975 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
| 4976 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| 4977 | DCHECK(!codegen_->IsLeafMethod()); |
| Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4978 | } |
| 4979 | |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4980 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4981 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4982 | instruction, LocationSummary::kCallOnMainOnly); |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4983 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 4984 | InvokeRuntimeCallingConvention calling_convention; |
| Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4985 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4986 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4987 | } |
| 4988 | |
| 4989 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
| Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 4990 | // Note: if heap poisoning is enabled, the entry point takes care of poisoning the reference. |
| 4991 | QuickEntrypointEnum entrypoint = CodeGenerator::GetArrayAllocationEntrypoint(instruction); |
| Nicolas Geoffray | d095844 | 2017-01-30 14:57:16 +0000 | [diff] [blame] | 4992 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
| Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4993 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4994 | DCHECK(!codegen_->IsLeafMethod()); |
| 4995 | } |
| 4996 | |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4997 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4998 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4999 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 5000 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 5001 | if (location.IsStackSlot()) { |
| 5002 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5003 | } else if (location.IsDoubleStackSlot()) { |
| 5004 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5005 | } |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 5006 | locations->SetOut(location); |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5007 | } |
| 5008 | |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5009 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 5010 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 5011 | } |
| 5012 | |
| 5013 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 5014 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5015 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5016 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 5017 | } |
| 5018 | |
| 5019 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5020 | } |
| 5021 | |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5022 | void LocationsBuilderX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 5023 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5024 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5025 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5026 | locations->SetOut(Location::RequiresRegister()); |
| 5027 | } |
| 5028 | |
| 5029 | void InstructionCodeGeneratorX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 5030 | LocationSummary* locations = instruction->GetLocations(); |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5031 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 5032 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5033 | instruction->GetIndex(), kX86PointerSize).SizeValue(); |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 5034 | __ movl(locations->Out().AsRegister<Register>(), |
| 5035 | Address(locations->InAt(0).AsRegister<Register>(), method_offset)); |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5036 | } else { |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 5037 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 5038 | instruction->GetIndex(), kX86PointerSize)); |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 5039 | __ movl(locations->Out().AsRegister<Register>(), |
| 5040 | Address(locations->InAt(0).AsRegister<Register>(), |
| 5041 | mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
| 5042 | // temp = temp->GetImtEntryAt(method_offset); |
| 5043 | __ movl(locations->Out().AsRegister<Register>(), |
| 5044 | Address(locations->Out().AsRegister<Register>(), method_offset)); |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5045 | } |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5046 | } |
| 5047 | |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 5048 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5049 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5050 | new (GetGraph()->GetAllocator()) LocationSummary(not_, LocationSummary::kNoCall); |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 5051 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5052 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5053 | } |
| 5054 | |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 5055 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 5056 | LocationSummary* locations = not_->GetLocations(); |
| Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 5057 | Location in = locations->InAt(0); |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 5058 | Location out = locations->Out(); |
| Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 5059 | DCHECK(in.Equals(out)); |
| Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 5060 | switch (not_->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5061 | case DataType::Type::kInt32: |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5062 | __ notl(out.AsRegister<Register>()); |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 5063 | break; |
| 5064 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5065 | case DataType::Type::kInt64: |
| Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 5066 | __ notl(out.AsRegisterPairLow<Register>()); |
| 5067 | __ notl(out.AsRegisterPairHigh<Register>()); |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 5068 | break; |
| 5069 | |
| 5070 | default: |
| 5071 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 5072 | } |
| Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5073 | } |
| 5074 | |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5075 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 5076 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5077 | new (GetGraph()->GetAllocator()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5078 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5079 | locations->SetOut(Location::SameAsFirstInput()); |
| 5080 | } |
| 5081 | |
| 5082 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5083 | LocationSummary* locations = bool_not->GetLocations(); |
| 5084 | Location in = locations->InAt(0); |
| 5085 | Location out = locations->Out(); |
| 5086 | DCHECK(in.Equals(out)); |
| 5087 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 5088 | } |
| 5089 | |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5090 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5091 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5092 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5093 | switch (compare->InputAt(0)->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5094 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5095 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5096 | case DataType::Type::kInt8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5097 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5098 | case DataType::Type::kInt16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5099 | case DataType::Type::kInt32: |
| 5100 | case DataType::Type::kInt64: { |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5101 | locations->SetInAt(0, Location::RequiresRegister()); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5102 | locations->SetInAt(1, Location::Any()); |
| 5103 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5104 | break; |
| 5105 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5106 | case DataType::Type::kFloat32: |
| 5107 | case DataType::Type::kFloat64: { |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5108 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 5109 | if (compare->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 5110 | DCHECK(compare->InputAt(1)->IsEmittedAtUseSite()); |
| 5111 | } else if (compare->InputAt(1)->IsConstant()) { |
| 5112 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 5113 | } else { |
| 5114 | locations->SetInAt(1, Location::Any()); |
| 5115 | } |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5116 | locations->SetOut(Location::RequiresRegister()); |
| 5117 | break; |
| 5118 | } |
| 5119 | default: |
| 5120 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 5121 | } |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5122 | } |
| 5123 | |
| 5124 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5125 | LocationSummary* locations = compare->GetLocations(); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5126 | Register out = locations->Out().AsRegister<Register>(); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5127 | Location left = locations->InAt(0); |
| 5128 | Location right = locations->InAt(1); |
| 5129 | |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 5130 | NearLabel less, greater, done; |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5131 | Condition less_cond = kLess; |
| 5132 | |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5133 | switch (compare->InputAt(0)->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5134 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5135 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5136 | case DataType::Type::kInt8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5137 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5138 | case DataType::Type::kInt16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5139 | case DataType::Type::kInt32: { |
| Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 5140 | codegen_->GenerateIntCompare(left, right); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5141 | break; |
| 5142 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5143 | case DataType::Type::kInt64: { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5144 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 5145 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 5146 | int32_t val_low = 0; |
| 5147 | int32_t val_high = 0; |
| 5148 | bool right_is_const = false; |
| 5149 | |
| 5150 | if (right.IsConstant()) { |
| 5151 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 5152 | right_is_const = true; |
| 5153 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 5154 | val_low = Low32Bits(val); |
| 5155 | val_high = High32Bits(val); |
| 5156 | } |
| 5157 | |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5158 | if (right.IsRegisterPair()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5159 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5160 | } else if (right.IsDoubleStackSlot()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5161 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5162 | } else { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5163 | DCHECK(right_is_const) << right; |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5164 | codegen_->Compare32BitValue(left_high, val_high); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5165 | } |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5166 | __ j(kLess, &less); // Signed compare. |
| 5167 | __ j(kGreater, &greater); // Signed compare. |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5168 | if (right.IsRegisterPair()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5169 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5170 | } else if (right.IsDoubleStackSlot()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5171 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5172 | } else { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5173 | DCHECK(right_is_const) << right; |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5174 | codegen_->Compare32BitValue(left_low, val_low); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5175 | } |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5176 | less_cond = kBelow; // for CF (unsigned). |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5177 | break; |
| 5178 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5179 | case DataType::Type::kFloat32: { |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 5180 | GenerateFPCompare(left, right, compare, false); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5181 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5182 | less_cond = kBelow; // for CF (floats). |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5183 | break; |
| 5184 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5185 | case DataType::Type::kFloat64: { |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 5186 | GenerateFPCompare(left, right, compare, true); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5187 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5188 | less_cond = kBelow; // for CF (floats). |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5189 | break; |
| 5190 | } |
| 5191 | default: |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5192 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5193 | } |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5194 | |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5195 | __ movl(out, Immediate(0)); |
| 5196 | __ j(kEqual, &done); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5197 | __ j(less_cond, &less); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5198 | |
| 5199 | __ Bind(&greater); |
| 5200 | __ movl(out, Immediate(1)); |
| 5201 | __ jmp(&done); |
| 5202 | |
| 5203 | __ Bind(&less); |
| 5204 | __ movl(out, Immediate(-1)); |
| 5205 | |
| 5206 | __ Bind(&done); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5207 | } |
| 5208 | |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 5209 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5210 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5211 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5212 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
| Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 5213 | locations->SetInAt(i, Location::Any()); |
| 5214 | } |
| 5215 | locations->SetOut(Location::Any()); |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 5216 | } |
| 5217 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5218 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5219 | LOG(FATAL) << "Unreachable"; |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 5220 | } |
| 5221 | |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5222 | void CodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5223 | /* |
| 5224 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 5225 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 5226 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 5227 | */ |
| 5228 | switch (kind) { |
| 5229 | case MemBarrierKind::kAnyAny: { |
| Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 5230 | MemoryFence(); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5231 | break; |
| 5232 | } |
| 5233 | case MemBarrierKind::kAnyStore: |
| 5234 | case MemBarrierKind::kLoadAny: |
| 5235 | case MemBarrierKind::kStoreStore: { |
| 5236 | // nop |
| 5237 | break; |
| 5238 | } |
| Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 5239 | case MemBarrierKind::kNTStoreStore: |
| 5240 | // Non-Temporal Store/Store needs an explicit fence. |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5241 | MemoryFence(/* non-temporal= */ true); |
| Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 5242 | break; |
| Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 5243 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5244 | } |
| 5245 | |
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5246 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( |
| 5247 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| Nicolas Geoffray | bdb2ecc | 2018-09-18 14:33:55 +0100 | [diff] [blame] | 5248 | ArtMethod* method ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 5249 | return desired_dispatch_info; |
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5250 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5251 | |
| Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5252 | Register CodeGeneratorX86::GetInvokeExtraParameter(HInvoke* invoke, Register temp) { |
| 5253 | if (invoke->IsInvokeStaticOrDirect()) { |
| 5254 | return GetInvokeStaticOrDirectExtraParameter(invoke->AsInvokeStaticOrDirect(), temp); |
| 5255 | } |
| 5256 | DCHECK(invoke->IsInvokeInterface()); |
| 5257 | Location location = |
| 5258 | invoke->GetLocations()->InAt(invoke->AsInvokeInterface()->GetSpecialInputIndex()); |
| 5259 | return location.AsRegister<Register>(); |
| 5260 | } |
| 5261 | |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 5262 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 5263 | Register temp) { |
| Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 5264 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 5265 | if (!invoke->GetLocations()->Intrinsified()) { |
| 5266 | return location.AsRegister<Register>(); |
| 5267 | } |
| 5268 | // For intrinsics we allow any location, so it may be on the stack. |
| 5269 | if (!location.IsRegister()) { |
| 5270 | __ movl(temp, Address(ESP, location.GetStackIndex())); |
| 5271 | return temp; |
| 5272 | } |
| 5273 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 5274 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 5275 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 5276 | // simple and more robust approach rather that trying to determine if that's the case. |
| 5277 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| Vladimir Marko | 4ee8e29 | 2017-06-02 15:39:30 +0000 | [diff] [blame] | 5278 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 5279 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 5280 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 5281 | __ movl(temp, Address(ESP, stack_offset)); |
| 5282 | return temp; |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 5283 | } |
| 5284 | return location.AsRegister<Register>(); |
| 5285 | } |
| 5286 | |
| Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5287 | void CodeGeneratorX86::LoadMethod(MethodLoadKind load_kind, Location temp, HInvoke* invoke) { |
| 5288 | switch (load_kind) { |
| 5289 | case MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 5290 | DCHECK(GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()); |
| 5291 | Register base_reg = GetInvokeExtraParameter(invoke, temp.AsRegister<Register>()); |
| 5292 | __ leal(temp.AsRegister<Register>(), |
| 5293 | Address(base_reg, CodeGeneratorX86::kPlaceholder32BitOffset)); |
| 5294 | RecordBootImageMethodPatch(invoke); |
| 5295 | break; |
| 5296 | } |
| 5297 | case MethodLoadKind::kBootImageRelRo: { |
| 5298 | size_t index = invoke->IsInvokeInterface() |
| 5299 | ? invoke->AsInvokeInterface()->GetSpecialInputIndex() |
| 5300 | : invoke->AsInvokeStaticOrDirect()->GetSpecialInputIndex(); |
| 5301 | Register base_reg = GetInvokeExtraParameter(invoke, temp.AsRegister<Register>()); |
| 5302 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kPlaceholder32BitOffset)); |
| 5303 | RecordBootImageRelRoPatch( |
| 5304 | invoke->InputAt(index)->AsX86ComputeBaseMethodAddress(), |
| 5305 | GetBootImageOffset(invoke)); |
| 5306 | break; |
| 5307 | } |
| 5308 | case MethodLoadKind::kBssEntry: { |
| 5309 | Register base_reg = GetInvokeExtraParameter(invoke, temp.AsRegister<Register>()); |
| 5310 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kPlaceholder32BitOffset)); |
| 5311 | RecordMethodBssEntryPatch(invoke); |
| 5312 | // No need for memory fence, thanks to the x86 memory model. |
| 5313 | break; |
| 5314 | } |
| 5315 | case MethodLoadKind::kJitDirectAddress: { |
| 5316 | __ movl(temp.AsRegister<Register>(), |
| 5317 | Immediate(reinterpret_cast32<uint32_t>(invoke->GetResolvedMethod()))); |
| 5318 | break; |
| 5319 | } |
| 5320 | case MethodLoadKind::kRuntimeCall: { |
| 5321 | // Test situation, don't do anything. |
| 5322 | break; |
| 5323 | } |
| 5324 | default: { |
| 5325 | LOG(FATAL) << "Load kind should have already been handled " << load_kind; |
| 5326 | UNREACHABLE(); |
| 5327 | } |
| 5328 | } |
| 5329 | } |
| 5330 | |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5331 | void CodeGeneratorX86::GenerateStaticOrDirectCall( |
| 5332 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5333 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 5334 | switch (invoke->GetMethodLoadKind()) { |
| Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 5335 | case MethodLoadKind::kStringInit: { |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5336 | // temp = thread->string_init_entrypoint |
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5337 | uint32_t offset = |
| 5338 | GetThreadOffset<kX86PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 5339 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(offset)); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5340 | break; |
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5341 | } |
| Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5342 | case MethodLoadKind::kRecursive: { |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 5343 | callee_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodIndex()); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5344 | break; |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5345 | } |
| Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 5346 | case MethodLoadKind::kRuntimeCall: { |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5347 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 5348 | return; // No code pointer retrieval; the runtime performs the call directly. |
| Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 5349 | } |
| Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 5350 | case MethodLoadKind::kBootImageLinkTimePcRelative: |
| 5351 | // For kCallCriticalNative we skip loading the method and do the call directly. |
| 5352 | if (invoke->GetCodePtrLocation() == CodePtrLocation::kCallCriticalNative) { |
| 5353 | break; |
| 5354 | } |
| 5355 | FALLTHROUGH_INTENDED; |
| Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5356 | default: { |
| 5357 | LoadMethod(invoke->GetMethodLoadKind(), callee_method, invoke); |
| 5358 | } |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5359 | } |
| 5360 | |
| 5361 | switch (invoke->GetCodePtrLocation()) { |
| Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 5362 | case CodePtrLocation::kCallSelf: |
| Nicolas Geoffray | 282795c | 2021-09-24 18:16:41 +0100 | [diff] [blame] | 5363 | DCHECK(!GetGraph()->HasShouldDeoptimizeFlag()); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5364 | __ call(GetFrameEntryLabel()); |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 5365 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5366 | break; |
| Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 5367 | case CodePtrLocation::kCallCriticalNative: { |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 5368 | size_t out_frame_size = |
| 5369 | PrepareCriticalNativeCall<CriticalNativeCallingConventionVisitorX86, |
| 5370 | kNativeStackAlignment, |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 5371 | GetCriticalNativeDirectCallFrameSize>(invoke); |
| Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 5372 | if (invoke->GetMethodLoadKind() == MethodLoadKind::kBootImageLinkTimePcRelative) { |
| 5373 | DCHECK(GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()); |
| 5374 | Register base_reg = GetInvokeExtraParameter(invoke, temp.AsRegister<Register>()); |
| 5375 | __ call(Address(base_reg, CodeGeneratorX86::kPlaceholder32BitOffset)); |
| 5376 | RecordBootImageJniEntrypointPatch(invoke); |
| 5377 | } else { |
| 5378 | // (callee_method + offset_of_jni_entry_point)() |
| 5379 | __ call(Address(callee_method.AsRegister<Register>(), |
| 5380 | ArtMethod::EntryPointFromJniOffset(kX86PointerSize).Int32Value())); |
| 5381 | } |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 5382 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 5383 | if (out_frame_size == 0u && DataType::IsFloatingPointType(invoke->GetType())) { |
| 5384 | // Create space for conversion. |
| 5385 | out_frame_size = 8u; |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 5386 | IncreaseFrame(out_frame_size); |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 5387 | } |
| 5388 | // Zero-/sign-extend or move the result when needed due to native and managed ABI mismatch. |
| 5389 | switch (invoke->GetType()) { |
| 5390 | case DataType::Type::kBool: |
| 5391 | __ movzxb(EAX, AL); |
| 5392 | break; |
| 5393 | case DataType::Type::kInt8: |
| 5394 | __ movsxb(EAX, AL); |
| 5395 | break; |
| 5396 | case DataType::Type::kUint16: |
| 5397 | __ movzxw(EAX, EAX); |
| 5398 | break; |
| 5399 | case DataType::Type::kInt16: |
| 5400 | __ movsxw(EAX, EAX); |
| 5401 | break; |
| 5402 | case DataType::Type::kFloat32: |
| 5403 | __ fstps(Address(ESP, 0)); |
| 5404 | __ movss(XMM0, Address(ESP, 0)); |
| 5405 | break; |
| 5406 | case DataType::Type::kFloat64: |
| 5407 | __ fstpl(Address(ESP, 0)); |
| 5408 | __ movsd(XMM0, Address(ESP, 0)); |
| 5409 | break; |
| 5410 | case DataType::Type::kInt32: |
| 5411 | case DataType::Type::kInt64: |
| 5412 | case DataType::Type::kVoid: |
| 5413 | break; |
| 5414 | default: |
| 5415 | DCHECK(false) << invoke->GetType(); |
| 5416 | break; |
| 5417 | } |
| 5418 | if (out_frame_size != 0u) { |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 5419 | DecreaseFrame(out_frame_size); |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 5420 | } |
| 5421 | break; |
| 5422 | } |
| Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 5423 | case CodePtrLocation::kCallArtMethod: |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5424 | // (callee_method + offset_of_quick_compiled_code)() |
| 5425 | __ call(Address(callee_method.AsRegister<Register>(), |
| 5426 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5427 | kX86PointerSize).Int32Value())); |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 5428 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5429 | break; |
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 5430 | } |
| 5431 | |
| 5432 | DCHECK(!IsLeafMethod()); |
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 5433 | } |
| 5434 | |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5435 | void CodeGeneratorX86::GenerateVirtualCall( |
| 5436 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5437 | Register temp = temp_in.AsRegister<Register>(); |
| 5438 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 5439 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
| Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 5440 | |
| 5441 | // Use the calling convention instead of the location of the receiver, as |
| 5442 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 5443 | // slow path, the arguments have been moved to the right place, so here we are |
| 5444 | // guaranteed that the receiver is the first register of the calling convention. |
| 5445 | InvokeDexCallingConvention calling_convention; |
| 5446 | Register receiver = calling_convention.GetRegisterAt(0); |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5447 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5448 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 5449 | __ movl(temp, Address(receiver, class_offset)); |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5450 | MaybeRecordImplicitNullCheck(invoke); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5451 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 5452 | // emit a read barrier for the previous class reference load. |
| 5453 | // However this is not required in practice, as this is an |
| 5454 | // intermediate/temporary reference and because the current |
| 5455 | // concurrent copying collector keeps the from-space memory |
| 5456 | // intact/accessible until the end of the marking phase (the |
| 5457 | // concurrent copying collector may not in the future). |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5458 | __ MaybeUnpoisonHeapReference(temp); |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 5459 | |
| 5460 | MaybeGenerateInlineCacheCheck(invoke, temp); |
| 5461 | |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5462 | // temp = temp->GetMethodAt(method_offset); |
| 5463 | __ movl(temp, Address(temp, method_offset)); |
| 5464 | // call temp->GetEntryPoint(); |
| 5465 | __ call(Address( |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5466 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5467 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5468 | } |
| 5469 | |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5470 | void CodeGeneratorX86::RecordBootImageIntrinsicPatch(HX86ComputeBaseMethodAddress* method_address, |
| 5471 | uint32_t intrinsic_data) { |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5472 | boot_image_other_patches_.emplace_back( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5473 | method_address, /* target_dex_file= */ nullptr, intrinsic_data); |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5474 | __ Bind(&boot_image_other_patches_.back().label); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5475 | } |
| 5476 | |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 5477 | void CodeGeneratorX86::RecordBootImageRelRoPatch(HX86ComputeBaseMethodAddress* method_address, |
| 5478 | uint32_t boot_image_offset) { |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5479 | boot_image_other_patches_.emplace_back( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5480 | method_address, /* target_dex_file= */ nullptr, boot_image_offset); |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5481 | __ Bind(&boot_image_other_patches_.back().label); |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 5482 | } |
| 5483 | |
| Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5484 | void CodeGeneratorX86::RecordBootImageMethodPatch(HInvoke* invoke) { |
| 5485 | size_t index = invoke->IsInvokeInterface() |
| 5486 | ? invoke->AsInvokeInterface()->GetSpecialInputIndex() |
| 5487 | : invoke->AsInvokeStaticOrDirect()->GetSpecialInputIndex(); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5488 | HX86ComputeBaseMethodAddress* method_address = |
| Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5489 | invoke->InputAt(index)->AsX86ComputeBaseMethodAddress(); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5490 | boot_image_method_patches_.emplace_back( |
| Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 5491 | method_address, |
| 5492 | invoke->GetResolvedMethodReference().dex_file, |
| 5493 | invoke->GetResolvedMethodReference().index); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5494 | __ Bind(&boot_image_method_patches_.back().label); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5495 | } |
| 5496 | |
| Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5497 | void CodeGeneratorX86::RecordMethodBssEntryPatch(HInvoke* invoke) { |
| 5498 | size_t index = invoke->IsInvokeInterface() |
| 5499 | ? invoke->AsInvokeInterface()->GetSpecialInputIndex() |
| 5500 | : invoke->AsInvokeStaticOrDirect()->GetSpecialInputIndex(); |
| Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 5501 | DCHECK(IsSameDexFile(GetGraph()->GetDexFile(), *invoke->GetMethodReference().dex_file)); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5502 | HX86ComputeBaseMethodAddress* method_address = |
| Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5503 | invoke->InputAt(index)->AsX86ComputeBaseMethodAddress(); |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5504 | // Add the patch entry and bind its label at the end of the instruction. |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5505 | method_bss_entry_patches_.emplace_back( |
| Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 5506 | method_address, |
| 5507 | invoke->GetMethodReference().dex_file, |
| 5508 | invoke->GetMethodReference().index); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5509 | __ Bind(&method_bss_entry_patches_.back().label); |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5510 | } |
| 5511 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5512 | void CodeGeneratorX86::RecordBootImageTypePatch(HLoadClass* load_class) { |
| 5513 | HX86ComputeBaseMethodAddress* method_address = |
| 5514 | load_class->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 5515 | boot_image_type_patches_.emplace_back( |
| 5516 | method_address, &load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5517 | __ Bind(&boot_image_type_patches_.back().label); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5518 | } |
| 5519 | |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5520 | Label* CodeGeneratorX86::NewTypeBssEntryPatch(HLoadClass* load_class) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5521 | HX86ComputeBaseMethodAddress* method_address = |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 5522 | load_class->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5523 | ArenaDeque<X86PcRelativePatchInfo>* patches = nullptr; |
| 5524 | switch (load_class->GetLoadKind()) { |
| 5525 | case HLoadClass::LoadKind::kBssEntry: |
| 5526 | patches = &type_bss_entry_patches_; |
| 5527 | break; |
| 5528 | case HLoadClass::LoadKind::kBssEntryPublic: |
| 5529 | patches = &public_type_bss_entry_patches_; |
| 5530 | break; |
| 5531 | case HLoadClass::LoadKind::kBssEntryPackage: |
| 5532 | patches = &package_type_bss_entry_patches_; |
| 5533 | break; |
| 5534 | default: |
| 5535 | LOG(FATAL) << "Unexpected load kind: " << load_class->GetLoadKind(); |
| 5536 | UNREACHABLE(); |
| 5537 | } |
| 5538 | patches->emplace_back( |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5539 | method_address, &load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
| Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5540 | return &patches->back().label; |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5541 | } |
| 5542 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5543 | void CodeGeneratorX86::RecordBootImageStringPatch(HLoadString* load_string) { |
| 5544 | HX86ComputeBaseMethodAddress* method_address = |
| 5545 | load_string->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 5546 | boot_image_string_patches_.emplace_back( |
| 5547 | method_address, &load_string->GetDexFile(), load_string->GetStringIndex().index_); |
| 5548 | __ Bind(&boot_image_string_patches_.back().label); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5549 | } |
| 5550 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5551 | Label* CodeGeneratorX86::NewStringBssEntryPatch(HLoadString* load_string) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5552 | HX86ComputeBaseMethodAddress* method_address = |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 5553 | load_string->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5554 | string_bss_entry_patches_.emplace_back( |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5555 | method_address, &load_string->GetDexFile(), load_string->GetStringIndex().index_); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5556 | return &string_bss_entry_patches_.back().label; |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5557 | } |
| 5558 | |
| Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 5559 | void CodeGeneratorX86::RecordBootImageJniEntrypointPatch(HInvokeStaticOrDirect* invoke) { |
| 5560 | HX86ComputeBaseMethodAddress* method_address = |
| 5561 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
| 5562 | boot_image_jni_entrypoint_patches_.emplace_back( |
| 5563 | method_address, |
| 5564 | invoke->GetResolvedMethodReference().dex_file, |
| 5565 | invoke->GetResolvedMethodReference().index); |
| 5566 | __ Bind(&boot_image_jni_entrypoint_patches_.back().label); |
| 5567 | } |
| 5568 | |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5569 | void CodeGeneratorX86::LoadBootImageAddress(Register reg, |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5570 | uint32_t boot_image_reference, |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5571 | HInvokeStaticOrDirect* invoke) { |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5572 | if (GetCompilerOptions().IsBootImage()) { |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5573 | HX86ComputeBaseMethodAddress* method_address = |
| 5574 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
| 5575 | DCHECK(method_address != nullptr); |
| 5576 | Register method_address_reg = |
| 5577 | invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()).AsRegister<Register>(); |
| Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 5578 | __ leal(reg, Address(method_address_reg, CodeGeneratorX86::kPlaceholder32BitOffset)); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5579 | RecordBootImageIntrinsicPatch(method_address, boot_image_reference); |
| Vladimir Marko | a2da9b9 | 2018-10-10 14:21:55 +0100 | [diff] [blame] | 5580 | } else if (GetCompilerOptions().GetCompilePic()) { |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5581 | HX86ComputeBaseMethodAddress* method_address = |
| 5582 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
| 5583 | DCHECK(method_address != nullptr); |
| 5584 | Register method_address_reg = |
| 5585 | invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()).AsRegister<Register>(); |
| Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 5586 | __ movl(reg, Address(method_address_reg, CodeGeneratorX86::kPlaceholder32BitOffset)); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5587 | RecordBootImageRelRoPatch(method_address, boot_image_reference); |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5588 | } else { |
| Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 5589 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5590 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 5591 | DCHECK(!heap->GetBootImageSpaces().empty()); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5592 | const uint8_t* address = heap->GetBootImageSpaces()[0]->Begin() + boot_image_reference; |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5593 | __ movl(reg, Immediate(dchecked_integral_cast<uint32_t>(reinterpret_cast<uintptr_t>(address)))); |
| 5594 | } |
| 5595 | } |
| 5596 | |
| Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 5597 | void CodeGeneratorX86::LoadIntrinsicDeclaringClass(Register reg, HInvokeStaticOrDirect* invoke) { |
| 5598 | DCHECK_NE(invoke->GetIntrinsic(), Intrinsics::kNone); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5599 | if (GetCompilerOptions().IsBootImage()) { |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5600 | // Load the class the same way as for HLoadClass::LoadKind::kBootImageLinkTimePcRelative. |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5601 | HX86ComputeBaseMethodAddress* method_address = |
| 5602 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
| 5603 | DCHECK(method_address != nullptr); |
| 5604 | Register method_address_reg = |
| 5605 | invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()).AsRegister<Register>(); |
| Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 5606 | __ leal(reg, Address(method_address_reg, CodeGeneratorX86::kPlaceholder32BitOffset)); |
| Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 5607 | MethodReference target_method = invoke->GetResolvedMethodReference(); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5608 | dex::TypeIndex type_idx = target_method.dex_file->GetMethodId(target_method.index).class_idx_; |
| 5609 | boot_image_type_patches_.emplace_back(method_address, target_method.dex_file, type_idx.index_); |
| 5610 | __ Bind(&boot_image_type_patches_.back().label); |
| 5611 | } else { |
| Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 5612 | uint32_t boot_image_offset = GetBootImageOffsetOfIntrinsicDeclaringClass(invoke); |
| 5613 | LoadBootImageAddress(reg, boot_image_offset, invoke); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5614 | } |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5615 | } |
| 5616 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5617 | // The label points to the end of the "movl" or another instruction but the literal offset |
| 5618 | // for method patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 5619 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
| 5620 | |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5621 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5622 | inline void CodeGeneratorX86::EmitPcRelativeLinkerPatches( |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 5623 | const ArenaDeque<X86PcRelativePatchInfo>& infos, |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5624 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 5625 | for (const X86PcRelativePatchInfo& info : infos) { |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5626 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5627 | linker_patches->push_back(Factory(literal_offset, |
| 5628 | info.target_dex_file, |
| 5629 | GetMethodAddressOffset(info.method_address), |
| 5630 | info.offset_or_index)); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5631 | } |
| 5632 | } |
| 5633 | |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5634 | template <linker::LinkerPatch (*Factory)(size_t, uint32_t, uint32_t)> |
| 5635 | linker::LinkerPatch NoDexFileAdapter(size_t literal_offset, |
| 5636 | const DexFile* target_dex_file, |
| 5637 | uint32_t pc_insn_offset, |
| 5638 | uint32_t boot_image_offset) { |
| 5639 | DCHECK(target_dex_file == nullptr); // Unused for these patches, should be null. |
| 5640 | return Factory(literal_offset, pc_insn_offset, boot_image_offset); |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 5641 | } |
| 5642 | |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5643 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5644 | DCHECK(linker_patches->empty()); |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 5645 | size_t size = |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5646 | boot_image_method_patches_.size() + |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5647 | method_bss_entry_patches_.size() + |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5648 | boot_image_type_patches_.size() + |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5649 | type_bss_entry_patches_.size() + |
| Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5650 | public_type_bss_entry_patches_.size() + |
| 5651 | package_type_bss_entry_patches_.size() + |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5652 | boot_image_string_patches_.size() + |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5653 | string_bss_entry_patches_.size() + |
| Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 5654 | boot_image_jni_entrypoint_patches_.size() + |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5655 | boot_image_other_patches_.size(); |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 5656 | linker_patches->reserve(size); |
| Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 5657 | if (GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()) { |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5658 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
| 5659 | boot_image_method_patches_, linker_patches); |
| 5660 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
| 5661 | boot_image_type_patches_, linker_patches); |
| 5662 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5663 | boot_image_string_patches_, linker_patches); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5664 | } else { |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5665 | DCHECK(boot_image_method_patches_.empty()); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5666 | DCHECK(boot_image_type_patches_.empty()); |
| 5667 | DCHECK(boot_image_string_patches_.empty()); |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5668 | } |
| 5669 | if (GetCompilerOptions().IsBootImage()) { |
| 5670 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::IntrinsicReferencePatch>>( |
| 5671 | boot_image_other_patches_, linker_patches); |
| 5672 | } else { |
| 5673 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::DataBimgRelRoPatch>>( |
| 5674 | boot_image_other_patches_, linker_patches); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5675 | } |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5676 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 5677 | method_bss_entry_patches_, linker_patches); |
| 5678 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 5679 | type_bss_entry_patches_, linker_patches); |
| Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5680 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::PublicTypeBssEntryPatch>( |
| 5681 | public_type_bss_entry_patches_, linker_patches); |
| 5682 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::PackageTypeBssEntryPatch>( |
| 5683 | package_type_bss_entry_patches_, linker_patches); |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5684 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 5685 | string_bss_entry_patches_, linker_patches); |
| Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 5686 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeJniEntrypointPatch>( |
| 5687 | boot_image_jni_entrypoint_patches_, linker_patches); |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5688 | DCHECK_EQ(size, linker_patches->size()); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5689 | } |
| 5690 | |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5691 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 5692 | Register card, |
| 5693 | Register object, |
| 5694 | Register value, |
| 5695 | bool value_can_be_null) { |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 5696 | NearLabel is_null; |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5697 | if (value_can_be_null) { |
| 5698 | __ testl(value, value); |
| 5699 | __ j(kEqual, &is_null); |
| 5700 | } |
| Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5701 | // Load the address of the card table into `card`. |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5702 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86PointerSize>().Int32Value())); |
| Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5703 | // Calculate the offset (in the card table) of the card corresponding to |
| 5704 | // `object`. |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5705 | __ movl(temp, object); |
| 5706 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
| Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5707 | // Write the `art::gc::accounting::CardTable::kCardDirty` value into the |
| 5708 | // `object`'s card. |
| 5709 | // |
| 5710 | // Register `card` contains the address of the card table. Note that the card |
| 5711 | // table's base is biased during its creation so that it always starts at an |
| 5712 | // address whose least-significant byte is equal to `kCardDirty` (see |
| 5713 | // art::gc::accounting::CardTable::Create). Therefore the MOVB instruction |
| 5714 | // below writes the `kCardDirty` (byte) value into the `object`'s card |
| 5715 | // (located at `card + object >> kCardShift`). |
| 5716 | // |
| 5717 | // This dual use of the value in register `card` (1. to calculate the location |
| 5718 | // of the card to mark; and 2. to load the `kCardDirty` value) saves a load |
| 5719 | // (no need to explicitly load `kCardDirty` as an immediate value). |
| Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 5720 | __ movb(Address(temp, card, TIMES_1, 0), |
| 5721 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5722 | if (value_can_be_null) { |
| 5723 | __ Bind(&is_null); |
| 5724 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5725 | } |
| 5726 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5727 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 5728 | DCHECK(instruction->IsInstanceFieldGet() || |
| 5729 | instruction->IsStaticFieldGet() || |
| 5730 | instruction->IsPredicatedInstanceFieldGet()); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5731 | |
| 5732 | bool object_field_get_with_read_barrier = |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5733 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
| Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 5734 | bool is_predicated = instruction->IsPredicatedInstanceFieldGet(); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5735 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5736 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 5737 | kEmitCompilerReadBarrier |
| 5738 | ? LocationSummary::kCallOnSlowPath |
| 5739 | : LocationSummary::kNoCall); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5740 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5741 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5742 | } |
| Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 5743 | // receiver_input |
| 5744 | locations->SetInAt(is_predicated ? 1 : 0, Location::RequiresRegister()); |
| 5745 | if (is_predicated) { |
| 5746 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
| 5747 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5748 | } else { |
| 5749 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5750 | } |
| 5751 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5752 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
| Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 5753 | locations->SetOut(is_predicated ? Location::SameAsFirstInput() |
| 5754 | : Location::RequiresFpuRegister()); |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5755 | } else { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5756 | // The output overlaps in case of long: we don't want the low move |
| 5757 | // to overwrite the object's location. Likewise, in the case of |
| 5758 | // an object field get with read barriers enabled, we do not want |
| 5759 | // the move to overwrite the object's location, as we need it to emit |
| 5760 | // the read barrier. |
| Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 5761 | locations->SetOut(is_predicated ? Location::SameAsFirstInput() : Location::RequiresRegister(), |
| 5762 | (object_field_get_with_read_barrier || |
| 5763 | instruction->GetType() == DataType::Type::kInt64 || |
| 5764 | is_predicated) |
| 5765 | ? Location::kOutputOverlap |
| 5766 | : Location::kNoOutputOverlap); |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5767 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5768 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5769 | if (field_info.IsVolatile() && (field_info.GetFieldType() == DataType::Type::kInt64)) { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5770 | // Long values can be loaded atomically into an XMM using movsd. |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5771 | // So we use an XMM register as a temp to achieve atomicity (first |
| 5772 | // load the temp into the XMM and then copy the XMM into the |
| 5773 | // output, 32 bits at a time). |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5774 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 5775 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5776 | } |
| 5777 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5778 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 5779 | const FieldInfo& field_info) { |
| Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 5780 | DCHECK(instruction->IsInstanceFieldGet() || |
| 5781 | instruction->IsStaticFieldGet() || |
| 5782 | instruction->IsPredicatedInstanceFieldGet()); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5783 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5784 | LocationSummary* locations = instruction->GetLocations(); |
| Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 5785 | Location base_loc = locations->InAt(instruction->IsPredicatedInstanceFieldGet() ? 1 : 0); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5786 | Register base = base_loc.AsRegister<Register>(); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5787 | Location out = locations->Out(); |
| 5788 | bool is_volatile = field_info.IsVolatile(); |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5789 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 5790 | DataType::Type load_type = instruction->GetType(); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5791 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5792 | |
| Ulya Trafimovich | 322eced | 2021-06-02 15:39:36 +0100 | [diff] [blame] | 5793 | if (load_type == DataType::Type::kReference) { |
| 5794 | // /* HeapReference<Object> */ out = *(base + offset) |
| 5795 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 5796 | // Note that a potential implicit null check is handled in this |
| 5797 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 5798 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 5799 | instruction, out, base, offset, /* needs_null_check= */ true); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5800 | if (is_volatile) { |
| Ulya Trafimovich | 322eced | 2021-06-02 15:39:36 +0100 | [diff] [blame] | 5801 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5802 | } |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5803 | } else { |
| Ulya Trafimovich | 322eced | 2021-06-02 15:39:36 +0100 | [diff] [blame] | 5804 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| 5805 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5806 | if (is_volatile) { |
| 5807 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5808 | } |
| 5809 | // If read barriers are enabled, emit read barriers other than |
| 5810 | // Baker's using a slow path (and also unpoison the loaded |
| 5811 | // reference, if heap poisoning is enabled). |
| 5812 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 5813 | } |
| 5814 | } else { |
| 5815 | Address src(base, offset); |
| 5816 | XmmRegister temp = (load_type == DataType::Type::kInt64 && is_volatile) |
| 5817 | ? locations->GetTemp(0).AsFpuRegister<XmmRegister>() |
| 5818 | : kNoXmmRegister; |
| 5819 | codegen_->LoadFromMemoryNoBarrier(load_type, out, src, instruction, temp, is_volatile); |
| 5820 | if (is_volatile) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5821 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5822 | } |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5823 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5824 | } |
| 5825 | |
| 5826 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 5827 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5828 | |
| 5829 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5830 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5831 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5832 | bool is_volatile = field_info.IsVolatile(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5833 | DataType::Type field_type = field_info.GetFieldType(); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5834 | bool is_byte_type = DataType::Size(field_type) == 1u; |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5835 | |
| 5836 | // The register allocator does not support multiple |
| 5837 | // inputs that die at entry with one in a specific register. |
| 5838 | if (is_byte_type) { |
| 5839 | // Ensure the value is in a byte register. |
| 5840 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5841 | } else if (DataType::IsFloatingPointType(field_type)) { |
| 5842 | if (is_volatile && field_type == DataType::Type::kFloat64) { |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5843 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 5844 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 5845 | } else { |
| 5846 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 5847 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5848 | } else if (is_volatile && field_type == DataType::Type::kInt64) { |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5849 | // 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] | 5850 | locations->SetInAt(1, Location::RequiresRegister()); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5851 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5852 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 5853 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 5854 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 5855 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 5856 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 5857 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 5858 | locations->AddTemp(Location::RequiresFpuRegister()); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5859 | } else { |
| 5860 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5861 | |
| 5862 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 5863 | // Temporary registers for the write barrier. |
| 5864 | locations->AddTemp(Location::RequiresRegister()); // May be used for reference poisoning too. |
| 5865 | // Ensure the card is in a byte register. |
| 5866 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 5867 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5868 | } |
| 5869 | } |
| 5870 | |
| 5871 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
| Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5872 | uint32_t value_index, |
| 5873 | DataType::Type field_type, |
| 5874 | Address field_addr, |
| 5875 | Register base, |
| 5876 | bool is_volatile, |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5877 | bool value_can_be_null) { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5878 | LocationSummary* locations = instruction->GetLocations(); |
| Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5879 | Location value = locations->InAt(value_index); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5880 | bool needs_write_barrier = |
| Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5881 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(value_index)); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5882 | |
| 5883 | if (is_volatile) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5884 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5885 | } |
| 5886 | |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5887 | bool maybe_record_implicit_null_check_done = false; |
| 5888 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5889 | switch (field_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5890 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5891 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5892 | case DataType::Type::kInt8: { |
| Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5893 | if (value.IsConstant()) { |
| 5894 | __ movb(field_addr, Immediate(CodeGenerator::GetInt8ValueOf(value.GetConstant()))); |
| 5895 | } else { |
| 5896 | __ movb(field_addr, value.AsRegister<ByteRegister>()); |
| 5897 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5898 | break; |
| 5899 | } |
| 5900 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5901 | case DataType::Type::kUint16: |
| 5902 | case DataType::Type::kInt16: { |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5903 | if (value.IsConstant()) { |
| Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5904 | __ movw(field_addr, Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5905 | } else { |
| Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5906 | __ movw(field_addr, value.AsRegister<Register>()); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5907 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5908 | break; |
| 5909 | } |
| 5910 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5911 | case DataType::Type::kInt32: |
| 5912 | case DataType::Type::kReference: { |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5913 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 5914 | // Note that in the case where `value` is a null reference, |
| 5915 | // we do not enter this block, as the reference does not |
| 5916 | // need poisoning. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5917 | DCHECK_EQ(field_type, DataType::Type::kReference); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5918 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5919 | __ movl(temp, value.AsRegister<Register>()); |
| 5920 | __ PoisonHeapReference(temp); |
| Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5921 | __ movl(field_addr, temp); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5922 | } else if (value.IsConstant()) { |
| 5923 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5924 | __ movl(field_addr, Immediate(v)); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5925 | } else { |
| Nicolas Geoffray | 0397163 | 2016-03-17 10:44:24 +0000 | [diff] [blame] | 5926 | DCHECK(value.IsRegister()) << value; |
| Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5927 | __ movl(field_addr, value.AsRegister<Register>()); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5928 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5929 | break; |
| 5930 | } |
| 5931 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5932 | case DataType::Type::kInt64: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5933 | if (is_volatile) { |
| 5934 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 5935 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 5936 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 5937 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 5938 | __ punpckldq(temp1, temp2); |
| Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5939 | __ movsd(field_addr, temp1); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5940 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5941 | } else if (value.IsConstant()) { |
| 5942 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5943 | __ movl(field_addr, Immediate(Low32Bits(v))); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5944 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Ulya Trafimovich | 893e2ed | 2021-06-10 16:18:12 +0100 | [diff] [blame] | 5945 | __ movl(Address::displace(field_addr, kX86WordSize), Immediate(High32Bits(v))); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5946 | } else { |
| Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5947 | __ movl(field_addr, value.AsRegisterPairLow<Register>()); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5948 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Ulya Trafimovich | 893e2ed | 2021-06-10 16:18:12 +0100 | [diff] [blame] | 5949 | __ movl(Address::displace(field_addr, kX86WordSize), value.AsRegisterPairHigh<Register>()); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5950 | } |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5951 | maybe_record_implicit_null_check_done = true; |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5952 | break; |
| 5953 | } |
| 5954 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5955 | case DataType::Type::kFloat32: { |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5956 | if (value.IsConstant()) { |
| 5957 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5958 | __ movl(field_addr, Immediate(v)); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5959 | } else { |
| Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5960 | __ movss(field_addr, value.AsFpuRegister<XmmRegister>()); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5961 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5962 | break; |
| 5963 | } |
| 5964 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5965 | case DataType::Type::kFloat64: { |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5966 | if (value.IsConstant()) { |
| Andra Danciu | c992e42 | 2020-09-16 08:12:02 +0000 | [diff] [blame] | 5967 | DCHECK(!is_volatile); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5968 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5969 | __ movl(field_addr, Immediate(Low32Bits(v))); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5970 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Ulya Trafimovich | 893e2ed | 2021-06-10 16:18:12 +0100 | [diff] [blame] | 5971 | __ movl(Address::displace(field_addr, kX86WordSize), Immediate(High32Bits(v))); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5972 | maybe_record_implicit_null_check_done = true; |
| 5973 | } else { |
| Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5974 | __ movsd(field_addr, value.AsFpuRegister<XmmRegister>()); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5975 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5976 | break; |
| 5977 | } |
| 5978 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5979 | case DataType::Type::kUint32: |
| 5980 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5981 | case DataType::Type::kVoid: |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5982 | LOG(FATAL) << "Unreachable type " << field_type; |
| 5983 | UNREACHABLE(); |
| 5984 | } |
| 5985 | |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5986 | if (!maybe_record_implicit_null_check_done) { |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5987 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5988 | } |
| 5989 | |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5990 | if (needs_write_barrier) { |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5991 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5992 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5993 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5994 | } |
| 5995 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5996 | if (is_volatile) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5997 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5998 | } |
| 5999 | } |
| 6000 | |
| Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 6001 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
| 6002 | const FieldInfo& field_info, |
| 6003 | bool value_can_be_null) { |
| 6004 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 6005 | |
| 6006 | LocationSummary* locations = instruction->GetLocations(); |
| 6007 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 6008 | bool is_volatile = field_info.IsVolatile(); |
| 6009 | DataType::Type field_type = field_info.GetFieldType(); |
| 6010 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 6011 | bool is_predicated = |
| 6012 | instruction->IsInstanceFieldSet() && instruction->AsInstanceFieldSet()->GetIsPredicatedSet(); |
| Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 6013 | |
| 6014 | Address field_addr(base, offset); |
| 6015 | |
| Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 6016 | NearLabel pred_is_null; |
| 6017 | if (is_predicated) { |
| 6018 | __ testl(base, base); |
| 6019 | __ j(kEqual, &pred_is_null); |
| 6020 | } |
| 6021 | |
| Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 6022 | HandleFieldSet(instruction, |
| 6023 | /* value_index= */ 1, |
| 6024 | field_type, |
| 6025 | field_addr, |
| 6026 | base, |
| 6027 | is_volatile, |
| 6028 | value_can_be_null); |
| Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 6029 | |
| 6030 | if (is_predicated) { |
| 6031 | __ Bind(&pred_is_null); |
| 6032 | } |
| Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 6033 | } |
| 6034 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6035 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 6036 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6037 | } |
| 6038 | |
| 6039 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 6040 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6041 | } |
| 6042 | |
| 6043 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 6044 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 6045 | } |
| 6046 | |
| 6047 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 6048 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6049 | } |
| 6050 | |
| 6051 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 6052 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 6053 | } |
| 6054 | |
| 6055 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 6056 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6057 | } |
| 6058 | |
| Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 6059 | void LocationsBuilderX86::VisitPredicatedInstanceFieldGet( |
| 6060 | HPredicatedInstanceFieldGet* instruction) { |
| 6061 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6062 | } |
| 6063 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6064 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 6065 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6066 | } |
| 6067 | |
| Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 6068 | void InstructionCodeGeneratorX86::VisitPredicatedInstanceFieldGet( |
| 6069 | HPredicatedInstanceFieldGet* instruction) { |
| 6070 | NearLabel finish; |
| 6071 | LocationSummary* locations = instruction->GetLocations(); |
| 6072 | Register recv = locations->InAt(1).AsRegister<Register>(); |
| 6073 | __ testl(recv, recv); |
| 6074 | __ j(kZero, &finish); |
| 6075 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6076 | __ Bind(&finish); |
| 6077 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6078 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 6079 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6080 | } |
| 6081 | |
| Vladimir Marko | 552a134 | 2017-10-31 10:56:47 +0000 | [diff] [blame] | 6082 | void LocationsBuilderX86::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 6083 | codegen_->CreateStringBuilderAppendLocations(instruction, Location::RegisterLocation(EAX)); |
| 6084 | } |
| 6085 | |
| 6086 | void InstructionCodeGeneratorX86::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 6087 | __ movl(EAX, Immediate(instruction->GetFormat()->GetValue())); |
| 6088 | codegen_->InvokeRuntime(kQuickStringBuilderAppend, instruction, instruction->GetDexPc()); |
| 6089 | } |
| 6090 | |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6091 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 6092 | HUnresolvedInstanceFieldGet* instruction) { |
| 6093 | FieldAccessCallingConventionX86 calling_convention; |
| 6094 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6095 | instruction, instruction->GetFieldType(), calling_convention); |
| 6096 | } |
| 6097 | |
| 6098 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 6099 | HUnresolvedInstanceFieldGet* instruction) { |
| 6100 | FieldAccessCallingConventionX86 calling_convention; |
| 6101 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6102 | instruction->GetFieldType(), |
| 6103 | instruction->GetFieldIndex(), |
| 6104 | instruction->GetDexPc(), |
| 6105 | calling_convention); |
| 6106 | } |
| 6107 | |
| 6108 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 6109 | HUnresolvedInstanceFieldSet* instruction) { |
| 6110 | FieldAccessCallingConventionX86 calling_convention; |
| 6111 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6112 | instruction, instruction->GetFieldType(), calling_convention); |
| 6113 | } |
| 6114 | |
| 6115 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 6116 | HUnresolvedInstanceFieldSet* instruction) { |
| 6117 | FieldAccessCallingConventionX86 calling_convention; |
| 6118 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6119 | instruction->GetFieldType(), |
| 6120 | instruction->GetFieldIndex(), |
| 6121 | instruction->GetDexPc(), |
| 6122 | calling_convention); |
| 6123 | } |
| 6124 | |
| 6125 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 6126 | HUnresolvedStaticFieldGet* instruction) { |
| 6127 | FieldAccessCallingConventionX86 calling_convention; |
| 6128 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6129 | instruction, instruction->GetFieldType(), calling_convention); |
| 6130 | } |
| 6131 | |
| 6132 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 6133 | HUnresolvedStaticFieldGet* instruction) { |
| 6134 | FieldAccessCallingConventionX86 calling_convention; |
| 6135 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6136 | instruction->GetFieldType(), |
| 6137 | instruction->GetFieldIndex(), |
| 6138 | instruction->GetDexPc(), |
| 6139 | calling_convention); |
| 6140 | } |
| 6141 | |
| 6142 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 6143 | HUnresolvedStaticFieldSet* instruction) { |
| 6144 | FieldAccessCallingConventionX86 calling_convention; |
| 6145 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6146 | instruction, instruction->GetFieldType(), calling_convention); |
| 6147 | } |
| 6148 | |
| 6149 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 6150 | HUnresolvedStaticFieldSet* instruction) { |
| 6151 | FieldAccessCallingConventionX86 calling_convention; |
| 6152 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6153 | instruction->GetFieldType(), |
| 6154 | instruction->GetFieldIndex(), |
| 6155 | instruction->GetDexPc(), |
| 6156 | calling_convention); |
| 6157 | } |
| 6158 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6159 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6160 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 6161 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 6162 | ? Location::RequiresRegister() |
| 6163 | : Location::Any(); |
| 6164 | locations->SetInAt(0, loc); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6165 | } |
| 6166 | |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6167 | void CodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 6168 | if (CanMoveNullCheckToUser(instruction)) { |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6169 | return; |
| 6170 | } |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 6171 | LocationSummary* locations = instruction->GetLocations(); |
| 6172 | Location obj = locations->InAt(0); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6173 | |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 6174 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6175 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 6176 | } |
| 6177 | |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6178 | void CodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6179 | SlowPathCode* slow_path = new (GetScopedAllocator()) NullCheckSlowPathX86(instruction); |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6180 | AddSlowPath(slow_path); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6181 | |
| 6182 | LocationSummary* locations = instruction->GetLocations(); |
| 6183 | Location obj = locations->InAt(0); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6184 | |
| 6185 | if (obj.IsRegister()) { |
| Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 6186 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 6187 | } else if (obj.IsStackSlot()) { |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6188 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 6189 | } else { |
| 6190 | DCHECK(obj.IsConstant()) << obj; |
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 6191 | DCHECK(obj.GetConstant()->IsNullConstant()); |
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 6192 | __ jmp(slow_path->GetEntryLabel()); |
| 6193 | return; |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6194 | } |
| 6195 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6196 | } |
| 6197 | |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 6198 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6199 | codegen_->GenerateNullCheck(instruction); |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 6200 | } |
| 6201 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6202 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6203 | bool object_array_get_with_read_barrier = |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6204 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 6205 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6206 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 6207 | object_array_get_with_read_barrier |
| 6208 | ? LocationSummary::kCallOnSlowPath |
| 6209 | : LocationSummary::kNoCall); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6210 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6211 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6212 | } |
| Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 6213 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6214 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6215 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 6216 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6217 | } else { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6218 | // The output overlaps in case of long: we don't want the low move |
| 6219 | // to overwrite the array's location. Likewise, in the case of an |
| 6220 | // object array get with read barriers enabled, we do not want the |
| 6221 | // move to overwrite the array's location, as we need it to emit |
| 6222 | // the read barrier. |
| 6223 | locations->SetOut( |
| 6224 | Location::RequiresRegister(), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6225 | (instruction->GetType() == DataType::Type::kInt64 || object_array_get_with_read_barrier) |
| 6226 | ? Location::kOutputOverlap |
| 6227 | : Location::kNoOutputOverlap); |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 6228 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6229 | } |
| 6230 | |
| 6231 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 6232 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6233 | Location obj_loc = locations->InAt(0); |
| 6234 | Register obj = obj_loc.AsRegister<Register>(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6235 | Location index = locations->InAt(1); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6236 | Location out_loc = locations->Out(); |
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6237 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6238 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6239 | DataType::Type type = instruction->GetType(); |
| Ulya Trafimovich | 322eced | 2021-06-02 15:39:36 +0100 | [diff] [blame] | 6240 | if (type == DataType::Type::kReference) { |
| 6241 | static_assert( |
| 6242 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6243 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 6244 | // /* HeapReference<Object> */ out = |
| 6245 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 6246 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 6247 | // Note that a potential implicit null check is handled in this |
| 6248 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 6249 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 6250 | instruction, out_loc, obj, data_offset, index, /* needs_null_check= */ true); |
| 6251 | } else { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6252 | Register out = out_loc.AsRegister<Register>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6253 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6254 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Ulya Trafimovich | 322eced | 2021-06-02 15:39:36 +0100 | [diff] [blame] | 6255 | // If read barriers are enabled, emit read barriers other than |
| 6256 | // Baker's using a slow path (and also unpoison the loaded |
| 6257 | // reference, if heap poisoning is enabled). |
| 6258 | if (index.IsConstant()) { |
| 6259 | uint32_t offset = |
| 6260 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 6261 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 6262 | } else { |
| 6263 | codegen_->MaybeGenerateReadBarrierSlow( |
| 6264 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 6265 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6266 | } |
| Ulya Trafimovich | 322eced | 2021-06-02 15:39:36 +0100 | [diff] [blame] | 6267 | } else if (type == DataType::Type::kUint16 |
| 6268 | && mirror::kUseStringCompression |
| 6269 | && instruction->IsStringCharAt()) { |
| 6270 | // Branch cases into compressed and uncompressed for each index's type. |
| 6271 | Register out = out_loc.AsRegister<Register>(); |
| 6272 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 6273 | NearLabel done, not_compressed; |
| 6274 | __ testb(Address(obj, count_offset), Immediate(1)); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6275 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Ulya Trafimovich | 322eced | 2021-06-02 15:39:36 +0100 | [diff] [blame] | 6276 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 6277 | "Expecting 0=compressed, 1=uncompressed"); |
| 6278 | __ j(kNotZero, ¬_compressed); |
| 6279 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| 6280 | __ jmp(&done); |
| 6281 | __ Bind(¬_compressed); |
| 6282 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 6283 | __ Bind(&done); |
| 6284 | } else { |
| Ulya Trafimovich | c8451cb | 2021-06-02 17:35:16 +0100 | [diff] [blame] | 6285 | ScaleFactor scale = CodeGenerator::ScaleFactorForType(type); |
| 6286 | Address src = CodeGeneratorX86::ArrayAddress(obj, index, scale, data_offset); |
| Ulya Trafimovich | 322eced | 2021-06-02 15:39:36 +0100 | [diff] [blame] | 6287 | codegen_->LoadFromMemoryNoBarrier(type, out_loc, src, instruction); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6288 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6289 | } |
| 6290 | |
| 6291 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6292 | DataType::Type value_type = instruction->GetComponentType(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6293 | |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6294 | bool needs_write_barrier = |
| 6295 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6296 | bool needs_type_check = instruction->NeedsTypeCheck(); |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6297 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6298 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 6299 | instruction, |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6300 | needs_type_check ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 6301 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6302 | bool is_byte_type = DataType::Size(value_type) == 1u; |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6303 | // We need the inputs to be different than the output in case of long operation. |
| 6304 | // In case of a byte operation, the register allocator does not support multiple |
| 6305 | // inputs that die at entry with one in a specific register. |
| 6306 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6307 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 6308 | if (is_byte_type) { |
| 6309 | // Ensure the value is in a byte register. |
| 6310 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6311 | } else if (DataType::IsFloatingPointType(value_type)) { |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6312 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6313 | } else { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6314 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 6315 | } |
| 6316 | if (needs_write_barrier) { |
| 6317 | // Temporary registers for the write barrier. |
| 6318 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 6319 | // Ensure the card is in a byte register. |
| Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 6320 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6321 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6322 | } |
| 6323 | |
| 6324 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 6325 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6326 | Location array_loc = locations->InAt(0); |
| 6327 | Register array = array_loc.AsRegister<Register>(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6328 | Location index = locations->InAt(1); |
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 6329 | Location value = locations->InAt(2); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6330 | DataType::Type value_type = instruction->GetComponentType(); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6331 | bool needs_type_check = instruction->NeedsTypeCheck(); |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6332 | bool needs_write_barrier = |
| 6333 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6334 | |
| 6335 | switch (value_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6336 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6337 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6338 | case DataType::Type::kInt8: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6339 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6340 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_1, offset); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6341 | if (value.IsRegister()) { |
| 6342 | __ movb(address, value.AsRegister<ByteRegister>()); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6343 | } else { |
| Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 6344 | __ movb(address, Immediate(CodeGenerator::GetInt8ValueOf(value.GetConstant()))); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6345 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6346 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6347 | break; |
| 6348 | } |
| 6349 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6350 | case DataType::Type::kUint16: |
| 6351 | case DataType::Type::kInt16: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6352 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6353 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_2, offset); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6354 | if (value.IsRegister()) { |
| 6355 | __ movw(address, value.AsRegister<Register>()); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6356 | } else { |
| Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 6357 | __ movw(address, Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6358 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6359 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6360 | break; |
| 6361 | } |
| 6362 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6363 | case DataType::Type::kReference: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6364 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6365 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6366 | |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6367 | if (!value.IsRegister()) { |
| 6368 | // Just setting null. |
| 6369 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 6370 | DCHECK(value.IsConstant()) << value; |
| 6371 | __ movl(address, Immediate(0)); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6372 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6373 | DCHECK(!needs_write_barrier); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6374 | DCHECK(!needs_type_check); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6375 | break; |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6376 | } |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6377 | |
| 6378 | DCHECK(needs_write_barrier); |
| 6379 | Register register_value = value.AsRegister<Register>(); |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6380 | Location temp_loc = locations->GetTemp(0); |
| 6381 | Register temp = temp_loc.AsRegister<Register>(); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6382 | |
| 6383 | bool can_value_be_null = instruction->GetValueCanBeNull(); |
| 6384 | NearLabel do_store; |
| 6385 | if (can_value_be_null) { |
| 6386 | __ testl(register_value, register_value); |
| 6387 | __ j(kEqual, &do_store); |
| 6388 | } |
| 6389 | |
| 6390 | SlowPathCode* slow_path = nullptr; |
| 6391 | if (needs_type_check) { |
| Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6392 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathX86(instruction); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6393 | codegen_->AddSlowPath(slow_path); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6394 | |
| 6395 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6396 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6397 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6398 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6399 | // Note that when Baker read barriers are enabled, the type |
| 6400 | // checks are performed without read barriers. This is fine, |
| 6401 | // even in the case where a class object is in the from-space |
| 6402 | // after the flip, as a comparison involving such a type would |
| 6403 | // not produce a false positive; it may of course produce a |
| 6404 | // false negative, in which case we would take the ArraySet |
| 6405 | // slow path. |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6406 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6407 | // /* HeapReference<Class> */ temp = array->klass_ |
| 6408 | __ movl(temp, Address(array, class_offset)); |
| 6409 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6410 | __ MaybeUnpoisonHeapReference(temp); |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6411 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6412 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 6413 | __ movl(temp, Address(temp, component_offset)); |
| 6414 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 6415 | // nor the object reference in `register_value->klass`, as |
| 6416 | // we are comparing two poisoned references. |
| 6417 | __ cmpl(temp, Address(register_value, class_offset)); |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6418 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6419 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6420 | NearLabel do_put; |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6421 | __ j(kEqual, &do_put); |
| 6422 | // If heap poisoning is enabled, the `temp` reference has |
| 6423 | // not been unpoisoned yet; unpoison it now. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6424 | __ MaybeUnpoisonHeapReference(temp); |
| 6425 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6426 | // If heap poisoning is enabled, no need to unpoison the |
| 6427 | // heap reference loaded below, as it is only used for a |
| 6428 | // comparison with null. |
| 6429 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 6430 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6431 | __ Bind(&do_put); |
| 6432 | } else { |
| 6433 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6434 | } |
| Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6435 | } |
| 6436 | |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6437 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 6438 | codegen_->MarkGCCard( |
| 6439 | temp, card, array, value.AsRegister<Register>(), /* value_can_be_null= */ false); |
| 6440 | |
| 6441 | if (can_value_be_null) { |
| 6442 | DCHECK(do_store.IsLinked()); |
| 6443 | __ Bind(&do_store); |
| 6444 | } |
| 6445 | |
| 6446 | Register source = register_value; |
| Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6447 | if (kPoisonHeapReferences) { |
| 6448 | __ movl(temp, register_value); |
| 6449 | __ PoisonHeapReference(temp); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6450 | source = temp; |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6451 | } |
| 6452 | |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6453 | __ movl(address, source); |
| 6454 | |
| 6455 | if (can_value_be_null || !needs_type_check) { |
| 6456 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6457 | } |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6458 | |
| Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6459 | if (slow_path != nullptr) { |
| 6460 | __ Bind(slow_path->GetExitLabel()); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6461 | } |
| 6462 | |
| 6463 | break; |
| 6464 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6465 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6466 | case DataType::Type::kInt32: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6467 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6468 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6469 | if (value.IsRegister()) { |
| 6470 | __ movl(address, value.AsRegister<Register>()); |
| 6471 | } else { |
| 6472 | DCHECK(value.IsConstant()) << value; |
| 6473 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 6474 | __ movl(address, Immediate(v)); |
| 6475 | } |
| 6476 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6477 | break; |
| 6478 | } |
| 6479 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6480 | case DataType::Type::kInt64: { |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6481 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6482 | if (value.IsRegisterPair()) { |
| 6483 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 6484 | value.AsRegisterPairLow<Register>()); |
| 6485 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6486 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 6487 | value.AsRegisterPairHigh<Register>()); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6488 | } else { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6489 | DCHECK(value.IsConstant()); |
| 6490 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
| 6491 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 6492 | Immediate(Low32Bits(val))); |
| 6493 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6494 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 6495 | Immediate(High32Bits(val))); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6496 | } |
| 6497 | break; |
| 6498 | } |
| 6499 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6500 | case DataType::Type::kFloat32: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6501 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6502 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6503 | if (value.IsFpuRegister()) { |
| 6504 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 6505 | } else { |
| 6506 | DCHECK(value.IsConstant()); |
| 6507 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 6508 | __ movl(address, Immediate(v)); |
| 6509 | } |
| 6510 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6511 | break; |
| 6512 | } |
| 6513 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6514 | case DataType::Type::kFloat64: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6515 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6516 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6517 | if (value.IsFpuRegister()) { |
| 6518 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 6519 | } else { |
| 6520 | DCHECK(value.IsConstant()); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6521 | Address address_hi = |
| 6522 | CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset + kX86WordSize); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6523 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 6524 | __ movl(address, Immediate(Low32Bits(v))); |
| 6525 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6526 | __ movl(address_hi, Immediate(High32Bits(v))); |
| 6527 | } |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6528 | break; |
| 6529 | } |
| 6530 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 6531 | case DataType::Type::kUint32: |
| 6532 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6533 | case DataType::Type::kVoid: |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6534 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 6535 | UNREACHABLE(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6536 | } |
| 6537 | } |
| 6538 | |
| 6539 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6540 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 6541 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6542 | if (!instruction->IsEmittedAtUseSite()) { |
| 6543 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6544 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6545 | } |
| 6546 | |
| 6547 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6548 | if (instruction->IsEmittedAtUseSite()) { |
| 6549 | return; |
| 6550 | } |
| 6551 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6552 | LocationSummary* locations = instruction->GetLocations(); |
| Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 6553 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6554 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 6555 | Register out = locations->Out().AsRegister<Register>(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6556 | __ movl(out, Address(obj, offset)); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6557 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6558 | // Mask out most significant bit in case the array is String's array of char. |
| 6559 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6560 | __ shrl(out, Immediate(1)); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6561 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6562 | } |
| 6563 | |
| 6564 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6565 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6566 | InvokeRuntimeCallingConvention calling_convention; |
| 6567 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6568 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 6569 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 6570 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6571 | HInstruction* length = instruction->InputAt(1); |
| 6572 | if (!length->IsEmittedAtUseSite()) { |
| 6573 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 6574 | } |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6575 | // Need register to see array's length. |
| 6576 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 6577 | locations->AddTemp(Location::RequiresRegister()); |
| 6578 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6579 | } |
| 6580 | |
| 6581 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6582 | const bool is_string_compressed_char_at = |
| 6583 | mirror::kUseStringCompression && instruction->IsStringCharAt(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6584 | LocationSummary* locations = instruction->GetLocations(); |
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 6585 | Location index_loc = locations->InAt(0); |
| 6586 | Location length_loc = locations->InAt(1); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6587 | SlowPathCode* slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6588 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathX86(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6589 | |
| Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 6590 | if (length_loc.IsConstant()) { |
| 6591 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 6592 | if (index_loc.IsConstant()) { |
| 6593 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 6594 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 6595 | if (index < 0 || index >= length) { |
| 6596 | codegen_->AddSlowPath(slow_path); |
| 6597 | __ jmp(slow_path->GetEntryLabel()); |
| 6598 | } else { |
| 6599 | // Some optimization after BCE may have generated this, and we should not |
| 6600 | // generate a bounds check if it is a valid range. |
| 6601 | } |
| 6602 | return; |
| 6603 | } |
| 6604 | |
| 6605 | // We have to reverse the jump condition because the length is the constant. |
| 6606 | Register index_reg = index_loc.AsRegister<Register>(); |
| 6607 | __ cmpl(index_reg, Immediate(length)); |
| 6608 | codegen_->AddSlowPath(slow_path); |
| 6609 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 6610 | } else { |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6611 | HInstruction* array_length = instruction->InputAt(1); |
| 6612 | if (array_length->IsEmittedAtUseSite()) { |
| 6613 | // Address the length field in the array. |
| 6614 | DCHECK(array_length->IsArrayLength()); |
| 6615 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 6616 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 6617 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6618 | if (is_string_compressed_char_at) { |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6619 | // TODO: if index_loc.IsConstant(), compare twice the index (to compensate for |
| 6620 | // the string compression flag) with the in-memory length and avoid the temporary. |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6621 | Register length_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 6622 | __ movl(length_reg, array_len); |
| 6623 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6624 | __ shrl(length_reg, Immediate(1)); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6625 | codegen_->GenerateIntCompare(length_reg, index_loc); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6626 | } else { |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6627 | // Checking bounds for general case: |
| 6628 | // Array of char or string's array with feature compression off. |
| 6629 | if (index_loc.IsConstant()) { |
| 6630 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 6631 | __ cmpl(array_len, Immediate(value)); |
| 6632 | } else { |
| 6633 | __ cmpl(array_len, index_loc.AsRegister<Register>()); |
| 6634 | } |
| 6635 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6636 | } |
| Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 6637 | } else { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6638 | codegen_->GenerateIntCompare(length_loc, index_loc); |
| Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 6639 | } |
| 6640 | codegen_->AddSlowPath(slow_path); |
| 6641 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 6642 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6643 | } |
| 6644 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6645 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6646 | LOG(FATAL) << "Unreachable"; |
| Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6647 | } |
| 6648 | |
| 6649 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
| Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 6650 | if (instruction->GetNext()->IsSuspendCheck() && |
| 6651 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 6652 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 6653 | // The back edge will generate the suspend check. |
| 6654 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 6655 | } |
| 6656 | |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6657 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 6658 | } |
| 6659 | |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6660 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6661 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6662 | instruction, LocationSummary::kCallOnSlowPath); |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 6663 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 6664 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 6665 | // registers in full width (since the runtime only saves/restores lower part). |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6666 | locations->SetCustomSlowPathCallerSaves( |
| 6667 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6668 | } |
| 6669 | |
| 6670 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6671 | HBasicBlock* block = instruction->GetBlock(); |
| 6672 | if (block->GetLoopInformation() != nullptr) { |
| 6673 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 6674 | // The back edge will generate the suspend check. |
| 6675 | return; |
| 6676 | } |
| 6677 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 6678 | // The goto will generate the suspend check. |
| 6679 | return; |
| 6680 | } |
| 6681 | GenerateSuspendCheck(instruction, nullptr); |
| 6682 | } |
| 6683 | |
| 6684 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 6685 | HBasicBlock* successor) { |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6686 | SuspendCheckSlowPathX86* slow_path = |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6687 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 6688 | if (slow_path == nullptr) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6689 | slow_path = |
| 6690 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathX86(instruction, successor); |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6691 | instruction->SetSlowPath(slow_path); |
| 6692 | codegen_->AddSlowPath(slow_path); |
| 6693 | if (successor != nullptr) { |
| 6694 | DCHECK(successor->IsLoopHeader()); |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6695 | } |
| 6696 | } else { |
| 6697 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 6698 | } |
| 6699 | |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6700 | __ fs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86PointerSize>().Int32Value()), |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6701 | Immediate(0)); |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6702 | if (successor == nullptr) { |
| 6703 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6704 | __ Bind(slow_path->GetReturnLabel()); |
| 6705 | } else { |
| 6706 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 6707 | __ jmp(slow_path->GetEntryLabel()); |
| 6708 | } |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6709 | } |
| 6710 | |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6711 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 6712 | return codegen_->GetAssembler(); |
| 6713 | } |
| 6714 | |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6715 | void ParallelMoveResolverX86::MoveMemoryToMemory(int dst, int src, int number_of_words) { |
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6716 | ScratchRegisterScope ensure_scratch( |
| 6717 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 6718 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 6719 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6720 | |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6721 | // Now that temp register is available (possibly spilled), move blocks of memory. |
| 6722 | for (int i = 0; i < number_of_words; i++) { |
| 6723 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 6724 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 6725 | stack_offset += kX86WordSize; |
| 6726 | } |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6727 | } |
| 6728 | |
| 6729 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6730 | MoveOperands* move = moves_[index]; |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6731 | Location source = move->GetSource(); |
| 6732 | Location destination = move->GetDestination(); |
| 6733 | |
| 6734 | if (source.IsRegister()) { |
| 6735 | if (destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6736 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6737 | } else if (destination.IsFpuRegister()) { |
| 6738 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6739 | } else { |
| 6740 | DCHECK(destination.IsStackSlot()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6741 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6742 | } |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6743 | } else if (source.IsRegisterPair()) { |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 6744 | if (destination.IsRegisterPair()) { |
| 6745 | __ movl(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 6746 | DCHECK_NE(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>()); |
| 6747 | __ movl(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
| 6748 | } else if (destination.IsFpuRegister()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6749 | size_t elem_size = DataType::Size(DataType::Type::kInt32); |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 6750 | // Push the 2 source registers to the stack. |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 6751 | __ pushl(source.AsRegisterPairHigh<Register>()); |
| 6752 | __ cfi().AdjustCFAOffset(elem_size); |
| 6753 | __ pushl(source.AsRegisterPairLow<Register>()); |
| 6754 | __ cfi().AdjustCFAOffset(elem_size); |
| 6755 | // Load the destination register. |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6756 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 6757 | // And remove the temporary stack space we allocated. |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 6758 | codegen_->DecreaseFrame(2 * elem_size); |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 6759 | } else { |
| 6760 | DCHECK(destination.IsDoubleStackSlot()); |
| 6761 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
| 6762 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
| 6763 | source.AsRegisterPairHigh<Register>()); |
| 6764 | } |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6765 | } else if (source.IsFpuRegister()) { |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6766 | if (destination.IsRegister()) { |
| 6767 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
| 6768 | } else if (destination.IsFpuRegister()) { |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6769 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6770 | } else if (destination.IsRegisterPair()) { |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 6771 | size_t elem_size = DataType::Size(DataType::Type::kInt32); |
| 6772 | // Create stack space for 2 elements. |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 6773 | codegen_->IncreaseFrame(2 * elem_size); |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 6774 | // Store the source register. |
| 6775 | __ movsd(Address(ESP, 0), source.AsFpuRegister<XmmRegister>()); |
| 6776 | // And pop the values into destination registers. |
| 6777 | __ popl(destination.AsRegisterPairLow<Register>()); |
| 6778 | __ cfi().AdjustCFAOffset(-elem_size); |
| 6779 | __ popl(destination.AsRegisterPairHigh<Register>()); |
| 6780 | __ cfi().AdjustCFAOffset(-elem_size); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6781 | } else if (destination.IsStackSlot()) { |
| 6782 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6783 | } else if (destination.IsDoubleStackSlot()) { |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6784 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6785 | } else { |
| 6786 | DCHECK(destination.IsSIMDStackSlot()); |
| 6787 | __ movups(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6788 | } |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6789 | } else if (source.IsStackSlot()) { |
| 6790 | if (destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6791 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6792 | } else if (destination.IsFpuRegister()) { |
| 6793 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6794 | } else { |
| 6795 | DCHECK(destination.IsStackSlot()); |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6796 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 1); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6797 | } |
| 6798 | } else if (source.IsDoubleStackSlot()) { |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6799 | if (destination.IsRegisterPair()) { |
| 6800 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 6801 | __ movl(destination.AsRegisterPairHigh<Register>(), |
| 6802 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 6803 | } else if (destination.IsFpuRegister()) { |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6804 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 6805 | } else { |
| 6806 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6807 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 2); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6808 | } |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6809 | } else if (source.IsSIMDStackSlot()) { |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6810 | if (destination.IsFpuRegister()) { |
| 6811 | __ movups(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 6812 | } else { |
| 6813 | DCHECK(destination.IsSIMDStackSlot()); |
| 6814 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 4); |
| 6815 | } |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 6816 | } else if (source.IsConstant()) { |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6817 | HConstant* constant = source.GetConstant(); |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 6818 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 6819 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6820 | if (destination.IsRegister()) { |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 6821 | if (value == 0) { |
| 6822 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 6823 | } else { |
| 6824 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 6825 | } |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6826 | } else { |
| 6827 | DCHECK(destination.IsStackSlot()) << destination; |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 6828 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6829 | } |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6830 | } else if (constant->IsFloatConstant()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6831 | float fp_value = constant->AsFloatConstant()->GetValue(); |
| Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 6832 | int32_t value = bit_cast<int32_t, float>(fp_value); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6833 | Immediate imm(value); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6834 | if (destination.IsFpuRegister()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6835 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 6836 | if (value == 0) { |
| 6837 | // Easy handling of 0.0. |
| 6838 | __ xorps(dest, dest); |
| 6839 | } else { |
| 6840 | ScratchRegisterScope ensure_scratch( |
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6841 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 6842 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 6843 | __ movl(temp, Immediate(value)); |
| 6844 | __ movd(dest, temp); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6845 | } |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6846 | } else { |
| 6847 | DCHECK(destination.IsStackSlot()) << destination; |
| 6848 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 6849 | } |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6850 | } else if (constant->IsLongConstant()) { |
| 6851 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 6852 | int32_t low_value = Low32Bits(value); |
| 6853 | int32_t high_value = High32Bits(value); |
| 6854 | Immediate low(low_value); |
| 6855 | Immediate high(high_value); |
| 6856 | if (destination.IsDoubleStackSlot()) { |
| 6857 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 6858 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 6859 | } else { |
| 6860 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 6861 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 6862 | } |
| 6863 | } else { |
| 6864 | DCHECK(constant->IsDoubleConstant()); |
| 6865 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
| Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 6866 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6867 | int32_t low_value = Low32Bits(value); |
| 6868 | int32_t high_value = High32Bits(value); |
| 6869 | Immediate low(low_value); |
| 6870 | Immediate high(high_value); |
| 6871 | if (destination.IsFpuRegister()) { |
| 6872 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 6873 | if (value == 0) { |
| 6874 | // Easy handling of 0.0. |
| 6875 | __ xorpd(dest, dest); |
| 6876 | } else { |
| 6877 | __ pushl(high); |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 6878 | __ cfi().AdjustCFAOffset(4); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6879 | __ pushl(low); |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 6880 | __ cfi().AdjustCFAOffset(4); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6881 | __ movsd(dest, Address(ESP, 0)); |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 6882 | codegen_->DecreaseFrame(8); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6883 | } |
| 6884 | } else { |
| 6885 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6886 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 6887 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 6888 | } |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 6889 | } |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6890 | } else { |
| Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 6891 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6892 | } |
| 6893 | } |
| 6894 | |
| Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 6895 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6896 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 6897 | ScratchRegisterScope ensure_scratch( |
| 6898 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 6899 | |
| 6900 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 6901 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 6902 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 6903 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6904 | } |
| 6905 | |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6906 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6907 | ScratchRegisterScope ensure_scratch( |
| 6908 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 6909 | |
| 6910 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 6911 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 6912 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 6913 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 6914 | __ movd(reg, temp_reg); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6915 | } |
| 6916 | |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6917 | void ParallelMoveResolverX86::Exchange128(XmmRegister reg, int mem) { |
| 6918 | size_t extra_slot = 4 * kX86WordSize; |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 6919 | codegen_->IncreaseFrame(extra_slot); |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6920 | __ movups(Address(ESP, 0), XmmRegister(reg)); |
| 6921 | ExchangeMemory(0, mem + extra_slot, 4); |
| 6922 | __ movups(XmmRegister(reg), Address(ESP, 0)); |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 6923 | codegen_->DecreaseFrame(extra_slot); |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6924 | } |
| 6925 | |
| 6926 | void ParallelMoveResolverX86::ExchangeMemory(int mem1, int mem2, int number_of_words) { |
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6927 | ScratchRegisterScope ensure_scratch1( |
| 6928 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6929 | |
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6930 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 6931 | ScratchRegisterScope ensure_scratch2( |
| 6932 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6933 | |
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6934 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 6935 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6936 | |
| 6937 | // Now that temp registers are available (possibly spilled), exchange blocks of memory. |
| 6938 | for (int i = 0; i < number_of_words; i++) { |
| 6939 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 6940 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 6941 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 6942 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
| 6943 | stack_offset += kX86WordSize; |
| 6944 | } |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6945 | } |
| 6946 | |
| 6947 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6948 | MoveOperands* move = moves_[index]; |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6949 | Location source = move->GetSource(); |
| 6950 | Location destination = move->GetDestination(); |
| 6951 | |
| 6952 | if (source.IsRegister() && destination.IsRegister()) { |
| Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 6953 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 6954 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 6955 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 6956 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 6957 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6958 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6959 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6960 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6961 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6962 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6963 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 1); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6964 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 6965 | // Use XOR Swap algorithm to avoid a temporary. |
| 6966 | DCHECK_NE(source.reg(), destination.reg()); |
| 6967 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 6968 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 6969 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 6970 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 6971 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 6972 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 6973 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6974 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 6975 | // Take advantage of the 16 bytes in the XMM register. |
| 6976 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 6977 | Address stack(ESP, destination.GetStackIndex()); |
| 6978 | // Load the double into the high doubleword. |
| 6979 | __ movhpd(reg, stack); |
| 6980 | |
| 6981 | // Store the low double into the destination. |
| 6982 | __ movsd(stack, reg); |
| 6983 | |
| 6984 | // Move the high double to the low double. |
| 6985 | __ psrldq(reg, Immediate(8)); |
| 6986 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 6987 | // Take advantage of the 16 bytes in the XMM register. |
| 6988 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 6989 | Address stack(ESP, source.GetStackIndex()); |
| 6990 | // Load the double into the high doubleword. |
| 6991 | __ movhpd(reg, stack); |
| 6992 | |
| 6993 | // Store the low double into the destination. |
| 6994 | __ movsd(stack, reg); |
| 6995 | |
| 6996 | // Move the high double to the low double. |
| 6997 | __ psrldq(reg, Immediate(8)); |
| 6998 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6999 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 2); |
| 7000 | } else if (source.IsSIMDStackSlot() && destination.IsSIMDStackSlot()) { |
| 7001 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 4); |
| 7002 | } else if (source.IsFpuRegister() && destination.IsSIMDStackSlot()) { |
| 7003 | Exchange128(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 7004 | } else if (destination.IsFpuRegister() && source.IsSIMDStackSlot()) { |
| 7005 | Exchange128(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 7006 | } else { |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 7007 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 7008 | } |
| 7009 | } |
| 7010 | |
| 7011 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 7012 | __ pushl(static_cast<Register>(reg)); |
| 7013 | } |
| 7014 | |
| 7015 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 7016 | __ popl(static_cast<Register>(reg)); |
| Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7017 | } |
| 7018 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7019 | HLoadClass::LoadKind CodeGeneratorX86::GetSupportedLoadClassKind( |
| 7020 | HLoadClass::LoadKind desired_class_load_kind) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7021 | switch (desired_class_load_kind) { |
| Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7022 | case HLoadClass::LoadKind::kInvalid: |
| 7023 | LOG(FATAL) << "UNREACHABLE"; |
| 7024 | UNREACHABLE(); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7025 | case HLoadClass::LoadKind::kReferrersClass: |
| 7026 | break; |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7027 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7028 | case HLoadClass::LoadKind::kBootImageRelRo: |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7029 | case HLoadClass::LoadKind::kBssEntry: |
| Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 7030 | case HLoadClass::LoadKind::kBssEntryPublic: |
| 7031 | case HLoadClass::LoadKind::kBssEntryPackage: |
| Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 7032 | DCHECK(!GetCompilerOptions().IsJitCompiler()); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7033 | break; |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7034 | case HLoadClass::LoadKind::kJitBootImageAddress: |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7035 | case HLoadClass::LoadKind::kJitTableAddress: |
| Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 7036 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7037 | break; |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7038 | case HLoadClass::LoadKind::kRuntimeCall: |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7039 | break; |
| 7040 | } |
| 7041 | return desired_class_load_kind; |
| 7042 | } |
| 7043 | |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7044 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7045 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7046 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7047 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7048 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7049 | cls, |
| 7050 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7051 | Location::RegisterLocation(EAX)); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7052 | DCHECK_EQ(calling_convention.GetRegisterAt(0), EAX); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7053 | return; |
| 7054 | } |
| Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 7055 | DCHECK_EQ(cls->NeedsAccessCheck(), |
| 7056 | load_kind == HLoadClass::LoadKind::kBssEntryPublic || |
| 7057 | load_kind == HLoadClass::LoadKind::kBssEntryPackage); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7058 | |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7059 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 7060 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7061 | ? LocationSummary::kCallOnSlowPath |
| 7062 | : LocationSummary::kNoCall; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7063 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7064 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 7065 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7066 | } |
| 7067 | |
| Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 7068 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || cls->HasPcRelativeLoadKind()) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7069 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7070 | } |
| 7071 | locations->SetOut(Location::RequiresRegister()); |
| Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 7072 | if (call_kind == LocationSummary::kCallOnSlowPath && cls->HasPcRelativeLoadKind()) { |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7073 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 7074 | // Rely on the type resolution and/or initialization to save everything. |
| Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 7075 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7076 | } else { |
| 7077 | // For non-Baker read barrier we have a temp-clobbering call. |
| 7078 | } |
| 7079 | } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7080 | } |
| 7081 | |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7082 | Label* CodeGeneratorX86::NewJitRootClassPatch(const DexFile& dex_file, |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7083 | dex::TypeIndex type_index, |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7084 | Handle<mirror::Class> handle) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7085 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7086 | // Add a patch entry and return the label. |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7087 | jit_class_patches_.emplace_back(&dex_file, type_index.index_); |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7088 | PatchInfo<Label>* info = &jit_class_patches_.back(); |
| 7089 | return &info->label; |
| 7090 | } |
| 7091 | |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7092 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 7093 | // move. |
| 7094 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7095 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7096 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7097 | codegen_->GenerateLoadClassRuntimeCall(cls); |
| Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 7098 | return; |
| 7099 | } |
| Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 7100 | DCHECK_EQ(cls->NeedsAccessCheck(), |
| 7101 | load_kind == HLoadClass::LoadKind::kBssEntryPublic || |
| 7102 | load_kind == HLoadClass::LoadKind::kBssEntryPackage); |
| Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 7103 | |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7104 | LocationSummary* locations = cls->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7105 | Location out_loc = locations->Out(); |
| 7106 | Register out = out_loc.AsRegister<Register>(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7107 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7108 | bool generate_null_check = false; |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7109 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 7110 | ? kWithoutReadBarrier |
| 7111 | : kCompilerReadBarrierOption; |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7112 | switch (load_kind) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7113 | case HLoadClass::LoadKind::kReferrersClass: { |
| 7114 | DCHECK(!cls->CanCallRuntime()); |
| 7115 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 7116 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 7117 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 7118 | GenerateGcRootFieldLoad( |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7119 | cls, |
| 7120 | out_loc, |
| 7121 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7122 | /* fixup_label= */ nullptr, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7123 | read_barrier_option); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7124 | break; |
| 7125 | } |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7126 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
| Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 7127 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 7128 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7129 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7130 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 7131 | __ leal(out, Address(method_address, CodeGeneratorX86::kPlaceholder32BitOffset)); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7132 | codegen_->RecordBootImageTypePatch(cls); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7133 | break; |
| 7134 | } |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7135 | case HLoadClass::LoadKind::kBootImageRelRo: { |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 7136 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 7137 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 7138 | __ movl(out, Address(method_address, CodeGeneratorX86::kPlaceholder32BitOffset)); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7139 | codegen_->RecordBootImageRelRoPatch(cls->InputAt(0)->AsX86ComputeBaseMethodAddress(), |
| Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 7140 | CodeGenerator::GetBootImageOffset(cls)); |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 7141 | break; |
| 7142 | } |
| Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 7143 | case HLoadClass::LoadKind::kBssEntry: |
| 7144 | case HLoadClass::LoadKind::kBssEntryPublic: |
| 7145 | case HLoadClass::LoadKind::kBssEntryPackage: { |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7146 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 7147 | Address address(method_address, CodeGeneratorX86::kPlaceholder32BitOffset); |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7148 | Label* fixup_label = codegen_->NewTypeBssEntryPatch(cls); |
| 7149 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
| Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 7150 | // No need for memory fence, thanks to the x86 memory model. |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7151 | generate_null_check = true; |
| 7152 | break; |
| 7153 | } |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7154 | case HLoadClass::LoadKind::kJitBootImageAddress: { |
| 7155 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 7156 | uint32_t address = reinterpret_cast32<uint32_t>(cls->GetClass().Get()); |
| 7157 | DCHECK_NE(address, 0u); |
| 7158 | __ movl(out, Immediate(address)); |
| 7159 | break; |
| 7160 | } |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7161 | case HLoadClass::LoadKind::kJitTableAddress: { |
| Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 7162 | Address address = Address::Absolute(CodeGeneratorX86::kPlaceholder32BitOffset); |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7163 | Label* fixup_label = codegen_->NewJitRootClassPatch( |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7164 | cls->GetDexFile(), cls->GetTypeIndex(), cls->GetClass()); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7165 | // /* GcRoot<mirror::Class> */ out = *address |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7166 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7167 | break; |
| 7168 | } |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7169 | case HLoadClass::LoadKind::kRuntimeCall: |
| Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7170 | case HLoadClass::LoadKind::kInvalid: |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7171 | LOG(FATAL) << "UNREACHABLE"; |
| 7172 | UNREACHABLE(); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7173 | } |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 7174 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7175 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 7176 | DCHECK(cls->CanCallRuntime()); |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 7177 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86(cls, cls); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7178 | codegen_->AddSlowPath(slow_path); |
| Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 7179 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7180 | if (generate_null_check) { |
| 7181 | __ testl(out, out); |
| 7182 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 7183 | } |
| Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 7184 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7185 | if (cls->MustGenerateClinitCheck()) { |
| 7186 | GenerateClassInitializationCheck(slow_path, out); |
| 7187 | } else { |
| 7188 | __ Bind(slow_path->GetExitLabel()); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 7189 | } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7190 | } |
| 7191 | } |
| 7192 | |
| Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 7193 | void LocationsBuilderX86::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 7194 | InvokeRuntimeCallingConvention calling_convention; |
| 7195 | Location location = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 7196 | CodeGenerator::CreateLoadMethodHandleRuntimeCallLocationSummary(load, location, location); |
| 7197 | } |
| 7198 | |
| 7199 | void InstructionCodeGeneratorX86::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 7200 | codegen_->GenerateLoadMethodHandleRuntimeCall(load); |
| 7201 | } |
| 7202 | |
| Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 7203 | void LocationsBuilderX86::VisitLoadMethodType(HLoadMethodType* load) { |
| 7204 | InvokeRuntimeCallingConvention calling_convention; |
| 7205 | Location location = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 7206 | CodeGenerator::CreateLoadMethodTypeRuntimeCallLocationSummary(load, location, location); |
| 7207 | } |
| 7208 | |
| 7209 | void InstructionCodeGeneratorX86::VisitLoadMethodType(HLoadMethodType* load) { |
| 7210 | codegen_->GenerateLoadMethodTypeRuntimeCall(load); |
| 7211 | } |
| 7212 | |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7213 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 7214 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7215 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7216 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7217 | if (check->HasUses()) { |
| 7218 | locations->SetOut(Location::SameAsFirstInput()); |
| 7219 | } |
| Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 7220 | // Rely on the type initialization to save everything we need. |
| 7221 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7222 | } |
| 7223 | |
| 7224 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 7225 | // We assume the class to not be null. |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 7226 | SlowPathCode* slow_path = |
| 7227 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86(check->GetLoadClass(), check); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7228 | codegen_->AddSlowPath(slow_path); |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 7229 | GenerateClassInitializationCheck(slow_path, |
| 7230 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 7231 | } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7232 | |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 7233 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7234 | SlowPathCode* slow_path, Register class_reg) { |
| Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 7235 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
| 7236 | const size_t status_byte_offset = |
| 7237 | mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte); |
| Vladimir Marko | bf12191 | 2019-06-04 13:49:05 +0100 | [diff] [blame] | 7238 | constexpr uint32_t shifted_visibly_initialized_value = |
| 7239 | enum_cast<uint32_t>(ClassStatus::kVisiblyInitialized) << (status_lsb_position % kBitsPerByte); |
| Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 7240 | |
| Vladimir Marko | bf12191 | 2019-06-04 13:49:05 +0100 | [diff] [blame] | 7241 | __ cmpb(Address(class_reg, status_byte_offset), Immediate(shifted_visibly_initialized_value)); |
| Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 7242 | __ j(kBelow, slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7243 | __ Bind(slow_path->GetExitLabel()); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7244 | } |
| 7245 | |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7246 | void InstructionCodeGeneratorX86::GenerateBitstringTypeCheckCompare(HTypeCheckInstruction* check, |
| 7247 | Register temp) { |
| 7248 | uint32_t path_to_root = check->GetBitstringPathToRoot(); |
| 7249 | uint32_t mask = check->GetBitstringMask(); |
| 7250 | DCHECK(IsPowerOfTwo(mask + 1)); |
| 7251 | size_t mask_bits = WhichPowerOf2(mask + 1); |
| 7252 | |
| 7253 | if (mask_bits == 16u) { |
| 7254 | // Compare the bitstring in memory. |
| 7255 | __ cmpw(Address(temp, mirror::Class::StatusOffset()), Immediate(path_to_root)); |
| 7256 | } else { |
| 7257 | // /* uint32_t */ temp = temp->status_ |
| 7258 | __ movl(temp, Address(temp, mirror::Class::StatusOffset())); |
| 7259 | // Compare the bitstring bits using SUB. |
| 7260 | __ subl(temp, Immediate(path_to_root)); |
| 7261 | // Shift out bits that do not contribute to the comparison. |
| 7262 | __ shll(temp, Immediate(32u - mask_bits)); |
| 7263 | } |
| 7264 | } |
| 7265 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7266 | HLoadString::LoadKind CodeGeneratorX86::GetSupportedLoadStringKind( |
| 7267 | HLoadString::LoadKind desired_string_load_kind) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7268 | switch (desired_string_load_kind) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7269 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7270 | case HLoadString::LoadKind::kBootImageRelRo: |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7271 | case HLoadString::LoadKind::kBssEntry: |
| Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 7272 | DCHECK(!GetCompilerOptions().IsJitCompiler()); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7273 | break; |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7274 | case HLoadString::LoadKind::kJitBootImageAddress: |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7275 | case HLoadString::LoadKind::kJitTableAddress: |
| Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 7276 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7277 | break; |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7278 | case HLoadString::LoadKind::kRuntimeCall: |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7279 | break; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7280 | } |
| 7281 | return desired_string_load_kind; |
| 7282 | } |
| 7283 | |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 7284 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7285 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7286 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7287 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 7288 | if (load_kind == HLoadString::LoadKind::kBootImageLinkTimePcRelative || |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7289 | load_kind == HLoadString::LoadKind::kBootImageRelRo || |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7290 | load_kind == HLoadString::LoadKind::kBssEntry) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7291 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7292 | } |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7293 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
| Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 7294 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 7295 | } else { |
| 7296 | locations->SetOut(Location::RequiresRegister()); |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 7297 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 7298 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7299 | // Rely on the pResolveString to save everything. |
| Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 7300 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 7301 | } else { |
| 7302 | // For non-Baker read barrier we have a temp-clobbering call. |
| 7303 | } |
| 7304 | } |
| Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 7305 | } |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 7306 | } |
| 7307 | |
| Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7308 | Label* CodeGeneratorX86::NewJitRootStringPatch(const DexFile& dex_file, |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7309 | dex::StringIndex string_index, |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7310 | Handle<mirror::String> handle) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7311 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7312 | // Add a patch entry and return the label. |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7313 | jit_string_patches_.emplace_back(&dex_file, string_index.index_); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7314 | PatchInfo<Label>* info = &jit_string_patches_.back(); |
| 7315 | return &info->label; |
| 7316 | } |
| 7317 | |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7318 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 7319 | // move. |
| 7320 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
| Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 7321 | LocationSummary* locations = load->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7322 | Location out_loc = locations->Out(); |
| 7323 | Register out = out_loc.AsRegister<Register>(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7324 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7325 | switch (load->GetLoadKind()) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7326 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 7327 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 7328 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7329 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 7330 | __ leal(out, Address(method_address, CodeGeneratorX86::kPlaceholder32BitOffset)); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7331 | codegen_->RecordBootImageStringPatch(load); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7332 | return; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7333 | } |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7334 | case HLoadString::LoadKind::kBootImageRelRo: { |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7335 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 7336 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 7337 | __ movl(out, Address(method_address, CodeGeneratorX86::kPlaceholder32BitOffset)); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7338 | codegen_->RecordBootImageRelRoPatch(load->InputAt(0)->AsX86ComputeBaseMethodAddress(), |
| Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 7339 | CodeGenerator::GetBootImageOffset(load)); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7340 | return; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7341 | } |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7342 | case HLoadString::LoadKind::kBssEntry: { |
| 7343 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 7344 | Address address = Address(method_address, CodeGeneratorX86::kPlaceholder32BitOffset); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7345 | Label* fixup_label = codegen_->NewStringBssEntryPatch(load); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7346 | // /* GcRoot<mirror::String> */ out = *address /* PC-relative */ |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7347 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
| Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 7348 | // No need for memory fence, thanks to the x86 memory model. |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7349 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadStringSlowPathX86(load); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7350 | codegen_->AddSlowPath(slow_path); |
| 7351 | __ testl(out, out); |
| 7352 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 7353 | __ Bind(slow_path->GetExitLabel()); |
| 7354 | return; |
| 7355 | } |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7356 | case HLoadString::LoadKind::kJitBootImageAddress: { |
| 7357 | uint32_t address = reinterpret_cast32<uint32_t>(load->GetString().Get()); |
| 7358 | DCHECK_NE(address, 0u); |
| 7359 | __ movl(out, Immediate(address)); |
| 7360 | return; |
| 7361 | } |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7362 | case HLoadString::LoadKind::kJitTableAddress: { |
| Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 7363 | Address address = Address::Absolute(CodeGeneratorX86::kPlaceholder32BitOffset); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7364 | Label* fixup_label = codegen_->NewJitRootStringPatch( |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7365 | load->GetDexFile(), load->GetStringIndex(), load->GetString()); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7366 | // /* GcRoot<mirror::String> */ out = *address |
| 7367 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
| 7368 | return; |
| 7369 | } |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7370 | default: |
| Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 7371 | break; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7372 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7373 | |
| Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 7374 | // 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] | 7375 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 7376 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
| Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7377 | __ movl(calling_convention.GetRegisterAt(0), Immediate(load->GetStringIndex().index_)); |
| Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 7378 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 7379 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 7380 | } |
| 7381 | |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7382 | static Address GetExceptionTlsAddress() { |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7383 | return Address::Absolute(Thread::ExceptionOffset<kX86PointerSize>().Int32Value()); |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7384 | } |
| 7385 | |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7386 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 7387 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7388 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7389 | locations->SetOut(Location::RequiresRegister()); |
| 7390 | } |
| 7391 | |
| 7392 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7393 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 7394 | } |
| 7395 | |
| 7396 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7397 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7398 | } |
| 7399 | |
| 7400 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 7401 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7402 | } |
| 7403 | |
| 7404 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7405 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 7406 | instruction, LocationSummary::kCallOnMainOnly); |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7407 | InvokeRuntimeCallingConvention calling_convention; |
| 7408 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 7409 | } |
| 7410 | |
| 7411 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 7412 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7413 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7414 | } |
| 7415 | |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7416 | // Temp is used for read barrier. |
| 7417 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 7418 | if (kEmitCompilerReadBarrier && |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7419 | !kUseBakerReadBarrier && |
| 7420 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7421 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7422 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 7423 | return 1; |
| 7424 | } |
| 7425 | return 0; |
| 7426 | } |
| 7427 | |
| Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 7428 | // Interface case has 2 temps, one for holding the number of interfaces, one for the current |
| 7429 | // interface pointer, the current interface is compared in memory. |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7430 | // The other checks have one temp for loading the object's class. |
| 7431 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 7432 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7433 | return 2; |
| 7434 | } |
| 7435 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7436 | } |
| 7437 | |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7438 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7439 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7440 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7441 | bool baker_read_barrier_slow_path = false; |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7442 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7443 | case TypeCheckKind::kExactCheck: |
| 7444 | case TypeCheckKind::kAbstractClassCheck: |
| 7445 | case TypeCheckKind::kClassHierarchyCheck: |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7446 | case TypeCheckKind::kArrayObjectCheck: { |
| 7447 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 7448 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 7449 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7450 | break; |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7451 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7452 | case TypeCheckKind::kArrayCheck: |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7453 | case TypeCheckKind::kUnresolvedCheck: |
| 7454 | case TypeCheckKind::kInterfaceCheck: |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7455 | call_kind = LocationSummary::kCallOnSlowPath; |
| 7456 | break; |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7457 | case TypeCheckKind::kBitstringCheck: |
| 7458 | break; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7459 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7460 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7461 | LocationSummary* locations = |
| 7462 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7463 | if (baker_read_barrier_slow_path) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 7464 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7465 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7466 | locations->SetInAt(0, Location::RequiresRegister()); |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7467 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 7468 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 7469 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 7470 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 7471 | } else { |
| 7472 | locations->SetInAt(1, Location::Any()); |
| 7473 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7474 | // Note that TypeCheckSlowPathX86 uses this "out" register too. |
| 7475 | locations->SetOut(Location::RequiresRegister()); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7476 | // When read barriers are enabled, we need a temporary register for some cases. |
| 7477 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7478 | } |
| 7479 | |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7480 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7481 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7482 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7483 | Location obj_loc = locations->InAt(0); |
| 7484 | Register obj = obj_loc.AsRegister<Register>(); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7485 | Location cls = locations->InAt(1); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7486 | Location out_loc = locations->Out(); |
| 7487 | Register out = out_loc.AsRegister<Register>(); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7488 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 7489 | DCHECK_LE(num_temps, 1u); |
| 7490 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7491 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7492 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7493 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7494 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7495 | SlowPathCode* slow_path = nullptr; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7496 | NearLabel done, zero; |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7497 | |
| 7498 | // Return 0 if `obj` is null. |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7499 | // Avoid null check if we know obj is not null. |
| 7500 | if (instruction->MustDoNullCheck()) { |
| 7501 | __ testl(obj, obj); |
| 7502 | __ j(kEqual, &zero); |
| 7503 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7504 | |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7505 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7506 | case TypeCheckKind::kExactCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7507 | ReadBarrierOption read_barrier_option = |
| 7508 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7509 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7510 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7511 | out_loc, |
| 7512 | obj_loc, |
| 7513 | class_offset, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7514 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7515 | if (cls.IsRegister()) { |
| 7516 | __ cmpl(out, cls.AsRegister<Register>()); |
| 7517 | } else { |
| 7518 | DCHECK(cls.IsStackSlot()) << cls; |
| 7519 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 7520 | } |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7521 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7522 | // Classes must be equal for the instanceof to succeed. |
| 7523 | __ j(kNotEqual, &zero); |
| 7524 | __ movl(out, Immediate(1)); |
| 7525 | __ jmp(&done); |
| 7526 | break; |
| 7527 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7528 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7529 | case TypeCheckKind::kAbstractClassCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7530 | ReadBarrierOption read_barrier_option = |
| 7531 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7532 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7533 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7534 | out_loc, |
| 7535 | obj_loc, |
| 7536 | class_offset, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7537 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7538 | // If the class is abstract, we eagerly fetch the super class of the |
| 7539 | // object to avoid doing a comparison we know will fail. |
| 7540 | NearLabel loop; |
| 7541 | __ Bind(&loop); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7542 | // /* HeapReference<Class> */ out = out->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7543 | GenerateReferenceLoadOneRegister(instruction, |
| 7544 | out_loc, |
| 7545 | super_offset, |
| 7546 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7547 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7548 | __ testl(out, out); |
| 7549 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7550 | __ j(kEqual, &done); |
| 7551 | if (cls.IsRegister()) { |
| 7552 | __ cmpl(out, cls.AsRegister<Register>()); |
| 7553 | } else { |
| 7554 | DCHECK(cls.IsStackSlot()) << cls; |
| 7555 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 7556 | } |
| 7557 | __ j(kNotEqual, &loop); |
| 7558 | __ movl(out, Immediate(1)); |
| 7559 | if (zero.IsLinked()) { |
| 7560 | __ jmp(&done); |
| 7561 | } |
| 7562 | break; |
| 7563 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7564 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7565 | case TypeCheckKind::kClassHierarchyCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7566 | ReadBarrierOption read_barrier_option = |
| 7567 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7568 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7569 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7570 | out_loc, |
| 7571 | obj_loc, |
| 7572 | class_offset, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7573 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7574 | // Walk over the class hierarchy to find a match. |
| 7575 | NearLabel loop, success; |
| 7576 | __ Bind(&loop); |
| 7577 | if (cls.IsRegister()) { |
| 7578 | __ cmpl(out, cls.AsRegister<Register>()); |
| 7579 | } else { |
| 7580 | DCHECK(cls.IsStackSlot()) << cls; |
| 7581 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 7582 | } |
| 7583 | __ j(kEqual, &success); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7584 | // /* HeapReference<Class> */ out = out->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7585 | GenerateReferenceLoadOneRegister(instruction, |
| 7586 | out_loc, |
| 7587 | super_offset, |
| 7588 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7589 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7590 | __ testl(out, out); |
| 7591 | __ j(kNotEqual, &loop); |
| 7592 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7593 | __ jmp(&done); |
| 7594 | __ Bind(&success); |
| 7595 | __ movl(out, Immediate(1)); |
| 7596 | if (zero.IsLinked()) { |
| 7597 | __ jmp(&done); |
| 7598 | } |
| 7599 | break; |
| 7600 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7601 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7602 | case TypeCheckKind::kArrayObjectCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7603 | ReadBarrierOption read_barrier_option = |
| 7604 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7605 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7606 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7607 | out_loc, |
| 7608 | obj_loc, |
| 7609 | class_offset, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7610 | read_barrier_option); |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7611 | // Do an exact check. |
| 7612 | NearLabel exact_check; |
| 7613 | if (cls.IsRegister()) { |
| 7614 | __ cmpl(out, cls.AsRegister<Register>()); |
| 7615 | } else { |
| 7616 | DCHECK(cls.IsStackSlot()) << cls; |
| 7617 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 7618 | } |
| 7619 | __ j(kEqual, &exact_check); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7620 | // 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] | 7621 | // /* HeapReference<Class> */ out = out->component_type_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7622 | GenerateReferenceLoadOneRegister(instruction, |
| 7623 | out_loc, |
| 7624 | component_offset, |
| 7625 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7626 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7627 | __ testl(out, out); |
| 7628 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7629 | __ j(kEqual, &done); |
| 7630 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 7631 | __ j(kNotEqual, &zero); |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7632 | __ Bind(&exact_check); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7633 | __ movl(out, Immediate(1)); |
| 7634 | __ jmp(&done); |
| 7635 | break; |
| 7636 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7637 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7638 | case TypeCheckKind::kArrayCheck: { |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7639 | // No read barrier since the slow path will retry upon failure. |
| 7640 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7641 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7642 | out_loc, |
| 7643 | obj_loc, |
| 7644 | class_offset, |
| 7645 | kWithoutReadBarrier); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7646 | if (cls.IsRegister()) { |
| 7647 | __ cmpl(out, cls.AsRegister<Register>()); |
| 7648 | } else { |
| 7649 | DCHECK(cls.IsStackSlot()) << cls; |
| 7650 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 7651 | } |
| 7652 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7653 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7654 | instruction, /* is_fatal= */ false); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7655 | codegen_->AddSlowPath(slow_path); |
| 7656 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 7657 | __ movl(out, Immediate(1)); |
| 7658 | if (zero.IsLinked()) { |
| 7659 | __ jmp(&done); |
| 7660 | } |
| 7661 | break; |
| 7662 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7663 | |
| Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 7664 | case TypeCheckKind::kUnresolvedCheck: |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7665 | case TypeCheckKind::kInterfaceCheck: { |
| 7666 | // 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] | 7667 | // into the slow path for the unresolved and interface check |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7668 | // cases. |
| 7669 | // |
| 7670 | // We cannot directly call the InstanceofNonTrivial runtime |
| 7671 | // entry point without resorting to a type checking slow path |
| 7672 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 7673 | // require to assign fixed registers for the inputs of this |
| 7674 | // HInstanceOf instruction (following the runtime calling |
| 7675 | // convention), which might be cluttered by the potential first |
| 7676 | // read barrier emission at the beginning of this method. |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7677 | // |
| 7678 | // TODO: Introduce a new runtime entry point taking the object |
| 7679 | // to test (instead of its class) as argument, and let it deal |
| 7680 | // with the read barrier issues. This will let us refactor this |
| 7681 | // case of the `switch` code as it was previously (with a direct |
| 7682 | // call to the runtime not using a type checking slow path). |
| 7683 | // This should also be beneficial for the other cases above. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7684 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7685 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7686 | instruction, /* is_fatal= */ false); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7687 | codegen_->AddSlowPath(slow_path); |
| 7688 | __ jmp(slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7689 | if (zero.IsLinked()) { |
| 7690 | __ jmp(&done); |
| 7691 | } |
| 7692 | break; |
| 7693 | } |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7694 | |
| 7695 | case TypeCheckKind::kBitstringCheck: { |
| 7696 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7697 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7698 | out_loc, |
| 7699 | obj_loc, |
| 7700 | class_offset, |
| 7701 | kWithoutReadBarrier); |
| 7702 | |
| 7703 | GenerateBitstringTypeCheckCompare(instruction, out); |
| 7704 | __ j(kNotEqual, &zero); |
| 7705 | __ movl(out, Immediate(1)); |
| 7706 | __ jmp(&done); |
| 7707 | break; |
| 7708 | } |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7709 | } |
| 7710 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7711 | if (zero.IsLinked()) { |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7712 | __ Bind(&zero); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7713 | __ xorl(out, out); |
| 7714 | } |
| 7715 | |
| 7716 | if (done.IsLinked()) { |
| 7717 | __ Bind(&done); |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7718 | } |
| 7719 | |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7720 | if (slow_path != nullptr) { |
| 7721 | __ Bind(slow_path->GetExitLabel()); |
| 7722 | } |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7723 | } |
| 7724 | |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7725 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7726 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7727 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7728 | LocationSummary* locations = |
| 7729 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7730 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7731 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 7732 | // Require a register for the interface check since there is a loop that compares the class to |
| 7733 | // a memory address. |
| 7734 | locations->SetInAt(1, Location::RequiresRegister()); |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7735 | } else if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 7736 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 7737 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 7738 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7739 | } else { |
| 7740 | locations->SetInAt(1, Location::Any()); |
| 7741 | } |
| Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 7742 | // Add temps for read barriers and other uses. One is used by TypeCheckSlowPathX86. |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7743 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
| 7744 | } |
| 7745 | |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7746 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7747 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7748 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7749 | Location obj_loc = locations->InAt(0); |
| 7750 | Register obj = obj_loc.AsRegister<Register>(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7751 | Location cls = locations->InAt(1); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7752 | Location temp_loc = locations->GetTemp(0); |
| 7753 | Register temp = temp_loc.AsRegister<Register>(); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7754 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 7755 | DCHECK_GE(num_temps, 1u); |
| 7756 | DCHECK_LE(num_temps, 2u); |
| 7757 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 7758 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7759 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7760 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7761 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 7762 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 7763 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 7764 | const uint32_t object_array_data_offset = |
| 7765 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7766 | |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7767 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7768 | SlowPathCode* type_check_slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7769 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
| 7770 | instruction, is_type_check_slow_path_fatal); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7771 | codegen_->AddSlowPath(type_check_slow_path); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7772 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7773 | NearLabel done; |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7774 | // Avoid null check if we know obj is not null. |
| 7775 | if (instruction->MustDoNullCheck()) { |
| 7776 | __ testl(obj, obj); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7777 | __ j(kEqual, &done); |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7778 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7779 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7780 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7781 | case TypeCheckKind::kExactCheck: |
| 7782 | case TypeCheckKind::kArrayCheck: { |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7783 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7784 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7785 | temp_loc, |
| 7786 | obj_loc, |
| 7787 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7788 | kWithoutReadBarrier); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7789 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7790 | if (cls.IsRegister()) { |
| 7791 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 7792 | } else { |
| 7793 | DCHECK(cls.IsStackSlot()) << cls; |
| 7794 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 7795 | } |
| 7796 | // Jump to slow path for throwing the exception or doing a |
| 7797 | // more involved array check. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7798 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7799 | break; |
| 7800 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7801 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7802 | case TypeCheckKind::kAbstractClassCheck: { |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7803 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7804 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7805 | temp_loc, |
| 7806 | obj_loc, |
| 7807 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7808 | kWithoutReadBarrier); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7809 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7810 | // If the class is abstract, we eagerly fetch the super class of the |
| 7811 | // object to avoid doing a comparison we know will fail. |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7812 | NearLabel loop; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7813 | __ Bind(&loop); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7814 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7815 | GenerateReferenceLoadOneRegister(instruction, |
| 7816 | temp_loc, |
| 7817 | super_offset, |
| 7818 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7819 | kWithoutReadBarrier); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7820 | |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7821 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 7822 | // exception. |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7823 | __ testl(temp, temp); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7824 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7825 | |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7826 | // Otherwise, compare the classes |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7827 | if (cls.IsRegister()) { |
| 7828 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 7829 | } else { |
| 7830 | DCHECK(cls.IsStackSlot()) << cls; |
| 7831 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 7832 | } |
| 7833 | __ j(kNotEqual, &loop); |
| 7834 | break; |
| 7835 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7836 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7837 | case TypeCheckKind::kClassHierarchyCheck: { |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7838 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7839 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7840 | temp_loc, |
| 7841 | obj_loc, |
| 7842 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7843 | kWithoutReadBarrier); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7844 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7845 | // Walk over the class hierarchy to find a match. |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7846 | NearLabel loop; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7847 | __ Bind(&loop); |
| 7848 | if (cls.IsRegister()) { |
| 7849 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 7850 | } else { |
| 7851 | DCHECK(cls.IsStackSlot()) << cls; |
| 7852 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 7853 | } |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7854 | __ j(kEqual, &done); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7855 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7856 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7857 | GenerateReferenceLoadOneRegister(instruction, |
| 7858 | temp_loc, |
| 7859 | super_offset, |
| 7860 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7861 | kWithoutReadBarrier); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7862 | |
| 7863 | // If the class reference currently in `temp` is not null, jump |
| 7864 | // back at the beginning of the loop. |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7865 | __ testl(temp, temp); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7866 | __ j(kNotZero, &loop); |
| 7867 | // Otherwise, jump to the slow path to throw the exception.; |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7868 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7869 | break; |
| 7870 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7871 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7872 | case TypeCheckKind::kArrayObjectCheck: { |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7873 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7874 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7875 | temp_loc, |
| 7876 | obj_loc, |
| 7877 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7878 | kWithoutReadBarrier); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7879 | |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7880 | // Do an exact check. |
| 7881 | if (cls.IsRegister()) { |
| 7882 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 7883 | } else { |
| 7884 | DCHECK(cls.IsStackSlot()) << cls; |
| 7885 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 7886 | } |
| 7887 | __ j(kEqual, &done); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7888 | |
| 7889 | // 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] | 7890 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7891 | GenerateReferenceLoadOneRegister(instruction, |
| 7892 | temp_loc, |
| 7893 | component_offset, |
| 7894 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7895 | kWithoutReadBarrier); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7896 | |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7897 | // If the component type is null (i.e. the object not an array), jump to the slow path to |
| 7898 | // throw the exception. Otherwise proceed with the check. |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7899 | __ testl(temp, temp); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7900 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7901 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7902 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7903 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7904 | break; |
| 7905 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7906 | |
| Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 7907 | case TypeCheckKind::kUnresolvedCheck: |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7908 | // 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] | 7909 | // We cannot directly call the CheckCast runtime entry point |
| 7910 | // without resorting to a type checking slow path here (i.e. by |
| 7911 | // calling InvokeRuntime directly), as it would require to |
| 7912 | // assign fixed registers for the inputs of this HInstanceOf |
| 7913 | // instruction (following the runtime calling convention), which |
| 7914 | // might be cluttered by the potential first read barrier |
| 7915 | // emission at the beginning of this method. |
| 7916 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7917 | break; |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7918 | |
| 7919 | case TypeCheckKind::kInterfaceCheck: { |
| Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 7920 | // Fast path for the interface check. Try to avoid read barriers to improve the fast path. |
| 7921 | // We can not get false positives by doing this. |
| 7922 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7923 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7924 | temp_loc, |
| 7925 | obj_loc, |
| 7926 | class_offset, |
| 7927 | kWithoutReadBarrier); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7928 | |
| Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 7929 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 7930 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7931 | temp_loc, |
| 7932 | temp_loc, |
| 7933 | iftable_offset, |
| 7934 | kWithoutReadBarrier); |
| 7935 | // Iftable is never null. |
| 7936 | __ movl(maybe_temp2_loc.AsRegister<Register>(), Address(temp, array_length_offset)); |
| 7937 | // Maybe poison the `cls` for direct comparison with memory. |
| 7938 | __ MaybePoisonHeapReference(cls.AsRegister<Register>()); |
| 7939 | // Loop through the iftable and check if any class matches. |
| 7940 | NearLabel start_loop; |
| 7941 | __ Bind(&start_loop); |
| 7942 | // Need to subtract first to handle the empty array case. |
| 7943 | __ subl(maybe_temp2_loc.AsRegister<Register>(), Immediate(2)); |
| 7944 | __ j(kNegative, type_check_slow_path->GetEntryLabel()); |
| 7945 | // Go to next interface if the classes do not match. |
| 7946 | __ cmpl(cls.AsRegister<Register>(), |
| 7947 | CodeGeneratorX86::ArrayAddress(temp, |
| 7948 | maybe_temp2_loc, |
| 7949 | TIMES_4, |
| 7950 | object_array_data_offset)); |
| 7951 | __ j(kNotEqual, &start_loop); |
| 7952 | // If `cls` was poisoned above, unpoison it. |
| 7953 | __ MaybeUnpoisonHeapReference(cls.AsRegister<Register>()); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7954 | break; |
| 7955 | } |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7956 | |
| 7957 | case TypeCheckKind::kBitstringCheck: { |
| 7958 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7959 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7960 | temp_loc, |
| 7961 | obj_loc, |
| 7962 | class_offset, |
| 7963 | kWithoutReadBarrier); |
| 7964 | |
| 7965 | GenerateBitstringTypeCheckCompare(instruction, temp); |
| 7966 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
| 7967 | break; |
| 7968 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7969 | } |
| 7970 | __ Bind(&done); |
| 7971 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7972 | __ Bind(type_check_slow_path->GetExitLabel()); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7973 | } |
| 7974 | |
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7975 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7976 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 7977 | instruction, LocationSummary::kCallOnMainOnly); |
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7978 | InvokeRuntimeCallingConvention calling_convention; |
| 7979 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 7980 | } |
| 7981 | |
| 7982 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 7983 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject |
| 7984 | : kQuickUnlockObject, |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 7985 | instruction, |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 7986 | instruction->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7987 | if (instruction->IsEnter()) { |
| 7988 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 7989 | } else { |
| 7990 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 7991 | } |
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7992 | } |
| 7993 | |
| Shalini Salomi Bodapati | dd121f6 | 2018-10-26 15:03:53 +0530 | [diff] [blame] | 7994 | void LocationsBuilderX86::VisitX86AndNot(HX86AndNot* instruction) { |
| 7995 | DCHECK(codegen_->GetInstructionSetFeatures().HasAVX2()); |
| 7996 | DCHECK(DataType::IsIntOrLongType(instruction->GetType())) << instruction->GetType(); |
| 7997 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| 7998 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7999 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8000 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8001 | } |
| 8002 | |
| 8003 | void InstructionCodeGeneratorX86::VisitX86AndNot(HX86AndNot* instruction) { |
| 8004 | LocationSummary* locations = instruction->GetLocations(); |
| 8005 | Location first = locations->InAt(0); |
| 8006 | Location second = locations->InAt(1); |
| 8007 | Location dest = locations->Out(); |
| 8008 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
| 8009 | __ andn(dest.AsRegister<Register>(), |
| 8010 | first.AsRegister<Register>(), |
| 8011 | second.AsRegister<Register>()); |
| 8012 | } else { |
| 8013 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
| 8014 | __ andn(dest.AsRegisterPairLow<Register>(), |
| 8015 | first.AsRegisterPairLow<Register>(), |
| 8016 | second.AsRegisterPairLow<Register>()); |
| 8017 | __ andn(dest.AsRegisterPairHigh<Register>(), |
| 8018 | first.AsRegisterPairHigh<Register>(), |
| 8019 | second.AsRegisterPairHigh<Register>()); |
| 8020 | } |
| 8021 | } |
| 8022 | |
| 8023 | void LocationsBuilderX86::VisitX86MaskOrResetLeastSetBit(HX86MaskOrResetLeastSetBit* instruction) { |
| 8024 | DCHECK(codegen_->GetInstructionSetFeatures().HasAVX2()); |
| 8025 | DCHECK(instruction->GetType() == DataType::Type::kInt32) << instruction->GetType(); |
| 8026 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| 8027 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8028 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8029 | } |
| 8030 | |
| 8031 | void InstructionCodeGeneratorX86::VisitX86MaskOrResetLeastSetBit( |
| 8032 | HX86MaskOrResetLeastSetBit* instruction) { |
| 8033 | LocationSummary* locations = instruction->GetLocations(); |
| 8034 | Location src = locations->InAt(0); |
| 8035 | Location dest = locations->Out(); |
| 8036 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
| 8037 | switch (instruction->GetOpKind()) { |
| 8038 | case HInstruction::kAnd: |
| 8039 | __ blsr(dest.AsRegister<Register>(), src.AsRegister<Register>()); |
| 8040 | break; |
| 8041 | case HInstruction::kXor: |
| 8042 | __ blsmsk(dest.AsRegister<Register>(), src.AsRegister<Register>()); |
| 8043 | break; |
| 8044 | default: |
| 8045 | LOG(FATAL) << "Unreachable"; |
| 8046 | } |
| 8047 | } |
| 8048 | |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8049 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 8050 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 8051 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 8052 | |
| 8053 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 8054 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8055 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8056 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 |
| 8057 | || instruction->GetResultType() == DataType::Type::kInt64); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8058 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8059 | locations->SetInAt(1, Location::Any()); |
| 8060 | locations->SetOut(Location::SameAsFirstInput()); |
| 8061 | } |
| 8062 | |
| 8063 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 8064 | HandleBitwiseOperation(instruction); |
| 8065 | } |
| 8066 | |
| 8067 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 8068 | HandleBitwiseOperation(instruction); |
| 8069 | } |
| 8070 | |
| 8071 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 8072 | HandleBitwiseOperation(instruction); |
| 8073 | } |
| 8074 | |
| 8075 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 8076 | LocationSummary* locations = instruction->GetLocations(); |
| 8077 | Location first = locations->InAt(0); |
| 8078 | Location second = locations->InAt(1); |
| 8079 | DCHECK(first.Equals(locations->Out())); |
| 8080 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8081 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8082 | if (second.IsRegister()) { |
| 8083 | if (instruction->IsAnd()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 8084 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8085 | } else if (instruction->IsOr()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 8086 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8087 | } else { |
| 8088 | DCHECK(instruction->IsXor()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 8089 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8090 | } |
| 8091 | } else if (second.IsConstant()) { |
| 8092 | if (instruction->IsAnd()) { |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 8093 | __ andl(first.AsRegister<Register>(), |
| 8094 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8095 | } else if (instruction->IsOr()) { |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 8096 | __ orl(first.AsRegister<Register>(), |
| 8097 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8098 | } else { |
| 8099 | DCHECK(instruction->IsXor()); |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 8100 | __ xorl(first.AsRegister<Register>(), |
| 8101 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8102 | } |
| 8103 | } else { |
| 8104 | if (instruction->IsAnd()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 8105 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8106 | } else if (instruction->IsOr()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 8107 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8108 | } else { |
| 8109 | DCHECK(instruction->IsXor()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 8110 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8111 | } |
| 8112 | } |
| 8113 | } else { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8114 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8115 | if (second.IsRegisterPair()) { |
| 8116 | if (instruction->IsAnd()) { |
| 8117 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 8118 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 8119 | } else if (instruction->IsOr()) { |
| 8120 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 8121 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 8122 | } else { |
| 8123 | DCHECK(instruction->IsXor()); |
| 8124 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 8125 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 8126 | } |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 8127 | } else if (second.IsDoubleStackSlot()) { |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8128 | if (instruction->IsAnd()) { |
| 8129 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 8130 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 8131 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 8132 | } else if (instruction->IsOr()) { |
| 8133 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 8134 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 8135 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 8136 | } else { |
| 8137 | DCHECK(instruction->IsXor()); |
| 8138 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 8139 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 8140 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 8141 | } |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 8142 | } else { |
| 8143 | DCHECK(second.IsConstant()) << second; |
| 8144 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 8145 | int32_t low_value = Low32Bits(value); |
| 8146 | int32_t high_value = High32Bits(value); |
| 8147 | Immediate low(low_value); |
| 8148 | Immediate high(high_value); |
| 8149 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 8150 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 8151 | if (instruction->IsAnd()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 8152 | if (low_value == 0) { |
| 8153 | __ xorl(first_low, first_low); |
| 8154 | } else if (low_value != -1) { |
| 8155 | __ andl(first_low, low); |
| 8156 | } |
| 8157 | if (high_value == 0) { |
| 8158 | __ xorl(first_high, first_high); |
| 8159 | } else if (high_value != -1) { |
| 8160 | __ andl(first_high, high); |
| 8161 | } |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 8162 | } else if (instruction->IsOr()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 8163 | if (low_value != 0) { |
| 8164 | __ orl(first_low, low); |
| 8165 | } |
| 8166 | if (high_value != 0) { |
| 8167 | __ orl(first_high, high); |
| 8168 | } |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 8169 | } else { |
| 8170 | DCHECK(instruction->IsXor()); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 8171 | if (low_value != 0) { |
| 8172 | __ xorl(first_low, low); |
| 8173 | } |
| 8174 | if (high_value != 0) { |
| 8175 | __ xorl(first_high, high); |
| 8176 | } |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 8177 | } |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8178 | } |
| 8179 | } |
| 8180 | } |
| 8181 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 8182 | void InstructionCodeGeneratorX86::GenerateReferenceLoadOneRegister( |
| 8183 | HInstruction* instruction, |
| 8184 | Location out, |
| 8185 | uint32_t offset, |
| 8186 | Location maybe_temp, |
| 8187 | ReadBarrierOption read_barrier_option) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8188 | Register out_reg = out.AsRegister<Register>(); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 8189 | if (read_barrier_option == kWithReadBarrier) { |
| 8190 | CHECK(kEmitCompilerReadBarrier); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8191 | if (kUseBakerReadBarrier) { |
| 8192 | // Load with fast path based Baker's read barrier. |
| 8193 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8194 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8195 | instruction, out, out_reg, offset, /* needs_null_check= */ false); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8196 | } else { |
| 8197 | // Load with slow path based read barrier. |
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 8198 | // Save the value of `out` into `maybe_temp` before overwriting it |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8199 | // in the following move operation, as we will need it for the |
| 8200 | // read barrier below. |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 8201 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 8202 | __ movl(maybe_temp.AsRegister<Register>(), out_reg); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8203 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8204 | __ movl(out_reg, Address(out_reg, offset)); |
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 8205 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8206 | } |
| 8207 | } else { |
| 8208 | // Plain load with no read barrier. |
| 8209 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8210 | __ movl(out_reg, Address(out_reg, offset)); |
| 8211 | __ MaybeUnpoisonHeapReference(out_reg); |
| 8212 | } |
| 8213 | } |
| 8214 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 8215 | void InstructionCodeGeneratorX86::GenerateReferenceLoadTwoRegisters( |
| 8216 | HInstruction* instruction, |
| 8217 | Location out, |
| 8218 | Location obj, |
| 8219 | uint32_t offset, |
| 8220 | ReadBarrierOption read_barrier_option) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8221 | Register out_reg = out.AsRegister<Register>(); |
| 8222 | Register obj_reg = obj.AsRegister<Register>(); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 8223 | if (read_barrier_option == kWithReadBarrier) { |
| 8224 | CHECK(kEmitCompilerReadBarrier); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8225 | if (kUseBakerReadBarrier) { |
| 8226 | // Load with fast path based Baker's read barrier. |
| 8227 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8228 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8229 | instruction, out, obj_reg, offset, /* needs_null_check= */ false); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8230 | } else { |
| 8231 | // Load with slow path based read barrier. |
| 8232 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8233 | __ movl(out_reg, Address(obj_reg, offset)); |
| 8234 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 8235 | } |
| 8236 | } else { |
| 8237 | // Plain load with no read barrier. |
| 8238 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8239 | __ movl(out_reg, Address(obj_reg, offset)); |
| 8240 | __ MaybeUnpoisonHeapReference(out_reg); |
| 8241 | } |
| 8242 | } |
| 8243 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 8244 | void InstructionCodeGeneratorX86::GenerateGcRootFieldLoad( |
| 8245 | HInstruction* instruction, |
| 8246 | Location root, |
| 8247 | const Address& address, |
| 8248 | Label* fixup_label, |
| 8249 | ReadBarrierOption read_barrier_option) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8250 | Register root_reg = root.AsRegister<Register>(); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 8251 | if (read_barrier_option == kWithReadBarrier) { |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 8252 | DCHECK(kEmitCompilerReadBarrier); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8253 | if (kUseBakerReadBarrier) { |
| 8254 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 8255 | // Baker's read barrier are used: |
| 8256 | // |
| Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 8257 | // root = obj.field; |
| 8258 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 8259 | // if (temp != null) { |
| 8260 | // root = temp(root) |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8261 | // } |
| 8262 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8263 | // /* GcRoot<mirror::Object> */ root = *address |
| 8264 | __ movl(root_reg, address); |
| 8265 | if (fixup_label != nullptr) { |
| 8266 | __ Bind(fixup_label); |
| 8267 | } |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8268 | static_assert( |
| 8269 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 8270 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 8271 | "have different sizes."); |
| 8272 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 8273 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 8274 | "have different sizes."); |
| 8275 | |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 8276 | // Slow path marking the GC root `root`. |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8277 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathX86( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8278 | instruction, root, /* unpoison_ref_before_marking= */ false); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8279 | codegen_->AddSlowPath(slow_path); |
| 8280 | |
| Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 8281 | // Test the entrypoint (`Thread::Current()->pReadBarrierMarkReg ## root.reg()`). |
| 8282 | const int32_t entry_point_offset = |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 8283 | Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(root.reg()); |
| Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 8284 | __ fs()->cmpl(Address::Absolute(entry_point_offset), Immediate(0)); |
| 8285 | // The entrypoint is null when the GC is not marking. |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8286 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 8287 | __ Bind(slow_path->GetExitLabel()); |
| 8288 | } else { |
| 8289 | // GC root loaded through a slow path for read barriers other |
| 8290 | // than Baker's. |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8291 | // /* GcRoot<mirror::Object>* */ root = address |
| 8292 | __ leal(root_reg, address); |
| 8293 | if (fixup_label != nullptr) { |
| 8294 | __ Bind(fixup_label); |
| 8295 | } |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8296 | // /* mirror::Object* */ root = root->Read() |
| 8297 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 8298 | } |
| 8299 | } else { |
| 8300 | // Plain GC root load with no read barrier. |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8301 | // /* GcRoot<mirror::Object> */ root = *address |
| 8302 | __ movl(root_reg, address); |
| 8303 | if (fixup_label != nullptr) { |
| 8304 | __ Bind(fixup_label); |
| 8305 | } |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 8306 | // Note that GC roots are not affected by heap poisoning, thus we |
| 8307 | // do not have to unpoison `root_reg` here. |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8308 | } |
| 8309 | } |
| 8310 | |
| 8311 | void CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8312 | Location ref, |
| 8313 | Register obj, |
| 8314 | uint32_t offset, |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8315 | bool needs_null_check) { |
| 8316 | DCHECK(kEmitCompilerReadBarrier); |
| 8317 | DCHECK(kUseBakerReadBarrier); |
| 8318 | |
| 8319 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 8320 | Address src(obj, offset); |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 8321 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8322 | } |
| 8323 | |
| 8324 | void CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8325 | Location ref, |
| 8326 | Register obj, |
| 8327 | uint32_t data_offset, |
| 8328 | Location index, |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8329 | bool needs_null_check) { |
| 8330 | DCHECK(kEmitCompilerReadBarrier); |
| 8331 | DCHECK(kUseBakerReadBarrier); |
| 8332 | |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 8333 | static_assert( |
| 8334 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 8335 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8336 | // /* HeapReference<Object> */ ref = |
| 8337 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8338 | Address src = CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset); |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 8339 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8340 | } |
| 8341 | |
| 8342 | void CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8343 | Location ref, |
| 8344 | Register obj, |
| 8345 | const Address& src, |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 8346 | bool needs_null_check, |
| 8347 | bool always_update_field, |
| 8348 | Register* temp) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8349 | DCHECK(kEmitCompilerReadBarrier); |
| 8350 | DCHECK(kUseBakerReadBarrier); |
| 8351 | |
| 8352 | // In slow path based read barriers, the read barrier call is |
| 8353 | // inserted after the original load. However, in fast path based |
| 8354 | // Baker's read barriers, we need to perform the load of |
| 8355 | // mirror::Object::monitor_ *before* the original reference load. |
| 8356 | // This load-load ordering is required by the read barrier. |
| 8357 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 8358 | // |
| 8359 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 8360 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 8361 | // HeapReference<Object> ref = *src; // Original reference load. |
| Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 8362 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8363 | // if (is_gray) { |
| 8364 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 8365 | // } |
| 8366 | // |
| 8367 | // Note: the original implementation in ReadBarrier::Barrier is |
| 8368 | // slightly more complex as: |
| 8369 | // - it implements the load-load fence using a data dependency on |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 8370 | // the high-bits of rb_state, which are expected to be all zeroes |
| 8371 | // (we use CodeGeneratorX86::GenerateMemoryBarrier instead here, |
| 8372 | // which is a no-op thanks to the x86 memory model); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8373 | // - it performs additional checks that we do not do here for |
| 8374 | // performance reasons. |
| 8375 | |
| 8376 | Register ref_reg = ref.AsRegister<Register>(); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8377 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 8378 | |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 8379 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| Roland Levillain | 14e5a29 | 2018-06-28 12:00:56 +0100 | [diff] [blame] | 8380 | static_assert(ReadBarrier::NonGrayState() == 0, "Expecting non-gray to have value 0"); |
| Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 8381 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 8382 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 8383 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 8384 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 8385 | |
| Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 8386 | // if (rb_state == ReadBarrier::GrayState()) |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 8387 | // ref = ReadBarrier::Mark(ref); |
| 8388 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 8389 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8390 | if (needs_null_check) { |
| 8391 | MaybeRecordImplicitNullCheck(instruction); |
| 8392 | } |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8393 | |
| 8394 | // Load fence to prevent load-load reordering. |
| 8395 | // Note that this is a no-op, thanks to the x86 memory model. |
| 8396 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 8397 | |
| 8398 | // The actual reference load. |
| 8399 | // /* HeapReference<Object> */ ref = *src |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 8400 | __ movl(ref_reg, src); // Flags are unaffected. |
| 8401 | |
| 8402 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 8403 | // Slow path marking the object `ref` when it is gray. |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 8404 | SlowPathCode* slow_path; |
| 8405 | if (always_update_field) { |
| 8406 | DCHECK(temp != nullptr); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8407 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkAndUpdateFieldSlowPathX86( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8408 | instruction, ref, obj, src, /* unpoison_ref_before_marking= */ true, *temp); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 8409 | } else { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8410 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkSlowPathX86( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8411 | instruction, ref, /* unpoison_ref_before_marking= */ true); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 8412 | } |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 8413 | AddSlowPath(slow_path); |
| 8414 | |
| 8415 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 8416 | __ j(kNotZero, slow_path->GetEntryLabel()); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8417 | |
| 8418 | // Object* ref = ref_addr->AsMirrorPtr() |
| 8419 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 8420 | |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8421 | __ Bind(slow_path->GetExitLabel()); |
| 8422 | } |
| 8423 | |
| 8424 | void CodeGeneratorX86::GenerateReadBarrierSlow(HInstruction* instruction, |
| 8425 | Location out, |
| 8426 | Location ref, |
| 8427 | Location obj, |
| 8428 | uint32_t offset, |
| 8429 | Location index) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8430 | DCHECK(kEmitCompilerReadBarrier); |
| 8431 | |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8432 | // Insert a slow path based read barrier *after* the reference load. |
| 8433 | // |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8434 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 8435 | // reference will be carried out by the runtime within the slow |
| 8436 | // path. |
| 8437 | // |
| 8438 | // Note that `ref` currently does not get unpoisoned (when heap |
| 8439 | // poisoning is enabled), which is alright as the `ref` argument is |
| 8440 | // not used by the artReadBarrierSlow entry point. |
| 8441 | // |
| 8442 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8443 | SlowPathCode* slow_path = new (GetScopedAllocator()) |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8444 | ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); |
| 8445 | AddSlowPath(slow_path); |
| 8446 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8447 | __ jmp(slow_path->GetEntryLabel()); |
| 8448 | __ Bind(slow_path->GetExitLabel()); |
| 8449 | } |
| 8450 | |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8451 | void CodeGeneratorX86::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 8452 | Location out, |
| 8453 | Location ref, |
| 8454 | Location obj, |
| 8455 | uint32_t offset, |
| 8456 | Location index) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8457 | if (kEmitCompilerReadBarrier) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8458 | // Baker's read barriers shall be handled by the fast path |
| 8459 | // (CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier). |
| 8460 | DCHECK(!kUseBakerReadBarrier); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8461 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 8462 | // by the runtime within the slow path. |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8463 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8464 | } else if (kPoisonHeapReferences) { |
| 8465 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 8466 | } |
| 8467 | } |
| 8468 | |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8469 | void CodeGeneratorX86::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 8470 | Location out, |
| 8471 | Location root) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8472 | DCHECK(kEmitCompilerReadBarrier); |
| 8473 | |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8474 | // Insert a slow path based read barrier *after* the GC root load. |
| 8475 | // |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8476 | // Note that GC roots are not affected by heap poisoning, so we do |
| 8477 | // not need to do anything special for this here. |
| 8478 | SlowPathCode* slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8479 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathX86(instruction, out, root); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8480 | AddSlowPath(slow_path); |
| 8481 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8482 | __ jmp(slow_path->GetEntryLabel()); |
| 8483 | __ Bind(slow_path->GetExitLabel()); |
| 8484 | } |
| 8485 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 8486 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8487 | // Nothing to do, this should be removed during prepare for register allocator. |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8488 | LOG(FATAL) << "Unreachable"; |
| 8489 | } |
| 8490 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 8491 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8492 | // Nothing to do, this should be removed during prepare for register allocator. |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8493 | LOG(FATAL) << "Unreachable"; |
| 8494 | } |
| 8495 | |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8496 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 8497 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 8498 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8499 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8500 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8501 | } |
| 8502 | |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8503 | void InstructionCodeGeneratorX86::GenPackedSwitchWithCompares(Register value_reg, |
| 8504 | int32_t lower_bound, |
| 8505 | uint32_t num_entries, |
| 8506 | HBasicBlock* switch_block, |
| 8507 | HBasicBlock* default_block) { |
| 8508 | // Figure out the correct compare values and jump conditions. |
| 8509 | // Handle the first compare/branch as a special case because it might |
| 8510 | // jump to the default case. |
| 8511 | DCHECK_GT(num_entries, 2u); |
| 8512 | Condition first_condition; |
| 8513 | uint32_t index; |
| 8514 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 8515 | if (lower_bound != 0) { |
| 8516 | first_condition = kLess; |
| 8517 | __ cmpl(value_reg, Immediate(lower_bound)); |
| 8518 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 8519 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8520 | |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8521 | index = 1; |
| 8522 | } else { |
| 8523 | // Handle all the compare/jumps below. |
| 8524 | first_condition = kBelow; |
| 8525 | index = 0; |
| 8526 | } |
| 8527 | |
| 8528 | // Handle the rest of the compare/jumps. |
| 8529 | for (; index + 1 < num_entries; index += 2) { |
| 8530 | int32_t compare_to_value = lower_bound + index + 1; |
| 8531 | __ cmpl(value_reg, Immediate(compare_to_value)); |
| 8532 | // Jump to successors[index] if value < case_value[index]. |
| 8533 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 8534 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 8535 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 8536 | } |
| 8537 | |
| 8538 | if (index != num_entries) { |
| 8539 | // There are an odd number of entries. Handle the last one. |
| 8540 | DCHECK_EQ(index + 1, num_entries); |
| 8541 | __ cmpl(value_reg, Immediate(lower_bound + index)); |
| 8542 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8543 | } |
| 8544 | |
| 8545 | // And the default for any other value. |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8546 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
| 8547 | __ jmp(codegen_->GetLabelOf(default_block)); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8548 | } |
| 8549 | } |
| 8550 | |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8551 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 8552 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 8553 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 8554 | LocationSummary* locations = switch_instr->GetLocations(); |
| 8555 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 8556 | |
| 8557 | GenPackedSwitchWithCompares(value_reg, |
| 8558 | lower_bound, |
| 8559 | num_entries, |
| 8560 | switch_instr->GetBlock(), |
| 8561 | switch_instr->GetDefaultBlock()); |
| 8562 | } |
| 8563 | |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8564 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 8565 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8566 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8567 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8568 | |
| 8569 | // Constant area pointer. |
| 8570 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8571 | |
| 8572 | // And the temporary we need. |
| 8573 | locations->AddTemp(Location::RequiresRegister()); |
| 8574 | } |
| 8575 | |
| 8576 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 8577 | int32_t lower_bound = switch_instr->GetStartValue(); |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8578 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8579 | LocationSummary* locations = switch_instr->GetLocations(); |
| 8580 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 8581 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 8582 | |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8583 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 8584 | GenPackedSwitchWithCompares(value_reg, |
| 8585 | lower_bound, |
| 8586 | num_entries, |
| 8587 | switch_instr->GetBlock(), |
| 8588 | default_block); |
| 8589 | return; |
| 8590 | } |
| 8591 | |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8592 | // Optimizing has a jump area. |
| 8593 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 8594 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 8595 | |
| 8596 | // Remove the bias, if needed. |
| 8597 | if (lower_bound != 0) { |
| 8598 | __ leal(temp_reg, Address(value_reg, -lower_bound)); |
| 8599 | value_reg = temp_reg; |
| 8600 | } |
| 8601 | |
| 8602 | // Is the value in range? |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8603 | DCHECK_GE(num_entries, 1u); |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8604 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 8605 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| 8606 | |
| 8607 | // We are in the range of the table. |
| 8608 | // Load (target-constant_area) from the jump table, indexing by the value. |
| 8609 | __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); |
| 8610 | |
| 8611 | // Compute the actual target address by adding in constant_area. |
| 8612 | __ addl(temp_reg, constant_area); |
| 8613 | |
| 8614 | // And jump. |
| 8615 | __ jmp(temp_reg); |
| 8616 | } |
| 8617 | |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8618 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 8619 | HX86ComputeBaseMethodAddress* insn) { |
| 8620 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8621 | new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8622 | locations->SetOut(Location::RequiresRegister()); |
| 8623 | } |
| 8624 | |
| 8625 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 8626 | HX86ComputeBaseMethodAddress* insn) { |
| 8627 | LocationSummary* locations = insn->GetLocations(); |
| 8628 | Register reg = locations->Out().AsRegister<Register>(); |
| 8629 | |
| 8630 | // Generate call to next instruction. |
| 8631 | Label next_instruction; |
| 8632 | __ call(&next_instruction); |
| 8633 | __ Bind(&next_instruction); |
| 8634 | |
| 8635 | // Remember this offset for later use with constant area. |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8636 | codegen_->AddMethodAddressOffset(insn, GetAssembler()->CodeSize()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8637 | |
| 8638 | // Grab the return address off the stack. |
| 8639 | __ popl(reg); |
| 8640 | } |
| 8641 | |
| 8642 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 8643 | HX86LoadFromConstantTable* insn) { |
| 8644 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8645 | new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8646 | |
| 8647 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8648 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 8649 | |
| 8650 | // 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] | 8651 | if (insn->IsEmittedAtUseSite()) { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8652 | return; |
| 8653 | } |
| 8654 | |
| 8655 | switch (insn->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8656 | case DataType::Type::kFloat32: |
| 8657 | case DataType::Type::kFloat64: |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8658 | locations->SetOut(Location::RequiresFpuRegister()); |
| 8659 | break; |
| 8660 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8661 | case DataType::Type::kInt32: |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8662 | locations->SetOut(Location::RequiresRegister()); |
| 8663 | break; |
| 8664 | |
| 8665 | default: |
| 8666 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 8667 | } |
| 8668 | } |
| 8669 | |
| 8670 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 8671 | if (insn->IsEmittedAtUseSite()) { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8672 | return; |
| 8673 | } |
| 8674 | |
| 8675 | LocationSummary* locations = insn->GetLocations(); |
| 8676 | Location out = locations->Out(); |
| 8677 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 8678 | HConstant *value = insn->GetConstant(); |
| 8679 | |
| 8680 | switch (insn->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8681 | case DataType::Type::kFloat32: |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8682 | __ movss(out.AsFpuRegister<XmmRegister>(), |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8683 | codegen_->LiteralFloatAddress( |
| 8684 | value->AsFloatConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8685 | break; |
| 8686 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8687 | case DataType::Type::kFloat64: |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8688 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8689 | codegen_->LiteralDoubleAddress( |
| 8690 | value->AsDoubleConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8691 | break; |
| 8692 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8693 | case DataType::Type::kInt32: |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8694 | __ movl(out.AsRegister<Register>(), |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8695 | codegen_->LiteralInt32Address( |
| 8696 | value->AsIntConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8697 | break; |
| 8698 | |
| 8699 | default: |
| 8700 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 8701 | } |
| 8702 | } |
| 8703 | |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8704 | /** |
| 8705 | * Class to handle late fixup of offsets into constant area. |
| 8706 | */ |
| Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 8707 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8708 | public: |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8709 | RIPFixup(CodeGeneratorX86& codegen, |
| 8710 | HX86ComputeBaseMethodAddress* base_method_address, |
| 8711 | size_t offset) |
| 8712 | : codegen_(&codegen), |
| 8713 | base_method_address_(base_method_address), |
| 8714 | offset_into_constant_area_(offset) {} |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8715 | |
| 8716 | protected: |
| 8717 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 8718 | |
| 8719 | CodeGeneratorX86* codegen_; |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8720 | HX86ComputeBaseMethodAddress* base_method_address_; |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8721 | |
| 8722 | private: |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8723 | void Process(const MemoryRegion& region, int pos) override { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8724 | // Patch the correct offset for the instruction. The place to patch is the |
| 8725 | // last 4 bytes of the instruction. |
| 8726 | // The value to patch is the distance from the offset in the constant area |
| 8727 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8728 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8729 | int32_t relative_position = |
| 8730 | constant_offset - codegen_->GetMethodAddressOffset(base_method_address_); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8731 | |
| 8732 | // Patch in the right value. |
| 8733 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 8734 | } |
| 8735 | |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8736 | // Location in constant area that the fixup refers to. |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8737 | int32_t offset_into_constant_area_; |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8738 | }; |
| 8739 | |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8740 | /** |
| 8741 | * Class to handle late fixup of offsets to a jump table that will be created in the |
| 8742 | * constant area. |
| 8743 | */ |
| 8744 | class JumpTableRIPFixup : public RIPFixup { |
| 8745 | public: |
| 8746 | JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8747 | : RIPFixup(codegen, switch_instr->GetBaseMethodAddress(), static_cast<size_t>(-1)), |
| 8748 | switch_instr_(switch_instr) {} |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8749 | |
| 8750 | void CreateJumpTable() { |
| 8751 | X86Assembler* assembler = codegen_->GetAssembler(); |
| 8752 | |
| 8753 | // Ensure that the reference to the jump table has the correct offset. |
| 8754 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 8755 | SetOffset(offset_in_constant_table); |
| 8756 | |
| 8757 | // The label values in the jump table are computed relative to the |
| 8758 | // instruction addressing the constant area. |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8759 | const int32_t relative_offset = codegen_->GetMethodAddressOffset(base_method_address_); |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8760 | |
| 8761 | // Populate the jump table with the correct values for the jump table. |
| 8762 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 8763 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 8764 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 8765 | // The value that we want is the target offset - the position of the table. |
| 8766 | for (int32_t i = 0; i < num_entries; i++) { |
| 8767 | HBasicBlock* b = successors[i]; |
| 8768 | Label* l = codegen_->GetLabelOf(b); |
| 8769 | DCHECK(l->IsBound()); |
| 8770 | int32_t offset_to_block = l->Position() - relative_offset; |
| 8771 | assembler->AppendInt32(offset_to_block); |
| 8772 | } |
| 8773 | } |
| 8774 | |
| 8775 | private: |
| 8776 | const HX86PackedSwitch* switch_instr_; |
| 8777 | }; |
| 8778 | |
| 8779 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 8780 | // Generate the constant area if needed. |
| 8781 | X86Assembler* assembler = GetAssembler(); |
| jaishank | 20d1c94 | 2019-03-08 15:08:17 +0530 | [diff] [blame] | 8782 | |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8783 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 8784 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 8785 | // byte values. |
| 8786 | assembler->Align(4, 0); |
| 8787 | constant_area_start_ = assembler->CodeSize(); |
| 8788 | |
| 8789 | // Populate any jump tables. |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 8790 | for (JumpTableRIPFixup* jump_table : fixups_to_jump_tables_) { |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8791 | jump_table->CreateJumpTable(); |
| 8792 | } |
| 8793 | |
| 8794 | // And now add the constant area to the generated code. |
| 8795 | assembler->AddConstantArea(); |
| 8796 | } |
| 8797 | |
| 8798 | // And finish up. |
| 8799 | CodeGenerator::Finalize(allocator); |
| 8800 | } |
| 8801 | |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8802 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, |
| 8803 | HX86ComputeBaseMethodAddress* method_base, |
| 8804 | Register reg) { |
| 8805 | AssemblerFixup* fixup = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8806 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddDouble(v)); |
| Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 8807 | return Address(reg, kPlaceholder32BitOffset, fixup); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8808 | } |
| 8809 | |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8810 | Address CodeGeneratorX86::LiteralFloatAddress(float v, |
| 8811 | HX86ComputeBaseMethodAddress* method_base, |
| 8812 | Register reg) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8813 | AssemblerFixup* fixup = |
| 8814 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddFloat(v)); |
| Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 8815 | return Address(reg, kPlaceholder32BitOffset, fixup); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8816 | } |
| 8817 | |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8818 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, |
| 8819 | HX86ComputeBaseMethodAddress* method_base, |
| 8820 | Register reg) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8821 | AssemblerFixup* fixup = |
| 8822 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddInt32(v)); |
| Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 8823 | return Address(reg, kPlaceholder32BitOffset, fixup); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8824 | } |
| 8825 | |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8826 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, |
| 8827 | HX86ComputeBaseMethodAddress* method_base, |
| 8828 | Register reg) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8829 | AssemblerFixup* fixup = |
| 8830 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddInt64(v)); |
| Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 8831 | return Address(reg, kPlaceholder32BitOffset, fixup); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8832 | } |
| 8833 | |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 8834 | void CodeGeneratorX86::Load32BitValue(Register dest, int32_t value) { |
| 8835 | if (value == 0) { |
| 8836 | __ xorl(dest, dest); |
| 8837 | } else { |
| 8838 | __ movl(dest, Immediate(value)); |
| 8839 | } |
| 8840 | } |
| 8841 | |
| 8842 | void CodeGeneratorX86::Compare32BitValue(Register dest, int32_t value) { |
| 8843 | if (value == 0) { |
| 8844 | __ testl(dest, dest); |
| 8845 | } else { |
| 8846 | __ cmpl(dest, Immediate(value)); |
| 8847 | } |
| 8848 | } |
| 8849 | |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8850 | void CodeGeneratorX86::GenerateIntCompare(Location lhs, Location rhs) { |
| 8851 | Register lhs_reg = lhs.AsRegister<Register>(); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8852 | GenerateIntCompare(lhs_reg, rhs); |
| 8853 | } |
| 8854 | |
| 8855 | void CodeGeneratorX86::GenerateIntCompare(Register lhs, Location rhs) { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8856 | if (rhs.IsConstant()) { |
| 8857 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8858 | Compare32BitValue(lhs, value); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8859 | } else if (rhs.IsStackSlot()) { |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8860 | __ cmpl(lhs, Address(ESP, rhs.GetStackIndex())); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8861 | } else { |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8862 | __ cmpl(lhs, rhs.AsRegister<Register>()); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8863 | } |
| 8864 | } |
| 8865 | |
| 8866 | Address CodeGeneratorX86::ArrayAddress(Register obj, |
| 8867 | Location index, |
| 8868 | ScaleFactor scale, |
| 8869 | uint32_t data_offset) { |
| 8870 | return index.IsConstant() ? |
| 8871 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) : |
| 8872 | Address(obj, index.AsRegister<Register>(), scale, data_offset); |
| 8873 | } |
| 8874 | |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8875 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, |
| 8876 | Register reg, |
| 8877 | Register value) { |
| 8878 | // Create a fixup to be used to create and address the jump table. |
| 8879 | JumpTableRIPFixup* table_fixup = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8880 | new (GetGraph()->GetAllocator()) JumpTableRIPFixup(*this, switch_instr); |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8881 | |
| 8882 | // We have to populate the jump tables. |
| 8883 | fixups_to_jump_tables_.push_back(table_fixup); |
| 8884 | |
| 8885 | // We want a scaled address, as we are extracting the correct offset from the table. |
| Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 8886 | return Address(reg, value, TIMES_4, kPlaceholder32BitOffset, table_fixup); |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8887 | } |
| 8888 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8889 | // TODO: target as memory. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8890 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, DataType::Type type) { |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8891 | if (!target.IsValid()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8892 | DCHECK_EQ(type, DataType::Type::kVoid); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8893 | return; |
| 8894 | } |
| 8895 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8896 | DCHECK_NE(type, DataType::Type::kVoid); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8897 | |
| 8898 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 8899 | if (target.Equals(return_loc)) { |
| 8900 | return; |
| 8901 | } |
| 8902 | |
| 8903 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 8904 | // with the else branch. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8905 | if (type == DataType::Type::kInt64) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8906 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8907 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), DataType::Type::kInt32, nullptr); |
| 8908 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), DataType::Type::kInt32, nullptr); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8909 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 8910 | } else { |
| 8911 | // Let the parallel move resolver take care of all of this. |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8912 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8913 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 8914 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 8915 | } |
| 8916 | } |
| 8917 | |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8918 | void CodeGeneratorX86::PatchJitRootUse(uint8_t* code, |
| 8919 | const uint8_t* roots_data, |
| 8920 | const PatchInfo<Label>& info, |
| 8921 | uint64_t index_in_table) const { |
| 8922 | uint32_t code_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 8923 | uintptr_t address = |
| 8924 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| Andreas Gampe | c55bb39 | 2018-09-21 00:02:02 +0000 | [diff] [blame] | 8925 | using unaligned_uint32_t __attribute__((__aligned__(1))) = uint32_t; |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8926 | reinterpret_cast<unaligned_uint32_t*>(code + code_offset)[0] = |
| 8927 | dchecked_integral_cast<uint32_t>(address); |
| 8928 | } |
| 8929 | |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 8930 | void CodeGeneratorX86::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 8931 | for (const PatchInfo<Label>& info : jit_string_patches_) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8932 | StringReference string_reference(info.target_dex_file, dex::StringIndex(info.offset_or_index)); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8933 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 8934 | PatchJitRootUse(code, roots_data, info, index_in_table); |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8935 | } |
| 8936 | |
| 8937 | for (const PatchInfo<Label>& info : jit_class_patches_) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8938 | TypeReference type_reference(info.target_dex_file, dex::TypeIndex(info.offset_or_index)); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8939 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 8940 | PatchJitRootUse(code, roots_data, info, index_in_table); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 8941 | } |
| 8942 | } |
| 8943 | |
| xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 8944 | void LocationsBuilderX86::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 8945 | ATTRIBUTE_UNUSED) { |
| 8946 | LOG(FATAL) << "Unreachable"; |
| 8947 | } |
| 8948 | |
| 8949 | void InstructionCodeGeneratorX86::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 8950 | ATTRIBUTE_UNUSED) { |
| 8951 | LOG(FATAL) << "Unreachable"; |
| 8952 | } |
| 8953 | |
| Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 8954 | bool LocationsBuilderX86::CpuHasAvxFeatureFlag() { |
| 8955 | return codegen_->GetInstructionSetFeatures().HasAVX(); |
| 8956 | } |
| 8957 | bool LocationsBuilderX86::CpuHasAvx2FeatureFlag() { |
| 8958 | return codegen_->GetInstructionSetFeatures().HasAVX2(); |
| 8959 | } |
| 8960 | bool InstructionCodeGeneratorX86::CpuHasAvxFeatureFlag() { |
| 8961 | return codegen_->GetInstructionSetFeatures().HasAVX(); |
| 8962 | } |
| 8963 | bool InstructionCodeGeneratorX86::CpuHasAvx2FeatureFlag() { |
| 8964 | return codegen_->GetInstructionSetFeatures().HasAVX2(); |
| 8965 | } |
| 8966 | |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 8967 | #undef __ |
| 8968 | |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 8969 | } // namespace x86 |
| 8970 | } // namespace art |