| 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() || |
| 492 | instruction_->IsStaticFieldGet() || |
| 493 | instruction_->IsArrayGet() || |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 494 | instruction_->IsArraySet() || |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 495 | instruction_->IsLoadClass() || |
| 496 | instruction_->IsLoadString() || |
| 497 | instruction_->IsInstanceOf() || |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 498 | instruction_->IsCheckCast() || |
| Andra Danciu | 1ca6f32 | 2020-08-12 08:58:07 +0000 | [diff] [blame] | 499 | (instruction_->IsInvoke() && instruction_->GetLocations()->Intrinsified())) |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 500 | << "Unexpected instruction in read barrier marking slow path: " |
| 501 | << instruction_->DebugName(); |
| 502 | |
| 503 | __ Bind(GetEntryLabel()); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 504 | if (unpoison_ref_before_marking_) { |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 505 | // Object* ref = ref_addr->AsMirrorPtr() |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 506 | __ MaybeUnpoisonHeapReference(ref_reg); |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 507 | } |
| Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 508 | // No need to save live registers; it's taken care of by the |
| 509 | // entrypoint. Also, there is no need to update the stack mask, |
| 510 | // as this runtime call will not trigger a garbage collection. |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 511 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 512 | DCHECK_NE(ref_reg, ESP); |
| 513 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 514 | // "Compact" slow path, saving two moves. |
| 515 | // |
| 516 | // Instead of using the standard runtime calling convention (input |
| 517 | // and output in EAX): |
| 518 | // |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 519 | // EAX <- ref |
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 520 | // EAX <- ReadBarrierMark(EAX) |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 521 | // ref <- EAX |
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 522 | // |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 523 | // we just use rX (the register containing `ref`) as input and output |
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 524 | // of a dedicated entrypoint: |
| 525 | // |
| 526 | // rX <- ReadBarrierMarkRegX(rX) |
| 527 | // |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 528 | int32_t entry_point_offset = Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(ref_reg); |
| Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 529 | // This runtime call does not require a stack map. |
| 530 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 531 | __ jmp(GetExitLabel()); |
| 532 | } |
| 533 | |
| 534 | private: |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 535 | // The location (register) of the marked object reference. |
| 536 | const Location ref_; |
| 537 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 538 | const bool unpoison_ref_before_marking_; |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 539 | |
| 540 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86); |
| 541 | }; |
| 542 | |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 543 | // Slow path marking an object reference `ref` during a read barrier, |
| 544 | // and if needed, atomically updating the field `obj.field` in the |
| 545 | // object `obj` holding this reference after marking (contrary to |
| 546 | // ReadBarrierMarkSlowPathX86 above, which never tries to update |
| 547 | // `obj.field`). |
| 548 | // |
| 549 | // This means that after the execution of this slow path, both `ref` |
| 550 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 551 | // hold the same to-space reference (unless another thread installed |
| 552 | // another object reference (different from `ref`) in `obj.field`). |
| 553 | class ReadBarrierMarkAndUpdateFieldSlowPathX86 : public SlowPathCode { |
| 554 | public: |
| 555 | ReadBarrierMarkAndUpdateFieldSlowPathX86(HInstruction* instruction, |
| 556 | Location ref, |
| 557 | Register obj, |
| 558 | const Address& field_addr, |
| 559 | bool unpoison_ref_before_marking, |
| 560 | Register temp) |
| 561 | : SlowPathCode(instruction), |
| 562 | ref_(ref), |
| 563 | obj_(obj), |
| 564 | field_addr_(field_addr), |
| 565 | unpoison_ref_before_marking_(unpoison_ref_before_marking), |
| 566 | temp_(temp) { |
| 567 | DCHECK(kEmitCompilerReadBarrier); |
| 568 | } |
| 569 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 570 | const char* GetDescription() const override { return "ReadBarrierMarkAndUpdateFieldSlowPathX86"; } |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 571 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 572 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 573 | LocationSummary* locations = instruction_->GetLocations(); |
| 574 | Register ref_reg = ref_.AsRegister<Register>(); |
| 575 | DCHECK(locations->CanCall()); |
| 576 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 577 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| Andra Danciu | 5e13d45 | 2020-09-08 14:35:09 +0000 | [diff] [blame] | 578 | DCHECK((instruction_->IsInvoke() && instruction_->GetLocations()->Intrinsified())) |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 579 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 580 | << instruction_->DebugName(); |
| 581 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| Andra Danciu | 52d2c0c | 2020-09-15 14:27:21 +0000 | [diff] [blame] | 582 | Intrinsics intrinsic = instruction_->AsInvoke()->GetIntrinsic(); |
| 583 | static constexpr auto kVarHandleCAS = mirror::VarHandle::AccessModeTemplate::kCompareAndSet; |
| Andra Danciu | 9dfb1a9 | 2020-09-22 13:27:18 +0000 | [diff] [blame] | 584 | static constexpr auto kVarHandleGetAndSet = |
| 585 | mirror::VarHandle::AccessModeTemplate::kGetAndUpdate; |
| Andra Danciu | 370948e | 2020-09-23 08:07:25 +0000 | [diff] [blame] | 586 | static constexpr auto kVarHandleCAX = |
| 587 | mirror::VarHandle::AccessModeTemplate::kCompareAndExchange; |
| Andra Danciu | 52d2c0c | 2020-09-15 14:27:21 +0000 | [diff] [blame] | 588 | DCHECK(intrinsic == Intrinsics::kUnsafeCASObject || |
| Andra Danciu | 9dfb1a9 | 2020-09-22 13:27:18 +0000 | [diff] [blame] | 589 | mirror::VarHandle::GetAccessModeTemplateByIntrinsic(intrinsic) == kVarHandleCAS || |
| Andra Danciu | 370948e | 2020-09-23 08:07:25 +0000 | [diff] [blame] | 590 | mirror::VarHandle::GetAccessModeTemplateByIntrinsic(intrinsic) == kVarHandleGetAndSet || |
| 591 | mirror::VarHandle::GetAccessModeTemplateByIntrinsic(intrinsic) == kVarHandleCAX); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 592 | |
| 593 | __ Bind(GetEntryLabel()); |
| 594 | if (unpoison_ref_before_marking_) { |
| 595 | // Object* ref = ref_addr->AsMirrorPtr() |
| 596 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 597 | } |
| 598 | |
| 599 | // Save the old (unpoisoned) reference. |
| 600 | __ movl(temp_, ref_reg); |
| 601 | |
| 602 | // No need to save live registers; it's taken care of by the |
| 603 | // entrypoint. Also, there is no need to update the stack mask, |
| 604 | // as this runtime call will not trigger a garbage collection. |
| 605 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 606 | DCHECK_NE(ref_reg, ESP); |
| 607 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
| 608 | // "Compact" slow path, saving two moves. |
| 609 | // |
| 610 | // Instead of using the standard runtime calling convention (input |
| 611 | // and output in EAX): |
| 612 | // |
| 613 | // EAX <- ref |
| 614 | // EAX <- ReadBarrierMark(EAX) |
| 615 | // ref <- EAX |
| 616 | // |
| 617 | // we just use rX (the register containing `ref`) as input and output |
| 618 | // of a dedicated entrypoint: |
| 619 | // |
| 620 | // rX <- ReadBarrierMarkRegX(rX) |
| 621 | // |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 622 | int32_t entry_point_offset = Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(ref_reg); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 623 | // This runtime call does not require a stack map. |
| 624 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 625 | |
| 626 | // If the new reference is different from the old reference, |
| 627 | // update the field in the holder (`*field_addr`). |
| 628 | // |
| 629 | // Note that this field could also hold a different object, if |
| 630 | // another thread had concurrently changed it. In that case, the |
| 631 | // LOCK CMPXCHGL instruction in the compare-and-set (CAS) |
| 632 | // operation below would abort the CAS, leaving the field as-is. |
| 633 | NearLabel done; |
| 634 | __ cmpl(temp_, ref_reg); |
| 635 | __ j(kEqual, &done); |
| 636 | |
| 637 | // Update the the holder's field atomically. This may fail if |
| 638 | // mutator updates before us, but it's OK. This is achieved |
| 639 | // using a strong compare-and-set (CAS) operation with relaxed |
| 640 | // memory synchronization ordering, where the expected value is |
| 641 | // the old reference and the desired value is the new reference. |
| 642 | // This operation is implemented with a 32-bit LOCK CMPXLCHG |
| 643 | // instruction, which requires the expected value (the old |
| 644 | // reference) to be in EAX. Save EAX beforehand, and move the |
| 645 | // expected value (stored in `temp_`) into EAX. |
| 646 | __ pushl(EAX); |
| 647 | __ movl(EAX, temp_); |
| 648 | |
| 649 | // Convenience aliases. |
| 650 | Register base = obj_; |
| 651 | Register expected = EAX; |
| 652 | Register value = ref_reg; |
| 653 | |
| 654 | bool base_equals_value = (base == value); |
| 655 | if (kPoisonHeapReferences) { |
| 656 | if (base_equals_value) { |
| 657 | // If `base` and `value` are the same register location, move |
| 658 | // `value` to a temporary register. This way, poisoning |
| 659 | // `value` won't invalidate `base`. |
| 660 | value = temp_; |
| 661 | __ movl(value, base); |
| 662 | } |
| 663 | |
| 664 | // Check that the register allocator did not assign the location |
| 665 | // of `expected` (EAX) to `value` nor to `base`, so that heap |
| 666 | // poisoning (when enabled) works as intended below. |
| 667 | // - If `value` were equal to `expected`, both references would |
| 668 | // be poisoned twice, meaning they would not be poisoned at |
| 669 | // all, as heap poisoning uses address negation. |
| 670 | // - If `base` were equal to `expected`, poisoning `expected` |
| 671 | // would invalidate `base`. |
| 672 | DCHECK_NE(value, expected); |
| 673 | DCHECK_NE(base, expected); |
| 674 | |
| 675 | __ PoisonHeapReference(expected); |
| 676 | __ PoisonHeapReference(value); |
| 677 | } |
| 678 | |
| 679 | __ LockCmpxchgl(field_addr_, value); |
| 680 | |
| 681 | // If heap poisoning is enabled, we need to unpoison the values |
| 682 | // that were poisoned earlier. |
| 683 | if (kPoisonHeapReferences) { |
| 684 | if (base_equals_value) { |
| 685 | // `value` has been moved to a temporary register, no need |
| 686 | // to unpoison it. |
| 687 | } else { |
| 688 | __ UnpoisonHeapReference(value); |
| 689 | } |
| 690 | // No need to unpoison `expected` (EAX), as it is be overwritten below. |
| 691 | } |
| 692 | |
| 693 | // Restore EAX. |
| 694 | __ popl(EAX); |
| 695 | |
| 696 | __ Bind(&done); |
| 697 | __ jmp(GetExitLabel()); |
| 698 | } |
| 699 | |
| 700 | private: |
| 701 | // The location (register) of the marked object reference. |
| 702 | const Location ref_; |
| 703 | // The register containing the object holding the marked object reference field. |
| 704 | const Register obj_; |
| 705 | // The address of the marked reference field. The base of this address must be `obj_`. |
| 706 | const Address field_addr_; |
| 707 | |
| 708 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 709 | const bool unpoison_ref_before_marking_; |
| 710 | |
| 711 | const Register temp_; |
| 712 | |
| 713 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathX86); |
| 714 | }; |
| 715 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 716 | // Slow path generating a read barrier for a heap reference. |
| 717 | class ReadBarrierForHeapReferenceSlowPathX86 : public SlowPathCode { |
| 718 | public: |
| 719 | ReadBarrierForHeapReferenceSlowPathX86(HInstruction* instruction, |
| 720 | Location out, |
| 721 | Location ref, |
| 722 | Location obj, |
| 723 | uint32_t offset, |
| 724 | Location index) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 725 | : SlowPathCode(instruction), |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 726 | out_(out), |
| 727 | ref_(ref), |
| 728 | obj_(obj), |
| 729 | offset_(offset), |
| 730 | index_(index) { |
| 731 | DCHECK(kEmitCompilerReadBarrier); |
| 732 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 733 | // has been overwritten by (or after) the heap object reference load |
| 734 | // to be instrumented, e.g.: |
| 735 | // |
| 736 | // __ movl(out, Address(out, offset)); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 737 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 738 | // |
| 739 | // In that case, we have lost the information about the original |
| 740 | // object, and the emitted read barrier cannot work properly. |
| 741 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 742 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 743 | } |
| 744 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 745 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 746 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 747 | LocationSummary* locations = instruction_->GetLocations(); |
| 748 | Register reg_out = out_.AsRegister<Register>(); |
| 749 | DCHECK(locations->CanCall()); |
| 750 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 751 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 752 | instruction_->IsStaticFieldGet() || |
| 753 | instruction_->IsArrayGet() || |
| 754 | instruction_->IsInstanceOf() || |
| 755 | instruction_->IsCheckCast() || |
| Vladimir Marko | 94d2c81 | 2020-11-05 10:04:45 +0000 | [diff] [blame] | 756 | (instruction_->IsInvoke() && instruction_->GetLocations()->Intrinsified())) |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 757 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 758 | << instruction_->DebugName(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 759 | |
| 760 | __ Bind(GetEntryLabel()); |
| 761 | SaveLiveRegisters(codegen, locations); |
| 762 | |
| 763 | // We may have to change the index's value, but as `index_` is a |
| 764 | // constant member (like other "inputs" of this slow path), |
| 765 | // introduce a copy of it, `index`. |
| 766 | Location index = index_; |
| 767 | if (index_.IsValid()) { |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 768 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 769 | if (instruction_->IsArrayGet()) { |
| 770 | // Compute the actual memory offset and store it in `index`. |
| 771 | Register index_reg = index_.AsRegister<Register>(); |
| 772 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 773 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 774 | // We are about to change the value of `index_reg` (see the |
| 775 | // calls to art::x86::X86Assembler::shll and |
| 776 | // art::x86::X86Assembler::AddImmediate below), but it has |
| 777 | // not been saved by the previous call to |
| 778 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 779 | // callee-save register -- |
| 780 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 781 | // callee-save registers, as it has been designed with the |
| 782 | // assumption that callee-save registers are supposed to be |
| 783 | // handled by the called function. So, as a callee-save |
| 784 | // register, `index_reg` _would_ eventually be saved onto |
| 785 | // the stack, but it would be too late: we would have |
| 786 | // changed its value earlier. Therefore, we manually save |
| 787 | // it here into another freely available register, |
| 788 | // `free_reg`, chosen of course among the caller-save |
| 789 | // registers (as a callee-save `free_reg` register would |
| 790 | // exhibit the same problem). |
| 791 | // |
| 792 | // Note we could have requested a temporary register from |
| 793 | // the register allocator instead; but we prefer not to, as |
| 794 | // this is a slow path, and we know we can find a |
| 795 | // caller-save register that is available. |
| 796 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 797 | __ movl(free_reg, index_reg); |
| 798 | index_reg = free_reg; |
| 799 | index = Location::RegisterLocation(index_reg); |
| 800 | } else { |
| 801 | // The initial register stored in `index_` has already been |
| 802 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 803 | // (as it is not a callee-save register), so we can freely |
| 804 | // use it. |
| 805 | } |
| 806 | // Shifting the index value contained in `index_reg` by the scale |
| 807 | // factor (2) cannot overflow in practice, as the runtime is |
| 808 | // unable to allocate object arrays with a size larger than |
| 809 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 810 | __ shll(index_reg, Immediate(TIMES_4)); |
| 811 | static_assert( |
| 812 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 813 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 814 | __ AddImmediate(index_reg, Immediate(offset_)); |
| 815 | } else { |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 816 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 817 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 818 | // (as in the case of ArrayGet), as it is actually an offset |
| 819 | // to an object field within an object. |
| 820 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 821 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 822 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 823 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 824 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 825 | DCHECK_EQ(offset_, 0U); |
| 826 | DCHECK(index_.IsRegisterPair()); |
| 827 | // UnsafeGet's offset location is a register pair, the low |
| 828 | // part contains the correct offset. |
| 829 | index = index_.ToLow(); |
| 830 | } |
| 831 | } |
| 832 | |
| 833 | // We're moving two or three locations to locations that could |
| 834 | // overlap, so we need a parallel move resolver. |
| 835 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 836 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 837 | parallel_move.AddMove(ref_, |
| 838 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 839 | DataType::Type::kReference, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 840 | nullptr); |
| 841 | parallel_move.AddMove(obj_, |
| 842 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 843 | DataType::Type::kReference, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 844 | nullptr); |
| 845 | if (index.IsValid()) { |
| 846 | parallel_move.AddMove(index, |
| 847 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 848 | DataType::Type::kInt32, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 849 | nullptr); |
| 850 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 851 | } else { |
| 852 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 853 | __ movl(calling_convention.GetRegisterAt(2), Immediate(offset_)); |
| 854 | } |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 855 | x86_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 856 | CheckEntrypointTypes< |
| 857 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 858 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 859 | |
| 860 | RestoreLiveRegisters(codegen, locations); |
| 861 | __ jmp(GetExitLabel()); |
| 862 | } |
| 863 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 864 | const char* GetDescription() const override { return "ReadBarrierForHeapReferenceSlowPathX86"; } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 865 | |
| 866 | private: |
| 867 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 868 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 869 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 870 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 871 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 872 | return static_cast<Register>(i); |
| 873 | } |
| 874 | } |
| 875 | // We shall never fail to find a free caller-save register, as |
| 876 | // there are more than two core caller-save registers on x86 |
| 877 | // (meaning it is possible to find one which is different from |
| 878 | // `ref` and `obj`). |
| 879 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 880 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 881 | UNREACHABLE(); |
| 882 | } |
| 883 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 884 | const Location out_; |
| 885 | const Location ref_; |
| 886 | const Location obj_; |
| 887 | const uint32_t offset_; |
| 888 | // An additional location containing an index to an array. |
| 889 | // Only used for HArrayGet and the UnsafeGetObject & |
| 890 | // UnsafeGetObjectVolatile intrinsics. |
| 891 | const Location index_; |
| 892 | |
| 893 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86); |
| 894 | }; |
| 895 | |
| 896 | // Slow path generating a read barrier for a GC root. |
| 897 | class ReadBarrierForRootSlowPathX86 : public SlowPathCode { |
| 898 | public: |
| 899 | ReadBarrierForRootSlowPathX86(HInstruction* instruction, Location out, Location root) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 900 | : SlowPathCode(instruction), out_(out), root_(root) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 901 | DCHECK(kEmitCompilerReadBarrier); |
| 902 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 903 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 904 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 905 | LocationSummary* locations = instruction_->GetLocations(); |
| 906 | Register reg_out = out_.AsRegister<Register>(); |
| 907 | DCHECK(locations->CanCall()); |
| 908 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 909 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 910 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 911 | << instruction_->DebugName(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 912 | |
| 913 | __ Bind(GetEntryLabel()); |
| 914 | SaveLiveRegisters(codegen, locations); |
| 915 | |
| 916 | InvokeRuntimeCallingConvention calling_convention; |
| 917 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 918 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 919 | x86_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 920 | instruction_, |
| 921 | instruction_->GetDexPc(), |
| 922 | this); |
| 923 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 924 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 925 | |
| 926 | RestoreLiveRegisters(codegen, locations); |
| 927 | __ jmp(GetExitLabel()); |
| 928 | } |
| 929 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 930 | const char* GetDescription() const override { return "ReadBarrierForRootSlowPathX86"; } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 931 | |
| 932 | private: |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 933 | const Location out_; |
| 934 | const Location root_; |
| 935 | |
| 936 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86); |
| 937 | }; |
| 938 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 939 | #undef __ |
| Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 940 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 941 | #define __ down_cast<X86Assembler*>(GetAssembler())-> // NOLINT |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 942 | |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 943 | inline Condition X86Condition(IfCondition cond) { |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 944 | switch (cond) { |
| 945 | case kCondEQ: return kEqual; |
| 946 | case kCondNE: return kNotEqual; |
| 947 | case kCondLT: return kLess; |
| 948 | case kCondLE: return kLessEqual; |
| 949 | case kCondGT: return kGreater; |
| 950 | case kCondGE: return kGreaterEqual; |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 951 | case kCondB: return kBelow; |
| 952 | case kCondBE: return kBelowEqual; |
| 953 | case kCondA: return kAbove; |
| 954 | case kCondAE: return kAboveEqual; |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 955 | } |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 956 | LOG(FATAL) << "Unreachable"; |
| 957 | UNREACHABLE(); |
| 958 | } |
| 959 | |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 960 | // Maps signed condition to unsigned condition and FP condition to x86 name. |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 961 | inline Condition X86UnsignedOrFPCondition(IfCondition cond) { |
| 962 | switch (cond) { |
| 963 | case kCondEQ: return kEqual; |
| 964 | case kCondNE: return kNotEqual; |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 965 | // Signed to unsigned, and FP to x86 name. |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 966 | case kCondLT: return kBelow; |
| 967 | case kCondLE: return kBelowEqual; |
| 968 | case kCondGT: return kAbove; |
| 969 | case kCondGE: return kAboveEqual; |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 970 | // Unsigned remain unchanged. |
| 971 | case kCondB: return kBelow; |
| 972 | case kCondBE: return kBelowEqual; |
| 973 | case kCondA: return kAbove; |
| 974 | case kCondAE: return kAboveEqual; |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 975 | } |
| 976 | LOG(FATAL) << "Unreachable"; |
| 977 | UNREACHABLE(); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 978 | } |
| 979 | |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 980 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 981 | stream << Register(reg); |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 982 | } |
| 983 | |
| 984 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 985 | stream << XmmRegister(reg); |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 986 | } |
| 987 | |
| Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 988 | const X86InstructionSetFeatures& CodeGeneratorX86::GetInstructionSetFeatures() const { |
| 989 | return *GetCompilerOptions().GetInstructionSetFeatures()->AsX86InstructionSetFeatures(); |
| 990 | } |
| 991 | |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 992 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 993 | __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); |
| 994 | return kX86WordSize; |
| Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 995 | } |
| 996 | |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 997 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 998 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); |
| 999 | return kX86WordSize; |
| Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1000 | } |
| 1001 | |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1002 | size_t CodeGeneratorX86::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1003 | if (GetGraph()->HasSIMD()) { |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 1004 | __ movups(Address(ESP, stack_index), XmmRegister(reg_id)); |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1005 | } else { |
| 1006 | __ movsd(Address(ESP, stack_index), XmmRegister(reg_id)); |
| 1007 | } |
| Artem Serov | 6a0b657 | 2019-07-26 20:38:37 +0100 | [diff] [blame] | 1008 | return GetSlowPathFPWidth(); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | size_t CodeGeneratorX86::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1012 | if (GetGraph()->HasSIMD()) { |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 1013 | __ movups(XmmRegister(reg_id), Address(ESP, stack_index)); |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1014 | } else { |
| 1015 | __ movsd(XmmRegister(reg_id), Address(ESP, stack_index)); |
| 1016 | } |
| Artem Serov | 6a0b657 | 2019-07-26 20:38:37 +0100 | [diff] [blame] | 1017 | return GetSlowPathFPWidth(); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1018 | } |
| 1019 | |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1020 | void CodeGeneratorX86::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1021 | HInstruction* instruction, |
| 1022 | uint32_t dex_pc, |
| 1023 | SlowPathCode* slow_path) { |
| Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1024 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1025 | GenerateInvokeRuntime(GetThreadOffset<kX86PointerSize>(entrypoint).Int32Value()); |
| 1026 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1027 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1028 | } |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 1029 | } |
| 1030 | |
| Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1031 | void CodeGeneratorX86::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1032 | HInstruction* instruction, |
| 1033 | SlowPathCode* slow_path) { |
| 1034 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1035 | GenerateInvokeRuntime(entry_point_offset); |
| 1036 | } |
| 1037 | |
| 1038 | void CodeGeneratorX86::GenerateInvokeRuntime(int32_t entry_point_offset) { |
| Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1039 | __ fs()->call(Address::Absolute(entry_point_offset)); |
| 1040 | } |
| 1041 | |
| Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1042 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1043 | const CompilerOptions& compiler_options, |
| 1044 | OptimizingCompilerStats* stats) |
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1045 | : CodeGenerator(graph, |
| 1046 | kNumberOfCpuRegisters, |
| 1047 | kNumberOfXmmRegisters, |
| 1048 | kNumberOfRegisterPairs, |
| 1049 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1050 | arraysize(kCoreCalleeSaves)) |
| 1051 | | (1 << kFakeReturnRegister), |
| Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1052 | 0, |
| 1053 | compiler_options, |
| 1054 | stats), |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1055 | block_labels_(nullptr), |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1056 | location_builder_(graph, this), |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1057 | instruction_visitor_(graph, this), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1058 | move_resolver_(graph->GetAllocator(), this), |
| 1059 | assembler_(graph->GetAllocator()), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1060 | boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1061 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1062 | boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1063 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 1064 | public_type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1065 | package_type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1066 | boot_image_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1067 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 1068 | boot_image_jni_entrypoint_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 1069 | boot_image_other_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1070 | jit_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1071 | jit_class_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1072 | constant_area_start_(-1), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1073 | fixups_to_jump_tables_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1074 | method_address_offset_(std::less<uint32_t>(), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1075 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1076 | // Use a fake return address register to mimic Quick. |
| 1077 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1078 | } |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1079 | |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1080 | void CodeGeneratorX86::SetupBlockedRegisters() const { |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1081 | // Stack register is always reserved. |
| Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1082 | blocked_core_registers_[ESP] = true; |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1083 | } |
| 1084 | |
| Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1085 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1086 | : InstructionCodeGenerator(graph, codegen), |
| Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1087 | assembler_(codegen->GetAssembler()), |
| 1088 | codegen_(codegen) {} |
| 1089 | |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1090 | static dwarf::Reg DWARFReg(Register reg) { |
| David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1091 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1092 | } |
| 1093 | |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1094 | void CodeGeneratorX86::MaybeIncrementHotness(bool is_frame_entry) { |
| 1095 | if (GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 1096 | Register reg = EAX; |
| 1097 | if (is_frame_entry) { |
| 1098 | reg = kMethodRegisterArgument; |
| 1099 | } else { |
| 1100 | __ pushl(EAX); |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1101 | __ cfi().AdjustCFAOffset(4); |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1102 | __ movl(EAX, Address(ESP, kX86WordSize)); |
| 1103 | } |
| 1104 | NearLabel overflow; |
| 1105 | __ cmpw(Address(reg, ArtMethod::HotnessCountOffset().Int32Value()), |
| 1106 | Immediate(ArtMethod::MaxCounter())); |
| 1107 | __ j(kEqual, &overflow); |
| 1108 | __ addw(Address(reg, ArtMethod::HotnessCountOffset().Int32Value()), |
| 1109 | Immediate(1)); |
| 1110 | __ Bind(&overflow); |
| 1111 | if (!is_frame_entry) { |
| 1112 | __ popl(EAX); |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1113 | __ cfi().AdjustCFAOffset(-4); |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1114 | } |
| 1115 | } |
| 1116 | |
| 1117 | if (GetGraph()->IsCompilingBaseline() && !Runtime::Current()->IsAotCompiler()) { |
| Nicolas Geoffray | 095dc46 | 2020-08-17 16:40:28 +0100 | [diff] [blame] | 1118 | ScopedProfilingInfoUse spiu( |
| 1119 | Runtime::Current()->GetJit(), GetGraph()->GetArtMethod(), Thread::Current()); |
| 1120 | ProfilingInfo* info = spiu.GetProfilingInfo(); |
| Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1121 | if (info != nullptr) { |
| 1122 | uint32_t address = reinterpret_cast32<uint32_t>(info); |
| 1123 | NearLabel done; |
| 1124 | if (HasEmptyFrame()) { |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1125 | CHECK(is_frame_entry); |
| Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1126 | // Alignment |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1127 | IncreaseFrame(8); |
| Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1128 | // We need a temporary. The stub also expects the method at bottom of stack. |
| 1129 | __ pushl(EAX); |
| 1130 | __ cfi().AdjustCFAOffset(4); |
| 1131 | __ movl(EAX, Immediate(address)); |
| 1132 | __ addw(Address(EAX, ProfilingInfo::BaselineHotnessCountOffset().Int32Value()), |
| 1133 | Immediate(1)); |
| Nicolas Geoffray | 8b8d93d | 2020-09-17 14:30:01 +0100 | [diff] [blame] | 1134 | __ andw(Address(EAX, ProfilingInfo::BaselineHotnessCountOffset().Int32Value()), |
| 1135 | Immediate(interpreter::kTieredHotnessMask)); |
| 1136 | __ j(kNotZero, &done); |
| Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1137 | GenerateInvokeRuntime( |
| 1138 | GetThreadOffset<kX86PointerSize>(kQuickCompileOptimized).Int32Value()); |
| 1139 | __ Bind(&done); |
| 1140 | // We don't strictly require to restore EAX, but this makes the generated |
| 1141 | // code easier to reason about. |
| 1142 | __ popl(EAX); |
| 1143 | __ cfi().AdjustCFAOffset(-4); |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1144 | DecreaseFrame(8); |
| Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1145 | } else { |
| 1146 | if (!RequiresCurrentMethod()) { |
| 1147 | CHECK(is_frame_entry); |
| 1148 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
| 1149 | } |
| 1150 | // We need a temporary. |
| 1151 | __ pushl(EAX); |
| 1152 | __ cfi().AdjustCFAOffset(4); |
| 1153 | __ movl(EAX, Immediate(address)); |
| 1154 | __ addw(Address(EAX, ProfilingInfo::BaselineHotnessCountOffset().Int32Value()), |
| 1155 | Immediate(1)); |
| 1156 | __ popl(EAX); // Put stack as expected before exiting or calling stub. |
| 1157 | __ cfi().AdjustCFAOffset(-4); |
| 1158 | __ j(kCarryClear, &done); |
| 1159 | GenerateInvokeRuntime( |
| 1160 | GetThreadOffset<kX86PointerSize>(kQuickCompileOptimized).Int32Value()); |
| 1161 | __ Bind(&done); |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1162 | } |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1163 | } |
| 1164 | } |
| 1165 | } |
| 1166 | |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1167 | void CodeGeneratorX86::GenerateFrameEntry() { |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1168 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
| Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1169 | __ Bind(&frame_entry_label_); |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1170 | bool skip_overflow_check = |
| 1171 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1172 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
| Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 1173 | |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1174 | if (!skip_overflow_check) { |
| Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1175 | size_t reserved_bytes = GetStackOverflowReservedBytes(InstructionSet::kX86); |
| 1176 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(reserved_bytes))); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1177 | RecordPcInfo(nullptr, 0); |
| Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 1178 | } |
| 1179 | |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1180 | if (!HasEmptyFrame()) { |
| 1181 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 1182 | Register reg = kCoreCalleeSaves[i]; |
| 1183 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1184 | __ pushl(reg); |
| 1185 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 1186 | __ cfi().RelOffset(DWARFReg(reg), 0); |
| 1187 | } |
| 1188 | } |
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1189 | |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1190 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1191 | IncreaseFrame(adjust); |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1192 | // Save the current method if we need it. Note that we do not |
| 1193 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1194 | // in the SSA graph. |
| 1195 | if (RequiresCurrentMethod()) { |
| 1196 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
| 1197 | } |
| 1198 | |
| 1199 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1200 | // Initialize should_deoptimize flag to 0. |
| 1201 | __ movl(Address(ESP, GetStackOffsetOfShouldDeoptimizeFlag()), Immediate(0)); |
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1202 | } |
| 1203 | } |
| 1204 | |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1205 | MaybeIncrementHotness(/* is_frame_entry= */ true); |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1206 | } |
| 1207 | |
| 1208 | void CodeGeneratorX86::GenerateFrameExit() { |
| David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1209 | __ cfi().RememberState(); |
| 1210 | if (!HasEmptyFrame()) { |
| 1211 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1212 | DecreaseFrame(adjust); |
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1213 | |
| David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1214 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1215 | Register reg = kCoreCalleeSaves[i]; |
| 1216 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1217 | __ popl(reg); |
| 1218 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 1219 | __ cfi().Restore(DWARFReg(reg)); |
| 1220 | } |
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1221 | } |
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1222 | } |
| David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1223 | __ ret(); |
| 1224 | __ cfi().RestoreState(); |
| 1225 | __ cfi().DefCFAOffset(GetFrameSize()); |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1226 | } |
| 1227 | |
| Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1228 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 1229 | __ Bind(GetLabelOf(block)); |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1230 | } |
| 1231 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1232 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(DataType::Type type) const { |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1233 | switch (type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1234 | case DataType::Type::kReference: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1235 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1236 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1237 | case DataType::Type::kInt8: |
| 1238 | case DataType::Type::kUint16: |
| 1239 | case DataType::Type::kInt16: |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1240 | case DataType::Type::kUint32: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1241 | case DataType::Type::kInt32: |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1242 | return Location::RegisterLocation(EAX); |
| 1243 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1244 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1245 | case DataType::Type::kInt64: |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1246 | return Location::RegisterPairLocation(EAX, EDX); |
| 1247 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1248 | case DataType::Type::kVoid: |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1249 | return Location::NoLocation(); |
| 1250 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1251 | case DataType::Type::kFloat64: |
| 1252 | case DataType::Type::kFloat32: |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1253 | return Location::FpuRegisterLocation(XMM0); |
| 1254 | } |
| Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1255 | |
| 1256 | UNREACHABLE(); |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1257 | } |
| 1258 | |
| 1259 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 1260 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1261 | } |
| 1262 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1263 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(DataType::Type type) { |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1264 | switch (type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1265 | case DataType::Type::kReference: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1266 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1267 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1268 | case DataType::Type::kInt8: |
| 1269 | case DataType::Type::kUint16: |
| 1270 | case DataType::Type::kInt16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1271 | case DataType::Type::kInt32: { |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1272 | uint32_t index = gp_index_++; |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1273 | stack_index_++; |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1274 | if (index < calling_convention.GetNumberOfRegisters()) { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1275 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1276 | } else { |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1277 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1278 | } |
| Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1279 | } |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1280 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1281 | case DataType::Type::kInt64: { |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1282 | uint32_t index = gp_index_; |
| 1283 | gp_index_ += 2; |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1284 | stack_index_ += 2; |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1285 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1286 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 1287 | calling_convention.GetRegisterPairAt(index)); |
| 1288 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1289 | } else { |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1290 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1291 | } |
| 1292 | } |
| 1293 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1294 | case DataType::Type::kFloat32: { |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1295 | uint32_t index = float_index_++; |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1296 | stack_index_++; |
| 1297 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1298 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1299 | } else { |
| 1300 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1301 | } |
| 1302 | } |
| 1303 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1304 | case DataType::Type::kFloat64: { |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1305 | uint32_t index = float_index_++; |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1306 | stack_index_ += 2; |
| 1307 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1308 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1309 | } else { |
| 1310 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1311 | } |
| 1312 | } |
| 1313 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1314 | case DataType::Type::kUint32: |
| 1315 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1316 | case DataType::Type::kVoid: |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1317 | LOG(FATAL) << "Unexpected parameter type " << type; |
| Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 1318 | UNREACHABLE(); |
| Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1319 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1320 | return Location::NoLocation(); |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1321 | } |
| Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1322 | |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 1323 | Location CriticalNativeCallingConventionVisitorX86::GetNextLocation(DataType::Type type) { |
| 1324 | DCHECK_NE(type, DataType::Type::kReference); |
| 1325 | |
| 1326 | Location location; |
| 1327 | if (DataType::Is64BitType(type)) { |
| 1328 | location = Location::DoubleStackSlot(stack_offset_); |
| 1329 | stack_offset_ += 2 * kFramePointerSize; |
| 1330 | } else { |
| 1331 | location = Location::StackSlot(stack_offset_); |
| 1332 | stack_offset_ += kFramePointerSize; |
| 1333 | } |
| 1334 | if (for_register_allocation_) { |
| 1335 | location = Location::Any(); |
| 1336 | } |
| 1337 | return location; |
| 1338 | } |
| 1339 | |
| 1340 | Location CriticalNativeCallingConventionVisitorX86::GetReturnLocation(DataType::Type type) const { |
| 1341 | // We perform conversion to the managed ABI return register after the call if needed. |
| 1342 | InvokeDexCallingConventionVisitorX86 dex_calling_convention; |
| 1343 | return dex_calling_convention.GetReturnLocation(type); |
| 1344 | } |
| 1345 | |
| 1346 | Location CriticalNativeCallingConventionVisitorX86::GetMethodLocation() const { |
| 1347 | // Pass the method in the hidden argument EAX. |
| 1348 | return Location::RegisterLocation(EAX); |
| 1349 | } |
| 1350 | |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1351 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 1352 | if (source.Equals(destination)) { |
| 1353 | return; |
| 1354 | } |
| 1355 | if (destination.IsRegister()) { |
| 1356 | if (source.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1357 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1358 | } else if (source.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1359 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
| Andra Danciu | 5e13d45 | 2020-09-08 14:35:09 +0000 | [diff] [blame] | 1360 | } else if (source.IsConstant()) { |
| 1361 | int32_t value = GetInt32ValueOf(source.GetConstant()); |
| 1362 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1363 | } else { |
| 1364 | DCHECK(source.IsStackSlot()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1365 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1366 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1367 | } else if (destination.IsFpuRegister()) { |
| 1368 | if (source.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1369 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1370 | } else if (source.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1371 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1372 | } else { |
| 1373 | DCHECK(source.IsStackSlot()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1374 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1375 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1376 | } else { |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1377 | DCHECK(destination.IsStackSlot()) << destination; |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1378 | if (source.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1379 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1380 | } else if (source.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1381 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1382 | } else if (source.IsConstant()) { |
| 1383 | HConstant* constant = source.GetConstant(); |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1384 | int32_t value = GetInt32ValueOf(constant); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1385 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1386 | } else { |
| 1387 | DCHECK(source.IsStackSlot()); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1388 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 1389 | __ popl(Address(ESP, destination.GetStackIndex())); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1390 | } |
| 1391 | } |
| 1392 | } |
| 1393 | |
| 1394 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 1395 | if (source.Equals(destination)) { |
| 1396 | return; |
| 1397 | } |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1398 | if (destination.IsRegisterPair()) { |
| 1399 | if (source.IsRegisterPair()) { |
| Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1400 | EmitParallelMoves( |
| 1401 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1402 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1403 | DataType::Type::kInt32, |
| Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1404 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
| Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1405 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1406 | DataType::Type::kInt32); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1407 | } else if (source.IsFpuRegister()) { |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1408 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 1409 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 1410 | __ psrlq(src_reg, Immediate(32)); |
| 1411 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1412 | } else { |
| Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1413 | // No conflict possible, so just do the moves. |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1414 | DCHECK(source.IsDoubleStackSlot()); |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1415 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 1416 | __ movl(destination.AsRegisterPairHigh<Register>(), |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1417 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 1418 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1419 | } else if (destination.IsFpuRegister()) { |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1420 | if (source.IsFpuRegister()) { |
| 1421 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 1422 | } else if (source.IsDoubleStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1423 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1424 | } else if (source.IsRegisterPair()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1425 | size_t elem_size = DataType::Size(DataType::Type::kInt32); |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1426 | // Push the 2 source registers to the stack. |
| 1427 | __ pushl(source.AsRegisterPairHigh<Register>()); |
| 1428 | __ cfi().AdjustCFAOffset(elem_size); |
| 1429 | __ pushl(source.AsRegisterPairLow<Register>()); |
| 1430 | __ cfi().AdjustCFAOffset(elem_size); |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1431 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 1432 | // And remove the temporary stack space we allocated. |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1433 | DecreaseFrame(2 * elem_size); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1434 | } else { |
| 1435 | LOG(FATAL) << "Unimplemented"; |
| 1436 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1437 | } else { |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1438 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1439 | if (source.IsRegisterPair()) { |
| Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1440 | // No conflict possible, so just do the moves. |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1441 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1442 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1443 | source.AsRegisterPairHigh<Register>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1444 | } else if (source.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1445 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1446 | } else if (source.IsConstant()) { |
| 1447 | HConstant* constant = source.GetConstant(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1448 | DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant()); |
| 1449 | int64_t value = GetInt64ValueOf(constant); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1450 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1451 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
| 1452 | Immediate(High32Bits(value))); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1453 | } else { |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1454 | DCHECK(source.IsDoubleStackSlot()) << source; |
| Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1455 | EmitParallelMoves( |
| 1456 | Location::StackSlot(source.GetStackIndex()), |
| 1457 | Location::StackSlot(destination.GetStackIndex()), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1458 | DataType::Type::kInt32, |
| Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1459 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
| Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1460 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1461 | DataType::Type::kInt32); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1462 | } |
| 1463 | } |
| 1464 | } |
| 1465 | |
| Andra Danciu | 1ca6f32 | 2020-08-12 08:58:07 +0000 | [diff] [blame] | 1466 | static Address CreateAddress(Register base, |
| 1467 | Register index = Register::kNoRegister, |
| 1468 | ScaleFactor scale = TIMES_1, |
| 1469 | int32_t disp = 0) { |
| 1470 | if (index == Register::kNoRegister) { |
| 1471 | return Address(base, disp); |
| 1472 | } |
| 1473 | |
| 1474 | return Address(base, index, scale, disp); |
| 1475 | } |
| 1476 | |
| Andra Danciu | d0f71f2 | 2020-09-17 09:00:15 +0000 | [diff] [blame] | 1477 | void CodeGeneratorX86::LoadFromMemoryNoBarrier(DataType::Type dst_type, |
| 1478 | Location dst, |
| 1479 | Address src, |
| 1480 | XmmRegister temp, |
| 1481 | bool is_atomic_load) { |
| Andra Danciu | 1ca6f32 | 2020-08-12 08:58:07 +0000 | [diff] [blame] | 1482 | switch (dst_type) { |
| 1483 | case DataType::Type::kBool: |
| 1484 | case DataType::Type::kUint8: |
| 1485 | __ movzxb(dst.AsRegister<Register>(), src); |
| 1486 | break; |
| 1487 | case DataType::Type::kInt8: |
| 1488 | __ movsxb(dst.AsRegister<Register>(), src); |
| 1489 | break; |
| 1490 | case DataType::Type::kInt16: |
| 1491 | __ movsxw(dst.AsRegister<Register>(), src); |
| 1492 | break; |
| 1493 | case DataType::Type::kUint16: |
| 1494 | __ movzxw(dst.AsRegister<Register>(), src); |
| 1495 | break; |
| 1496 | case DataType::Type::kInt32: |
| Andra Danciu | 1ca6f32 | 2020-08-12 08:58:07 +0000 | [diff] [blame] | 1497 | __ movl(dst.AsRegister<Register>(), src); |
| 1498 | break; |
| Andra Danciu | d0f71f2 | 2020-09-17 09:00:15 +0000 | [diff] [blame] | 1499 | case DataType::Type::kInt64: { |
| 1500 | if (is_atomic_load) { |
| 1501 | __ movsd(temp, src); |
| 1502 | __ movd(dst.AsRegisterPairLow<Register>(), temp); |
| 1503 | __ psrlq(temp, Immediate(32)); |
| 1504 | __ movd(dst.AsRegisterPairHigh<Register>(), temp); |
| 1505 | } else { |
| 1506 | DCHECK_NE(src.GetBaseRegister(), dst.AsRegisterPairLow<Register>()); |
| 1507 | Address src_high = src.displaceBy(kX86WordSize); |
| 1508 | __ movl(dst.AsRegisterPairLow<Register>(), src); |
| 1509 | __ movl(dst.AsRegisterPairHigh<Register>(), src_high); |
| 1510 | } |
| Andra Danciu | 1ca6f32 | 2020-08-12 08:58:07 +0000 | [diff] [blame] | 1511 | break; |
| 1512 | } |
| 1513 | case DataType::Type::kFloat32: |
| 1514 | __ movss(dst.AsFpuRegister<XmmRegister>(), src); |
| 1515 | break; |
| 1516 | case DataType::Type::kFloat64: |
| 1517 | __ movsd(dst.AsFpuRegister<XmmRegister>(), src); |
| 1518 | break; |
| Andra Danciu | 1ca6f32 | 2020-08-12 08:58:07 +0000 | [diff] [blame] | 1519 | case DataType::Type::kReference: |
| Andra Danciu | d0f71f2 | 2020-09-17 09:00:15 +0000 | [diff] [blame] | 1520 | __ movl(dst.AsRegister<Register>(), src); |
| 1521 | __ MaybeUnpoisonHeapReference(dst.AsRegister<Register>()); |
| 1522 | break; |
| 1523 | default: |
| Andra Danciu | 1ca6f32 | 2020-08-12 08:58:07 +0000 | [diff] [blame] | 1524 | LOG(FATAL) << "Unreachable type " << dst_type; |
| 1525 | } |
| 1526 | } |
| 1527 | |
| Andra Danciu | 73c3180 | 2020-09-01 13:17:05 +0000 | [diff] [blame] | 1528 | void CodeGeneratorX86::MoveToMemory(DataType::Type src_type, |
| 1529 | Location src, |
| 1530 | Register dst_base, |
| 1531 | Register dst_index, |
| 1532 | ScaleFactor dst_scale, |
| 1533 | int32_t dst_disp) { |
| 1534 | DCHECK(dst_base != Register::kNoRegister); |
| 1535 | Address dst = CreateAddress(dst_base, dst_index, dst_scale, dst_disp); |
| 1536 | |
| 1537 | switch (src_type) { |
| 1538 | case DataType::Type::kBool: |
| 1539 | case DataType::Type::kUint8: |
| 1540 | case DataType::Type::kInt8: { |
| 1541 | if (src.IsConstant()) { |
| 1542 | __ movb(dst, Immediate(CodeGenerator::GetInt8ValueOf(src.GetConstant()))); |
| 1543 | } else { |
| 1544 | __ movb(dst, src.AsRegister<ByteRegister>()); |
| 1545 | } |
| 1546 | break; |
| 1547 | } |
| 1548 | case DataType::Type::kUint16: |
| 1549 | case DataType::Type::kInt16: { |
| 1550 | if (src.IsConstant()) { |
| 1551 | __ movw(dst, Immediate(CodeGenerator::GetInt16ValueOf(src.GetConstant()))); |
| 1552 | } else { |
| 1553 | __ movw(dst, src.AsRegister<Register>()); |
| 1554 | } |
| 1555 | break; |
| 1556 | } |
| 1557 | case DataType::Type::kUint32: |
| 1558 | case DataType::Type::kInt32: { |
| 1559 | if (src.IsConstant()) { |
| 1560 | int32_t v = CodeGenerator::GetInt32ValueOf(src.GetConstant()); |
| 1561 | __ movl(dst, Immediate(v)); |
| 1562 | } else { |
| 1563 | __ movl(dst, src.AsRegister<Register>()); |
| 1564 | } |
| 1565 | break; |
| 1566 | } |
| 1567 | case DataType::Type::kUint64: |
| 1568 | case DataType::Type::kInt64: { |
| 1569 | Address dst_next_4_bytes = CreateAddress(dst_base, dst_index, dst_scale, dst_disp + 4); |
| 1570 | if (src.IsConstant()) { |
| 1571 | int64_t v = CodeGenerator::GetInt64ValueOf(src.GetConstant()); |
| 1572 | __ movl(dst, Immediate(Low32Bits(v))); |
| 1573 | __ movl(dst_next_4_bytes, Immediate(High32Bits(v))); |
| 1574 | } else { |
| 1575 | __ movl(dst, src.AsRegisterPairLow<Register>()); |
| 1576 | __ movl(dst_next_4_bytes, src.AsRegisterPairHigh<Register>()); |
| 1577 | } |
| 1578 | break; |
| 1579 | } |
| 1580 | case DataType::Type::kFloat32: { |
| 1581 | if (src.IsConstant()) { |
| 1582 | int32_t v = CodeGenerator::GetInt32ValueOf(src.GetConstant()); |
| 1583 | __ movl(dst, Immediate(v)); |
| 1584 | } else { |
| 1585 | __ movss(dst, src.AsFpuRegister<XmmRegister>()); |
| 1586 | } |
| 1587 | break; |
| 1588 | } |
| 1589 | case DataType::Type::kFloat64: { |
| 1590 | Address dst_next_4_bytes = CreateAddress(dst_base, dst_index, dst_scale, dst_disp + 4); |
| 1591 | if (src.IsConstant()) { |
| 1592 | int64_t v = CodeGenerator::GetInt64ValueOf(src.GetConstant()); |
| 1593 | __ movl(dst, Immediate(Low32Bits(v))); |
| 1594 | __ movl(dst_next_4_bytes, Immediate(High32Bits(v))); |
| 1595 | } else { |
| 1596 | __ movsd(dst, src.AsFpuRegister<XmmRegister>()); |
| 1597 | } |
| 1598 | break; |
| 1599 | } |
| 1600 | case DataType::Type::kVoid: |
| 1601 | case DataType::Type::kReference: |
| 1602 | LOG(FATAL) << "Unreachable type " << src_type; |
| 1603 | } |
| 1604 | } |
| 1605 | |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1606 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { |
| 1607 | DCHECK(location.IsRegister()); |
| 1608 | __ movl(location.AsRegister<Register>(), Immediate(value)); |
| 1609 | } |
| 1610 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1611 | void CodeGeneratorX86::MoveLocation(Location dst, Location src, DataType::Type dst_type) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1612 | HParallelMove move(GetGraph()->GetAllocator()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1613 | if (dst_type == DataType::Type::kInt64 && !src.IsConstant() && !src.IsFpuRegister()) { |
| 1614 | move.AddMove(src.ToLow(), dst.ToLow(), DataType::Type::kInt32, nullptr); |
| 1615 | move.AddMove(src.ToHigh(), dst.ToHigh(), DataType::Type::kInt32, nullptr); |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1616 | } else { |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1617 | move.AddMove(src, dst, dst_type, nullptr); |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1618 | } |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1619 | GetMoveResolver()->EmitNativeCode(&move); |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1620 | } |
| 1621 | |
| 1622 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1623 | if (location.IsRegister()) { |
| 1624 | locations->AddTemp(location); |
| 1625 | } else if (location.IsRegisterPair()) { |
| 1626 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1627 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1628 | } else { |
| 1629 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1630 | } |
| 1631 | } |
| 1632 | |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1633 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
| Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 1634 | if (successor->IsExitBlock()) { |
| 1635 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 1636 | return; // no code needed |
| 1637 | } |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1638 | |
| 1639 | HBasicBlock* block = got->GetBlock(); |
| 1640 | HInstruction* previous = got->GetPrevious(); |
| 1641 | |
| 1642 | HLoopInformation* info = block->GetLoopInformation(); |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1643 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1644 | codegen_->MaybeIncrementHotness(/* is_frame_entry= */ false); |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1645 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1646 | return; |
| 1647 | } |
| 1648 | |
| 1649 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1650 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1651 | } |
| 1652 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1653 | __ jmp(codegen_->GetLabelOf(successor)); |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1654 | } |
| 1655 | } |
| 1656 | |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1657 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 1658 | got->SetLocations(nullptr); |
| 1659 | } |
| 1660 | |
| 1661 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 1662 | HandleGoto(got, got->GetSuccessor()); |
| 1663 | } |
| 1664 | |
| 1665 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1666 | try_boundary->SetLocations(nullptr); |
| 1667 | } |
| 1668 | |
| 1669 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1670 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1671 | if (!successor->IsExitBlock()) { |
| 1672 | HandleGoto(try_boundary, successor); |
| 1673 | } |
| 1674 | } |
| 1675 | |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1676 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1677 | exit->SetLocations(nullptr); |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1678 | } |
| 1679 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1680 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1681 | } |
| 1682 | |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1683 | template<class LabelType> |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1684 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1685 | LabelType* true_label, |
| 1686 | LabelType* false_label) { |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1687 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1688 | __ j(kUnordered, true_label); |
| 1689 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1690 | __ j(kUnordered, false_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1691 | } |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1692 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1693 | } |
| 1694 | |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1695 | template<class LabelType> |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1696 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1697 | LabelType* true_label, |
| 1698 | LabelType* false_label) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1699 | LocationSummary* locations = cond->GetLocations(); |
| 1700 | Location left = locations->InAt(0); |
| 1701 | Location right = locations->InAt(1); |
| 1702 | IfCondition if_cond = cond->GetCondition(); |
| 1703 | |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1704 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1705 | Register left_low = left.AsRegisterPairLow<Register>(); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1706 | IfCondition true_high_cond = if_cond; |
| 1707 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1708 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); // unsigned on lower part |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1709 | |
| 1710 | // Set the conditions for the test, remembering that == needs to be |
| 1711 | // decided using the low words. |
| 1712 | switch (if_cond) { |
| 1713 | case kCondEQ: |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1714 | case kCondNE: |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1715 | // Nothing to do. |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1716 | break; |
| 1717 | case kCondLT: |
| 1718 | false_high_cond = kCondGT; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1719 | break; |
| 1720 | case kCondLE: |
| 1721 | true_high_cond = kCondLT; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1722 | break; |
| 1723 | case kCondGT: |
| 1724 | false_high_cond = kCondLT; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1725 | break; |
| 1726 | case kCondGE: |
| 1727 | true_high_cond = kCondGT; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1728 | break; |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1729 | case kCondB: |
| 1730 | false_high_cond = kCondA; |
| 1731 | break; |
| 1732 | case kCondBE: |
| 1733 | true_high_cond = kCondB; |
| 1734 | break; |
| 1735 | case kCondA: |
| 1736 | false_high_cond = kCondB; |
| 1737 | break; |
| 1738 | case kCondAE: |
| 1739 | true_high_cond = kCondA; |
| 1740 | break; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1741 | } |
| 1742 | |
| 1743 | if (right.IsConstant()) { |
| 1744 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1745 | int32_t val_high = High32Bits(value); |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1746 | int32_t val_low = Low32Bits(value); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1747 | |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1748 | codegen_->Compare32BitValue(left_high, val_high); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1749 | if (if_cond == kCondNE) { |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1750 | __ j(X86Condition(true_high_cond), true_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1751 | } else if (if_cond == kCondEQ) { |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1752 | __ j(X86Condition(false_high_cond), false_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1753 | } else { |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1754 | __ j(X86Condition(true_high_cond), true_label); |
| 1755 | __ j(X86Condition(false_high_cond), false_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1756 | } |
| 1757 | // Must be equal high, so compare the lows. |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1758 | codegen_->Compare32BitValue(left_low, val_low); |
| Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1759 | } else if (right.IsRegisterPair()) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1760 | Register right_high = right.AsRegisterPairHigh<Register>(); |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1761 | Register right_low = right.AsRegisterPairLow<Register>(); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1762 | |
| 1763 | __ cmpl(left_high, right_high); |
| 1764 | if (if_cond == kCondNE) { |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1765 | __ j(X86Condition(true_high_cond), true_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1766 | } else if (if_cond == kCondEQ) { |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1767 | __ j(X86Condition(false_high_cond), false_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1768 | } else { |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1769 | __ j(X86Condition(true_high_cond), true_label); |
| 1770 | __ j(X86Condition(false_high_cond), false_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1771 | } |
| 1772 | // Must be equal high, so compare the lows. |
| 1773 | __ cmpl(left_low, right_low); |
| Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1774 | } else { |
| 1775 | DCHECK(right.IsDoubleStackSlot()); |
| 1776 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
| 1777 | if (if_cond == kCondNE) { |
| 1778 | __ j(X86Condition(true_high_cond), true_label); |
| 1779 | } else if (if_cond == kCondEQ) { |
| 1780 | __ j(X86Condition(false_high_cond), false_label); |
| 1781 | } else { |
| 1782 | __ j(X86Condition(true_high_cond), true_label); |
| 1783 | __ j(X86Condition(false_high_cond), false_label); |
| 1784 | } |
| 1785 | // Must be equal high, so compare the lows. |
| 1786 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1787 | } |
| 1788 | // The last comparison might be unsigned. |
| 1789 | __ j(final_condition, true_label); |
| 1790 | } |
| 1791 | |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1792 | void InstructionCodeGeneratorX86::GenerateFPCompare(Location lhs, |
| 1793 | Location rhs, |
| 1794 | HInstruction* insn, |
| 1795 | bool is_double) { |
| 1796 | HX86LoadFromConstantTable* const_area = insn->InputAt(1)->AsX86LoadFromConstantTable(); |
| 1797 | if (is_double) { |
| 1798 | if (rhs.IsFpuRegister()) { |
| 1799 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1800 | } else if (const_area != nullptr) { |
| 1801 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1802 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), |
| 1803 | codegen_->LiteralDoubleAddress( |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1804 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 1805 | const_area->GetBaseMethodAddress(), |
| 1806 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1807 | } else { |
| 1808 | DCHECK(rhs.IsDoubleStackSlot()); |
| 1809 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1810 | } |
| 1811 | } else { |
| 1812 | if (rhs.IsFpuRegister()) { |
| 1813 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1814 | } else if (const_area != nullptr) { |
| 1815 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1816 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), |
| 1817 | codegen_->LiteralFloatAddress( |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1818 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 1819 | const_area->GetBaseMethodAddress(), |
| 1820 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1821 | } else { |
| 1822 | DCHECK(rhs.IsStackSlot()); |
| 1823 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1824 | } |
| 1825 | } |
| 1826 | } |
| 1827 | |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1828 | template<class LabelType> |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1829 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1830 | LabelType* true_target_in, |
| 1831 | LabelType* false_target_in) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1832 | // Generated branching requires both targets to be explicit. If either of the |
| 1833 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1834 | LabelType fallthrough_target; |
| 1835 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1836 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1837 | |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1838 | LocationSummary* locations = condition->GetLocations(); |
| 1839 | Location left = locations->InAt(0); |
| 1840 | Location right = locations->InAt(1); |
| 1841 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1842 | DataType::Type type = condition->InputAt(0)->GetType(); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1843 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1844 | case DataType::Type::kInt64: |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1845 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1846 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1847 | case DataType::Type::kFloat32: |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1848 | GenerateFPCompare(left, right, condition, false); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1849 | GenerateFPJumps(condition, true_target, false_target); |
| 1850 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1851 | case DataType::Type::kFloat64: |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1852 | GenerateFPCompare(left, right, condition, true); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1853 | GenerateFPJumps(condition, true_target, false_target); |
| 1854 | break; |
| 1855 | default: |
| 1856 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1857 | } |
| 1858 | |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1859 | if (false_target != &fallthrough_target) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1860 | __ jmp(false_target); |
| 1861 | } |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1862 | |
| 1863 | if (fallthrough_target.IsLinked()) { |
| 1864 | __ Bind(&fallthrough_target); |
| 1865 | } |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1866 | } |
| 1867 | |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1868 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1869 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1870 | // are set only strictly before `branch`. We can't use the eflags on long/FP |
| 1871 | // conditions if they are materialized due to the complex branching. |
| 1872 | return cond->IsCondition() && |
| 1873 | cond->GetNext() == branch && |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1874 | cond->InputAt(0)->GetType() != DataType::Type::kInt64 && |
| 1875 | !DataType::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1876 | } |
| 1877 | |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1878 | template<class LabelType> |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1879 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1880 | size_t condition_input_index, |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1881 | LabelType* true_target, |
| 1882 | LabelType* false_target) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1883 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1884 | |
| 1885 | if (true_target == nullptr && false_target == nullptr) { |
| 1886 | // Nothing to do. The code always falls through. |
| 1887 | return; |
| 1888 | } else if (cond->IsIntConstant()) { |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1889 | // Constant condition, statically compared against "true" (integer value 1). |
| 1890 | if (cond->AsIntConstant()->IsTrue()) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1891 | if (true_target != nullptr) { |
| 1892 | __ jmp(true_target); |
| Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1893 | } |
| Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1894 | } else { |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1895 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1896 | if (false_target != nullptr) { |
| 1897 | __ jmp(false_target); |
| 1898 | } |
| 1899 | } |
| 1900 | return; |
| 1901 | } |
| 1902 | |
| 1903 | // The following code generates these patterns: |
| 1904 | // (1) true_target == nullptr && false_target != nullptr |
| 1905 | // - opposite condition true => branch to false_target |
| 1906 | // (2) true_target != nullptr && false_target == nullptr |
| 1907 | // - condition true => branch to true_target |
| 1908 | // (3) true_target != nullptr && false_target != nullptr |
| 1909 | // - condition true => branch to true_target |
| 1910 | // - branch to false_target |
| 1911 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1912 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1913 | if (true_target == nullptr) { |
| 1914 | __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1915 | } else { |
| 1916 | __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); |
| 1917 | } |
| 1918 | } else { |
| 1919 | // Materialized condition, compare against 0. |
| 1920 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1921 | if (lhs.IsRegister()) { |
| 1922 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1923 | } else { |
| 1924 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1925 | } |
| 1926 | if (true_target == nullptr) { |
| 1927 | __ j(kEqual, false_target); |
| 1928 | } else { |
| 1929 | __ j(kNotEqual, true_target); |
| 1930 | } |
| Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1931 | } |
| 1932 | } else { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1933 | // Condition has not been materialized, use its inputs as the comparison and |
| 1934 | // its condition as the branch condition. |
| Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1935 | HCondition* condition = cond->AsCondition(); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1936 | |
| 1937 | // If this is a long or FP comparison that has been folded into |
| 1938 | // the HCondition, generate the comparison directly. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1939 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 1940 | if (type == DataType::Type::kInt64 || DataType::IsFloatingPointType(type)) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1941 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1942 | return; |
| 1943 | } |
| 1944 | |
| 1945 | Location lhs = condition->GetLocations()->InAt(0); |
| 1946 | Location rhs = condition->GetLocations()->InAt(1); |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1947 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition). |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1948 | codegen_->GenerateIntCompare(lhs, rhs); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1949 | if (true_target == nullptr) { |
| 1950 | __ j(X86Condition(condition->GetOppositeCondition()), false_target); |
| 1951 | } else { |
| Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1952 | __ j(X86Condition(condition->GetCondition()), true_target); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1953 | } |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1954 | } |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1955 | |
| 1956 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1957 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1958 | if (true_target != nullptr && false_target != nullptr) { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1959 | __ jmp(false_target); |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1960 | } |
| 1961 | } |
| 1962 | |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1963 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1964 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1965 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1966 | locations->SetInAt(0, Location::Any()); |
| 1967 | } |
| 1968 | } |
| 1969 | |
| 1970 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1971 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1972 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1973 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1974 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1975 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1976 | nullptr : codegen_->GetLabelOf(false_successor); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1977 | GenerateTestAndBranch(if_instr, /* condition_input_index= */ 0, true_target, false_target); |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1978 | } |
| 1979 | |
| 1980 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1981 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1982 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 1983 | InvokeRuntimeCallingConvention calling_convention; |
| 1984 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 1985 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1986 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1987 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1988 | locations->SetInAt(0, Location::Any()); |
| 1989 | } |
| 1990 | } |
| 1991 | |
| 1992 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1993 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86>(deoptimize); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1994 | GenerateTestAndBranch<Label>(deoptimize, |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1995 | /* condition_input_index= */ 0, |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1996 | slow_path->GetEntryLabel(), |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1997 | /* false_target= */ nullptr); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1998 | } |
| 1999 | |
| Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 2000 | void LocationsBuilderX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2001 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
| Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 2002 | LocationSummary(flag, LocationSummary::kNoCall); |
| 2003 | locations->SetOut(Location::RequiresRegister()); |
| 2004 | } |
| 2005 | |
| 2006 | void InstructionCodeGeneratorX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 2007 | __ movl(flag->GetLocations()->Out().AsRegister<Register>(), |
| 2008 | Address(ESP, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 2009 | } |
| 2010 | |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2011 | static bool SelectCanUseCMOV(HSelect* select) { |
| 2012 | // There are no conditional move instructions for XMMs. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2013 | if (DataType::IsFloatingPointType(select->GetType())) { |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2014 | return false; |
| 2015 | } |
| 2016 | |
| 2017 | // A FP condition doesn't generate the single CC that we need. |
| 2018 | // In 32 bit mode, a long condition doesn't generate a single CC either. |
| 2019 | HInstruction* condition = select->GetCondition(); |
| 2020 | if (condition->IsCondition()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2021 | DataType::Type compare_type = condition->InputAt(0)->GetType(); |
| 2022 | if (compare_type == DataType::Type::kInt64 || |
| 2023 | DataType::IsFloatingPointType(compare_type)) { |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2024 | return false; |
| 2025 | } |
| 2026 | } |
| 2027 | |
| 2028 | // We can generate a CMOV for this Select. |
| 2029 | return true; |
| 2030 | } |
| 2031 | |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2032 | void LocationsBuilderX86::VisitSelect(HSelect* select) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2033 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2034 | if (DataType::IsFloatingPointType(select->GetType())) { |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2035 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2036 | locations->SetInAt(1, Location::Any()); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2037 | } else { |
| 2038 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2039 | if (SelectCanUseCMOV(select)) { |
| 2040 | if (select->InputAt(1)->IsConstant()) { |
| 2041 | // Cmov can't handle a constant value. |
| 2042 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2043 | } else { |
| 2044 | locations->SetInAt(1, Location::Any()); |
| 2045 | } |
| 2046 | } else { |
| 2047 | locations->SetInAt(1, Location::Any()); |
| 2048 | } |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2049 | } |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2050 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 2051 | locations->SetInAt(2, Location::RequiresRegister()); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2052 | } |
| 2053 | locations->SetOut(Location::SameAsFirstInput()); |
| 2054 | } |
| 2055 | |
| 2056 | void InstructionCodeGeneratorX86::VisitSelect(HSelect* select) { |
| 2057 | LocationSummary* locations = select->GetLocations(); |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2058 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 2059 | if (SelectCanUseCMOV(select)) { |
| 2060 | // If both the condition and the source types are integer, we can generate |
| 2061 | // a CMOV to implement Select. |
| 2062 | |
| 2063 | HInstruction* select_condition = select->GetCondition(); |
| 2064 | Condition cond = kNotEqual; |
| 2065 | |
| 2066 | // Figure out how to test the 'condition'. |
| 2067 | if (select_condition->IsCondition()) { |
| 2068 | HCondition* condition = select_condition->AsCondition(); |
| 2069 | if (!condition->IsEmittedAtUseSite()) { |
| 2070 | // This was a previously materialized condition. |
| 2071 | // Can we use the existing condition code? |
| 2072 | if (AreEflagsSetFrom(condition, select)) { |
| 2073 | // Materialization was the previous instruction. Condition codes are right. |
| 2074 | cond = X86Condition(condition->GetCondition()); |
| 2075 | } else { |
| 2076 | // No, we have to recreate the condition code. |
| 2077 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 2078 | __ testl(cond_reg, cond_reg); |
| 2079 | } |
| 2080 | } else { |
| 2081 | // We can't handle FP or long here. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2082 | DCHECK_NE(condition->InputAt(0)->GetType(), DataType::Type::kInt64); |
| 2083 | DCHECK(!DataType::IsFloatingPointType(condition->InputAt(0)->GetType())); |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2084 | LocationSummary* cond_locations = condition->GetLocations(); |
| Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2085 | codegen_->GenerateIntCompare(cond_locations->InAt(0), cond_locations->InAt(1)); |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2086 | cond = X86Condition(condition->GetCondition()); |
| 2087 | } |
| 2088 | } else { |
| Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 2089 | // Must be a Boolean condition, which needs to be compared to 0. |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2090 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 2091 | __ testl(cond_reg, cond_reg); |
| 2092 | } |
| 2093 | |
| 2094 | // If the condition is true, overwrite the output, which already contains false. |
| 2095 | Location false_loc = locations->InAt(0); |
| 2096 | Location true_loc = locations->InAt(1); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2097 | if (select->GetType() == DataType::Type::kInt64) { |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2098 | // 64 bit conditional move. |
| 2099 | Register false_high = false_loc.AsRegisterPairHigh<Register>(); |
| 2100 | Register false_low = false_loc.AsRegisterPairLow<Register>(); |
| 2101 | if (true_loc.IsRegisterPair()) { |
| 2102 | __ cmovl(cond, false_high, true_loc.AsRegisterPairHigh<Register>()); |
| 2103 | __ cmovl(cond, false_low, true_loc.AsRegisterPairLow<Register>()); |
| 2104 | } else { |
| 2105 | __ cmovl(cond, false_high, Address(ESP, true_loc.GetHighStackIndex(kX86WordSize))); |
| 2106 | __ cmovl(cond, false_low, Address(ESP, true_loc.GetStackIndex())); |
| 2107 | } |
| 2108 | } else { |
| 2109 | // 32 bit conditional move. |
| 2110 | Register false_reg = false_loc.AsRegister<Register>(); |
| 2111 | if (true_loc.IsRegister()) { |
| 2112 | __ cmovl(cond, false_reg, true_loc.AsRegister<Register>()); |
| 2113 | } else { |
| 2114 | __ cmovl(cond, false_reg, Address(ESP, true_loc.GetStackIndex())); |
| 2115 | } |
| 2116 | } |
| 2117 | } else { |
| 2118 | NearLabel false_target; |
| 2119 | GenerateTestAndBranch<NearLabel>( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2120 | select, /* condition_input_index= */ 2, /* true_target= */ nullptr, &false_target); |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2121 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 2122 | __ Bind(&false_target); |
| 2123 | } |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2124 | } |
| 2125 | |
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 2126 | void LocationsBuilderX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2127 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 2128 | } |
| 2129 | |
| David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 2130 | void InstructionCodeGeneratorX86::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 2131 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
| David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 2132 | } |
| 2133 | |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 2134 | void CodeGeneratorX86::IncreaseFrame(size_t adjustment) { |
| 2135 | __ subl(ESP, Immediate(adjustment)); |
| 2136 | __ cfi().AdjustCFAOffset(adjustment); |
| 2137 | } |
| 2138 | |
| 2139 | void CodeGeneratorX86::DecreaseFrame(size_t adjustment) { |
| 2140 | __ addl(ESP, Immediate(adjustment)); |
| 2141 | __ cfi().AdjustCFAOffset(-adjustment); |
| 2142 | } |
| 2143 | |
| David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 2144 | void CodeGeneratorX86::GenerateNop() { |
| 2145 | __ nop(); |
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 2146 | } |
| 2147 | |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2148 | void LocationsBuilderX86::HandleCondition(HCondition* cond) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2149 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2150 | new (GetGraph()->GetAllocator()) LocationSummary(cond, LocationSummary::kNoCall); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2151 | // Handle the long/FP comparisons made in instruction simplification. |
| 2152 | switch (cond->InputAt(0)->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2153 | case DataType::Type::kInt64: { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2154 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 2155 | locations->SetInAt(1, Location::Any()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2156 | if (!cond->IsEmittedAtUseSite()) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2157 | locations->SetOut(Location::RequiresRegister()); |
| 2158 | } |
| 2159 | break; |
| 2160 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2161 | case DataType::Type::kFloat32: |
| 2162 | case DataType::Type::kFloat64: { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2163 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2164 | if (cond->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2165 | DCHECK(cond->InputAt(1)->IsEmittedAtUseSite()); |
| 2166 | } else if (cond->InputAt(1)->IsConstant()) { |
| 2167 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2168 | } else { |
| 2169 | locations->SetInAt(1, Location::Any()); |
| 2170 | } |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2171 | if (!cond->IsEmittedAtUseSite()) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2172 | locations->SetOut(Location::RequiresRegister()); |
| 2173 | } |
| 2174 | break; |
| 2175 | } |
| 2176 | default: |
| 2177 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2178 | locations->SetInAt(1, Location::Any()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2179 | if (!cond->IsEmittedAtUseSite()) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2180 | // We need a byte register. |
| 2181 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 2182 | } |
| 2183 | break; |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2184 | } |
| Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2185 | } |
| 2186 | |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2187 | void InstructionCodeGeneratorX86::HandleCondition(HCondition* cond) { |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2188 | if (cond->IsEmittedAtUseSite()) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2189 | return; |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2190 | } |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2191 | |
| 2192 | LocationSummary* locations = cond->GetLocations(); |
| 2193 | Location lhs = locations->InAt(0); |
| 2194 | Location rhs = locations->InAt(1); |
| 2195 | Register reg = locations->Out().AsRegister<Register>(); |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 2196 | NearLabel true_label, false_label; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2197 | |
| 2198 | switch (cond->InputAt(0)->GetType()) { |
| 2199 | default: { |
| 2200 | // Integer case. |
| 2201 | |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 2202 | // Clear output register: setb only sets the low byte. |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2203 | __ xorl(reg, reg); |
| Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2204 | codegen_->GenerateIntCompare(lhs, rhs); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2205 | __ setb(X86Condition(cond->GetCondition()), reg); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2206 | return; |
| 2207 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2208 | case DataType::Type::kInt64: |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2209 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 2210 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2211 | case DataType::Type::kFloat32: |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2212 | GenerateFPCompare(lhs, rhs, cond, false); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2213 | GenerateFPJumps(cond, &true_label, &false_label); |
| 2214 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2215 | case DataType::Type::kFloat64: |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2216 | GenerateFPCompare(lhs, rhs, cond, true); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2217 | GenerateFPJumps(cond, &true_label, &false_label); |
| 2218 | break; |
| 2219 | } |
| 2220 | |
| 2221 | // Convert the jumps into the result. |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2222 | NearLabel done_label; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2223 | |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2224 | // False case: result = 0. |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2225 | __ Bind(&false_label); |
| 2226 | __ xorl(reg, reg); |
| 2227 | __ jmp(&done_label); |
| 2228 | |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2229 | // True case: result = 1. |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2230 | __ Bind(&true_label); |
| 2231 | __ movl(reg, Immediate(1)); |
| 2232 | __ Bind(&done_label); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2233 | } |
| 2234 | |
| 2235 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2236 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2237 | } |
| 2238 | |
| 2239 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2240 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2241 | } |
| 2242 | |
| 2243 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2244 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2245 | } |
| 2246 | |
| 2247 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2248 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2249 | } |
| 2250 | |
| 2251 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2252 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2253 | } |
| 2254 | |
| 2255 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2256 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2257 | } |
| 2258 | |
| 2259 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2260 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2261 | } |
| 2262 | |
| 2263 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2264 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2265 | } |
| 2266 | |
| 2267 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2268 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2269 | } |
| 2270 | |
| 2271 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2272 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2273 | } |
| 2274 | |
| 2275 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2276 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2277 | } |
| 2278 | |
| 2279 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2280 | HandleCondition(comp); |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2281 | } |
| 2282 | |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2283 | void LocationsBuilderX86::VisitBelow(HBelow* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2284 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2285 | } |
| 2286 | |
| 2287 | void InstructionCodeGeneratorX86::VisitBelow(HBelow* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2288 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2289 | } |
| 2290 | |
| 2291 | void LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2292 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2293 | } |
| 2294 | |
| 2295 | void InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2296 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2297 | } |
| 2298 | |
| 2299 | void LocationsBuilderX86::VisitAbove(HAbove* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2300 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2301 | } |
| 2302 | |
| 2303 | void InstructionCodeGeneratorX86::VisitAbove(HAbove* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2304 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2305 | } |
| 2306 | |
| 2307 | void LocationsBuilderX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2308 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2309 | } |
| 2310 | |
| 2311 | void InstructionCodeGeneratorX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2312 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2313 | } |
| 2314 | |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2315 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2316 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2317 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2318 | locations->SetOut(Location::ConstantLocation(constant)); |
| Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2319 | } |
| 2320 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2321 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2322 | // Will be generated at use site. |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2323 | } |
| 2324 | |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2325 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 2326 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2327 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2328 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2329 | } |
| 2330 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2331 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2332 | // Will be generated at use site. |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2333 | } |
| 2334 | |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2335 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2336 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2337 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2338 | locations->SetOut(Location::ConstantLocation(constant)); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2339 | } |
| 2340 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2341 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2342 | // Will be generated at use site. |
| 2343 | } |
| 2344 | |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2345 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 2346 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2347 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2348 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2349 | } |
| 2350 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2351 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2352 | // Will be generated at use site. |
| 2353 | } |
| 2354 | |
| 2355 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2356 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2357 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2358 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2359 | } |
| 2360 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2361 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2362 | // Will be generated at use site. |
| 2363 | } |
| 2364 | |
| Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2365 | void LocationsBuilderX86::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 2366 | constructor_fence->SetLocations(nullptr); |
| 2367 | } |
| 2368 | |
| 2369 | void InstructionCodeGeneratorX86::VisitConstructorFence( |
| 2370 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 2371 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 2372 | } |
| 2373 | |
| Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2374 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2375 | memory_barrier->SetLocations(nullptr); |
| 2376 | } |
| 2377 | |
| 2378 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 2379 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2380 | } |
| 2381 | |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2382 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2383 | ret->SetLocations(nullptr); |
| Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2384 | } |
| 2385 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2386 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2387 | codegen_->GenerateFrameExit(); |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2388 | } |
| 2389 | |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2390 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2391 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2392 | new (GetGraph()->GetAllocator()) LocationSummary(ret, LocationSummary::kNoCall); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2393 | switch (ret->InputAt(0)->GetType()) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2394 | case DataType::Type::kReference: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2395 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2396 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2397 | case DataType::Type::kInt8: |
| 2398 | case DataType::Type::kUint16: |
| 2399 | case DataType::Type::kInt16: |
| 2400 | case DataType::Type::kInt32: |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2401 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2402 | break; |
| 2403 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2404 | case DataType::Type::kInt64: |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2405 | locations->SetInAt( |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2406 | 0, Location::RegisterPairLocation(EAX, EDX)); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2407 | break; |
| 2408 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2409 | case DataType::Type::kFloat32: |
| 2410 | case DataType::Type::kFloat64: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2411 | locations->SetInAt( |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2412 | 0, Location::FpuRegisterLocation(XMM0)); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2413 | break; |
| 2414 | |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2415 | default: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2416 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2417 | } |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2418 | } |
| 2419 | |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2420 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
| Nicolas Geoffray | 57cacb7 | 2019-12-08 22:07:08 +0000 | [diff] [blame] | 2421 | switch (ret->InputAt(0)->GetType()) { |
| 2422 | case DataType::Type::kReference: |
| 2423 | case DataType::Type::kBool: |
| 2424 | case DataType::Type::kUint8: |
| 2425 | case DataType::Type::kInt8: |
| 2426 | case DataType::Type::kUint16: |
| 2427 | case DataType::Type::kInt16: |
| 2428 | case DataType::Type::kInt32: |
| 2429 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
| 2430 | break; |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2431 | |
| Nicolas Geoffray | 57cacb7 | 2019-12-08 22:07:08 +0000 | [diff] [blame] | 2432 | case DataType::Type::kInt64: |
| 2433 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 2434 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
| 2435 | break; |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2436 | |
| Nicolas Geoffray | 57cacb7 | 2019-12-08 22:07:08 +0000 | [diff] [blame] | 2437 | case DataType::Type::kFloat32: |
| 2438 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
| 2439 | if (GetGraph()->IsCompilingOsr()) { |
| 2440 | // To simplify callers of an OSR method, we put the return value in both |
| 2441 | // floating point and core registers. |
| 2442 | __ movd(EAX, XMM0); |
| 2443 | } |
| 2444 | break; |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2445 | |
| Nicolas Geoffray | 57cacb7 | 2019-12-08 22:07:08 +0000 | [diff] [blame] | 2446 | case DataType::Type::kFloat64: |
| 2447 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
| 2448 | if (GetGraph()->IsCompilingOsr()) { |
| 2449 | // To simplify callers of an OSR method, we put the return value in both |
| 2450 | // floating point and core registers. |
| 2451 | __ movd(EAX, XMM0); |
| 2452 | // Use XMM1 as temporary register to not clobber XMM0. |
| 2453 | __ movaps(XMM1, XMM0); |
| 2454 | __ psrlq(XMM1, Immediate(32)); |
| 2455 | __ movd(EDX, XMM1); |
| 2456 | } |
| 2457 | break; |
| 2458 | |
| 2459 | default: |
| 2460 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2461 | } |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2462 | codegen_->GenerateFrameExit(); |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2463 | } |
| 2464 | |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2465 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2466 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2467 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2468 | // the method_idx. |
| 2469 | HandleInvoke(invoke); |
| 2470 | } |
| 2471 | |
| 2472 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2473 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2474 | } |
| 2475 | |
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2476 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2477 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2478 | // art::PrepareForRegisterAllocation. |
| 2479 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2480 | |
| Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2481 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2482 | if (intrinsic.TryDispatch(invoke)) { |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 2483 | if (invoke->GetLocations()->CanCall() && |
| 2484 | invoke->HasPcRelativeMethodLoadKind() && |
| 2485 | invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()).IsInvalid()) { |
| Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 2486 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2487 | } |
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2488 | return; |
| 2489 | } |
| 2490 | |
| Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 2491 | if (invoke->GetCodePtrLocation() == CodePtrLocation::kCallCriticalNative) { |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 2492 | CriticalNativeCallingConventionVisitorX86 calling_convention_visitor( |
| 2493 | /*for_register_allocation=*/ true); |
| 2494 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 2495 | } else { |
| 2496 | HandleInvoke(invoke); |
| 2497 | } |
| Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2498 | |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 2499 | // 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] | 2500 | if (invoke->HasPcRelativeMethodLoadKind()) { |
| Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2501 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2502 | } |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2503 | } |
| 2504 | |
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2505 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 2506 | if (invoke->GetLocations()->Intrinsified()) { |
| 2507 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 2508 | intrinsic.Dispatch(invoke); |
| 2509 | return true; |
| 2510 | } |
| 2511 | return false; |
| 2512 | } |
| 2513 | |
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2514 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2515 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2516 | // art::PrepareForRegisterAllocation. |
| 2517 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2518 | |
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2519 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2520 | return; |
| Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2521 | } |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2522 | |
| Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2523 | LocationSummary* locations = invoke->GetLocations(); |
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2524 | codegen_->GenerateStaticOrDirectCall( |
| Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2525 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2526 | } |
| 2527 | |
| 2528 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 2529 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 2530 | if (intrinsic.TryDispatch(invoke)) { |
| 2531 | return; |
| 2532 | } |
| 2533 | |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2534 | HandleInvoke(invoke); |
| Nicolas Geoffray | 9b5271e | 2019-12-04 14:39:46 +0000 | [diff] [blame] | 2535 | |
| 2536 | if (GetGraph()->IsCompilingBaseline() && !Runtime::Current()->IsAotCompiler()) { |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2537 | // Add one temporary for inline cache update. |
| 2538 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(EBP)); |
| 2539 | } |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2540 | } |
| 2541 | |
| 2542 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2543 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2544 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2545 | } |
| 2546 | |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2547 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2548 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2549 | return; |
| 2550 | } |
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2551 | |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2552 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2553 | DCHECK(!codegen_->IsLeafMethod()); |
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2554 | } |
| 2555 | |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2556 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2557 | // This call to HandleInvoke allocates a temporary (core) register |
| 2558 | // which is also used to transfer the hidden argument from FP to |
| 2559 | // core register. |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2560 | HandleInvoke(invoke); |
| 2561 | // Add the hidden argument. |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2562 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2563 | |
| Nicolas Geoffray | 9b5271e | 2019-12-04 14:39:46 +0000 | [diff] [blame] | 2564 | if (GetGraph()->IsCompilingBaseline() && !Runtime::Current()->IsAotCompiler()) { |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2565 | // Add one temporary for inline cache update. |
| 2566 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(EBP)); |
| 2567 | } |
| Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 2568 | |
| 2569 | // For PC-relative load kinds the invoke has an extra input, the PC-relative address base. |
| 2570 | if (IsPcRelativeMethodLoadKind(invoke->GetHiddenArgumentLoadKind())) { |
| 2571 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| 2572 | } |
| 2573 | |
| 2574 | if (invoke->GetHiddenArgumentLoadKind() == MethodLoadKind::kRecursive) { |
| 2575 | invoke->GetLocations()->SetInAt(invoke->GetNumberOfArguments() - 1, |
| 2576 | Location::RequiresRegister()); |
| 2577 | } |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2578 | } |
| 2579 | |
| 2580 | void CodeGeneratorX86::MaybeGenerateInlineCacheCheck(HInstruction* instruction, Register klass) { |
| 2581 | DCHECK_EQ(EAX, klass); |
| Nicolas Geoffray | 17a39ba | 2019-11-27 20:57:48 +0000 | [diff] [blame] | 2582 | // We know the destination of an intrinsic, so no need to record inline |
| 2583 | // caches (also the intrinsic location builder doesn't request an additional |
| 2584 | // temporary). |
| 2585 | if (!instruction->GetLocations()->Intrinsified() && |
| Nicolas Geoffray | 9b5271e | 2019-12-04 14:39:46 +0000 | [diff] [blame] | 2586 | GetGraph()->IsCompilingBaseline() && |
| Nicolas Geoffray | 17a39ba | 2019-11-27 20:57:48 +0000 | [diff] [blame] | 2587 | !Runtime::Current()->IsAotCompiler()) { |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2588 | DCHECK(!instruction->GetEnvironment()->IsFromInlinedInvoke()); |
| Nicolas Geoffray | 095dc46 | 2020-08-17 16:40:28 +0100 | [diff] [blame] | 2589 | ScopedProfilingInfoUse spiu( |
| 2590 | Runtime::Current()->GetJit(), GetGraph()->GetArtMethod(), Thread::Current()); |
| 2591 | ProfilingInfo* info = spiu.GetProfilingInfo(); |
| Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 2592 | if (info != nullptr) { |
| 2593 | InlineCache* cache = info->GetInlineCache(instruction->GetDexPc()); |
| 2594 | uint32_t address = reinterpret_cast32<uint32_t>(cache); |
| 2595 | if (kIsDebugBuild) { |
| 2596 | uint32_t temp_index = instruction->GetLocations()->GetTempCount() - 1u; |
| 2597 | CHECK_EQ(EBP, instruction->GetLocations()->GetTemp(temp_index).AsRegister<Register>()); |
| 2598 | } |
| 2599 | Register temp = EBP; |
| 2600 | NearLabel done; |
| 2601 | __ movl(temp, Immediate(address)); |
| 2602 | // Fast path for a monomorphic cache. |
| 2603 | __ cmpl(klass, Address(temp, InlineCache::ClassesOffset().Int32Value())); |
| 2604 | __ j(kEqual, &done); |
| 2605 | GenerateInvokeRuntime(GetThreadOffset<kX86PointerSize>(kQuickUpdateInlineCache).Int32Value()); |
| 2606 | __ Bind(&done); |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2607 | } |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2608 | } |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2609 | } |
| 2610 | |
| 2611 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2612 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2613 | LocationSummary* locations = invoke->GetLocations(); |
| 2614 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2615 | XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2616 | Location receiver = locations->InAt(0); |
| 2617 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2618 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2619 | // Set the hidden argument. This is safe to do this here, as XMM7 |
| 2620 | // won't be modified thereafter, before the `call` instruction. |
| 2621 | DCHECK_EQ(XMM7, hidden_reg); |
| Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 2622 | if (invoke->GetHiddenArgumentLoadKind() == MethodLoadKind::kRecursive) { |
| 2623 | __ movd(hidden_reg, locations->InAt(invoke->GetNumberOfArguments() - 1).AsRegister<Register>()); |
| Nicolas Geoffray | d6bd107 | 2020-11-30 18:42:01 +0000 | [diff] [blame^] | 2624 | } else if (invoke->GetHiddenArgumentLoadKind() != MethodLoadKind::kRuntimeCall) { |
| Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 2625 | codegen_->LoadMethod(invoke->GetHiddenArgumentLoadKind(), locations->GetTemp(0), invoke); |
| 2626 | __ movd(hidden_reg, temp); |
| 2627 | } |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2628 | |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2629 | if (receiver.IsStackSlot()) { |
| 2630 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2631 | // /* HeapReference<Class> */ temp = temp->klass_ |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2632 | __ movl(temp, Address(temp, class_offset)); |
| 2633 | } else { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2634 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2635 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2636 | } |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2637 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2638 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2639 | // emit a read barrier for the previous class reference load. |
| 2640 | // However this is not required in practice, as this is an |
| 2641 | // intermediate/temporary reference and because the current |
| 2642 | // concurrent copying collector keeps the from-space memory |
| 2643 | // intact/accessible until the end of the marking phase (the |
| 2644 | // concurrent copying collector may not in the future). |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2645 | __ MaybeUnpoisonHeapReference(temp); |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2646 | |
| 2647 | codegen_->MaybeGenerateInlineCacheCheck(invoke, temp); |
| 2648 | |
| Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2649 | // temp = temp->GetAddressOfIMT() |
| 2650 | __ movl(temp, |
| 2651 | Address(temp, mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2652 | // temp = temp->GetImtEntryAt(method_offset); |
| Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2653 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2654 | invoke->GetImtIndex(), kX86PointerSize)); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2655 | __ movl(temp, Address(temp, method_offset)); |
| Nicolas Geoffray | d6bd107 | 2020-11-30 18:42:01 +0000 | [diff] [blame^] | 2656 | if (invoke->GetHiddenArgumentLoadKind() == MethodLoadKind::kRuntimeCall) { |
| 2657 | // We pass the method from the IMT in case of a conflict. This will ensure |
| 2658 | // we go into the runtime to resolve the actual method. |
| 2659 | __ movd(hidden_reg, temp); |
| 2660 | } |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2661 | // call temp->GetEntryPoint(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2662 | __ call(Address(temp, |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2663 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2664 | |
| 2665 | DCHECK(!codegen_->IsLeafMethod()); |
| 2666 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2667 | } |
| 2668 | |
| Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2669 | void LocationsBuilderX86::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 2670 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 2671 | if (intrinsic.TryDispatch(invoke)) { |
| 2672 | return; |
| 2673 | } |
| Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2674 | HandleInvoke(invoke); |
| 2675 | } |
| 2676 | |
| 2677 | void InstructionCodeGeneratorX86::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 2678 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2679 | return; |
| 2680 | } |
| Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2681 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 2682 | } |
| 2683 | |
| Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 2684 | void LocationsBuilderX86::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 2685 | HandleInvoke(invoke); |
| 2686 | } |
| 2687 | |
| 2688 | void InstructionCodeGeneratorX86::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 2689 | codegen_->GenerateInvokeCustomCall(invoke); |
| 2690 | } |
| 2691 | |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2692 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 2693 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2694 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2695 | switch (neg->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2696 | case DataType::Type::kInt32: |
| 2697 | case DataType::Type::kInt64: |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2698 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2699 | locations->SetOut(Location::SameAsFirstInput()); |
| 2700 | break; |
| 2701 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2702 | case DataType::Type::kFloat32: |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2703 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2704 | locations->SetOut(Location::SameAsFirstInput()); |
| 2705 | locations->AddTemp(Location::RequiresRegister()); |
| 2706 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2707 | break; |
| 2708 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2709 | case DataType::Type::kFloat64: |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2710 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2711 | locations->SetOut(Location::SameAsFirstInput()); |
| 2712 | locations->AddTemp(Location::RequiresFpuRegister()); |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2713 | break; |
| 2714 | |
| 2715 | default: |
| 2716 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2717 | } |
| 2718 | } |
| 2719 | |
| 2720 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 2721 | LocationSummary* locations = neg->GetLocations(); |
| 2722 | Location out = locations->Out(); |
| 2723 | Location in = locations->InAt(0); |
| 2724 | switch (neg->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2725 | case DataType::Type::kInt32: |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2726 | DCHECK(in.IsRegister()); |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2727 | DCHECK(in.Equals(out)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2728 | __ negl(out.AsRegister<Register>()); |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2729 | break; |
| 2730 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2731 | case DataType::Type::kInt64: |
| Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2732 | DCHECK(in.IsRegisterPair()); |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2733 | DCHECK(in.Equals(out)); |
| Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2734 | __ negl(out.AsRegisterPairLow<Register>()); |
| 2735 | // Negation is similar to subtraction from zero. The least |
| 2736 | // significant byte triggers a borrow when it is different from |
| 2737 | // zero; to take it into account, add 1 to the most significant |
| 2738 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 2739 | // operation. |
| 2740 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2741 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 2742 | break; |
| 2743 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2744 | case DataType::Type::kFloat32: { |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2745 | DCHECK(in.Equals(out)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2746 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 2747 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2748 | // Implement float negation with an exclusive or with value |
| 2749 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2750 | // single-precision floating-point number). |
| 2751 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 2752 | __ movd(mask, constant); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2753 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2754 | break; |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2755 | } |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2756 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2757 | case DataType::Type::kFloat64: { |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2758 | DCHECK(in.Equals(out)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2759 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2760 | // Implement double negation with an exclusive or with value |
| 2761 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 2762 | // a double-precision floating-point number). |
| 2763 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2764 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2765 | break; |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2766 | } |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2767 | |
| 2768 | default: |
| 2769 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2770 | } |
| 2771 | } |
| 2772 | |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2773 | void LocationsBuilderX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2774 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2775 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2776 | DCHECK(DataType::IsFloatingPointType(neg->GetType())); |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2777 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2778 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2779 | locations->SetOut(Location::SameAsFirstInput()); |
| 2780 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2781 | } |
| 2782 | |
| 2783 | void InstructionCodeGeneratorX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2784 | LocationSummary* locations = neg->GetLocations(); |
| 2785 | Location out = locations->Out(); |
| 2786 | DCHECK(locations->InAt(0).Equals(out)); |
| 2787 | |
| 2788 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 2789 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2790 | if (neg->GetType() == DataType::Type::kFloat32) { |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 2791 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x80000000), |
| 2792 | neg->GetBaseMethodAddress(), |
| 2793 | constant_area)); |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2794 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| 2795 | } else { |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 2796 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000), |
| 2797 | neg->GetBaseMethodAddress(), |
| 2798 | constant_area)); |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2799 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| 2800 | } |
| 2801 | } |
| 2802 | |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2803 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2804 | DataType::Type result_type = conversion->GetResultType(); |
| 2805 | DataType::Type input_type = conversion->GetInputType(); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2806 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 2807 | << input_type << " -> " << result_type; |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2808 | |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2809 | // The float-to-long and double-to-long type conversions rely on a |
| 2810 | // call to the runtime. |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2811 | LocationSummary::CallKind call_kind = |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2812 | ((input_type == DataType::Type::kFloat32 || input_type == DataType::Type::kFloat64) |
| 2813 | && result_type == DataType::Type::kInt64) |
| Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2814 | ? LocationSummary::kCallOnMainOnly |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2815 | : LocationSummary::kNoCall; |
| 2816 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2817 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, call_kind); |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2818 | |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2819 | switch (result_type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2820 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2821 | case DataType::Type::kInt8: |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2822 | switch (input_type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2823 | case DataType::Type::kUint8: |
| 2824 | case DataType::Type::kInt8: |
| 2825 | case DataType::Type::kUint16: |
| 2826 | case DataType::Type::kInt16: |
| 2827 | case DataType::Type::kInt32: |
| 2828 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 2829 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2830 | // the validation of the linear scan implementation |
| 2831 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2832 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2833 | case DataType::Type::kInt64: { |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2834 | HInstruction* input = conversion->InputAt(0); |
| 2835 | Location input_location = input->IsConstant() |
| 2836 | ? Location::ConstantLocation(input->AsConstant()) |
| 2837 | : Location::RegisterPairLocation(EAX, EDX); |
| 2838 | locations->SetInAt(0, input_location); |
| 2839 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2840 | // the validation of the linear scan implementation |
| 2841 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2842 | break; |
| 2843 | } |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2844 | |
| 2845 | default: |
| 2846 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2847 | << " to " << result_type; |
| 2848 | } |
| 2849 | break; |
| 2850 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2851 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2852 | case DataType::Type::kInt16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2853 | DCHECK(DataType::IsIntegralType(input_type)) << input_type; |
| 2854 | locations->SetInAt(0, Location::Any()); |
| 2855 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2856 | break; |
| 2857 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2858 | case DataType::Type::kInt32: |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2859 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2860 | case DataType::Type::kInt64: |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2861 | locations->SetInAt(0, Location::Any()); |
| 2862 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2863 | break; |
| 2864 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2865 | case DataType::Type::kFloat32: |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2866 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2867 | locations->SetOut(Location::RequiresRegister()); |
| 2868 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2869 | break; |
| 2870 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2871 | case DataType::Type::kFloat64: |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2872 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2873 | locations->SetOut(Location::RequiresRegister()); |
| 2874 | locations->AddTemp(Location::RequiresFpuRegister()); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2875 | break; |
| 2876 | |
| 2877 | default: |
| 2878 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2879 | << " to " << result_type; |
| 2880 | } |
| 2881 | break; |
| 2882 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2883 | case DataType::Type::kInt64: |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2884 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2885 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2886 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2887 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2888 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2889 | case DataType::Type::kInt16: |
| 2890 | case DataType::Type::kInt32: |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2891 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 2892 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2893 | break; |
| 2894 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2895 | case DataType::Type::kFloat32: |
| 2896 | case DataType::Type::kFloat64: { |
| Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2897 | InvokeRuntimeCallingConvention calling_convention; |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2898 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 2899 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 2900 | |
| Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2901 | // The runtime helper puts the result in EAX, EDX. |
| 2902 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2903 | } |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2904 | break; |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2905 | |
| 2906 | default: |
| 2907 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2908 | << " to " << result_type; |
| 2909 | } |
| 2910 | break; |
| 2911 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2912 | case DataType::Type::kFloat32: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2913 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2914 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2915 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2916 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2917 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2918 | case DataType::Type::kInt16: |
| 2919 | case DataType::Type::kInt32: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2920 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2921 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2922 | break; |
| 2923 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2924 | case DataType::Type::kInt64: |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2925 | locations->SetInAt(0, Location::Any()); |
| 2926 | locations->SetOut(Location::Any()); |
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2927 | break; |
| 2928 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2929 | case DataType::Type::kFloat64: |
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2930 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2931 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2932 | break; |
| 2933 | |
| 2934 | default: |
| 2935 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2936 | << " to " << result_type; |
| Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 2937 | } |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2938 | break; |
| 2939 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2940 | case DataType::Type::kFloat64: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2941 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2942 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2943 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2944 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2945 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2946 | case DataType::Type::kInt16: |
| 2947 | case DataType::Type::kInt32: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2948 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2949 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2950 | break; |
| 2951 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2952 | case DataType::Type::kInt64: |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2953 | locations->SetInAt(0, Location::Any()); |
| 2954 | locations->SetOut(Location::Any()); |
| Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2955 | break; |
| 2956 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2957 | case DataType::Type::kFloat32: |
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2958 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2959 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2960 | break; |
| 2961 | |
| 2962 | default: |
| 2963 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2964 | << " to " << result_type; |
| 2965 | } |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2966 | break; |
| 2967 | |
| 2968 | default: |
| 2969 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2970 | << " to " << result_type; |
| 2971 | } |
| 2972 | } |
| 2973 | |
| 2974 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 2975 | LocationSummary* locations = conversion->GetLocations(); |
| 2976 | Location out = locations->Out(); |
| 2977 | Location in = locations->InAt(0); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2978 | DataType::Type result_type = conversion->GetResultType(); |
| 2979 | DataType::Type input_type = conversion->GetInputType(); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2980 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 2981 | << input_type << " -> " << result_type; |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2982 | switch (result_type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2983 | case DataType::Type::kUint8: |
| 2984 | switch (input_type) { |
| 2985 | case DataType::Type::kInt8: |
| 2986 | case DataType::Type::kUint16: |
| 2987 | case DataType::Type::kInt16: |
| 2988 | case DataType::Type::kInt32: |
| 2989 | if (in.IsRegister()) { |
| 2990 | __ movzxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
| 2991 | } else { |
| 2992 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2993 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2994 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint8_t>(value))); |
| 2995 | } |
| 2996 | break; |
| 2997 | case DataType::Type::kInt64: |
| 2998 | if (in.IsRegisterPair()) { |
| 2999 | __ movzxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 3000 | } else { |
| 3001 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 3002 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3003 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint8_t>(value))); |
| 3004 | } |
| 3005 | break; |
| 3006 | |
| 3007 | default: |
| 3008 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3009 | << " to " << result_type; |
| 3010 | } |
| 3011 | break; |
| 3012 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3013 | case DataType::Type::kInt8: |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3014 | switch (input_type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3015 | case DataType::Type::kUint8: |
| 3016 | case DataType::Type::kUint16: |
| 3017 | case DataType::Type::kInt16: |
| 3018 | case DataType::Type::kInt32: |
| 3019 | if (in.IsRegister()) { |
| 3020 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
| 3021 | } else { |
| 3022 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 3023 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 3024 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 3025 | } |
| 3026 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3027 | case DataType::Type::kInt64: |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3028 | if (in.IsRegisterPair()) { |
| 3029 | __ movsxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 3030 | } else { |
| 3031 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 3032 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3033 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 3034 | } |
| 3035 | break; |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3036 | |
| 3037 | default: |
| 3038 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3039 | << " to " << result_type; |
| 3040 | } |
| 3041 | break; |
| 3042 | |
| 3043 | case DataType::Type::kUint16: |
| 3044 | switch (input_type) { |
| 3045 | case DataType::Type::kInt8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3046 | case DataType::Type::kInt16: |
| 3047 | case DataType::Type::kInt32: |
| Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 3048 | if (in.IsRegister()) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3049 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
| 3050 | } else if (in.IsStackSlot()) { |
| 3051 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 3052 | } else { |
| 3053 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 3054 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3055 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
| 3056 | } |
| 3057 | break; |
| 3058 | case DataType::Type::kInt64: |
| 3059 | if (in.IsRegisterPair()) { |
| 3060 | __ movzxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 3061 | } else if (in.IsDoubleStackSlot()) { |
| 3062 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 3063 | } else { |
| 3064 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 3065 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3066 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
| Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 3067 | } |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3068 | break; |
| 3069 | |
| 3070 | default: |
| 3071 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3072 | << " to " << result_type; |
| 3073 | } |
| 3074 | break; |
| 3075 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3076 | case DataType::Type::kInt16: |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3077 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3078 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3079 | case DataType::Type::kInt32: |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3080 | if (in.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3081 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3082 | } else if (in.IsStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3083 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3084 | } else { |
| 3085 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 3086 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3087 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3088 | } |
| 3089 | break; |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3090 | case DataType::Type::kInt64: |
| 3091 | if (in.IsRegisterPair()) { |
| 3092 | __ movsxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 3093 | } else if (in.IsDoubleStackSlot()) { |
| 3094 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 3095 | } else { |
| 3096 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 3097 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3098 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
| 3099 | } |
| 3100 | break; |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3101 | |
| 3102 | default: |
| 3103 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3104 | << " to " << result_type; |
| 3105 | } |
| 3106 | break; |
| 3107 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3108 | case DataType::Type::kInt32: |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3109 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3110 | case DataType::Type::kInt64: |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3111 | if (in.IsRegisterPair()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3112 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3113 | } else if (in.IsDoubleStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3114 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3115 | } else { |
| 3116 | DCHECK(in.IsConstant()); |
| 3117 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 3118 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3119 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3120 | } |
| 3121 | break; |
| 3122 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3123 | case DataType::Type::kFloat32: { |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 3124 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 3125 | Register output = out.AsRegister<Register>(); |
| 3126 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3127 | NearLabel done, nan; |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 3128 | |
| 3129 | __ movl(output, Immediate(kPrimIntMax)); |
| 3130 | // temp = int-to-float(output) |
| 3131 | __ cvtsi2ss(temp, output); |
| 3132 | // if input >= temp goto done |
| 3133 | __ comiss(input, temp); |
| 3134 | __ j(kAboveEqual, &done); |
| 3135 | // if input == NaN goto nan |
| 3136 | __ j(kUnordered, &nan); |
| 3137 | // output = float-to-int-truncate(input) |
| 3138 | __ cvttss2si(output, input); |
| 3139 | __ jmp(&done); |
| 3140 | __ Bind(&nan); |
| 3141 | // output = 0 |
| 3142 | __ xorl(output, output); |
| 3143 | __ Bind(&done); |
| 3144 | break; |
| 3145 | } |
| 3146 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3147 | case DataType::Type::kFloat64: { |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3148 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 3149 | Register output = out.AsRegister<Register>(); |
| 3150 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3151 | NearLabel done, nan; |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3152 | |
| 3153 | __ movl(output, Immediate(kPrimIntMax)); |
| 3154 | // temp = int-to-double(output) |
| 3155 | __ cvtsi2sd(temp, output); |
| 3156 | // if input >= temp goto done |
| 3157 | __ comisd(input, temp); |
| 3158 | __ j(kAboveEqual, &done); |
| 3159 | // if input == NaN goto nan |
| 3160 | __ j(kUnordered, &nan); |
| 3161 | // output = double-to-int-truncate(input) |
| 3162 | __ cvttsd2si(output, input); |
| 3163 | __ jmp(&done); |
| 3164 | __ Bind(&nan); |
| 3165 | // output = 0 |
| 3166 | __ xorl(output, output); |
| 3167 | __ Bind(&done); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3168 | break; |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3169 | } |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3170 | |
| 3171 | default: |
| 3172 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3173 | << " to " << result_type; |
| 3174 | } |
| 3175 | break; |
| 3176 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3177 | case DataType::Type::kInt64: |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3178 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3179 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3180 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3181 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3182 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3183 | case DataType::Type::kInt16: |
| 3184 | case DataType::Type::kInt32: |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3185 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 3186 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3187 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3188 | __ cdq(); |
| 3189 | break; |
| 3190 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3191 | case DataType::Type::kFloat32: |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3192 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3193 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3194 | break; |
| 3195 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3196 | case DataType::Type::kFloat64: |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3197 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3198 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3199 | break; |
| 3200 | |
| 3201 | default: |
| 3202 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3203 | << " to " << result_type; |
| 3204 | } |
| 3205 | break; |
| 3206 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3207 | case DataType::Type::kFloat32: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3208 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3209 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3210 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3211 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3212 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3213 | case DataType::Type::kInt16: |
| 3214 | case DataType::Type::kInt32: |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3215 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3216 | break; |
| 3217 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3218 | case DataType::Type::kInt64: { |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3219 | size_t adjustment = 0; |
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3220 | |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3221 | // Create stack space for the call to |
| 3222 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 3223 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3224 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3225 | adjustment = DataType::Size(DataType::Type::kInt64); |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 3226 | codegen_->IncreaseFrame(adjustment); |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3227 | } |
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3228 | |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3229 | // Load the value to the FP stack, using temporaries if needed. |
| 3230 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 3231 | |
| 3232 | if (out.IsStackSlot()) { |
| 3233 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 3234 | } else { |
| 3235 | __ fstps(Address(ESP, 0)); |
| 3236 | Location stack_temp = Location::StackSlot(0); |
| 3237 | codegen_->Move32(out, stack_temp); |
| 3238 | } |
| 3239 | |
| 3240 | // Remove the temporary stack space we allocated. |
| 3241 | if (adjustment != 0) { |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 3242 | codegen_->DecreaseFrame(adjustment); |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3243 | } |
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3244 | break; |
| 3245 | } |
| 3246 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3247 | case DataType::Type::kFloat64: |
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3248 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3249 | break; |
| 3250 | |
| 3251 | default: |
| 3252 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3253 | << " to " << result_type; |
| Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3254 | } |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3255 | break; |
| 3256 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3257 | case DataType::Type::kFloat64: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3258 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3259 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3260 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3261 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3262 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3263 | case DataType::Type::kInt16: |
| 3264 | case DataType::Type::kInt32: |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3265 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3266 | break; |
| 3267 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3268 | case DataType::Type::kInt64: { |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3269 | size_t adjustment = 0; |
| Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3270 | |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3271 | // Create stack space for the call to |
| 3272 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 3273 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3274 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3275 | adjustment = DataType::Size(DataType::Type::kInt64); |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 3276 | codegen_->IncreaseFrame(adjustment); |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3277 | } |
| 3278 | |
| 3279 | // Load the value to the FP stack, using temporaries if needed. |
| 3280 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 3281 | |
| 3282 | if (out.IsDoubleStackSlot()) { |
| 3283 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 3284 | } else { |
| 3285 | __ fstpl(Address(ESP, 0)); |
| 3286 | Location stack_temp = Location::DoubleStackSlot(0); |
| 3287 | codegen_->Move64(out, stack_temp); |
| 3288 | } |
| 3289 | |
| 3290 | // Remove the temporary stack space we allocated. |
| 3291 | if (adjustment != 0) { |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 3292 | codegen_->DecreaseFrame(adjustment); |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3293 | } |
| Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3294 | break; |
| 3295 | } |
| 3296 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3297 | case DataType::Type::kFloat32: |
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3298 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3299 | break; |
| 3300 | |
| 3301 | default: |
| 3302 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3303 | << " to " << result_type; |
| Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3304 | } |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3305 | break; |
| 3306 | |
| 3307 | default: |
| 3308 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3309 | << " to " << result_type; |
| 3310 | } |
| 3311 | } |
| 3312 | |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3313 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3314 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3315 | new (GetGraph()->GetAllocator()) LocationSummary(add, LocationSummary::kNoCall); |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3316 | switch (add->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3317 | case DataType::Type::kInt32: { |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3318 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3319 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 3320 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3321 | break; |
| 3322 | } |
| 3323 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3324 | case DataType::Type::kInt64: { |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3325 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3326 | locations->SetInAt(1, Location::Any()); |
| 3327 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3328 | break; |
| 3329 | } |
| 3330 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3331 | case DataType::Type::kFloat32: |
| 3332 | case DataType::Type::kFloat64: { |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3333 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3334 | if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3335 | DCHECK(add->InputAt(1)->IsEmittedAtUseSite()); |
| Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3336 | } else if (add->InputAt(1)->IsConstant()) { |
| 3337 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3338 | } else { |
| 3339 | locations->SetInAt(1, Location::Any()); |
| 3340 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3341 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3342 | break; |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3343 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3344 | |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3345 | default: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3346 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 3347 | UNREACHABLE(); |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3348 | } |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3349 | } |
| 3350 | |
| 3351 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 3352 | LocationSummary* locations = add->GetLocations(); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3353 | Location first = locations->InAt(0); |
| 3354 | Location second = locations->InAt(1); |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3355 | Location out = locations->Out(); |
| 3356 | |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3357 | switch (add->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3358 | case DataType::Type::kInt32: { |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3359 | if (second.IsRegister()) { |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3360 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3361 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
| Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 3362 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 3363 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3364 | } else { |
| 3365 | __ leal(out.AsRegister<Register>(), Address( |
| 3366 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 3367 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3368 | } else if (second.IsConstant()) { |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3369 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3370 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3371 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 3372 | } else { |
| 3373 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 3374 | } |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3375 | } else { |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3376 | DCHECK(first.Equals(locations->Out())); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3377 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3378 | } |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3379 | break; |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3380 | } |
| 3381 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3382 | case DataType::Type::kInt64: { |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3383 | if (second.IsRegisterPair()) { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3384 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3385 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3386 | } else if (second.IsDoubleStackSlot()) { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3387 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 3388 | __ adcl(first.AsRegisterPairHigh<Register>(), |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3389 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3390 | } else { |
| 3391 | DCHECK(second.IsConstant()) << second; |
| 3392 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3393 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 3394 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3395 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3396 | break; |
| 3397 | } |
| 3398 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3399 | case DataType::Type::kFloat32: { |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3400 | if (second.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3401 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3402 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3403 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3404 | DCHECK(const_area->IsEmittedAtUseSite()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3405 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 3406 | codegen_->LiteralFloatAddress( |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3407 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3408 | const_area->GetBaseMethodAddress(), |
| 3409 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3410 | } else { |
| 3411 | DCHECK(second.IsStackSlot()); |
| 3412 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3413 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3414 | break; |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3415 | } |
| 3416 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3417 | case DataType::Type::kFloat64: { |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3418 | if (second.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3419 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3420 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3421 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3422 | DCHECK(const_area->IsEmittedAtUseSite()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3423 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 3424 | codegen_->LiteralDoubleAddress( |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3425 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3426 | const_area->GetBaseMethodAddress(), |
| 3427 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3428 | } else { |
| 3429 | DCHECK(second.IsDoubleStackSlot()); |
| 3430 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3431 | } |
| 3432 | break; |
| 3433 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3434 | |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3435 | default: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3436 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3437 | } |
| 3438 | } |
| 3439 | |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3440 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3441 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3442 | new (GetGraph()->GetAllocator()) LocationSummary(sub, LocationSummary::kNoCall); |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3443 | switch (sub->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3444 | case DataType::Type::kInt32: |
| 3445 | case DataType::Type::kInt64: { |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3446 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3447 | locations->SetInAt(1, Location::Any()); |
| 3448 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3449 | break; |
| 3450 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3451 | case DataType::Type::kFloat32: |
| 3452 | case DataType::Type::kFloat64: { |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3453 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3454 | if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3455 | DCHECK(sub->InputAt(1)->IsEmittedAtUseSite()); |
| Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3456 | } else if (sub->InputAt(1)->IsConstant()) { |
| 3457 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3458 | } else { |
| 3459 | locations->SetInAt(1, Location::Any()); |
| 3460 | } |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3461 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3462 | break; |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3463 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3464 | |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3465 | default: |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3466 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3467 | } |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3468 | } |
| 3469 | |
| 3470 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 3471 | LocationSummary* locations = sub->GetLocations(); |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3472 | Location first = locations->InAt(0); |
| 3473 | Location second = locations->InAt(1); |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3474 | DCHECK(first.Equals(locations->Out())); |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3475 | switch (sub->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3476 | case DataType::Type::kInt32: { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3477 | if (second.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3478 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3479 | } else if (second.IsConstant()) { |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3480 | __ subl(first.AsRegister<Register>(), |
| 3481 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3482 | } else { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3483 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3484 | } |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3485 | break; |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3486 | } |
| 3487 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3488 | case DataType::Type::kInt64: { |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3489 | if (second.IsRegisterPair()) { |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3490 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3491 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3492 | } else if (second.IsDoubleStackSlot()) { |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3493 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3494 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 3495 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3496 | } else { |
| 3497 | DCHECK(second.IsConstant()) << second; |
| 3498 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3499 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 3500 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3501 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3502 | break; |
| 3503 | } |
| 3504 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3505 | case DataType::Type::kFloat32: { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3506 | if (second.IsFpuRegister()) { |
| 3507 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3508 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3509 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3510 | DCHECK(const_area->IsEmittedAtUseSite()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3511 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3512 | codegen_->LiteralFloatAddress( |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3513 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3514 | const_area->GetBaseMethodAddress(), |
| 3515 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3516 | } else { |
| 3517 | DCHECK(second.IsStackSlot()); |
| 3518 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3519 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3520 | break; |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3521 | } |
| 3522 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3523 | case DataType::Type::kFloat64: { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3524 | if (second.IsFpuRegister()) { |
| 3525 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3526 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3527 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3528 | DCHECK(const_area->IsEmittedAtUseSite()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3529 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3530 | codegen_->LiteralDoubleAddress( |
| 3531 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3532 | const_area->GetBaseMethodAddress(), |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3533 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3534 | } else { |
| 3535 | DCHECK(second.IsDoubleStackSlot()); |
| 3536 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3537 | } |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3538 | break; |
| 3539 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3540 | |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3541 | default: |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3542 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3543 | } |
| 3544 | } |
| 3545 | |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3546 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 3547 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3548 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3549 | switch (mul->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3550 | case DataType::Type::kInt32: |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3551 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3552 | locations->SetInAt(1, Location::Any()); |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3553 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3554 | // Can use 3 operand multiply. |
| 3555 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3556 | } else { |
| 3557 | locations->SetOut(Location::SameAsFirstInput()); |
| 3558 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3559 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3560 | case DataType::Type::kInt64: { |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3561 | locations->SetInAt(0, Location::RequiresRegister()); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3562 | locations->SetInAt(1, Location::Any()); |
| 3563 | locations->SetOut(Location::SameAsFirstInput()); |
| 3564 | // Needed for imul on 32bits with 64bits output. |
| 3565 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 3566 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 3567 | break; |
| 3568 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3569 | case DataType::Type::kFloat32: |
| 3570 | case DataType::Type::kFloat64: { |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3571 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3572 | if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3573 | DCHECK(mul->InputAt(1)->IsEmittedAtUseSite()); |
| Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3574 | } else if (mul->InputAt(1)->IsConstant()) { |
| 3575 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3576 | } else { |
| 3577 | locations->SetInAt(1, Location::Any()); |
| 3578 | } |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3579 | locations->SetOut(Location::SameAsFirstInput()); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3580 | break; |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3581 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3582 | |
| 3583 | default: |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3584 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3585 | } |
| 3586 | } |
| 3587 | |
| 3588 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 3589 | LocationSummary* locations = mul->GetLocations(); |
| 3590 | Location first = locations->InAt(0); |
| 3591 | Location second = locations->InAt(1); |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3592 | Location out = locations->Out(); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3593 | |
| 3594 | switch (mul->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3595 | case DataType::Type::kInt32: |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3596 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3597 | // problems where the output may not be the same as the first operand. |
| 3598 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3599 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3600 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 3601 | } else if (second.IsRegister()) { |
| 3602 | DCHECK(first.Equals(out)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3603 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3604 | } else { |
| 3605 | DCHECK(second.IsStackSlot()); |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3606 | DCHECK(first.Equals(out)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3607 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3608 | } |
| 3609 | break; |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3610 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3611 | case DataType::Type::kInt64: { |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3612 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 3613 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3614 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 3615 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3616 | |
| 3617 | DCHECK_EQ(EAX, eax); |
| 3618 | DCHECK_EQ(EDX, edx); |
| 3619 | |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3620 | // input: in1 - 64 bits, in2 - 64 bits. |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3621 | // output: in1 |
| 3622 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3623 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3624 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3625 | if (second.IsConstant()) { |
| 3626 | DCHECK(second.GetConstant()->IsLongConstant()); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3627 | |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3628 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3629 | int32_t low_value = Low32Bits(value); |
| 3630 | int32_t high_value = High32Bits(value); |
| 3631 | Immediate low(low_value); |
| 3632 | Immediate high(high_value); |
| 3633 | |
| 3634 | __ movl(eax, high); |
| 3635 | // eax <- in1.lo * in2.hi |
| 3636 | __ imull(eax, in1_lo); |
| 3637 | // in1.hi <- in1.hi * in2.lo |
| 3638 | __ imull(in1_hi, low); |
| 3639 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3640 | __ addl(in1_hi, eax); |
| 3641 | // move in2_lo to eax to prepare for double precision |
| 3642 | __ movl(eax, low); |
| 3643 | // edx:eax <- in1.lo * in2.lo |
| 3644 | __ mull(in1_lo); |
| 3645 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3646 | __ addl(in1_hi, edx); |
| 3647 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3648 | __ movl(in1_lo, eax); |
| 3649 | } else if (second.IsRegisterPair()) { |
| 3650 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3651 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3652 | |
| 3653 | __ movl(eax, in2_hi); |
| 3654 | // eax <- in1.lo * in2.hi |
| 3655 | __ imull(eax, in1_lo); |
| 3656 | // in1.hi <- in1.hi * in2.lo |
| 3657 | __ imull(in1_hi, in2_lo); |
| 3658 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3659 | __ addl(in1_hi, eax); |
| 3660 | // move in1_lo to eax to prepare for double precision |
| 3661 | __ movl(eax, in1_lo); |
| 3662 | // edx:eax <- in1.lo * in2.lo |
| 3663 | __ mull(in2_lo); |
| 3664 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3665 | __ addl(in1_hi, edx); |
| 3666 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3667 | __ movl(in1_lo, eax); |
| 3668 | } else { |
| 3669 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 3670 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 3671 | Address in2_lo(ESP, second.GetStackIndex()); |
| 3672 | |
| 3673 | __ movl(eax, in2_hi); |
| 3674 | // eax <- in1.lo * in2.hi |
| 3675 | __ imull(eax, in1_lo); |
| 3676 | // in1.hi <- in1.hi * in2.lo |
| 3677 | __ imull(in1_hi, in2_lo); |
| 3678 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3679 | __ addl(in1_hi, eax); |
| 3680 | // move in1_lo to eax to prepare for double precision |
| 3681 | __ movl(eax, in1_lo); |
| 3682 | // edx:eax <- in1.lo * in2.lo |
| 3683 | __ mull(in2_lo); |
| 3684 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3685 | __ addl(in1_hi, edx); |
| 3686 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3687 | __ movl(in1_lo, eax); |
| 3688 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3689 | |
| 3690 | break; |
| 3691 | } |
| 3692 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3693 | case DataType::Type::kFloat32: { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3694 | DCHECK(first.Equals(locations->Out())); |
| 3695 | if (second.IsFpuRegister()) { |
| 3696 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3697 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3698 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3699 | DCHECK(const_area->IsEmittedAtUseSite()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3700 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3701 | codegen_->LiteralFloatAddress( |
| 3702 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3703 | const_area->GetBaseMethodAddress(), |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3704 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3705 | } else { |
| 3706 | DCHECK(second.IsStackSlot()); |
| 3707 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3708 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3709 | break; |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3710 | } |
| 3711 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3712 | case DataType::Type::kFloat64: { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3713 | DCHECK(first.Equals(locations->Out())); |
| 3714 | if (second.IsFpuRegister()) { |
| 3715 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3716 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3717 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3718 | DCHECK(const_area->IsEmittedAtUseSite()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3719 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3720 | codegen_->LiteralDoubleAddress( |
| 3721 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3722 | const_area->GetBaseMethodAddress(), |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3723 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3724 | } else { |
| 3725 | DCHECK(second.IsDoubleStackSlot()); |
| 3726 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3727 | } |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3728 | break; |
| 3729 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3730 | |
| 3731 | default: |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3732 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3733 | } |
| 3734 | } |
| 3735 | |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3736 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 3737 | uint32_t temp_offset, |
| 3738 | uint32_t stack_adjustment, |
| 3739 | bool is_fp, |
| 3740 | bool is_wide) { |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3741 | if (source.IsStackSlot()) { |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3742 | DCHECK(!is_wide); |
| 3743 | if (is_fp) { |
| 3744 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3745 | } else { |
| 3746 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3747 | } |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3748 | } else if (source.IsDoubleStackSlot()) { |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3749 | DCHECK(is_wide); |
| 3750 | if (is_fp) { |
| 3751 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3752 | } else { |
| 3753 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3754 | } |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3755 | } else { |
| 3756 | // 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] | 3757 | if (!is_wide) { |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3758 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3759 | codegen_->Move32(stack_temp, source); |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3760 | if (is_fp) { |
| 3761 | __ flds(Address(ESP, temp_offset)); |
| 3762 | } else { |
| 3763 | __ filds(Address(ESP, temp_offset)); |
| 3764 | } |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3765 | } else { |
| 3766 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3767 | codegen_->Move64(stack_temp, source); |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3768 | if (is_fp) { |
| 3769 | __ fldl(Address(ESP, temp_offset)); |
| 3770 | } else { |
| 3771 | __ fildl(Address(ESP, temp_offset)); |
| 3772 | } |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3773 | } |
| 3774 | } |
| 3775 | } |
| 3776 | |
| 3777 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3778 | DataType::Type type = rem->GetResultType(); |
| 3779 | bool is_float = type == DataType::Type::kFloat32; |
| 3780 | size_t elem_size = DataType::Size(type); |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3781 | LocationSummary* locations = rem->GetLocations(); |
| 3782 | Location first = locations->InAt(0); |
| 3783 | Location second = locations->InAt(1); |
| 3784 | Location out = locations->Out(); |
| 3785 | |
| 3786 | // Create stack space for 2 elements. |
| 3787 | // TODO: enhance register allocator to ask for stack temporaries. |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 3788 | codegen_->IncreaseFrame(2 * elem_size); |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3789 | |
| 3790 | // 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] | 3791 | const bool is_wide = !is_float; |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3792 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp= */ true, is_wide); |
| 3793 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp= */ true, is_wide); |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3794 | |
| 3795 | // Loop doing FPREM until we stabilize. |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3796 | NearLabel retry; |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3797 | __ Bind(&retry); |
| 3798 | __ fprem(); |
| 3799 | |
| 3800 | // Move FP status to AX. |
| 3801 | __ fstsw(); |
| 3802 | |
| 3803 | // And see if the argument reduction is complete. This is signaled by the |
| 3804 | // C2 FPU flag bit set to 0. |
| 3805 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 3806 | __ j(kNotEqual, &retry); |
| 3807 | |
| 3808 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3809 | // Store FP top of stack to real stack. |
| 3810 | if (is_float) { |
| 3811 | __ fsts(Address(ESP, 0)); |
| 3812 | } else { |
| 3813 | __ fstl(Address(ESP, 0)); |
| 3814 | } |
| 3815 | |
| 3816 | // Pop the 2 items from the FP stack. |
| 3817 | __ fucompp(); |
| 3818 | |
| 3819 | // Load the value from the stack into an XMM register. |
| 3820 | DCHECK(out.IsFpuRegister()) << out; |
| 3821 | if (is_float) { |
| 3822 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3823 | } else { |
| 3824 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3825 | } |
| 3826 | |
| 3827 | // And remove the temporary stack space we allocated. |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 3828 | codegen_->DecreaseFrame(2 * elem_size); |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3829 | } |
| 3830 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3831 | |
| 3832 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3833 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3834 | |
| 3835 | LocationSummary* locations = instruction->GetLocations(); |
| 3836 | DCHECK(locations->InAt(1).IsConstant()); |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3837 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3838 | |
| 3839 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3840 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3841 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3842 | |
| 3843 | DCHECK(imm == 1 || imm == -1); |
| 3844 | |
| 3845 | if (instruction->IsRem()) { |
| 3846 | __ xorl(out_register, out_register); |
| 3847 | } else { |
| 3848 | __ movl(out_register, input_register); |
| 3849 | if (imm == -1) { |
| 3850 | __ negl(out_register); |
| 3851 | } |
| 3852 | } |
| 3853 | } |
| 3854 | |
| Shalini Salomi Bodapati | a66784b | 2018-11-06 13:05:44 +0530 | [diff] [blame] | 3855 | void InstructionCodeGeneratorX86::RemByPowerOfTwo(HRem* instruction) { |
| 3856 | LocationSummary* locations = instruction->GetLocations(); |
| 3857 | Location second = locations->InAt(1); |
| 3858 | |
| 3859 | Register out = locations->Out().AsRegister<Register>(); |
| 3860 | Register numerator = locations->InAt(0).AsRegister<Register>(); |
| 3861 | |
| 3862 | int32_t imm = Int64FromConstant(second.GetConstant()); |
| 3863 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3864 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
| 3865 | |
| 3866 | Register tmp = locations->GetTemp(0).AsRegister<Register>(); |
| 3867 | NearLabel done; |
| 3868 | __ movl(out, numerator); |
| 3869 | __ andl(out, Immediate(abs_imm-1)); |
| 3870 | __ j(Condition::kZero, &done); |
| 3871 | __ leal(tmp, Address(out, static_cast<int32_t>(~(abs_imm-1)))); |
| 3872 | __ testl(numerator, numerator); |
| 3873 | __ cmovl(Condition::kLess, out, tmp); |
| 3874 | __ Bind(&done); |
| 3875 | } |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3876 | |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3877 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3878 | LocationSummary* locations = instruction->GetLocations(); |
| 3879 | |
| 3880 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3881 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3882 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3883 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3884 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3885 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3886 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 3887 | |
| Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3888 | __ leal(num, Address(input_register, abs_imm - 1)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3889 | __ testl(input_register, input_register); |
| 3890 | __ cmovl(kGreaterEqual, num, input_register); |
| 3891 | int shift = CTZ(imm); |
| 3892 | __ sarl(num, Immediate(shift)); |
| 3893 | |
| 3894 | if (imm < 0) { |
| 3895 | __ negl(num); |
| 3896 | } |
| 3897 | |
| 3898 | __ movl(out_register, num); |
| 3899 | } |
| 3900 | |
| 3901 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3902 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3903 | |
| 3904 | LocationSummary* locations = instruction->GetLocations(); |
| 3905 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 3906 | |
| 3907 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 3908 | Register out = locations->Out().AsRegister<Register>(); |
| 3909 | Register num; |
| 3910 | Register edx; |
| 3911 | |
| 3912 | if (instruction->IsDiv()) { |
| 3913 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 3914 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 3915 | } else { |
| 3916 | edx = locations->Out().AsRegister<Register>(); |
| 3917 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 3918 | } |
| 3919 | |
| 3920 | DCHECK_EQ(EAX, eax); |
| 3921 | DCHECK_EQ(EDX, edx); |
| 3922 | if (instruction->IsDiv()) { |
| 3923 | DCHECK_EQ(EAX, out); |
| 3924 | } else { |
| 3925 | DCHECK_EQ(EDX, out); |
| 3926 | } |
| 3927 | |
| 3928 | int64_t magic; |
| 3929 | int shift; |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3930 | CalculateMagicAndShiftForDivRem(imm, /* is_long= */ false, &magic, &shift); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3931 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3932 | // Save the numerator. |
| 3933 | __ movl(num, eax); |
| 3934 | |
| 3935 | // EAX = magic |
| 3936 | __ movl(eax, Immediate(magic)); |
| 3937 | |
| 3938 | // EDX:EAX = magic * numerator |
| 3939 | __ imull(num); |
| 3940 | |
| 3941 | if (imm > 0 && magic < 0) { |
| 3942 | // EDX += num |
| 3943 | __ addl(edx, num); |
| 3944 | } else if (imm < 0 && magic > 0) { |
| 3945 | __ subl(edx, num); |
| 3946 | } |
| 3947 | |
| 3948 | // Shift if needed. |
| 3949 | if (shift != 0) { |
| 3950 | __ sarl(edx, Immediate(shift)); |
| 3951 | } |
| 3952 | |
| 3953 | // EDX += 1 if EDX < 0 |
| 3954 | __ movl(eax, edx); |
| 3955 | __ shrl(edx, Immediate(31)); |
| 3956 | __ addl(edx, eax); |
| 3957 | |
| 3958 | if (instruction->IsRem()) { |
| 3959 | __ movl(eax, num); |
| 3960 | __ imull(edx, Immediate(imm)); |
| 3961 | __ subl(eax, edx); |
| 3962 | __ movl(edx, eax); |
| 3963 | } else { |
| 3964 | __ movl(eax, edx); |
| 3965 | } |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3966 | } |
| 3967 | |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3968 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3969 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3970 | |
| 3971 | LocationSummary* locations = instruction->GetLocations(); |
| 3972 | Location out = locations->Out(); |
| 3973 | Location first = locations->InAt(0); |
| 3974 | Location second = locations->InAt(1); |
| 3975 | bool is_div = instruction->IsDiv(); |
| 3976 | |
| 3977 | switch (instruction->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3978 | case DataType::Type::kInt32: { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3979 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 3980 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3981 | |
| Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3982 | if (second.IsConstant()) { |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3983 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3984 | |
| 3985 | if (imm == 0) { |
| 3986 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 3987 | } else if (imm == 1 || imm == -1) { |
| 3988 | DivRemOneOrMinusOne(instruction); |
| Shalini Salomi Bodapati | a66784b | 2018-11-06 13:05:44 +0530 | [diff] [blame] | 3989 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 3990 | if (is_div) { |
| 3991 | DivByPowerOfTwo(instruction->AsDiv()); |
| 3992 | } else { |
| 3993 | RemByPowerOfTwo(instruction->AsRem()); |
| 3994 | } |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3995 | } else { |
| 3996 | DCHECK(imm <= -2 || imm >= 2); |
| 3997 | GenerateDivRemWithAnyConstant(instruction); |
| 3998 | } |
| 3999 | } else { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4000 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) DivRemMinusOneSlowPathX86( |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 4001 | instruction, out.AsRegister<Register>(), is_div); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4002 | codegen_->AddSlowPath(slow_path); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4003 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4004 | Register second_reg = second.AsRegister<Register>(); |
| 4005 | // 0x80000000/-1 triggers an arithmetic exception! |
| 4006 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 4007 | // it's safe to just use negl instead of more complex comparisons. |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4008 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4009 | __ cmpl(second_reg, Immediate(-1)); |
| 4010 | __ j(kEqual, slow_path->GetEntryLabel()); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4011 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4012 | // edx:eax <- sign-extended of eax |
| 4013 | __ cdq(); |
| 4014 | // eax = quotient, edx = remainder |
| 4015 | __ idivl(second_reg); |
| 4016 | __ Bind(slow_path->GetExitLabel()); |
| 4017 | } |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4018 | break; |
| 4019 | } |
| 4020 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4021 | case DataType::Type::kInt64: { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4022 | InvokeRuntimeCallingConvention calling_convention; |
| 4023 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 4024 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 4025 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 4026 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 4027 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 4028 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 4029 | |
| 4030 | if (is_div) { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 4031 | codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4032 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4033 | } else { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 4034 | codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4035 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4036 | } |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4037 | break; |
| 4038 | } |
| 4039 | |
| 4040 | default: |
| 4041 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 4042 | } |
| 4043 | } |
| 4044 | |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4045 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4046 | LocationSummary::CallKind call_kind = (div->GetResultType() == DataType::Type::kInt64) |
| Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4047 | ? LocationSummary::kCallOnMainOnly |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4048 | : LocationSummary::kNoCall; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4049 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(div, call_kind); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4050 | |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4051 | switch (div->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4052 | case DataType::Type::kInt32: { |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4053 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4054 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4055 | locations->SetOut(Location::SameAsFirstInput()); |
| 4056 | // Intel uses edx:eax as the dividend. |
| 4057 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4058 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 4059 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 4060 | // output and request another temp. |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 4061 | if (div->InputAt(1)->IsIntConstant()) { |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4062 | locations->AddTemp(Location::RequiresRegister()); |
| 4063 | } |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4064 | break; |
| 4065 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4066 | case DataType::Type::kInt64: { |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4067 | InvokeRuntimeCallingConvention calling_convention; |
| 4068 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 4069 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4070 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 4071 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4072 | // Runtime helper puts the result in EAX, EDX. |
| 4073 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4074 | break; |
| 4075 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4076 | case DataType::Type::kFloat32: |
| 4077 | case DataType::Type::kFloat64: { |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4078 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 4079 | if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4080 | DCHECK(div->InputAt(1)->IsEmittedAtUseSite()); |
| Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 4081 | } else if (div->InputAt(1)->IsConstant()) { |
| 4082 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 4083 | } else { |
| 4084 | locations->SetInAt(1, Location::Any()); |
| 4085 | } |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4086 | locations->SetOut(Location::SameAsFirstInput()); |
| 4087 | break; |
| 4088 | } |
| 4089 | |
| 4090 | default: |
| 4091 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4092 | } |
| 4093 | } |
| 4094 | |
| 4095 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 4096 | LocationSummary* locations = div->GetLocations(); |
| 4097 | Location first = locations->InAt(0); |
| 4098 | Location second = locations->InAt(1); |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4099 | |
| 4100 | switch (div->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4101 | case DataType::Type::kInt32: |
| 4102 | case DataType::Type::kInt64: { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4103 | GenerateDivRemIntegral(div); |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4104 | break; |
| 4105 | } |
| 4106 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4107 | case DataType::Type::kFloat32: { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 4108 | if (second.IsFpuRegister()) { |
| 4109 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 4110 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4111 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 4112 | DCHECK(const_area->IsEmittedAtUseSite()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 4113 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 4114 | codegen_->LiteralFloatAddress( |
| 4115 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4116 | const_area->GetBaseMethodAddress(), |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 4117 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 4118 | } else { |
| 4119 | DCHECK(second.IsStackSlot()); |
| 4120 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 4121 | } |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4122 | break; |
| 4123 | } |
| 4124 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4125 | case DataType::Type::kFloat64: { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 4126 | if (second.IsFpuRegister()) { |
| 4127 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 4128 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4129 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 4130 | DCHECK(const_area->IsEmittedAtUseSite()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 4131 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 4132 | codegen_->LiteralDoubleAddress( |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4133 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 4134 | const_area->GetBaseMethodAddress(), |
| 4135 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 4136 | } else { |
| 4137 | DCHECK(second.IsDoubleStackSlot()); |
| 4138 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 4139 | } |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4140 | break; |
| 4141 | } |
| 4142 | |
| 4143 | default: |
| 4144 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4145 | } |
| 4146 | } |
| 4147 | |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4148 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4149 | DataType::Type type = rem->GetResultType(); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4150 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4151 | LocationSummary::CallKind call_kind = (rem->GetResultType() == DataType::Type::kInt64) |
| Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4152 | ? LocationSummary::kCallOnMainOnly |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4153 | : LocationSummary::kNoCall; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4154 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4155 | |
| Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4156 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4157 | case DataType::Type::kInt32: { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4158 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4159 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4160 | locations->SetOut(Location::RegisterLocation(EDX)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4161 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 4162 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 4163 | // output and request another temp. |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 4164 | if (rem->InputAt(1)->IsIntConstant()) { |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4165 | locations->AddTemp(Location::RequiresRegister()); |
| 4166 | } |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4167 | break; |
| 4168 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4169 | case DataType::Type::kInt64: { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4170 | InvokeRuntimeCallingConvention calling_convention; |
| 4171 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 4172 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4173 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 4174 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4175 | // Runtime helper puts the result in EAX, EDX. |
| 4176 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 4177 | break; |
| 4178 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4179 | case DataType::Type::kFloat64: |
| 4180 | case DataType::Type::kFloat32: { |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 4181 | locations->SetInAt(0, Location::Any()); |
| 4182 | locations->SetInAt(1, Location::Any()); |
| 4183 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4184 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4185 | break; |
| 4186 | } |
| 4187 | |
| 4188 | default: |
| Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4189 | LOG(FATAL) << "Unexpected rem type " << type; |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4190 | } |
| 4191 | } |
| 4192 | |
| 4193 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4194 | DataType::Type type = rem->GetResultType(); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4195 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4196 | case DataType::Type::kInt32: |
| 4197 | case DataType::Type::kInt64: { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4198 | GenerateDivRemIntegral(rem); |
| 4199 | break; |
| 4200 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4201 | case DataType::Type::kFloat32: |
| 4202 | case DataType::Type::kFloat64: { |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 4203 | GenerateRemFP(rem); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4204 | break; |
| 4205 | } |
| 4206 | default: |
| 4207 | LOG(FATAL) << "Unexpected rem type " << type; |
| 4208 | } |
| 4209 | } |
| 4210 | |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4211 | static void CreateMinMaxLocations(ArenaAllocator* allocator, HBinaryOperation* minmax) { |
| 4212 | LocationSummary* locations = new (allocator) LocationSummary(minmax); |
| 4213 | switch (minmax->GetResultType()) { |
| 4214 | case DataType::Type::kInt32: |
| 4215 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4216 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4217 | locations->SetOut(Location::SameAsFirstInput()); |
| 4218 | break; |
| 4219 | case DataType::Type::kInt64: |
| 4220 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4221 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4222 | locations->SetOut(Location::SameAsFirstInput()); |
| 4223 | // Register to use to perform a long subtract to set cc. |
| 4224 | locations->AddTemp(Location::RequiresRegister()); |
| 4225 | break; |
| 4226 | case DataType::Type::kFloat32: |
| 4227 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4228 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4229 | locations->SetOut(Location::SameAsFirstInput()); |
| 4230 | locations->AddTemp(Location::RequiresRegister()); |
| 4231 | break; |
| 4232 | case DataType::Type::kFloat64: |
| 4233 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4234 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4235 | locations->SetOut(Location::SameAsFirstInput()); |
| 4236 | break; |
| 4237 | default: |
| 4238 | LOG(FATAL) << "Unexpected type for HMinMax " << minmax->GetResultType(); |
| 4239 | } |
| 4240 | } |
| 4241 | |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4242 | void InstructionCodeGeneratorX86::GenerateMinMaxInt(LocationSummary* locations, |
| 4243 | bool is_min, |
| 4244 | DataType::Type type) { |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4245 | Location op1_loc = locations->InAt(0); |
| 4246 | Location op2_loc = locations->InAt(1); |
| 4247 | |
| 4248 | // Shortcut for same input locations. |
| 4249 | if (op1_loc.Equals(op2_loc)) { |
| 4250 | // Can return immediately, as op1_loc == out_loc. |
| 4251 | // Note: if we ever support separate registers, e.g., output into memory, we need to check for |
| 4252 | // a copy here. |
| 4253 | DCHECK(locations->Out().Equals(op1_loc)); |
| 4254 | return; |
| 4255 | } |
| 4256 | |
| 4257 | if (type == DataType::Type::kInt64) { |
| 4258 | // Need to perform a subtract to get the sign right. |
| 4259 | // op1 is already in the same location as the output. |
| 4260 | Location output = locations->Out(); |
| 4261 | Register output_lo = output.AsRegisterPairLow<Register>(); |
| 4262 | Register output_hi = output.AsRegisterPairHigh<Register>(); |
| 4263 | |
| 4264 | Register op2_lo = op2_loc.AsRegisterPairLow<Register>(); |
| 4265 | Register op2_hi = op2_loc.AsRegisterPairHigh<Register>(); |
| 4266 | |
| 4267 | // The comparison is performed by subtracting the second operand from |
| 4268 | // the first operand and then setting the status flags in the same |
| 4269 | // manner as the SUB instruction." |
| 4270 | __ cmpl(output_lo, op2_lo); |
| 4271 | |
| 4272 | // Now use a temp and the borrow to finish the subtraction of op2_hi. |
| 4273 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4274 | __ movl(temp, output_hi); |
| 4275 | __ sbbl(temp, op2_hi); |
| 4276 | |
| 4277 | // Now the condition code is correct. |
| 4278 | Condition cond = is_min ? Condition::kGreaterEqual : Condition::kLess; |
| 4279 | __ cmovl(cond, output_lo, op2_lo); |
| 4280 | __ cmovl(cond, output_hi, op2_hi); |
| 4281 | } else { |
| 4282 | DCHECK_EQ(type, DataType::Type::kInt32); |
| 4283 | Register out = locations->Out().AsRegister<Register>(); |
| 4284 | Register op2 = op2_loc.AsRegister<Register>(); |
| 4285 | |
| 4286 | // (out := op1) |
| 4287 | // out <=? op2 |
| 4288 | // if out is min jmp done |
| 4289 | // out := op2 |
| 4290 | // done: |
| 4291 | |
| 4292 | __ cmpl(out, op2); |
| 4293 | Condition cond = is_min ? Condition::kGreater : Condition::kLess; |
| 4294 | __ cmovl(cond, out, op2); |
| 4295 | } |
| 4296 | } |
| 4297 | |
| 4298 | void InstructionCodeGeneratorX86::GenerateMinMaxFP(LocationSummary* locations, |
| 4299 | bool is_min, |
| 4300 | DataType::Type type) { |
| 4301 | Location op1_loc = locations->InAt(0); |
| 4302 | Location op2_loc = locations->InAt(1); |
| 4303 | Location out_loc = locations->Out(); |
| 4304 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
| 4305 | |
| 4306 | // Shortcut for same input locations. |
| 4307 | if (op1_loc.Equals(op2_loc)) { |
| 4308 | DCHECK(out_loc.Equals(op1_loc)); |
| 4309 | return; |
| 4310 | } |
| 4311 | |
| 4312 | // (out := op1) |
| 4313 | // out <=? op2 |
| 4314 | // if Nan jmp Nan_label |
| 4315 | // if out is min jmp done |
| 4316 | // if op2 is min jmp op2_label |
| 4317 | // handle -0/+0 |
| 4318 | // jmp done |
| 4319 | // Nan_label: |
| 4320 | // out := NaN |
| 4321 | // op2_label: |
| 4322 | // out := op2 |
| 4323 | // done: |
| 4324 | // |
| 4325 | // This removes one jmp, but needs to copy one input (op1) to out. |
| 4326 | // |
| 4327 | // TODO: This is straight from Quick (except literal pool). Make NaN an out-of-line slowpath? |
| 4328 | |
| 4329 | XmmRegister op2 = op2_loc.AsFpuRegister<XmmRegister>(); |
| 4330 | |
| 4331 | NearLabel nan, done, op2_label; |
| 4332 | if (type == DataType::Type::kFloat64) { |
| 4333 | __ ucomisd(out, op2); |
| 4334 | } else { |
| 4335 | DCHECK_EQ(type, DataType::Type::kFloat32); |
| 4336 | __ ucomiss(out, op2); |
| 4337 | } |
| 4338 | |
| 4339 | __ j(Condition::kParityEven, &nan); |
| 4340 | |
| 4341 | __ j(is_min ? Condition::kAbove : Condition::kBelow, &op2_label); |
| 4342 | __ j(is_min ? Condition::kBelow : Condition::kAbove, &done); |
| 4343 | |
| 4344 | // Handle 0.0/-0.0. |
| 4345 | if (is_min) { |
| 4346 | if (type == DataType::Type::kFloat64) { |
| 4347 | __ orpd(out, op2); |
| 4348 | } else { |
| 4349 | __ orps(out, op2); |
| 4350 | } |
| 4351 | } else { |
| 4352 | if (type == DataType::Type::kFloat64) { |
| 4353 | __ andpd(out, op2); |
| 4354 | } else { |
| 4355 | __ andps(out, op2); |
| 4356 | } |
| 4357 | } |
| 4358 | __ jmp(&done); |
| 4359 | |
| 4360 | // NaN handling. |
| 4361 | __ Bind(&nan); |
| 4362 | if (type == DataType::Type::kFloat64) { |
| 4363 | // TODO: Use a constant from the constant table (requires extra input). |
| 4364 | __ LoadLongConstant(out, kDoubleNaN); |
| 4365 | } else { |
| 4366 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 4367 | __ movl(constant, Immediate(kFloatNaN)); |
| 4368 | __ movd(out, constant); |
| 4369 | } |
| 4370 | __ jmp(&done); |
| 4371 | |
| 4372 | // out := op2; |
| 4373 | __ Bind(&op2_label); |
| 4374 | if (type == DataType::Type::kFloat64) { |
| 4375 | __ movsd(out, op2); |
| 4376 | } else { |
| 4377 | __ movss(out, op2); |
| 4378 | } |
| 4379 | |
| 4380 | // Done. |
| 4381 | __ Bind(&done); |
| 4382 | } |
| 4383 | |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4384 | void InstructionCodeGeneratorX86::GenerateMinMax(HBinaryOperation* minmax, bool is_min) { |
| 4385 | DataType::Type type = minmax->GetResultType(); |
| 4386 | switch (type) { |
| 4387 | case DataType::Type::kInt32: |
| 4388 | case DataType::Type::kInt64: |
| 4389 | GenerateMinMaxInt(minmax->GetLocations(), is_min, type); |
| 4390 | break; |
| 4391 | case DataType::Type::kFloat32: |
| 4392 | case DataType::Type::kFloat64: |
| 4393 | GenerateMinMaxFP(minmax->GetLocations(), is_min, type); |
| 4394 | break; |
| 4395 | default: |
| 4396 | LOG(FATAL) << "Unexpected type for HMinMax " << type; |
| 4397 | } |
| 4398 | } |
| 4399 | |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4400 | void LocationsBuilderX86::VisitMin(HMin* min) { |
| 4401 | CreateMinMaxLocations(GetGraph()->GetAllocator(), min); |
| 4402 | } |
| 4403 | |
| 4404 | void InstructionCodeGeneratorX86::VisitMin(HMin* min) { |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4405 | GenerateMinMax(min, /*is_min*/ true); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4406 | } |
| 4407 | |
| 4408 | void LocationsBuilderX86::VisitMax(HMax* max) { |
| 4409 | CreateMinMaxLocations(GetGraph()->GetAllocator(), max); |
| 4410 | } |
| 4411 | |
| 4412 | void InstructionCodeGeneratorX86::VisitMax(HMax* max) { |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4413 | GenerateMinMax(max, /*is_min*/ false); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4414 | } |
| 4415 | |
| Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 4416 | void LocationsBuilderX86::VisitAbs(HAbs* abs) { |
| 4417 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 4418 | switch (abs->GetResultType()) { |
| 4419 | case DataType::Type::kInt32: |
| 4420 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 4421 | locations->SetOut(Location::SameAsFirstInput()); |
| 4422 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 4423 | break; |
| 4424 | case DataType::Type::kInt64: |
| 4425 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4426 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4427 | locations->AddTemp(Location::RequiresRegister()); |
| 4428 | break; |
| 4429 | case DataType::Type::kFloat32: |
| 4430 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4431 | locations->SetOut(Location::SameAsFirstInput()); |
| 4432 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4433 | locations->AddTemp(Location::RequiresRegister()); |
| 4434 | break; |
| 4435 | case DataType::Type::kFloat64: |
| 4436 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4437 | locations->SetOut(Location::SameAsFirstInput()); |
| 4438 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4439 | break; |
| 4440 | default: |
| 4441 | LOG(FATAL) << "Unexpected type for HAbs " << abs->GetResultType(); |
| 4442 | } |
| 4443 | } |
| 4444 | |
| 4445 | void InstructionCodeGeneratorX86::VisitAbs(HAbs* abs) { |
| 4446 | LocationSummary* locations = abs->GetLocations(); |
| 4447 | switch (abs->GetResultType()) { |
| 4448 | case DataType::Type::kInt32: { |
| 4449 | Register out = locations->Out().AsRegister<Register>(); |
| 4450 | DCHECK_EQ(out, EAX); |
| 4451 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4452 | DCHECK_EQ(temp, EDX); |
| 4453 | // Sign extend EAX into EDX. |
| 4454 | __ cdq(); |
| 4455 | // XOR EAX with sign. |
| 4456 | __ xorl(EAX, EDX); |
| 4457 | // Subtract out sign to correct. |
| 4458 | __ subl(EAX, EDX); |
| 4459 | // The result is in EAX. |
| 4460 | break; |
| 4461 | } |
| 4462 | case DataType::Type::kInt64: { |
| 4463 | Location input = locations->InAt(0); |
| 4464 | Register input_lo = input.AsRegisterPairLow<Register>(); |
| 4465 | Register input_hi = input.AsRegisterPairHigh<Register>(); |
| 4466 | Location output = locations->Out(); |
| 4467 | Register output_lo = output.AsRegisterPairLow<Register>(); |
| 4468 | Register output_hi = output.AsRegisterPairHigh<Register>(); |
| 4469 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4470 | // Compute the sign into the temporary. |
| 4471 | __ movl(temp, input_hi); |
| 4472 | __ sarl(temp, Immediate(31)); |
| 4473 | // Store the sign into the output. |
| 4474 | __ movl(output_lo, temp); |
| 4475 | __ movl(output_hi, temp); |
| 4476 | // XOR the input to the output. |
| 4477 | __ xorl(output_lo, input_lo); |
| 4478 | __ xorl(output_hi, input_hi); |
| 4479 | // Subtract the sign. |
| 4480 | __ subl(output_lo, temp); |
| 4481 | __ sbbl(output_hi, temp); |
| 4482 | break; |
| 4483 | } |
| 4484 | case DataType::Type::kFloat32: { |
| 4485 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4486 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4487 | Register constant = locations->GetTemp(1).AsRegister<Register>(); |
| 4488 | __ movl(constant, Immediate(INT32_C(0x7FFFFFFF))); |
| 4489 | __ movd(temp, constant); |
| 4490 | __ andps(out, temp); |
| 4491 | break; |
| 4492 | } |
| 4493 | case DataType::Type::kFloat64: { |
| 4494 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4495 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4496 | // TODO: Use a constant from the constant table (requires extra input). |
| 4497 | __ LoadLongConstant(temp, INT64_C(0x7FFFFFFFFFFFFFFF)); |
| 4498 | __ andpd(out, temp); |
| 4499 | break; |
| 4500 | } |
| 4501 | default: |
| 4502 | LOG(FATAL) << "Unexpected type for HAbs " << abs->GetResultType(); |
| 4503 | } |
| 4504 | } |
| 4505 | |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4506 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4507 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4508 | switch (instruction->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4509 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4510 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4511 | case DataType::Type::kInt8: |
| 4512 | case DataType::Type::kUint16: |
| 4513 | case DataType::Type::kInt16: |
| 4514 | case DataType::Type::kInt32: { |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4515 | locations->SetInAt(0, Location::Any()); |
| 4516 | break; |
| 4517 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4518 | case DataType::Type::kInt64: { |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4519 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 4520 | if (!instruction->IsConstant()) { |
| 4521 | locations->AddTemp(Location::RequiresRegister()); |
| 4522 | } |
| 4523 | break; |
| 4524 | } |
| 4525 | default: |
| 4526 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 4527 | } |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4528 | } |
| 4529 | |
| 4530 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4531 | SlowPathCode* slow_path = |
| 4532 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathX86(instruction); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4533 | codegen_->AddSlowPath(slow_path); |
| 4534 | |
| 4535 | LocationSummary* locations = instruction->GetLocations(); |
| 4536 | Location value = locations->InAt(0); |
| 4537 | |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4538 | switch (instruction->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4539 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4540 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4541 | case DataType::Type::kInt8: |
| 4542 | case DataType::Type::kUint16: |
| 4543 | case DataType::Type::kInt16: |
| 4544 | case DataType::Type::kInt32: { |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4545 | if (value.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4546 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4547 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4548 | } else if (value.IsStackSlot()) { |
| 4549 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 4550 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4551 | } else { |
| 4552 | DCHECK(value.IsConstant()) << value; |
| 4553 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4554 | __ jmp(slow_path->GetEntryLabel()); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4555 | } |
| 4556 | } |
| 4557 | break; |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4558 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4559 | case DataType::Type::kInt64: { |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4560 | if (value.IsRegisterPair()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4561 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4562 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 4563 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 4564 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4565 | } else { |
| 4566 | DCHECK(value.IsConstant()) << value; |
| 4567 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 4568 | __ jmp(slow_path->GetEntryLabel()); |
| 4569 | } |
| 4570 | } |
| 4571 | break; |
| 4572 | } |
| 4573 | default: |
| 4574 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4575 | } |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4576 | } |
| 4577 | |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4578 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 4579 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4580 | |
| 4581 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4582 | new (GetGraph()->GetAllocator()) LocationSummary(op, LocationSummary::kNoCall); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4583 | |
| 4584 | switch (op->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4585 | case DataType::Type::kInt32: |
| 4586 | case DataType::Type::kInt64: { |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4587 | // Can't have Location::Any() and output SameAsFirstInput() |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4588 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4589 | // The shift count needs to be in CL or a constant. |
| 4590 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4591 | locations->SetOut(Location::SameAsFirstInput()); |
| 4592 | break; |
| 4593 | } |
| 4594 | default: |
| 4595 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 4596 | } |
| 4597 | } |
| 4598 | |
| 4599 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 4600 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4601 | |
| 4602 | LocationSummary* locations = op->GetLocations(); |
| 4603 | Location first = locations->InAt(0); |
| 4604 | Location second = locations->InAt(1); |
| 4605 | DCHECK(first.Equals(locations->Out())); |
| 4606 | |
| 4607 | switch (op->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4608 | case DataType::Type::kInt32: { |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4609 | DCHECK(first.IsRegister()); |
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4610 | Register first_reg = first.AsRegister<Register>(); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4611 | if (second.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4612 | Register second_reg = second.AsRegister<Register>(); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4613 | DCHECK_EQ(ECX, second_reg); |
| 4614 | if (op->IsShl()) { |
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4615 | __ shll(first_reg, second_reg); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4616 | } else if (op->IsShr()) { |
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4617 | __ sarl(first_reg, second_reg); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4618 | } else { |
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4619 | __ shrl(first_reg, second_reg); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4620 | } |
| 4621 | } else { |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4622 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance; |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4623 | if (shift == 0) { |
| 4624 | return; |
| 4625 | } |
| 4626 | Immediate imm(shift); |
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4627 | if (op->IsShl()) { |
| 4628 | __ shll(first_reg, imm); |
| 4629 | } else if (op->IsShr()) { |
| 4630 | __ sarl(first_reg, imm); |
| 4631 | } else { |
| 4632 | __ shrl(first_reg, imm); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4633 | } |
| 4634 | } |
| 4635 | break; |
| 4636 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4637 | case DataType::Type::kInt64: { |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4638 | if (second.IsRegister()) { |
| 4639 | Register second_reg = second.AsRegister<Register>(); |
| 4640 | DCHECK_EQ(ECX, second_reg); |
| 4641 | if (op->IsShl()) { |
| 4642 | GenerateShlLong(first, second_reg); |
| 4643 | } else if (op->IsShr()) { |
| 4644 | GenerateShrLong(first, second_reg); |
| 4645 | } else { |
| 4646 | GenerateUShrLong(first, second_reg); |
| 4647 | } |
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4648 | } else { |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4649 | // Shift by a constant. |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4650 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4651 | // Nothing to do if the shift is 0, as the input is already the output. |
| 4652 | if (shift != 0) { |
| 4653 | if (op->IsShl()) { |
| 4654 | GenerateShlLong(first, shift); |
| 4655 | } else if (op->IsShr()) { |
| 4656 | GenerateShrLong(first, shift); |
| 4657 | } else { |
| 4658 | GenerateUShrLong(first, shift); |
| 4659 | } |
| 4660 | } |
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4661 | } |
| 4662 | break; |
| 4663 | } |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4664 | default: |
| 4665 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 4666 | } |
| 4667 | } |
| 4668 | |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4669 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 4670 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4671 | Register high = loc.AsRegisterPairHigh<Register>(); |
| Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 4672 | if (shift == 1) { |
| 4673 | // This is just an addition. |
| 4674 | __ addl(low, low); |
| 4675 | __ adcl(high, high); |
| 4676 | } else if (shift == 32) { |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4677 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 4678 | codegen_->EmitParallelMoves( |
| 4679 | loc.ToLow(), |
| 4680 | loc.ToHigh(), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4681 | DataType::Type::kInt32, |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4682 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 4683 | loc.ToLow(), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4684 | DataType::Type::kInt32); |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4685 | } else if (shift > 32) { |
| 4686 | // Low part becomes 0. High part is low part << (shift-32). |
| 4687 | __ movl(high, low); |
| 4688 | __ shll(high, Immediate(shift - 32)); |
| 4689 | __ xorl(low, low); |
| 4690 | } else { |
| 4691 | // Between 1 and 31. |
| 4692 | __ shld(high, low, Immediate(shift)); |
| 4693 | __ shll(low, Immediate(shift)); |
| 4694 | } |
| 4695 | } |
| 4696 | |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4697 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4698 | NearLabel done; |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4699 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 4700 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 4701 | __ testl(shifter, Immediate(32)); |
| 4702 | __ j(kEqual, &done); |
| 4703 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 4704 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 4705 | __ Bind(&done); |
| 4706 | } |
| 4707 | |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4708 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 4709 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4710 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 4711 | if (shift == 32) { |
| 4712 | // Need to copy the sign. |
| 4713 | DCHECK_NE(low, high); |
| 4714 | __ movl(low, high); |
| 4715 | __ sarl(high, Immediate(31)); |
| 4716 | } else if (shift > 32) { |
| 4717 | DCHECK_NE(low, high); |
| 4718 | // High part becomes sign. Low part is shifted by shift - 32. |
| 4719 | __ movl(low, high); |
| 4720 | __ sarl(high, Immediate(31)); |
| 4721 | __ sarl(low, Immediate(shift - 32)); |
| 4722 | } else { |
| 4723 | // Between 1 and 31. |
| 4724 | __ shrd(low, high, Immediate(shift)); |
| 4725 | __ sarl(high, Immediate(shift)); |
| 4726 | } |
| 4727 | } |
| 4728 | |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4729 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4730 | NearLabel done; |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4731 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4732 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4733 | __ testl(shifter, Immediate(32)); |
| 4734 | __ j(kEqual, &done); |
| 4735 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4736 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 4737 | __ Bind(&done); |
| 4738 | } |
| 4739 | |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4740 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 4741 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4742 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 4743 | if (shift == 32) { |
| 4744 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 4745 | codegen_->EmitParallelMoves( |
| 4746 | loc.ToHigh(), |
| 4747 | loc.ToLow(), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4748 | DataType::Type::kInt32, |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4749 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 4750 | loc.ToHigh(), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4751 | DataType::Type::kInt32); |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4752 | } else if (shift > 32) { |
| 4753 | // Low part is high >> (shift - 32). High part becomes 0. |
| 4754 | __ movl(low, high); |
| 4755 | __ shrl(low, Immediate(shift - 32)); |
| 4756 | __ xorl(high, high); |
| 4757 | } else { |
| 4758 | // Between 1 and 31. |
| 4759 | __ shrd(low, high, Immediate(shift)); |
| 4760 | __ shrl(high, Immediate(shift)); |
| 4761 | } |
| 4762 | } |
| 4763 | |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4764 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4765 | NearLabel done; |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4766 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4767 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4768 | __ testl(shifter, Immediate(32)); |
| 4769 | __ j(kEqual, &done); |
| 4770 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4771 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 4772 | __ Bind(&done); |
| 4773 | } |
| 4774 | |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4775 | void LocationsBuilderX86::VisitRor(HRor* ror) { |
| 4776 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4777 | new (GetGraph()->GetAllocator()) LocationSummary(ror, LocationSummary::kNoCall); |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4778 | |
| 4779 | switch (ror->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4780 | case DataType::Type::kInt64: |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4781 | // Add the temporary needed. |
| 4782 | locations->AddTemp(Location::RequiresRegister()); |
| 4783 | FALLTHROUGH_INTENDED; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4784 | case DataType::Type::kInt32: |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4785 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4786 | // The shift count needs to be in CL (unless it is a constant). |
| 4787 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); |
| 4788 | locations->SetOut(Location::SameAsFirstInput()); |
| 4789 | break; |
| 4790 | default: |
| 4791 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4792 | UNREACHABLE(); |
| 4793 | } |
| 4794 | } |
| 4795 | |
| 4796 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { |
| 4797 | LocationSummary* locations = ror->GetLocations(); |
| 4798 | Location first = locations->InAt(0); |
| 4799 | Location second = locations->InAt(1); |
| 4800 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4801 | if (ror->GetResultType() == DataType::Type::kInt32) { |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4802 | Register first_reg = first.AsRegister<Register>(); |
| 4803 | if (second.IsRegister()) { |
| 4804 | Register second_reg = second.AsRegister<Register>(); |
| 4805 | __ rorl(first_reg, second_reg); |
| 4806 | } else { |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4807 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4808 | __ rorl(first_reg, imm); |
| 4809 | } |
| 4810 | return; |
| 4811 | } |
| 4812 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4813 | DCHECK_EQ(ror->GetResultType(), DataType::Type::kInt64); |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4814 | Register first_reg_lo = first.AsRegisterPairLow<Register>(); |
| 4815 | Register first_reg_hi = first.AsRegisterPairHigh<Register>(); |
| 4816 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 4817 | if (second.IsRegister()) { |
| 4818 | Register second_reg = second.AsRegister<Register>(); |
| 4819 | DCHECK_EQ(second_reg, ECX); |
| 4820 | __ movl(temp_reg, first_reg_hi); |
| 4821 | __ shrd(first_reg_hi, first_reg_lo, second_reg); |
| 4822 | __ shrd(first_reg_lo, temp_reg, second_reg); |
| 4823 | __ movl(temp_reg, first_reg_hi); |
| 4824 | __ testl(second_reg, Immediate(32)); |
| 4825 | __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); |
| 4826 | __ cmovl(kNotEqual, first_reg_lo, temp_reg); |
| 4827 | } else { |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4828 | int32_t shift_amt = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4829 | if (shift_amt == 0) { |
| 4830 | // Already fine. |
| 4831 | return; |
| 4832 | } |
| 4833 | if (shift_amt == 32) { |
| 4834 | // Just swap. |
| 4835 | __ movl(temp_reg, first_reg_lo); |
| 4836 | __ movl(first_reg_lo, first_reg_hi); |
| 4837 | __ movl(first_reg_hi, temp_reg); |
| 4838 | return; |
| 4839 | } |
| 4840 | |
| 4841 | Immediate imm(shift_amt); |
| 4842 | // Save the constents of the low value. |
| 4843 | __ movl(temp_reg, first_reg_lo); |
| 4844 | |
| 4845 | // Shift right into low, feeding bits from high. |
| 4846 | __ shrd(first_reg_lo, first_reg_hi, imm); |
| 4847 | |
| 4848 | // Shift right into high, feeding bits from the original low. |
| 4849 | __ shrd(first_reg_hi, temp_reg, imm); |
| 4850 | |
| 4851 | // Swap if needed. |
| 4852 | if (shift_amt > 32) { |
| 4853 | __ movl(temp_reg, first_reg_lo); |
| 4854 | __ movl(first_reg_lo, first_reg_hi); |
| 4855 | __ movl(first_reg_hi, temp_reg); |
| 4856 | } |
| 4857 | } |
| 4858 | } |
| 4859 | |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4860 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 4861 | HandleShift(shl); |
| 4862 | } |
| 4863 | |
| 4864 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 4865 | HandleShift(shl); |
| 4866 | } |
| 4867 | |
| 4868 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 4869 | HandleShift(shr); |
| 4870 | } |
| 4871 | |
| 4872 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 4873 | HandleShift(shr); |
| 4874 | } |
| 4875 | |
| 4876 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 4877 | HandleShift(ushr); |
| 4878 | } |
| 4879 | |
| 4880 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 4881 | HandleShift(ushr); |
| 4882 | } |
| 4883 | |
| Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4884 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4885 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4886 | instruction, LocationSummary::kCallOnMainOnly); |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4887 | locations->SetOut(Location::RegisterLocation(EAX)); |
| Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 4888 | InvokeRuntimeCallingConvention calling_convention; |
| 4889 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4890 | } |
| 4891 | |
| 4892 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
| Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 4893 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
| 4894 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| 4895 | DCHECK(!codegen_->IsLeafMethod()); |
| Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4896 | } |
| 4897 | |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4898 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4899 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4900 | instruction, LocationSummary::kCallOnMainOnly); |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4901 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 4902 | InvokeRuntimeCallingConvention calling_convention; |
| Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4903 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4904 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4905 | } |
| 4906 | |
| 4907 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
| Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 4908 | // Note: if heap poisoning is enabled, the entry point takes care of poisoning the reference. |
| 4909 | QuickEntrypointEnum entrypoint = CodeGenerator::GetArrayAllocationEntrypoint(instruction); |
| Nicolas Geoffray | d095844 | 2017-01-30 14:57:16 +0000 | [diff] [blame] | 4910 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
| Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4911 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4912 | DCHECK(!codegen_->IsLeafMethod()); |
| 4913 | } |
| 4914 | |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4915 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4916 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4917 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4918 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4919 | if (location.IsStackSlot()) { |
| 4920 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4921 | } else if (location.IsDoubleStackSlot()) { |
| 4922 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4923 | } |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4924 | locations->SetOut(location); |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4925 | } |
| 4926 | |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4927 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 4928 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 4929 | } |
| 4930 | |
| 4931 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4932 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4933 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4934 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4935 | } |
| 4936 | |
| 4937 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4938 | } |
| 4939 | |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4940 | void LocationsBuilderX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4941 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4942 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4943 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4944 | locations->SetOut(Location::RequiresRegister()); |
| 4945 | } |
| 4946 | |
| 4947 | void InstructionCodeGeneratorX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4948 | LocationSummary* locations = instruction->GetLocations(); |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4949 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4950 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4951 | instruction->GetIndex(), kX86PointerSize).SizeValue(); |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4952 | __ movl(locations->Out().AsRegister<Register>(), |
| 4953 | Address(locations->InAt(0).AsRegister<Register>(), method_offset)); |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4954 | } else { |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4955 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4956 | instruction->GetIndex(), kX86PointerSize)); |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4957 | __ movl(locations->Out().AsRegister<Register>(), |
| 4958 | Address(locations->InAt(0).AsRegister<Register>(), |
| 4959 | mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
| 4960 | // temp = temp->GetImtEntryAt(method_offset); |
| 4961 | __ movl(locations->Out().AsRegister<Register>(), |
| 4962 | Address(locations->Out().AsRegister<Register>(), method_offset)); |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4963 | } |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4964 | } |
| 4965 | |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4966 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4967 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4968 | new (GetGraph()->GetAllocator()) LocationSummary(not_, LocationSummary::kNoCall); |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4969 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4970 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4971 | } |
| 4972 | |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4973 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 4974 | LocationSummary* locations = not_->GetLocations(); |
| Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4975 | Location in = locations->InAt(0); |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4976 | Location out = locations->Out(); |
| Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4977 | DCHECK(in.Equals(out)); |
| Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4978 | switch (not_->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4979 | case DataType::Type::kInt32: |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4980 | __ notl(out.AsRegister<Register>()); |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4981 | break; |
| 4982 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4983 | case DataType::Type::kInt64: |
| Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4984 | __ notl(out.AsRegisterPairLow<Register>()); |
| 4985 | __ notl(out.AsRegisterPairHigh<Register>()); |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4986 | break; |
| 4987 | |
| 4988 | default: |
| 4989 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4990 | } |
| Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4991 | } |
| 4992 | |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4993 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4994 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4995 | new (GetGraph()->GetAllocator()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4996 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4997 | locations->SetOut(Location::SameAsFirstInput()); |
| 4998 | } |
| 4999 | |
| 5000 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5001 | LocationSummary* locations = bool_not->GetLocations(); |
| 5002 | Location in = locations->InAt(0); |
| 5003 | Location out = locations->Out(); |
| 5004 | DCHECK(in.Equals(out)); |
| 5005 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 5006 | } |
| 5007 | |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5008 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5009 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5010 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5011 | switch (compare->InputAt(0)->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5012 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5013 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5014 | case DataType::Type::kInt8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5015 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5016 | case DataType::Type::kInt16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5017 | case DataType::Type::kInt32: |
| 5018 | case DataType::Type::kInt64: { |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5019 | locations->SetInAt(0, Location::RequiresRegister()); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5020 | locations->SetInAt(1, Location::Any()); |
| 5021 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5022 | break; |
| 5023 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5024 | case DataType::Type::kFloat32: |
| 5025 | case DataType::Type::kFloat64: { |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5026 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 5027 | if (compare->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 5028 | DCHECK(compare->InputAt(1)->IsEmittedAtUseSite()); |
| 5029 | } else if (compare->InputAt(1)->IsConstant()) { |
| 5030 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 5031 | } else { |
| 5032 | locations->SetInAt(1, Location::Any()); |
| 5033 | } |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5034 | locations->SetOut(Location::RequiresRegister()); |
| 5035 | break; |
| 5036 | } |
| 5037 | default: |
| 5038 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 5039 | } |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5040 | } |
| 5041 | |
| 5042 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5043 | LocationSummary* locations = compare->GetLocations(); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5044 | Register out = locations->Out().AsRegister<Register>(); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5045 | Location left = locations->InAt(0); |
| 5046 | Location right = locations->InAt(1); |
| 5047 | |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 5048 | NearLabel less, greater, done; |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5049 | Condition less_cond = kLess; |
| 5050 | |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5051 | switch (compare->InputAt(0)->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5052 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5053 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5054 | case DataType::Type::kInt8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5055 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5056 | case DataType::Type::kInt16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5057 | case DataType::Type::kInt32: { |
| Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 5058 | codegen_->GenerateIntCompare(left, right); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5059 | break; |
| 5060 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5061 | case DataType::Type::kInt64: { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5062 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 5063 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 5064 | int32_t val_low = 0; |
| 5065 | int32_t val_high = 0; |
| 5066 | bool right_is_const = false; |
| 5067 | |
| 5068 | if (right.IsConstant()) { |
| 5069 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 5070 | right_is_const = true; |
| 5071 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 5072 | val_low = Low32Bits(val); |
| 5073 | val_high = High32Bits(val); |
| 5074 | } |
| 5075 | |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5076 | if (right.IsRegisterPair()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5077 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5078 | } else if (right.IsDoubleStackSlot()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5079 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5080 | } else { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5081 | DCHECK(right_is_const) << right; |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5082 | codegen_->Compare32BitValue(left_high, val_high); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5083 | } |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5084 | __ j(kLess, &less); // Signed compare. |
| 5085 | __ j(kGreater, &greater); // Signed compare. |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5086 | if (right.IsRegisterPair()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5087 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5088 | } else if (right.IsDoubleStackSlot()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5089 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5090 | } else { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5091 | DCHECK(right_is_const) << right; |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5092 | codegen_->Compare32BitValue(left_low, val_low); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5093 | } |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5094 | less_cond = kBelow; // for CF (unsigned). |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5095 | break; |
| 5096 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5097 | case DataType::Type::kFloat32: { |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 5098 | GenerateFPCompare(left, right, compare, false); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5099 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5100 | less_cond = kBelow; // for CF (floats). |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5101 | break; |
| 5102 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5103 | case DataType::Type::kFloat64: { |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 5104 | GenerateFPCompare(left, right, compare, true); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5105 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5106 | less_cond = kBelow; // for CF (floats). |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5107 | break; |
| 5108 | } |
| 5109 | default: |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5110 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5111 | } |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5112 | |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5113 | __ movl(out, Immediate(0)); |
| 5114 | __ j(kEqual, &done); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5115 | __ j(less_cond, &less); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5116 | |
| 5117 | __ Bind(&greater); |
| 5118 | __ movl(out, Immediate(1)); |
| 5119 | __ jmp(&done); |
| 5120 | |
| 5121 | __ Bind(&less); |
| 5122 | __ movl(out, Immediate(-1)); |
| 5123 | |
| 5124 | __ Bind(&done); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5125 | } |
| 5126 | |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 5127 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5128 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5129 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5130 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
| Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 5131 | locations->SetInAt(i, Location::Any()); |
| 5132 | } |
| 5133 | locations->SetOut(Location::Any()); |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 5134 | } |
| 5135 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5136 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5137 | LOG(FATAL) << "Unreachable"; |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 5138 | } |
| 5139 | |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5140 | void CodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5141 | /* |
| 5142 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 5143 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 5144 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 5145 | */ |
| 5146 | switch (kind) { |
| 5147 | case MemBarrierKind::kAnyAny: { |
| Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 5148 | MemoryFence(); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5149 | break; |
| 5150 | } |
| 5151 | case MemBarrierKind::kAnyStore: |
| 5152 | case MemBarrierKind::kLoadAny: |
| 5153 | case MemBarrierKind::kStoreStore: { |
| 5154 | // nop |
| 5155 | break; |
| 5156 | } |
| Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 5157 | case MemBarrierKind::kNTStoreStore: |
| 5158 | // Non-Temporal Store/Store needs an explicit fence. |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5159 | MemoryFence(/* non-temporal= */ true); |
| Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 5160 | break; |
| Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 5161 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5162 | } |
| 5163 | |
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5164 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( |
| 5165 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| Nicolas Geoffray | bdb2ecc | 2018-09-18 14:33:55 +0100 | [diff] [blame] | 5166 | ArtMethod* method ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 5167 | return desired_dispatch_info; |
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5168 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5169 | |
| Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5170 | Register CodeGeneratorX86::GetInvokeExtraParameter(HInvoke* invoke, Register temp) { |
| 5171 | if (invoke->IsInvokeStaticOrDirect()) { |
| 5172 | return GetInvokeStaticOrDirectExtraParameter(invoke->AsInvokeStaticOrDirect(), temp); |
| 5173 | } |
| 5174 | DCHECK(invoke->IsInvokeInterface()); |
| 5175 | Location location = |
| 5176 | invoke->GetLocations()->InAt(invoke->AsInvokeInterface()->GetSpecialInputIndex()); |
| 5177 | return location.AsRegister<Register>(); |
| 5178 | } |
| 5179 | |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 5180 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 5181 | Register temp) { |
| Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 5182 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 5183 | if (!invoke->GetLocations()->Intrinsified()) { |
| 5184 | return location.AsRegister<Register>(); |
| 5185 | } |
| 5186 | // For intrinsics we allow any location, so it may be on the stack. |
| 5187 | if (!location.IsRegister()) { |
| 5188 | __ movl(temp, Address(ESP, location.GetStackIndex())); |
| 5189 | return temp; |
| 5190 | } |
| 5191 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 5192 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 5193 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 5194 | // simple and more robust approach rather that trying to determine if that's the case. |
| 5195 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| Vladimir Marko | 4ee8e29 | 2017-06-02 15:39:30 +0000 | [diff] [blame] | 5196 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 5197 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 5198 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 5199 | __ movl(temp, Address(ESP, stack_offset)); |
| 5200 | return temp; |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 5201 | } |
| 5202 | return location.AsRegister<Register>(); |
| 5203 | } |
| 5204 | |
| Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5205 | void CodeGeneratorX86::LoadMethod(MethodLoadKind load_kind, Location temp, HInvoke* invoke) { |
| 5206 | switch (load_kind) { |
| 5207 | case MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 5208 | DCHECK(GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()); |
| 5209 | Register base_reg = GetInvokeExtraParameter(invoke, temp.AsRegister<Register>()); |
| 5210 | __ leal(temp.AsRegister<Register>(), |
| 5211 | Address(base_reg, CodeGeneratorX86::kPlaceholder32BitOffset)); |
| 5212 | RecordBootImageMethodPatch(invoke); |
| 5213 | break; |
| 5214 | } |
| 5215 | case MethodLoadKind::kBootImageRelRo: { |
| 5216 | size_t index = invoke->IsInvokeInterface() |
| 5217 | ? invoke->AsInvokeInterface()->GetSpecialInputIndex() |
| 5218 | : invoke->AsInvokeStaticOrDirect()->GetSpecialInputIndex(); |
| 5219 | Register base_reg = GetInvokeExtraParameter(invoke, temp.AsRegister<Register>()); |
| 5220 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kPlaceholder32BitOffset)); |
| 5221 | RecordBootImageRelRoPatch( |
| 5222 | invoke->InputAt(index)->AsX86ComputeBaseMethodAddress(), |
| 5223 | GetBootImageOffset(invoke)); |
| 5224 | break; |
| 5225 | } |
| 5226 | case MethodLoadKind::kBssEntry: { |
| 5227 | Register base_reg = GetInvokeExtraParameter(invoke, temp.AsRegister<Register>()); |
| 5228 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kPlaceholder32BitOffset)); |
| 5229 | RecordMethodBssEntryPatch(invoke); |
| 5230 | // No need for memory fence, thanks to the x86 memory model. |
| 5231 | break; |
| 5232 | } |
| 5233 | case MethodLoadKind::kJitDirectAddress: { |
| 5234 | __ movl(temp.AsRegister<Register>(), |
| 5235 | Immediate(reinterpret_cast32<uint32_t>(invoke->GetResolvedMethod()))); |
| 5236 | break; |
| 5237 | } |
| 5238 | case MethodLoadKind::kRuntimeCall: { |
| 5239 | // Test situation, don't do anything. |
| 5240 | break; |
| 5241 | } |
| 5242 | default: { |
| 5243 | LOG(FATAL) << "Load kind should have already been handled " << load_kind; |
| 5244 | UNREACHABLE(); |
| 5245 | } |
| 5246 | } |
| 5247 | } |
| 5248 | |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5249 | void CodeGeneratorX86::GenerateStaticOrDirectCall( |
| 5250 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5251 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 5252 | switch (invoke->GetMethodLoadKind()) { |
| Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 5253 | case MethodLoadKind::kStringInit: { |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5254 | // temp = thread->string_init_entrypoint |
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5255 | uint32_t offset = |
| 5256 | GetThreadOffset<kX86PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 5257 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(offset)); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5258 | break; |
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5259 | } |
| Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5260 | case MethodLoadKind::kRecursive: { |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 5261 | callee_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodIndex()); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5262 | break; |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5263 | } |
| Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 5264 | case MethodLoadKind::kRuntimeCall: { |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5265 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 5266 | return; // No code pointer retrieval; the runtime performs the call directly. |
| Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 5267 | } |
| Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 5268 | case MethodLoadKind::kBootImageLinkTimePcRelative: |
| 5269 | // For kCallCriticalNative we skip loading the method and do the call directly. |
| 5270 | if (invoke->GetCodePtrLocation() == CodePtrLocation::kCallCriticalNative) { |
| 5271 | break; |
| 5272 | } |
| 5273 | FALLTHROUGH_INTENDED; |
| Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5274 | default: { |
| 5275 | LoadMethod(invoke->GetMethodLoadKind(), callee_method, invoke); |
| 5276 | } |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5277 | } |
| 5278 | |
| 5279 | switch (invoke->GetCodePtrLocation()) { |
| Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 5280 | case CodePtrLocation::kCallSelf: |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5281 | __ call(GetFrameEntryLabel()); |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 5282 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5283 | break; |
| Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 5284 | case CodePtrLocation::kCallCriticalNative: { |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 5285 | size_t out_frame_size = |
| 5286 | PrepareCriticalNativeCall<CriticalNativeCallingConventionVisitorX86, |
| 5287 | kNativeStackAlignment, |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 5288 | GetCriticalNativeDirectCallFrameSize>(invoke); |
| Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 5289 | if (invoke->GetMethodLoadKind() == MethodLoadKind::kBootImageLinkTimePcRelative) { |
| 5290 | DCHECK(GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()); |
| 5291 | Register base_reg = GetInvokeExtraParameter(invoke, temp.AsRegister<Register>()); |
| 5292 | __ call(Address(base_reg, CodeGeneratorX86::kPlaceholder32BitOffset)); |
| 5293 | RecordBootImageJniEntrypointPatch(invoke); |
| 5294 | } else { |
| 5295 | // (callee_method + offset_of_jni_entry_point)() |
| 5296 | __ call(Address(callee_method.AsRegister<Register>(), |
| 5297 | ArtMethod::EntryPointFromJniOffset(kX86PointerSize).Int32Value())); |
| 5298 | } |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 5299 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 5300 | if (out_frame_size == 0u && DataType::IsFloatingPointType(invoke->GetType())) { |
| 5301 | // Create space for conversion. |
| 5302 | out_frame_size = 8u; |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 5303 | IncreaseFrame(out_frame_size); |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 5304 | } |
| 5305 | // Zero-/sign-extend or move the result when needed due to native and managed ABI mismatch. |
| 5306 | switch (invoke->GetType()) { |
| 5307 | case DataType::Type::kBool: |
| 5308 | __ movzxb(EAX, AL); |
| 5309 | break; |
| 5310 | case DataType::Type::kInt8: |
| 5311 | __ movsxb(EAX, AL); |
| 5312 | break; |
| 5313 | case DataType::Type::kUint16: |
| 5314 | __ movzxw(EAX, EAX); |
| 5315 | break; |
| 5316 | case DataType::Type::kInt16: |
| 5317 | __ movsxw(EAX, EAX); |
| 5318 | break; |
| 5319 | case DataType::Type::kFloat32: |
| 5320 | __ fstps(Address(ESP, 0)); |
| 5321 | __ movss(XMM0, Address(ESP, 0)); |
| 5322 | break; |
| 5323 | case DataType::Type::kFloat64: |
| 5324 | __ fstpl(Address(ESP, 0)); |
| 5325 | __ movsd(XMM0, Address(ESP, 0)); |
| 5326 | break; |
| 5327 | case DataType::Type::kInt32: |
| 5328 | case DataType::Type::kInt64: |
| 5329 | case DataType::Type::kVoid: |
| 5330 | break; |
| 5331 | default: |
| 5332 | DCHECK(false) << invoke->GetType(); |
| 5333 | break; |
| 5334 | } |
| 5335 | if (out_frame_size != 0u) { |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 5336 | DecreaseFrame(out_frame_size); |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 5337 | } |
| 5338 | break; |
| 5339 | } |
| Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 5340 | case CodePtrLocation::kCallArtMethod: |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5341 | // (callee_method + offset_of_quick_compiled_code)() |
| 5342 | __ call(Address(callee_method.AsRegister<Register>(), |
| 5343 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5344 | kX86PointerSize).Int32Value())); |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 5345 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5346 | break; |
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 5347 | } |
| 5348 | |
| 5349 | DCHECK(!IsLeafMethod()); |
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 5350 | } |
| 5351 | |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5352 | void CodeGeneratorX86::GenerateVirtualCall( |
| 5353 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5354 | Register temp = temp_in.AsRegister<Register>(); |
| 5355 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 5356 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
| Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 5357 | |
| 5358 | // Use the calling convention instead of the location of the receiver, as |
| 5359 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 5360 | // slow path, the arguments have been moved to the right place, so here we are |
| 5361 | // guaranteed that the receiver is the first register of the calling convention. |
| 5362 | InvokeDexCallingConvention calling_convention; |
| 5363 | Register receiver = calling_convention.GetRegisterAt(0); |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5364 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5365 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 5366 | __ movl(temp, Address(receiver, class_offset)); |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5367 | MaybeRecordImplicitNullCheck(invoke); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5368 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 5369 | // emit a read barrier for the previous class reference load. |
| 5370 | // However this is not required in practice, as this is an |
| 5371 | // intermediate/temporary reference and because the current |
| 5372 | // concurrent copying collector keeps the from-space memory |
| 5373 | // intact/accessible until the end of the marking phase (the |
| 5374 | // concurrent copying collector may not in the future). |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5375 | __ MaybeUnpoisonHeapReference(temp); |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 5376 | |
| 5377 | MaybeGenerateInlineCacheCheck(invoke, temp); |
| 5378 | |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5379 | // temp = temp->GetMethodAt(method_offset); |
| 5380 | __ movl(temp, Address(temp, method_offset)); |
| 5381 | // call temp->GetEntryPoint(); |
| 5382 | __ call(Address( |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5383 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5384 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5385 | } |
| 5386 | |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5387 | void CodeGeneratorX86::RecordBootImageIntrinsicPatch(HX86ComputeBaseMethodAddress* method_address, |
| 5388 | uint32_t intrinsic_data) { |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5389 | boot_image_other_patches_.emplace_back( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5390 | method_address, /* target_dex_file= */ nullptr, intrinsic_data); |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5391 | __ Bind(&boot_image_other_patches_.back().label); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5392 | } |
| 5393 | |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 5394 | void CodeGeneratorX86::RecordBootImageRelRoPatch(HX86ComputeBaseMethodAddress* method_address, |
| 5395 | uint32_t boot_image_offset) { |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5396 | boot_image_other_patches_.emplace_back( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5397 | method_address, /* target_dex_file= */ nullptr, boot_image_offset); |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5398 | __ Bind(&boot_image_other_patches_.back().label); |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 5399 | } |
| 5400 | |
| Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5401 | void CodeGeneratorX86::RecordBootImageMethodPatch(HInvoke* invoke) { |
| 5402 | size_t index = invoke->IsInvokeInterface() |
| 5403 | ? invoke->AsInvokeInterface()->GetSpecialInputIndex() |
| 5404 | : invoke->AsInvokeStaticOrDirect()->GetSpecialInputIndex(); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5405 | HX86ComputeBaseMethodAddress* method_address = |
| Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5406 | invoke->InputAt(index)->AsX86ComputeBaseMethodAddress(); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5407 | boot_image_method_patches_.emplace_back( |
| Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 5408 | method_address, |
| 5409 | invoke->GetResolvedMethodReference().dex_file, |
| 5410 | invoke->GetResolvedMethodReference().index); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5411 | __ Bind(&boot_image_method_patches_.back().label); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5412 | } |
| 5413 | |
| Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5414 | void CodeGeneratorX86::RecordMethodBssEntryPatch(HInvoke* invoke) { |
| 5415 | size_t index = invoke->IsInvokeInterface() |
| 5416 | ? invoke->AsInvokeInterface()->GetSpecialInputIndex() |
| 5417 | : invoke->AsInvokeStaticOrDirect()->GetSpecialInputIndex(); |
| Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 5418 | DCHECK(IsSameDexFile(GetGraph()->GetDexFile(), *invoke->GetMethodReference().dex_file)); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5419 | HX86ComputeBaseMethodAddress* method_address = |
| Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5420 | invoke->InputAt(index)->AsX86ComputeBaseMethodAddress(); |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5421 | // 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] | 5422 | method_bss_entry_patches_.emplace_back( |
| Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 5423 | method_address, |
| 5424 | invoke->GetMethodReference().dex_file, |
| 5425 | invoke->GetMethodReference().index); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5426 | __ Bind(&method_bss_entry_patches_.back().label); |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5427 | } |
| 5428 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5429 | void CodeGeneratorX86::RecordBootImageTypePatch(HLoadClass* load_class) { |
| 5430 | HX86ComputeBaseMethodAddress* method_address = |
| 5431 | load_class->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 5432 | boot_image_type_patches_.emplace_back( |
| 5433 | method_address, &load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5434 | __ Bind(&boot_image_type_patches_.back().label); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5435 | } |
| 5436 | |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5437 | Label* CodeGeneratorX86::NewTypeBssEntryPatch(HLoadClass* load_class) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5438 | HX86ComputeBaseMethodAddress* method_address = |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 5439 | load_class->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5440 | ArenaDeque<X86PcRelativePatchInfo>* patches = nullptr; |
| 5441 | switch (load_class->GetLoadKind()) { |
| 5442 | case HLoadClass::LoadKind::kBssEntry: |
| 5443 | patches = &type_bss_entry_patches_; |
| 5444 | break; |
| 5445 | case HLoadClass::LoadKind::kBssEntryPublic: |
| 5446 | patches = &public_type_bss_entry_patches_; |
| 5447 | break; |
| 5448 | case HLoadClass::LoadKind::kBssEntryPackage: |
| 5449 | patches = &package_type_bss_entry_patches_; |
| 5450 | break; |
| 5451 | default: |
| 5452 | LOG(FATAL) << "Unexpected load kind: " << load_class->GetLoadKind(); |
| 5453 | UNREACHABLE(); |
| 5454 | } |
| 5455 | patches->emplace_back( |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5456 | method_address, &load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
| Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5457 | return &patches->back().label; |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5458 | } |
| 5459 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5460 | void CodeGeneratorX86::RecordBootImageStringPatch(HLoadString* load_string) { |
| 5461 | HX86ComputeBaseMethodAddress* method_address = |
| 5462 | load_string->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 5463 | boot_image_string_patches_.emplace_back( |
| 5464 | method_address, &load_string->GetDexFile(), load_string->GetStringIndex().index_); |
| 5465 | __ Bind(&boot_image_string_patches_.back().label); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5466 | } |
| 5467 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5468 | Label* CodeGeneratorX86::NewStringBssEntryPatch(HLoadString* load_string) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5469 | HX86ComputeBaseMethodAddress* method_address = |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 5470 | load_string->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5471 | string_bss_entry_patches_.emplace_back( |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5472 | method_address, &load_string->GetDexFile(), load_string->GetStringIndex().index_); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5473 | return &string_bss_entry_patches_.back().label; |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5474 | } |
| 5475 | |
| Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 5476 | void CodeGeneratorX86::RecordBootImageJniEntrypointPatch(HInvokeStaticOrDirect* invoke) { |
| 5477 | HX86ComputeBaseMethodAddress* method_address = |
| 5478 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
| 5479 | boot_image_jni_entrypoint_patches_.emplace_back( |
| 5480 | method_address, |
| 5481 | invoke->GetResolvedMethodReference().dex_file, |
| 5482 | invoke->GetResolvedMethodReference().index); |
| 5483 | __ Bind(&boot_image_jni_entrypoint_patches_.back().label); |
| 5484 | } |
| 5485 | |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5486 | void CodeGeneratorX86::LoadBootImageAddress(Register reg, |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5487 | uint32_t boot_image_reference, |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5488 | HInvokeStaticOrDirect* invoke) { |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5489 | if (GetCompilerOptions().IsBootImage()) { |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5490 | HX86ComputeBaseMethodAddress* method_address = |
| 5491 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
| 5492 | DCHECK(method_address != nullptr); |
| 5493 | Register method_address_reg = |
| 5494 | invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()).AsRegister<Register>(); |
| Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 5495 | __ leal(reg, Address(method_address_reg, CodeGeneratorX86::kPlaceholder32BitOffset)); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5496 | RecordBootImageIntrinsicPatch(method_address, boot_image_reference); |
| Vladimir Marko | a2da9b9 | 2018-10-10 14:21:55 +0100 | [diff] [blame] | 5497 | } else if (GetCompilerOptions().GetCompilePic()) { |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5498 | HX86ComputeBaseMethodAddress* method_address = |
| 5499 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
| 5500 | DCHECK(method_address != nullptr); |
| 5501 | Register method_address_reg = |
| 5502 | invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()).AsRegister<Register>(); |
| Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 5503 | __ movl(reg, Address(method_address_reg, CodeGeneratorX86::kPlaceholder32BitOffset)); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5504 | RecordBootImageRelRoPatch(method_address, boot_image_reference); |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5505 | } else { |
| Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 5506 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5507 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 5508 | DCHECK(!heap->GetBootImageSpaces().empty()); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5509 | const uint8_t* address = heap->GetBootImageSpaces()[0]->Begin() + boot_image_reference; |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5510 | __ movl(reg, Immediate(dchecked_integral_cast<uint32_t>(reinterpret_cast<uintptr_t>(address)))); |
| 5511 | } |
| 5512 | } |
| 5513 | |
| Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 5514 | void CodeGeneratorX86::LoadIntrinsicDeclaringClass(Register reg, HInvokeStaticOrDirect* invoke) { |
| 5515 | DCHECK_NE(invoke->GetIntrinsic(), Intrinsics::kNone); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5516 | if (GetCompilerOptions().IsBootImage()) { |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5517 | // Load the class the same way as for HLoadClass::LoadKind::kBootImageLinkTimePcRelative. |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5518 | HX86ComputeBaseMethodAddress* method_address = |
| 5519 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
| 5520 | DCHECK(method_address != nullptr); |
| 5521 | Register method_address_reg = |
| 5522 | invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()).AsRegister<Register>(); |
| Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 5523 | __ leal(reg, Address(method_address_reg, CodeGeneratorX86::kPlaceholder32BitOffset)); |
| Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 5524 | MethodReference target_method = invoke->GetResolvedMethodReference(); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5525 | dex::TypeIndex type_idx = target_method.dex_file->GetMethodId(target_method.index).class_idx_; |
| 5526 | boot_image_type_patches_.emplace_back(method_address, target_method.dex_file, type_idx.index_); |
| 5527 | __ Bind(&boot_image_type_patches_.back().label); |
| 5528 | } else { |
| Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 5529 | uint32_t boot_image_offset = GetBootImageOffsetOfIntrinsicDeclaringClass(invoke); |
| 5530 | LoadBootImageAddress(reg, boot_image_offset, invoke); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5531 | } |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5532 | } |
| 5533 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5534 | // The label points to the end of the "movl" or another instruction but the literal offset |
| 5535 | // for method patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 5536 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
| 5537 | |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5538 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5539 | inline void CodeGeneratorX86::EmitPcRelativeLinkerPatches( |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 5540 | const ArenaDeque<X86PcRelativePatchInfo>& infos, |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5541 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 5542 | for (const X86PcRelativePatchInfo& info : infos) { |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5543 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5544 | linker_patches->push_back(Factory(literal_offset, |
| 5545 | info.target_dex_file, |
| 5546 | GetMethodAddressOffset(info.method_address), |
| 5547 | info.offset_or_index)); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5548 | } |
| 5549 | } |
| 5550 | |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5551 | template <linker::LinkerPatch (*Factory)(size_t, uint32_t, uint32_t)> |
| 5552 | linker::LinkerPatch NoDexFileAdapter(size_t literal_offset, |
| 5553 | const DexFile* target_dex_file, |
| 5554 | uint32_t pc_insn_offset, |
| 5555 | uint32_t boot_image_offset) { |
| 5556 | DCHECK(target_dex_file == nullptr); // Unused for these patches, should be null. |
| 5557 | return Factory(literal_offset, pc_insn_offset, boot_image_offset); |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 5558 | } |
| 5559 | |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5560 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5561 | DCHECK(linker_patches->empty()); |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 5562 | size_t size = |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5563 | boot_image_method_patches_.size() + |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5564 | method_bss_entry_patches_.size() + |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5565 | boot_image_type_patches_.size() + |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5566 | type_bss_entry_patches_.size() + |
| Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5567 | public_type_bss_entry_patches_.size() + |
| 5568 | package_type_bss_entry_patches_.size() + |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5569 | boot_image_string_patches_.size() + |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5570 | string_bss_entry_patches_.size() + |
| Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 5571 | boot_image_jni_entrypoint_patches_.size() + |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5572 | boot_image_other_patches_.size(); |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 5573 | linker_patches->reserve(size); |
| Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 5574 | if (GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()) { |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5575 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
| 5576 | boot_image_method_patches_, linker_patches); |
| 5577 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
| 5578 | boot_image_type_patches_, linker_patches); |
| 5579 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5580 | boot_image_string_patches_, linker_patches); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5581 | } else { |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5582 | DCHECK(boot_image_method_patches_.empty()); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5583 | DCHECK(boot_image_type_patches_.empty()); |
| 5584 | DCHECK(boot_image_string_patches_.empty()); |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5585 | } |
| 5586 | if (GetCompilerOptions().IsBootImage()) { |
| 5587 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::IntrinsicReferencePatch>>( |
| 5588 | boot_image_other_patches_, linker_patches); |
| 5589 | } else { |
| 5590 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::DataBimgRelRoPatch>>( |
| 5591 | boot_image_other_patches_, linker_patches); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5592 | } |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5593 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 5594 | method_bss_entry_patches_, linker_patches); |
| 5595 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 5596 | type_bss_entry_patches_, linker_patches); |
| Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5597 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::PublicTypeBssEntryPatch>( |
| 5598 | public_type_bss_entry_patches_, linker_patches); |
| 5599 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::PackageTypeBssEntryPatch>( |
| 5600 | package_type_bss_entry_patches_, linker_patches); |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5601 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 5602 | string_bss_entry_patches_, linker_patches); |
| Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 5603 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeJniEntrypointPatch>( |
| 5604 | boot_image_jni_entrypoint_patches_, linker_patches); |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5605 | DCHECK_EQ(size, linker_patches->size()); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5606 | } |
| 5607 | |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5608 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 5609 | Register card, |
| 5610 | Register object, |
| 5611 | Register value, |
| 5612 | bool value_can_be_null) { |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 5613 | NearLabel is_null; |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5614 | if (value_can_be_null) { |
| 5615 | __ testl(value, value); |
| 5616 | __ j(kEqual, &is_null); |
| 5617 | } |
| Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5618 | // Load the address of the card table into `card`. |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5619 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86PointerSize>().Int32Value())); |
| Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5620 | // Calculate the offset (in the card table) of the card corresponding to |
| 5621 | // `object`. |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5622 | __ movl(temp, object); |
| 5623 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
| Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5624 | // Write the `art::gc::accounting::CardTable::kCardDirty` value into the |
| 5625 | // `object`'s card. |
| 5626 | // |
| 5627 | // Register `card` contains the address of the card table. Note that the card |
| 5628 | // table's base is biased during its creation so that it always starts at an |
| 5629 | // address whose least-significant byte is equal to `kCardDirty` (see |
| 5630 | // art::gc::accounting::CardTable::Create). Therefore the MOVB instruction |
| 5631 | // below writes the `kCardDirty` (byte) value into the `object`'s card |
| 5632 | // (located at `card + object >> kCardShift`). |
| 5633 | // |
| 5634 | // This dual use of the value in register `card` (1. to calculate the location |
| 5635 | // of the card to mark; and 2. to load the `kCardDirty` value) saves a load |
| 5636 | // (no need to explicitly load `kCardDirty` as an immediate value). |
| Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 5637 | __ movb(Address(temp, card, TIMES_1, 0), |
| 5638 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5639 | if (value_can_be_null) { |
| 5640 | __ Bind(&is_null); |
| 5641 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5642 | } |
| 5643 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5644 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 5645 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5646 | |
| 5647 | bool object_field_get_with_read_barrier = |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5648 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5649 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5650 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 5651 | kEmitCompilerReadBarrier |
| 5652 | ? LocationSummary::kCallOnSlowPath |
| 5653 | : LocationSummary::kNoCall); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5654 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5655 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5656 | } |
| Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5657 | locations->SetInAt(0, Location::RequiresRegister()); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5658 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5659 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5660 | locations->SetOut(Location::RequiresFpuRegister()); |
| 5661 | } else { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5662 | // The output overlaps in case of long: we don't want the low move |
| 5663 | // to overwrite the object's location. Likewise, in the case of |
| 5664 | // an object field get with read barriers enabled, we do not want |
| 5665 | // the move to overwrite the object's location, as we need it to emit |
| 5666 | // the read barrier. |
| 5667 | locations->SetOut( |
| 5668 | Location::RequiresRegister(), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5669 | (object_field_get_with_read_barrier || instruction->GetType() == DataType::Type::kInt64) ? |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5670 | Location::kOutputOverlap : |
| 5671 | Location::kNoOutputOverlap); |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5672 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5673 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5674 | if (field_info.IsVolatile() && (field_info.GetFieldType() == DataType::Type::kInt64)) { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5675 | // Long values can be loaded atomically into an XMM using movsd. |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5676 | // So we use an XMM register as a temp to achieve atomicity (first |
| 5677 | // load the temp into the XMM and then copy the XMM into the |
| 5678 | // output, 32 bits at a time). |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5679 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 5680 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5681 | } |
| 5682 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5683 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 5684 | const FieldInfo& field_info) { |
| 5685 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5686 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5687 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5688 | Location base_loc = locations->InAt(0); |
| 5689 | Register base = base_loc.AsRegister<Register>(); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5690 | Location out = locations->Out(); |
| 5691 | bool is_volatile = field_info.IsVolatile(); |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5692 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 5693 | DataType::Type load_type = instruction->GetType(); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5694 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5695 | |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5696 | switch (load_type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5697 | case DataType::Type::kBool: |
| 5698 | case DataType::Type::kUint8: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5699 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5700 | break; |
| 5701 | } |
| 5702 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5703 | case DataType::Type::kInt8: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5704 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5705 | break; |
| 5706 | } |
| 5707 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5708 | case DataType::Type::kUint16: { |
| 5709 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5710 | break; |
| 5711 | } |
| 5712 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5713 | case DataType::Type::kInt16: { |
| 5714 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5715 | break; |
| 5716 | } |
| 5717 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5718 | case DataType::Type::kInt32: |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5719 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5720 | break; |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5721 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5722 | case DataType::Type::kReference: { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5723 | // /* HeapReference<Object> */ out = *(base + offset) |
| 5724 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5725 | // Note that a potential implicit null check is handled in this |
| 5726 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 5727 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5728 | instruction, out, base, offset, /* needs_null_check= */ true); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5729 | if (is_volatile) { |
| 5730 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5731 | } |
| 5732 | } else { |
| 5733 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| 5734 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5735 | if (is_volatile) { |
| 5736 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5737 | } |
| 5738 | // If read barriers are enabled, emit read barriers other than |
| 5739 | // Baker's using a slow path (and also unpoison the loaded |
| 5740 | // reference, if heap poisoning is enabled). |
| 5741 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 5742 | } |
| 5743 | break; |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5744 | } |
| 5745 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5746 | case DataType::Type::kInt64: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5747 | if (is_volatile) { |
| 5748 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 5749 | __ movsd(temp, Address(base, offset)); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5750 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5751 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 5752 | __ psrlq(temp, Immediate(32)); |
| 5753 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 5754 | } else { |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5755 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5756 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5757 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5758 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 5759 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5760 | break; |
| 5761 | } |
| 5762 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5763 | case DataType::Type::kFloat32: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5764 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5765 | break; |
| 5766 | } |
| 5767 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5768 | case DataType::Type::kFloat64: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5769 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5770 | break; |
| 5771 | } |
| 5772 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5773 | case DataType::Type::kUint32: |
| 5774 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5775 | case DataType::Type::kVoid: |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5776 | LOG(FATAL) << "Unreachable type " << load_type; |
| Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5777 | UNREACHABLE(); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5778 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5779 | |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5780 | if (load_type == DataType::Type::kReference || load_type == DataType::Type::kInt64) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5781 | // Potential implicit null checks, in the case of reference or |
| 5782 | // long fields, are handled in the previous switch statement. |
| 5783 | } else { |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5784 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5785 | } |
| 5786 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5787 | if (is_volatile) { |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5788 | if (load_type == DataType::Type::kReference) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5789 | // Memory barriers, in the case of references, are also handled |
| 5790 | // in the previous switch statement. |
| 5791 | } else { |
| 5792 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5793 | } |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5794 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5795 | } |
| 5796 | |
| 5797 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 5798 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5799 | |
| 5800 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5801 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5802 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5803 | bool is_volatile = field_info.IsVolatile(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5804 | DataType::Type field_type = field_info.GetFieldType(); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5805 | bool is_byte_type = DataType::Size(field_type) == 1u; |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5806 | |
| 5807 | // The register allocator does not support multiple |
| 5808 | // inputs that die at entry with one in a specific register. |
| 5809 | if (is_byte_type) { |
| 5810 | // Ensure the value is in a byte register. |
| 5811 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5812 | } else if (DataType::IsFloatingPointType(field_type)) { |
| 5813 | if (is_volatile && field_type == DataType::Type::kFloat64) { |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5814 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 5815 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 5816 | } else { |
| 5817 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 5818 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5819 | } else if (is_volatile && field_type == DataType::Type::kInt64) { |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5820 | // 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] | 5821 | locations->SetInAt(1, Location::RequiresRegister()); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5822 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5823 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 5824 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 5825 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 5826 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 5827 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 5828 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 5829 | locations->AddTemp(Location::RequiresFpuRegister()); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5830 | } else { |
| 5831 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5832 | |
| 5833 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 5834 | // Temporary registers for the write barrier. |
| 5835 | locations->AddTemp(Location::RequiresRegister()); // May be used for reference poisoning too. |
| 5836 | // Ensure the card is in a byte register. |
| 5837 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 5838 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5839 | } |
| 5840 | } |
| 5841 | |
| 5842 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
| Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5843 | uint32_t value_index, |
| 5844 | DataType::Type field_type, |
| 5845 | Address field_addr, |
| 5846 | Register base, |
| 5847 | bool is_volatile, |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5848 | bool value_can_be_null) { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5849 | LocationSummary* locations = instruction->GetLocations(); |
| Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5850 | Location value = locations->InAt(value_index); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5851 | bool needs_write_barrier = |
| Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5852 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(value_index)); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5853 | |
| 5854 | if (is_volatile) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5855 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5856 | } |
| 5857 | |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5858 | bool maybe_record_implicit_null_check_done = false; |
| 5859 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5860 | switch (field_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5861 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5862 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5863 | case DataType::Type::kInt8: { |
| Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5864 | if (value.IsConstant()) { |
| 5865 | __ movb(field_addr, Immediate(CodeGenerator::GetInt8ValueOf(value.GetConstant()))); |
| 5866 | } else { |
| 5867 | __ movb(field_addr, value.AsRegister<ByteRegister>()); |
| 5868 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5869 | break; |
| 5870 | } |
| 5871 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5872 | case DataType::Type::kUint16: |
| 5873 | case DataType::Type::kInt16: { |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5874 | if (value.IsConstant()) { |
| Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5875 | __ movw(field_addr, Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5876 | } else { |
| Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5877 | __ movw(field_addr, value.AsRegister<Register>()); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5878 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5879 | break; |
| 5880 | } |
| 5881 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5882 | case DataType::Type::kInt32: |
| 5883 | case DataType::Type::kReference: { |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5884 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 5885 | // Note that in the case where `value` is a null reference, |
| 5886 | // we do not enter this block, as the reference does not |
| 5887 | // need poisoning. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5888 | DCHECK_EQ(field_type, DataType::Type::kReference); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5889 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5890 | __ movl(temp, value.AsRegister<Register>()); |
| 5891 | __ PoisonHeapReference(temp); |
| Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5892 | __ movl(field_addr, temp); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5893 | } else if (value.IsConstant()) { |
| 5894 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5895 | __ movl(field_addr, Immediate(v)); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5896 | } else { |
| Nicolas Geoffray | 0397163 | 2016-03-17 10:44:24 +0000 | [diff] [blame] | 5897 | DCHECK(value.IsRegister()) << value; |
| Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5898 | __ movl(field_addr, value.AsRegister<Register>()); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5899 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5900 | break; |
| 5901 | } |
| 5902 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5903 | case DataType::Type::kInt64: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5904 | if (is_volatile) { |
| 5905 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 5906 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 5907 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 5908 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 5909 | __ punpckldq(temp1, temp2); |
| Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5910 | __ movsd(field_addr, temp1); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5911 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5912 | } else if (value.IsConstant()) { |
| 5913 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5914 | __ movl(field_addr, Immediate(Low32Bits(v))); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5915 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5916 | __ movl(field_addr.displaceBy(kX86WordSize), Immediate(High32Bits(v))); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5917 | } else { |
| Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5918 | __ movl(field_addr, value.AsRegisterPairLow<Register>()); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5919 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5920 | __ movl(field_addr.displaceBy(kX86WordSize), value.AsRegisterPairHigh<Register>()); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5921 | } |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5922 | maybe_record_implicit_null_check_done = true; |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5923 | break; |
| 5924 | } |
| 5925 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5926 | case DataType::Type::kFloat32: { |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5927 | if (value.IsConstant()) { |
| 5928 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5929 | __ movl(field_addr, Immediate(v)); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5930 | } else { |
| Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5931 | __ movss(field_addr, value.AsFpuRegister<XmmRegister>()); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5932 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5933 | break; |
| 5934 | } |
| 5935 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5936 | case DataType::Type::kFloat64: { |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5937 | if (value.IsConstant()) { |
| Andra Danciu | c992e42 | 2020-09-16 08:12:02 +0000 | [diff] [blame] | 5938 | DCHECK(!is_volatile); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5939 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5940 | __ movl(field_addr, Immediate(Low32Bits(v))); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5941 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5942 | __ movl(field_addr.displaceBy(kX86WordSize), Immediate(High32Bits(v))); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5943 | maybe_record_implicit_null_check_done = true; |
| 5944 | } else { |
| Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5945 | __ movsd(field_addr, value.AsFpuRegister<XmmRegister>()); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5946 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5947 | break; |
| 5948 | } |
| 5949 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5950 | case DataType::Type::kUint32: |
| 5951 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5952 | case DataType::Type::kVoid: |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5953 | LOG(FATAL) << "Unreachable type " << field_type; |
| 5954 | UNREACHABLE(); |
| 5955 | } |
| 5956 | |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5957 | if (!maybe_record_implicit_null_check_done) { |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5958 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5959 | } |
| 5960 | |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5961 | if (needs_write_barrier) { |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5962 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5963 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5964 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5965 | } |
| 5966 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5967 | if (is_volatile) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5968 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5969 | } |
| 5970 | } |
| 5971 | |
| Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5972 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
| 5973 | const FieldInfo& field_info, |
| 5974 | bool value_can_be_null) { |
| 5975 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5976 | |
| 5977 | LocationSummary* locations = instruction->GetLocations(); |
| 5978 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 5979 | bool is_volatile = field_info.IsVolatile(); |
| 5980 | DataType::Type field_type = field_info.GetFieldType(); |
| 5981 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5982 | |
| 5983 | Address field_addr(base, offset); |
| 5984 | |
| 5985 | HandleFieldSet(instruction, |
| 5986 | /* value_index= */ 1, |
| 5987 | field_type, |
| 5988 | field_addr, |
| 5989 | base, |
| 5990 | is_volatile, |
| 5991 | value_can_be_null); |
| 5992 | } |
| 5993 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5994 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5995 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5996 | } |
| 5997 | |
| 5998 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5999 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6000 | } |
| 6001 | |
| 6002 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 6003 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 6004 | } |
| 6005 | |
| 6006 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 6007 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6008 | } |
| 6009 | |
| 6010 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 6011 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 6012 | } |
| 6013 | |
| 6014 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 6015 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6016 | } |
| 6017 | |
| 6018 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 6019 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6020 | } |
| 6021 | |
| 6022 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 6023 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6024 | } |
| 6025 | |
| Vladimir Marko | 552a134 | 2017-10-31 10:56:47 +0000 | [diff] [blame] | 6026 | void LocationsBuilderX86::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 6027 | codegen_->CreateStringBuilderAppendLocations(instruction, Location::RegisterLocation(EAX)); |
| 6028 | } |
| 6029 | |
| 6030 | void InstructionCodeGeneratorX86::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 6031 | __ movl(EAX, Immediate(instruction->GetFormat()->GetValue())); |
| 6032 | codegen_->InvokeRuntime(kQuickStringBuilderAppend, instruction, instruction->GetDexPc()); |
| 6033 | } |
| 6034 | |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6035 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 6036 | HUnresolvedInstanceFieldGet* instruction) { |
| 6037 | FieldAccessCallingConventionX86 calling_convention; |
| 6038 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6039 | instruction, instruction->GetFieldType(), calling_convention); |
| 6040 | } |
| 6041 | |
| 6042 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 6043 | HUnresolvedInstanceFieldGet* instruction) { |
| 6044 | FieldAccessCallingConventionX86 calling_convention; |
| 6045 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6046 | instruction->GetFieldType(), |
| 6047 | instruction->GetFieldIndex(), |
| 6048 | instruction->GetDexPc(), |
| 6049 | calling_convention); |
| 6050 | } |
| 6051 | |
| 6052 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 6053 | HUnresolvedInstanceFieldSet* instruction) { |
| 6054 | FieldAccessCallingConventionX86 calling_convention; |
| 6055 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6056 | instruction, instruction->GetFieldType(), calling_convention); |
| 6057 | } |
| 6058 | |
| 6059 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 6060 | HUnresolvedInstanceFieldSet* instruction) { |
| 6061 | FieldAccessCallingConventionX86 calling_convention; |
| 6062 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6063 | instruction->GetFieldType(), |
| 6064 | instruction->GetFieldIndex(), |
| 6065 | instruction->GetDexPc(), |
| 6066 | calling_convention); |
| 6067 | } |
| 6068 | |
| 6069 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 6070 | HUnresolvedStaticFieldGet* instruction) { |
| 6071 | FieldAccessCallingConventionX86 calling_convention; |
| 6072 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6073 | instruction, instruction->GetFieldType(), calling_convention); |
| 6074 | } |
| 6075 | |
| 6076 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 6077 | HUnresolvedStaticFieldGet* instruction) { |
| 6078 | FieldAccessCallingConventionX86 calling_convention; |
| 6079 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6080 | instruction->GetFieldType(), |
| 6081 | instruction->GetFieldIndex(), |
| 6082 | instruction->GetDexPc(), |
| 6083 | calling_convention); |
| 6084 | } |
| 6085 | |
| 6086 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 6087 | HUnresolvedStaticFieldSet* instruction) { |
| 6088 | FieldAccessCallingConventionX86 calling_convention; |
| 6089 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6090 | instruction, instruction->GetFieldType(), calling_convention); |
| 6091 | } |
| 6092 | |
| 6093 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 6094 | HUnresolvedStaticFieldSet* instruction) { |
| 6095 | FieldAccessCallingConventionX86 calling_convention; |
| 6096 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6097 | instruction->GetFieldType(), |
| 6098 | instruction->GetFieldIndex(), |
| 6099 | instruction->GetDexPc(), |
| 6100 | calling_convention); |
| 6101 | } |
| 6102 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6103 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6104 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 6105 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 6106 | ? Location::RequiresRegister() |
| 6107 | : Location::Any(); |
| 6108 | locations->SetInAt(0, loc); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6109 | } |
| 6110 | |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6111 | void CodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 6112 | if (CanMoveNullCheckToUser(instruction)) { |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6113 | return; |
| 6114 | } |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 6115 | LocationSummary* locations = instruction->GetLocations(); |
| 6116 | Location obj = locations->InAt(0); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6117 | |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 6118 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6119 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 6120 | } |
| 6121 | |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6122 | void CodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6123 | SlowPathCode* slow_path = new (GetScopedAllocator()) NullCheckSlowPathX86(instruction); |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6124 | AddSlowPath(slow_path); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6125 | |
| 6126 | LocationSummary* locations = instruction->GetLocations(); |
| 6127 | Location obj = locations->InAt(0); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6128 | |
| 6129 | if (obj.IsRegister()) { |
| Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 6130 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 6131 | } else if (obj.IsStackSlot()) { |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6132 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 6133 | } else { |
| 6134 | DCHECK(obj.IsConstant()) << obj; |
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 6135 | DCHECK(obj.GetConstant()->IsNullConstant()); |
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 6136 | __ jmp(slow_path->GetEntryLabel()); |
| 6137 | return; |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6138 | } |
| 6139 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6140 | } |
| 6141 | |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 6142 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6143 | codegen_->GenerateNullCheck(instruction); |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 6144 | } |
| 6145 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6146 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6147 | bool object_array_get_with_read_barrier = |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6148 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 6149 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6150 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 6151 | object_array_get_with_read_barrier |
| 6152 | ? LocationSummary::kCallOnSlowPath |
| 6153 | : LocationSummary::kNoCall); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6154 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6155 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6156 | } |
| Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 6157 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6158 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6159 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 6160 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6161 | } else { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6162 | // The output overlaps in case of long: we don't want the low move |
| 6163 | // to overwrite the array's location. Likewise, in the case of an |
| 6164 | // object array get with read barriers enabled, we do not want the |
| 6165 | // move to overwrite the array's location, as we need it to emit |
| 6166 | // the read barrier. |
| 6167 | locations->SetOut( |
| 6168 | Location::RequiresRegister(), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6169 | (instruction->GetType() == DataType::Type::kInt64 || object_array_get_with_read_barrier) |
| 6170 | ? Location::kOutputOverlap |
| 6171 | : Location::kNoOutputOverlap); |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 6172 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6173 | } |
| 6174 | |
| 6175 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 6176 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6177 | Location obj_loc = locations->InAt(0); |
| 6178 | Register obj = obj_loc.AsRegister<Register>(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6179 | Location index = locations->InAt(1); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6180 | Location out_loc = locations->Out(); |
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6181 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6182 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6183 | DataType::Type type = instruction->GetType(); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6184 | switch (type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6185 | case DataType::Type::kBool: |
| 6186 | case DataType::Type::kUint8: { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6187 | Register out = out_loc.AsRegister<Register>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6188 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6189 | break; |
| 6190 | } |
| 6191 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6192 | case DataType::Type::kInt8: { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6193 | Register out = out_loc.AsRegister<Register>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6194 | __ movsxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6195 | break; |
| 6196 | } |
| 6197 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6198 | case DataType::Type::kUint16: { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6199 | Register out = out_loc.AsRegister<Register>(); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6200 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 6201 | // Branch cases into compressed and uncompressed for each index's type. |
| 6202 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 6203 | NearLabel done, not_compressed; |
| Vladimir Marko | 3c89d42 | 2017-02-17 11:30:23 +0000 | [diff] [blame] | 6204 | __ testb(Address(obj, count_offset), Immediate(1)); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6205 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6206 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 6207 | "Expecting 0=compressed, 1=uncompressed"); |
| 6208 | __ j(kNotZero, ¬_compressed); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6209 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| 6210 | __ jmp(&done); |
| 6211 | __ Bind(¬_compressed); |
| 6212 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 6213 | __ Bind(&done); |
| 6214 | } else { |
| 6215 | // Common case for charAt of array of char or when string compression's |
| 6216 | // feature is turned off. |
| 6217 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 6218 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6219 | break; |
| 6220 | } |
| 6221 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6222 | case DataType::Type::kInt16: { |
| 6223 | Register out = out_loc.AsRegister<Register>(); |
| 6224 | __ movsxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 6225 | break; |
| 6226 | } |
| 6227 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6228 | case DataType::Type::kInt32: { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6229 | Register out = out_loc.AsRegister<Register>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6230 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6231 | break; |
| 6232 | } |
| 6233 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6234 | case DataType::Type::kReference: { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6235 | static_assert( |
| 6236 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6237 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6238 | // /* HeapReference<Object> */ out = |
| 6239 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 6240 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6241 | // Note that a potential implicit null check is handled in this |
| 6242 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 6243 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6244 | instruction, out_loc, obj, data_offset, index, /* needs_null_check= */ true); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6245 | } else { |
| 6246 | Register out = out_loc.AsRegister<Register>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6247 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| 6248 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6249 | // If read barriers are enabled, emit read barriers other than |
| 6250 | // Baker's using a slow path (and also unpoison the loaded |
| 6251 | // reference, if heap poisoning is enabled). |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6252 | if (index.IsConstant()) { |
| 6253 | uint32_t offset = |
| 6254 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6255 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 6256 | } else { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6257 | codegen_->MaybeGenerateReadBarrierSlow( |
| 6258 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 6259 | } |
| 6260 | } |
| 6261 | break; |
| 6262 | } |
| 6263 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6264 | case DataType::Type::kInt64: { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6265 | DCHECK_NE(obj, out_loc.AsRegisterPairLow<Register>()); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6266 | __ movl(out_loc.AsRegisterPairLow<Register>(), |
| 6267 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
| 6268 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6269 | __ movl(out_loc.AsRegisterPairHigh<Register>(), |
| 6270 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset + kX86WordSize)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6271 | break; |
| 6272 | } |
| 6273 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6274 | case DataType::Type::kFloat32: { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6275 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6276 | __ movss(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6277 | break; |
| 6278 | } |
| 6279 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6280 | case DataType::Type::kFloat64: { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6281 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6282 | __ movsd(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6283 | break; |
| 6284 | } |
| 6285 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 6286 | case DataType::Type::kUint32: |
| 6287 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6288 | case DataType::Type::kVoid: |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6289 | LOG(FATAL) << "Unreachable type " << type; |
| Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 6290 | UNREACHABLE(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6291 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6292 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6293 | if (type == DataType::Type::kReference || type == DataType::Type::kInt64) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6294 | // Potential implicit null checks, in the case of reference or |
| 6295 | // long arrays, are handled in the previous switch statement. |
| 6296 | } else { |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6297 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6298 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6299 | } |
| 6300 | |
| 6301 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6302 | DataType::Type value_type = instruction->GetComponentType(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6303 | |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6304 | bool needs_write_barrier = |
| 6305 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6306 | bool needs_type_check = instruction->NeedsTypeCheck(); |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6307 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6308 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 6309 | instruction, |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6310 | needs_type_check ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 6311 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6312 | bool is_byte_type = DataType::Size(value_type) == 1u; |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6313 | // We need the inputs to be different than the output in case of long operation. |
| 6314 | // In case of a byte operation, the register allocator does not support multiple |
| 6315 | // inputs that die at entry with one in a specific register. |
| 6316 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6317 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 6318 | if (is_byte_type) { |
| 6319 | // Ensure the value is in a byte register. |
| 6320 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6321 | } else if (DataType::IsFloatingPointType(value_type)) { |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6322 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6323 | } else { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6324 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 6325 | } |
| 6326 | if (needs_write_barrier) { |
| 6327 | // Temporary registers for the write barrier. |
| 6328 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 6329 | // Ensure the card is in a byte register. |
| Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 6330 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6331 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6332 | } |
| 6333 | |
| 6334 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 6335 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6336 | Location array_loc = locations->InAt(0); |
| 6337 | Register array = array_loc.AsRegister<Register>(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6338 | Location index = locations->InAt(1); |
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 6339 | Location value = locations->InAt(2); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6340 | DataType::Type value_type = instruction->GetComponentType(); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6341 | bool needs_type_check = instruction->NeedsTypeCheck(); |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6342 | bool needs_write_barrier = |
| 6343 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6344 | |
| 6345 | switch (value_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6346 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6347 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6348 | case DataType::Type::kInt8: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6349 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6350 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_1, offset); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6351 | if (value.IsRegister()) { |
| 6352 | __ movb(address, value.AsRegister<ByteRegister>()); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6353 | } else { |
| Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 6354 | __ movb(address, Immediate(CodeGenerator::GetInt8ValueOf(value.GetConstant()))); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6355 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6356 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6357 | break; |
| 6358 | } |
| 6359 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6360 | case DataType::Type::kUint16: |
| 6361 | case DataType::Type::kInt16: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6362 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6363 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_2, offset); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6364 | if (value.IsRegister()) { |
| 6365 | __ movw(address, value.AsRegister<Register>()); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6366 | } else { |
| Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 6367 | __ movw(address, Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6368 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6369 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6370 | break; |
| 6371 | } |
| 6372 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6373 | case DataType::Type::kReference: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6374 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6375 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6376 | |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6377 | if (!value.IsRegister()) { |
| 6378 | // Just setting null. |
| 6379 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 6380 | DCHECK(value.IsConstant()) << value; |
| 6381 | __ movl(address, Immediate(0)); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6382 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6383 | DCHECK(!needs_write_barrier); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6384 | DCHECK(!needs_type_check); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6385 | break; |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6386 | } |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6387 | |
| 6388 | DCHECK(needs_write_barrier); |
| 6389 | Register register_value = value.AsRegister<Register>(); |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6390 | Location temp_loc = locations->GetTemp(0); |
| 6391 | Register temp = temp_loc.AsRegister<Register>(); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6392 | |
| 6393 | bool can_value_be_null = instruction->GetValueCanBeNull(); |
| 6394 | NearLabel do_store; |
| 6395 | if (can_value_be_null) { |
| 6396 | __ testl(register_value, register_value); |
| 6397 | __ j(kEqual, &do_store); |
| 6398 | } |
| 6399 | |
| 6400 | SlowPathCode* slow_path = nullptr; |
| 6401 | if (needs_type_check) { |
| Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6402 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathX86(instruction); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6403 | codegen_->AddSlowPath(slow_path); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6404 | |
| 6405 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6406 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6407 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6408 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6409 | // Note that when Baker read barriers are enabled, the type |
| 6410 | // checks are performed without read barriers. This is fine, |
| 6411 | // even in the case where a class object is in the from-space |
| 6412 | // after the flip, as a comparison involving such a type would |
| 6413 | // not produce a false positive; it may of course produce a |
| 6414 | // false negative, in which case we would take the ArraySet |
| 6415 | // slow path. |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6416 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6417 | // /* HeapReference<Class> */ temp = array->klass_ |
| 6418 | __ movl(temp, Address(array, class_offset)); |
| 6419 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6420 | __ MaybeUnpoisonHeapReference(temp); |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6421 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6422 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 6423 | __ movl(temp, Address(temp, component_offset)); |
| 6424 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 6425 | // nor the object reference in `register_value->klass`, as |
| 6426 | // we are comparing two poisoned references. |
| 6427 | __ cmpl(temp, Address(register_value, class_offset)); |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6428 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6429 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6430 | NearLabel do_put; |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6431 | __ j(kEqual, &do_put); |
| 6432 | // If heap poisoning is enabled, the `temp` reference has |
| 6433 | // not been unpoisoned yet; unpoison it now. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6434 | __ MaybeUnpoisonHeapReference(temp); |
| 6435 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6436 | // If heap poisoning is enabled, no need to unpoison the |
| 6437 | // heap reference loaded below, as it is only used for a |
| 6438 | // comparison with null. |
| 6439 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 6440 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6441 | __ Bind(&do_put); |
| 6442 | } else { |
| 6443 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6444 | } |
| Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6445 | } |
| 6446 | |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6447 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 6448 | codegen_->MarkGCCard( |
| 6449 | temp, card, array, value.AsRegister<Register>(), /* value_can_be_null= */ false); |
| 6450 | |
| 6451 | if (can_value_be_null) { |
| 6452 | DCHECK(do_store.IsLinked()); |
| 6453 | __ Bind(&do_store); |
| 6454 | } |
| 6455 | |
| 6456 | Register source = register_value; |
| Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6457 | if (kPoisonHeapReferences) { |
| 6458 | __ movl(temp, register_value); |
| 6459 | __ PoisonHeapReference(temp); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6460 | source = temp; |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6461 | } |
| 6462 | |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6463 | __ movl(address, source); |
| 6464 | |
| 6465 | if (can_value_be_null || !needs_type_check) { |
| 6466 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6467 | } |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6468 | |
| Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6469 | if (slow_path != nullptr) { |
| 6470 | __ Bind(slow_path->GetExitLabel()); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6471 | } |
| 6472 | |
| 6473 | break; |
| 6474 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6475 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6476 | case DataType::Type::kInt32: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6477 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6478 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6479 | if (value.IsRegister()) { |
| 6480 | __ movl(address, value.AsRegister<Register>()); |
| 6481 | } else { |
| 6482 | DCHECK(value.IsConstant()) << value; |
| 6483 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 6484 | __ movl(address, Immediate(v)); |
| 6485 | } |
| 6486 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6487 | break; |
| 6488 | } |
| 6489 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6490 | case DataType::Type::kInt64: { |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6491 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6492 | if (value.IsRegisterPair()) { |
| 6493 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 6494 | value.AsRegisterPairLow<Register>()); |
| 6495 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6496 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 6497 | value.AsRegisterPairHigh<Register>()); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6498 | } else { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6499 | DCHECK(value.IsConstant()); |
| 6500 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
| 6501 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 6502 | Immediate(Low32Bits(val))); |
| 6503 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6504 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 6505 | Immediate(High32Bits(val))); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6506 | } |
| 6507 | break; |
| 6508 | } |
| 6509 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6510 | case DataType::Type::kFloat32: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6511 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6512 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6513 | if (value.IsFpuRegister()) { |
| 6514 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 6515 | } else { |
| 6516 | DCHECK(value.IsConstant()); |
| 6517 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 6518 | __ movl(address, Immediate(v)); |
| 6519 | } |
| 6520 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6521 | break; |
| 6522 | } |
| 6523 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6524 | case DataType::Type::kFloat64: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6525 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6526 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6527 | if (value.IsFpuRegister()) { |
| 6528 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 6529 | } else { |
| 6530 | DCHECK(value.IsConstant()); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6531 | Address address_hi = |
| 6532 | CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset + kX86WordSize); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6533 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 6534 | __ movl(address, Immediate(Low32Bits(v))); |
| 6535 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6536 | __ movl(address_hi, Immediate(High32Bits(v))); |
| 6537 | } |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6538 | break; |
| 6539 | } |
| 6540 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 6541 | case DataType::Type::kUint32: |
| 6542 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6543 | case DataType::Type::kVoid: |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6544 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 6545 | UNREACHABLE(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6546 | } |
| 6547 | } |
| 6548 | |
| 6549 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6550 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 6551 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6552 | if (!instruction->IsEmittedAtUseSite()) { |
| 6553 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6554 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6555 | } |
| 6556 | |
| 6557 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6558 | if (instruction->IsEmittedAtUseSite()) { |
| 6559 | return; |
| 6560 | } |
| 6561 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6562 | LocationSummary* locations = instruction->GetLocations(); |
| Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 6563 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6564 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 6565 | Register out = locations->Out().AsRegister<Register>(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6566 | __ movl(out, Address(obj, offset)); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6567 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6568 | // Mask out most significant bit in case the array is String's array of char. |
| 6569 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6570 | __ shrl(out, Immediate(1)); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6571 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6572 | } |
| 6573 | |
| 6574 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6575 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6576 | InvokeRuntimeCallingConvention calling_convention; |
| 6577 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6578 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 6579 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 6580 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6581 | HInstruction* length = instruction->InputAt(1); |
| 6582 | if (!length->IsEmittedAtUseSite()) { |
| 6583 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 6584 | } |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6585 | // Need register to see array's length. |
| 6586 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 6587 | locations->AddTemp(Location::RequiresRegister()); |
| 6588 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6589 | } |
| 6590 | |
| 6591 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6592 | const bool is_string_compressed_char_at = |
| 6593 | mirror::kUseStringCompression && instruction->IsStringCharAt(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6594 | LocationSummary* locations = instruction->GetLocations(); |
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 6595 | Location index_loc = locations->InAt(0); |
| 6596 | Location length_loc = locations->InAt(1); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6597 | SlowPathCode* slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6598 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathX86(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6599 | |
| Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 6600 | if (length_loc.IsConstant()) { |
| 6601 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 6602 | if (index_loc.IsConstant()) { |
| 6603 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 6604 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 6605 | if (index < 0 || index >= length) { |
| 6606 | codegen_->AddSlowPath(slow_path); |
| 6607 | __ jmp(slow_path->GetEntryLabel()); |
| 6608 | } else { |
| 6609 | // Some optimization after BCE may have generated this, and we should not |
| 6610 | // generate a bounds check if it is a valid range. |
| 6611 | } |
| 6612 | return; |
| 6613 | } |
| 6614 | |
| 6615 | // We have to reverse the jump condition because the length is the constant. |
| 6616 | Register index_reg = index_loc.AsRegister<Register>(); |
| 6617 | __ cmpl(index_reg, Immediate(length)); |
| 6618 | codegen_->AddSlowPath(slow_path); |
| 6619 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 6620 | } else { |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6621 | HInstruction* array_length = instruction->InputAt(1); |
| 6622 | if (array_length->IsEmittedAtUseSite()) { |
| 6623 | // Address the length field in the array. |
| 6624 | DCHECK(array_length->IsArrayLength()); |
| 6625 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 6626 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 6627 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6628 | if (is_string_compressed_char_at) { |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6629 | // TODO: if index_loc.IsConstant(), compare twice the index (to compensate for |
| 6630 | // the string compression flag) with the in-memory length and avoid the temporary. |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6631 | Register length_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 6632 | __ movl(length_reg, array_len); |
| 6633 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6634 | __ shrl(length_reg, Immediate(1)); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6635 | codegen_->GenerateIntCompare(length_reg, index_loc); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6636 | } else { |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6637 | // Checking bounds for general case: |
| 6638 | // Array of char or string's array with feature compression off. |
| 6639 | if (index_loc.IsConstant()) { |
| 6640 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 6641 | __ cmpl(array_len, Immediate(value)); |
| 6642 | } else { |
| 6643 | __ cmpl(array_len, index_loc.AsRegister<Register>()); |
| 6644 | } |
| 6645 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6646 | } |
| Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 6647 | } else { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6648 | codegen_->GenerateIntCompare(length_loc, index_loc); |
| Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 6649 | } |
| 6650 | codegen_->AddSlowPath(slow_path); |
| 6651 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 6652 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6653 | } |
| 6654 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6655 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6656 | LOG(FATAL) << "Unreachable"; |
| Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6657 | } |
| 6658 | |
| 6659 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
| Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 6660 | if (instruction->GetNext()->IsSuspendCheck() && |
| 6661 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 6662 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 6663 | // The back edge will generate the suspend check. |
| 6664 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 6665 | } |
| 6666 | |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6667 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 6668 | } |
| 6669 | |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6670 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6671 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6672 | instruction, LocationSummary::kCallOnSlowPath); |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 6673 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 6674 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 6675 | // registers in full width (since the runtime only saves/restores lower part). |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6676 | locations->SetCustomSlowPathCallerSaves( |
| 6677 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6678 | } |
| 6679 | |
| 6680 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6681 | HBasicBlock* block = instruction->GetBlock(); |
| 6682 | if (block->GetLoopInformation() != nullptr) { |
| 6683 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 6684 | // The back edge will generate the suspend check. |
| 6685 | return; |
| 6686 | } |
| 6687 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 6688 | // The goto will generate the suspend check. |
| 6689 | return; |
| 6690 | } |
| 6691 | GenerateSuspendCheck(instruction, nullptr); |
| 6692 | } |
| 6693 | |
| 6694 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 6695 | HBasicBlock* successor) { |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6696 | SuspendCheckSlowPathX86* slow_path = |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6697 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 6698 | if (slow_path == nullptr) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6699 | slow_path = |
| 6700 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathX86(instruction, successor); |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6701 | instruction->SetSlowPath(slow_path); |
| 6702 | codegen_->AddSlowPath(slow_path); |
| 6703 | if (successor != nullptr) { |
| 6704 | DCHECK(successor->IsLoopHeader()); |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6705 | } |
| 6706 | } else { |
| 6707 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 6708 | } |
| 6709 | |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6710 | __ fs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86PointerSize>().Int32Value()), |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6711 | Immediate(0)); |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6712 | if (successor == nullptr) { |
| 6713 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6714 | __ Bind(slow_path->GetReturnLabel()); |
| 6715 | } else { |
| 6716 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 6717 | __ jmp(slow_path->GetEntryLabel()); |
| 6718 | } |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6719 | } |
| 6720 | |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6721 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 6722 | return codegen_->GetAssembler(); |
| 6723 | } |
| 6724 | |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6725 | void ParallelMoveResolverX86::MoveMemoryToMemory(int dst, int src, int number_of_words) { |
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6726 | ScratchRegisterScope ensure_scratch( |
| 6727 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 6728 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 6729 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6730 | |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6731 | // Now that temp register is available (possibly spilled), move blocks of memory. |
| 6732 | for (int i = 0; i < number_of_words; i++) { |
| 6733 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 6734 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 6735 | stack_offset += kX86WordSize; |
| 6736 | } |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6737 | } |
| 6738 | |
| 6739 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6740 | MoveOperands* move = moves_[index]; |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6741 | Location source = move->GetSource(); |
| 6742 | Location destination = move->GetDestination(); |
| 6743 | |
| 6744 | if (source.IsRegister()) { |
| 6745 | if (destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6746 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6747 | } else if (destination.IsFpuRegister()) { |
| 6748 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6749 | } else { |
| 6750 | DCHECK(destination.IsStackSlot()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6751 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6752 | } |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6753 | } else if (source.IsRegisterPair()) { |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 6754 | if (destination.IsRegisterPair()) { |
| 6755 | __ movl(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 6756 | DCHECK_NE(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>()); |
| 6757 | __ movl(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
| 6758 | } else if (destination.IsFpuRegister()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6759 | size_t elem_size = DataType::Size(DataType::Type::kInt32); |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 6760 | // Push the 2 source registers to the stack. |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 6761 | __ pushl(source.AsRegisterPairHigh<Register>()); |
| 6762 | __ cfi().AdjustCFAOffset(elem_size); |
| 6763 | __ pushl(source.AsRegisterPairLow<Register>()); |
| 6764 | __ cfi().AdjustCFAOffset(elem_size); |
| 6765 | // Load the destination register. |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6766 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 6767 | // And remove the temporary stack space we allocated. |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 6768 | codegen_->DecreaseFrame(2 * elem_size); |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 6769 | } else { |
| 6770 | DCHECK(destination.IsDoubleStackSlot()); |
| 6771 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
| 6772 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
| 6773 | source.AsRegisterPairHigh<Register>()); |
| 6774 | } |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6775 | } else if (source.IsFpuRegister()) { |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6776 | if (destination.IsRegister()) { |
| 6777 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
| 6778 | } else if (destination.IsFpuRegister()) { |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6779 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6780 | } else if (destination.IsRegisterPair()) { |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 6781 | size_t elem_size = DataType::Size(DataType::Type::kInt32); |
| 6782 | // Create stack space for 2 elements. |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 6783 | codegen_->IncreaseFrame(2 * elem_size); |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 6784 | // Store the source register. |
| 6785 | __ movsd(Address(ESP, 0), source.AsFpuRegister<XmmRegister>()); |
| 6786 | // And pop the values into destination registers. |
| 6787 | __ popl(destination.AsRegisterPairLow<Register>()); |
| 6788 | __ cfi().AdjustCFAOffset(-elem_size); |
| 6789 | __ popl(destination.AsRegisterPairHigh<Register>()); |
| 6790 | __ cfi().AdjustCFAOffset(-elem_size); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6791 | } else if (destination.IsStackSlot()) { |
| 6792 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6793 | } else if (destination.IsDoubleStackSlot()) { |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6794 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6795 | } else { |
| 6796 | DCHECK(destination.IsSIMDStackSlot()); |
| 6797 | __ movups(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6798 | } |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6799 | } else if (source.IsStackSlot()) { |
| 6800 | if (destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6801 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6802 | } else if (destination.IsFpuRegister()) { |
| 6803 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6804 | } else { |
| 6805 | DCHECK(destination.IsStackSlot()); |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6806 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 1); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6807 | } |
| 6808 | } else if (source.IsDoubleStackSlot()) { |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6809 | if (destination.IsRegisterPair()) { |
| 6810 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 6811 | __ movl(destination.AsRegisterPairHigh<Register>(), |
| 6812 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 6813 | } else if (destination.IsFpuRegister()) { |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6814 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 6815 | } else { |
| 6816 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6817 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 2); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6818 | } |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6819 | } else if (source.IsSIMDStackSlot()) { |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6820 | if (destination.IsFpuRegister()) { |
| 6821 | __ movups(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 6822 | } else { |
| 6823 | DCHECK(destination.IsSIMDStackSlot()); |
| 6824 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 4); |
| 6825 | } |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 6826 | } else if (source.IsConstant()) { |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6827 | HConstant* constant = source.GetConstant(); |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 6828 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 6829 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6830 | if (destination.IsRegister()) { |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 6831 | if (value == 0) { |
| 6832 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 6833 | } else { |
| 6834 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 6835 | } |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6836 | } else { |
| 6837 | DCHECK(destination.IsStackSlot()) << destination; |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 6838 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6839 | } |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6840 | } else if (constant->IsFloatConstant()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6841 | float fp_value = constant->AsFloatConstant()->GetValue(); |
| Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 6842 | int32_t value = bit_cast<int32_t, float>(fp_value); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6843 | Immediate imm(value); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6844 | if (destination.IsFpuRegister()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6845 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 6846 | if (value == 0) { |
| 6847 | // Easy handling of 0.0. |
| 6848 | __ xorps(dest, dest); |
| 6849 | } else { |
| 6850 | ScratchRegisterScope ensure_scratch( |
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6851 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 6852 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 6853 | __ movl(temp, Immediate(value)); |
| 6854 | __ movd(dest, temp); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6855 | } |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6856 | } else { |
| 6857 | DCHECK(destination.IsStackSlot()) << destination; |
| 6858 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 6859 | } |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6860 | } else if (constant->IsLongConstant()) { |
| 6861 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 6862 | int32_t low_value = Low32Bits(value); |
| 6863 | int32_t high_value = High32Bits(value); |
| 6864 | Immediate low(low_value); |
| 6865 | Immediate high(high_value); |
| 6866 | if (destination.IsDoubleStackSlot()) { |
| 6867 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 6868 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 6869 | } else { |
| 6870 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 6871 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 6872 | } |
| 6873 | } else { |
| 6874 | DCHECK(constant->IsDoubleConstant()); |
| 6875 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
| Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 6876 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6877 | int32_t low_value = Low32Bits(value); |
| 6878 | int32_t high_value = High32Bits(value); |
| 6879 | Immediate low(low_value); |
| 6880 | Immediate high(high_value); |
| 6881 | if (destination.IsFpuRegister()) { |
| 6882 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 6883 | if (value == 0) { |
| 6884 | // Easy handling of 0.0. |
| 6885 | __ xorpd(dest, dest); |
| 6886 | } else { |
| 6887 | __ pushl(high); |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 6888 | __ cfi().AdjustCFAOffset(4); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6889 | __ pushl(low); |
| Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 6890 | __ cfi().AdjustCFAOffset(4); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6891 | __ movsd(dest, Address(ESP, 0)); |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 6892 | codegen_->DecreaseFrame(8); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6893 | } |
| 6894 | } else { |
| 6895 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6896 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 6897 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 6898 | } |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 6899 | } |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6900 | } else { |
| Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 6901 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6902 | } |
| 6903 | } |
| 6904 | |
| Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 6905 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6906 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 6907 | ScratchRegisterScope ensure_scratch( |
| 6908 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 6909 | |
| 6910 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 6911 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 6912 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 6913 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6914 | } |
| 6915 | |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6916 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6917 | ScratchRegisterScope ensure_scratch( |
| 6918 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 6919 | |
| 6920 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 6921 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 6922 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 6923 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 6924 | __ movd(reg, temp_reg); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6925 | } |
| 6926 | |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6927 | void ParallelMoveResolverX86::Exchange128(XmmRegister reg, int mem) { |
| 6928 | size_t extra_slot = 4 * kX86WordSize; |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 6929 | codegen_->IncreaseFrame(extra_slot); |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6930 | __ movups(Address(ESP, 0), XmmRegister(reg)); |
| 6931 | ExchangeMemory(0, mem + extra_slot, 4); |
| 6932 | __ movups(XmmRegister(reg), Address(ESP, 0)); |
| Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 6933 | codegen_->DecreaseFrame(extra_slot); |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6934 | } |
| 6935 | |
| 6936 | void ParallelMoveResolverX86::ExchangeMemory(int mem1, int mem2, int number_of_words) { |
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6937 | ScratchRegisterScope ensure_scratch1( |
| 6938 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6939 | |
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6940 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 6941 | ScratchRegisterScope ensure_scratch2( |
| 6942 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6943 | |
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6944 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 6945 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6946 | |
| 6947 | // Now that temp registers are available (possibly spilled), exchange blocks of memory. |
| 6948 | for (int i = 0; i < number_of_words; i++) { |
| 6949 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 6950 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 6951 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 6952 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
| 6953 | stack_offset += kX86WordSize; |
| 6954 | } |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6955 | } |
| 6956 | |
| 6957 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6958 | MoveOperands* move = moves_[index]; |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6959 | Location source = move->GetSource(); |
| 6960 | Location destination = move->GetDestination(); |
| 6961 | |
| 6962 | if (source.IsRegister() && destination.IsRegister()) { |
| Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 6963 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 6964 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 6965 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 6966 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 6967 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6968 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6969 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6970 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6971 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6972 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6973 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 1); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6974 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 6975 | // Use XOR Swap algorithm to avoid a temporary. |
| 6976 | DCHECK_NE(source.reg(), destination.reg()); |
| 6977 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 6978 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 6979 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 6980 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 6981 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 6982 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 6983 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6984 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 6985 | // Take advantage of the 16 bytes in the XMM register. |
| 6986 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 6987 | Address stack(ESP, destination.GetStackIndex()); |
| 6988 | // Load the double into the high doubleword. |
| 6989 | __ movhpd(reg, stack); |
| 6990 | |
| 6991 | // Store the low double into the destination. |
| 6992 | __ movsd(stack, reg); |
| 6993 | |
| 6994 | // Move the high double to the low double. |
| 6995 | __ psrldq(reg, Immediate(8)); |
| 6996 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 6997 | // Take advantage of the 16 bytes in the XMM register. |
| 6998 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 6999 | Address stack(ESP, source.GetStackIndex()); |
| 7000 | // Load the double into the high doubleword. |
| 7001 | __ movhpd(reg, stack); |
| 7002 | |
| 7003 | // Store the low double into the destination. |
| 7004 | __ movsd(stack, reg); |
| 7005 | |
| 7006 | // Move the high double to the low double. |
| 7007 | __ psrldq(reg, Immediate(8)); |
| 7008 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 7009 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 2); |
| 7010 | } else if (source.IsSIMDStackSlot() && destination.IsSIMDStackSlot()) { |
| 7011 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 4); |
| 7012 | } else if (source.IsFpuRegister() && destination.IsSIMDStackSlot()) { |
| 7013 | Exchange128(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 7014 | } else if (destination.IsFpuRegister() && source.IsSIMDStackSlot()) { |
| 7015 | Exchange128(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 7016 | } else { |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 7017 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 7018 | } |
| 7019 | } |
| 7020 | |
| 7021 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 7022 | __ pushl(static_cast<Register>(reg)); |
| 7023 | } |
| 7024 | |
| 7025 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 7026 | __ popl(static_cast<Register>(reg)); |
| Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7027 | } |
| 7028 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7029 | HLoadClass::LoadKind CodeGeneratorX86::GetSupportedLoadClassKind( |
| 7030 | HLoadClass::LoadKind desired_class_load_kind) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7031 | switch (desired_class_load_kind) { |
| Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7032 | case HLoadClass::LoadKind::kInvalid: |
| 7033 | LOG(FATAL) << "UNREACHABLE"; |
| 7034 | UNREACHABLE(); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7035 | case HLoadClass::LoadKind::kReferrersClass: |
| 7036 | break; |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7037 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7038 | case HLoadClass::LoadKind::kBootImageRelRo: |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7039 | case HLoadClass::LoadKind::kBssEntry: |
| Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 7040 | case HLoadClass::LoadKind::kBssEntryPublic: |
| 7041 | case HLoadClass::LoadKind::kBssEntryPackage: |
| Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 7042 | DCHECK(!GetCompilerOptions().IsJitCompiler()); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7043 | break; |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7044 | case HLoadClass::LoadKind::kJitBootImageAddress: |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7045 | case HLoadClass::LoadKind::kJitTableAddress: |
| Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 7046 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7047 | break; |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7048 | case HLoadClass::LoadKind::kRuntimeCall: |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7049 | break; |
| 7050 | } |
| 7051 | return desired_class_load_kind; |
| 7052 | } |
| 7053 | |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7054 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7055 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7056 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7057 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7058 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7059 | cls, |
| 7060 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7061 | Location::RegisterLocation(EAX)); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7062 | DCHECK_EQ(calling_convention.GetRegisterAt(0), EAX); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7063 | return; |
| 7064 | } |
| Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 7065 | DCHECK_EQ(cls->NeedsAccessCheck(), |
| 7066 | load_kind == HLoadClass::LoadKind::kBssEntryPublic || |
| 7067 | load_kind == HLoadClass::LoadKind::kBssEntryPackage); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7068 | |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7069 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 7070 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7071 | ? LocationSummary::kCallOnSlowPath |
| 7072 | : LocationSummary::kNoCall; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7073 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7074 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 7075 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7076 | } |
| 7077 | |
| Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 7078 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || cls->HasPcRelativeLoadKind()) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7079 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7080 | } |
| 7081 | locations->SetOut(Location::RequiresRegister()); |
| Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 7082 | if (call_kind == LocationSummary::kCallOnSlowPath && cls->HasPcRelativeLoadKind()) { |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7083 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 7084 | // Rely on the type resolution and/or initialization to save everything. |
| Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 7085 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7086 | } else { |
| 7087 | // For non-Baker read barrier we have a temp-clobbering call. |
| 7088 | } |
| 7089 | } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7090 | } |
| 7091 | |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7092 | Label* CodeGeneratorX86::NewJitRootClassPatch(const DexFile& dex_file, |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7093 | dex::TypeIndex type_index, |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7094 | Handle<mirror::Class> handle) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7095 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7096 | // Add a patch entry and return the label. |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7097 | jit_class_patches_.emplace_back(&dex_file, type_index.index_); |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7098 | PatchInfo<Label>* info = &jit_class_patches_.back(); |
| 7099 | return &info->label; |
| 7100 | } |
| 7101 | |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7102 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 7103 | // move. |
| 7104 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7105 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7106 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7107 | codegen_->GenerateLoadClassRuntimeCall(cls); |
| Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 7108 | return; |
| 7109 | } |
| Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 7110 | DCHECK_EQ(cls->NeedsAccessCheck(), |
| 7111 | load_kind == HLoadClass::LoadKind::kBssEntryPublic || |
| 7112 | load_kind == HLoadClass::LoadKind::kBssEntryPackage); |
| Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 7113 | |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7114 | LocationSummary* locations = cls->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7115 | Location out_loc = locations->Out(); |
| 7116 | Register out = out_loc.AsRegister<Register>(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7117 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7118 | bool generate_null_check = false; |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7119 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 7120 | ? kWithoutReadBarrier |
| 7121 | : kCompilerReadBarrierOption; |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7122 | switch (load_kind) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7123 | case HLoadClass::LoadKind::kReferrersClass: { |
| 7124 | DCHECK(!cls->CanCallRuntime()); |
| 7125 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 7126 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 7127 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 7128 | GenerateGcRootFieldLoad( |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7129 | cls, |
| 7130 | out_loc, |
| 7131 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7132 | /* fixup_label= */ nullptr, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7133 | read_barrier_option); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7134 | break; |
| 7135 | } |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7136 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
| Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 7137 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 7138 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7139 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7140 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 7141 | __ leal(out, Address(method_address, CodeGeneratorX86::kPlaceholder32BitOffset)); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7142 | codegen_->RecordBootImageTypePatch(cls); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7143 | break; |
| 7144 | } |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7145 | case HLoadClass::LoadKind::kBootImageRelRo: { |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 7146 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 7147 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 7148 | __ movl(out, Address(method_address, CodeGeneratorX86::kPlaceholder32BitOffset)); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7149 | codegen_->RecordBootImageRelRoPatch(cls->InputAt(0)->AsX86ComputeBaseMethodAddress(), |
| Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 7150 | CodeGenerator::GetBootImageOffset(cls)); |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 7151 | break; |
| 7152 | } |
| Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 7153 | case HLoadClass::LoadKind::kBssEntry: |
| 7154 | case HLoadClass::LoadKind::kBssEntryPublic: |
| 7155 | case HLoadClass::LoadKind::kBssEntryPackage: { |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7156 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 7157 | Address address(method_address, CodeGeneratorX86::kPlaceholder32BitOffset); |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7158 | Label* fixup_label = codegen_->NewTypeBssEntryPatch(cls); |
| 7159 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
| Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 7160 | // No need for memory fence, thanks to the x86 memory model. |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7161 | generate_null_check = true; |
| 7162 | break; |
| 7163 | } |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7164 | case HLoadClass::LoadKind::kJitBootImageAddress: { |
| 7165 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 7166 | uint32_t address = reinterpret_cast32<uint32_t>(cls->GetClass().Get()); |
| 7167 | DCHECK_NE(address, 0u); |
| 7168 | __ movl(out, Immediate(address)); |
| 7169 | break; |
| 7170 | } |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7171 | case HLoadClass::LoadKind::kJitTableAddress: { |
| Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 7172 | Address address = Address::Absolute(CodeGeneratorX86::kPlaceholder32BitOffset); |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7173 | Label* fixup_label = codegen_->NewJitRootClassPatch( |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7174 | cls->GetDexFile(), cls->GetTypeIndex(), cls->GetClass()); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7175 | // /* GcRoot<mirror::Class> */ out = *address |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7176 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7177 | break; |
| 7178 | } |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7179 | case HLoadClass::LoadKind::kRuntimeCall: |
| Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7180 | case HLoadClass::LoadKind::kInvalid: |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7181 | LOG(FATAL) << "UNREACHABLE"; |
| 7182 | UNREACHABLE(); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7183 | } |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 7184 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7185 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 7186 | DCHECK(cls->CanCallRuntime()); |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 7187 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86(cls, cls); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7188 | codegen_->AddSlowPath(slow_path); |
| Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 7189 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7190 | if (generate_null_check) { |
| 7191 | __ testl(out, out); |
| 7192 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 7193 | } |
| Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 7194 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7195 | if (cls->MustGenerateClinitCheck()) { |
| 7196 | GenerateClassInitializationCheck(slow_path, out); |
| 7197 | } else { |
| 7198 | __ Bind(slow_path->GetExitLabel()); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 7199 | } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7200 | } |
| 7201 | } |
| 7202 | |
| Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 7203 | void LocationsBuilderX86::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 7204 | InvokeRuntimeCallingConvention calling_convention; |
| 7205 | Location location = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 7206 | CodeGenerator::CreateLoadMethodHandleRuntimeCallLocationSummary(load, location, location); |
| 7207 | } |
| 7208 | |
| 7209 | void InstructionCodeGeneratorX86::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 7210 | codegen_->GenerateLoadMethodHandleRuntimeCall(load); |
| 7211 | } |
| 7212 | |
| Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 7213 | void LocationsBuilderX86::VisitLoadMethodType(HLoadMethodType* load) { |
| 7214 | InvokeRuntimeCallingConvention calling_convention; |
| 7215 | Location location = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 7216 | CodeGenerator::CreateLoadMethodTypeRuntimeCallLocationSummary(load, location, location); |
| 7217 | } |
| 7218 | |
| 7219 | void InstructionCodeGeneratorX86::VisitLoadMethodType(HLoadMethodType* load) { |
| 7220 | codegen_->GenerateLoadMethodTypeRuntimeCall(load); |
| 7221 | } |
| 7222 | |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7223 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 7224 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7225 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7226 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7227 | if (check->HasUses()) { |
| 7228 | locations->SetOut(Location::SameAsFirstInput()); |
| 7229 | } |
| Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 7230 | // Rely on the type initialization to save everything we need. |
| 7231 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7232 | } |
| 7233 | |
| 7234 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 7235 | // We assume the class to not be null. |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 7236 | SlowPathCode* slow_path = |
| 7237 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86(check->GetLoadClass(), check); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7238 | codegen_->AddSlowPath(slow_path); |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 7239 | GenerateClassInitializationCheck(slow_path, |
| 7240 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 7241 | } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7242 | |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 7243 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7244 | SlowPathCode* slow_path, Register class_reg) { |
| Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 7245 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
| 7246 | const size_t status_byte_offset = |
| 7247 | mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte); |
| Vladimir Marko | bf12191 | 2019-06-04 13:49:05 +0100 | [diff] [blame] | 7248 | constexpr uint32_t shifted_visibly_initialized_value = |
| 7249 | enum_cast<uint32_t>(ClassStatus::kVisiblyInitialized) << (status_lsb_position % kBitsPerByte); |
| Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 7250 | |
| Vladimir Marko | bf12191 | 2019-06-04 13:49:05 +0100 | [diff] [blame] | 7251 | __ cmpb(Address(class_reg, status_byte_offset), Immediate(shifted_visibly_initialized_value)); |
| Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 7252 | __ j(kBelow, slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7253 | __ Bind(slow_path->GetExitLabel()); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7254 | } |
| 7255 | |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7256 | void InstructionCodeGeneratorX86::GenerateBitstringTypeCheckCompare(HTypeCheckInstruction* check, |
| 7257 | Register temp) { |
| 7258 | uint32_t path_to_root = check->GetBitstringPathToRoot(); |
| 7259 | uint32_t mask = check->GetBitstringMask(); |
| 7260 | DCHECK(IsPowerOfTwo(mask + 1)); |
| 7261 | size_t mask_bits = WhichPowerOf2(mask + 1); |
| 7262 | |
| 7263 | if (mask_bits == 16u) { |
| 7264 | // Compare the bitstring in memory. |
| 7265 | __ cmpw(Address(temp, mirror::Class::StatusOffset()), Immediate(path_to_root)); |
| 7266 | } else { |
| 7267 | // /* uint32_t */ temp = temp->status_ |
| 7268 | __ movl(temp, Address(temp, mirror::Class::StatusOffset())); |
| 7269 | // Compare the bitstring bits using SUB. |
| 7270 | __ subl(temp, Immediate(path_to_root)); |
| 7271 | // Shift out bits that do not contribute to the comparison. |
| 7272 | __ shll(temp, Immediate(32u - mask_bits)); |
| 7273 | } |
| 7274 | } |
| 7275 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7276 | HLoadString::LoadKind CodeGeneratorX86::GetSupportedLoadStringKind( |
| 7277 | HLoadString::LoadKind desired_string_load_kind) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7278 | switch (desired_string_load_kind) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7279 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7280 | case HLoadString::LoadKind::kBootImageRelRo: |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7281 | case HLoadString::LoadKind::kBssEntry: |
| Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 7282 | DCHECK(!GetCompilerOptions().IsJitCompiler()); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7283 | break; |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7284 | case HLoadString::LoadKind::kJitBootImageAddress: |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7285 | case HLoadString::LoadKind::kJitTableAddress: |
| Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 7286 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7287 | break; |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7288 | case HLoadString::LoadKind::kRuntimeCall: |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7289 | break; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7290 | } |
| 7291 | return desired_string_load_kind; |
| 7292 | } |
| 7293 | |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 7294 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7295 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7296 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7297 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 7298 | if (load_kind == HLoadString::LoadKind::kBootImageLinkTimePcRelative || |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7299 | load_kind == HLoadString::LoadKind::kBootImageRelRo || |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7300 | load_kind == HLoadString::LoadKind::kBssEntry) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7301 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7302 | } |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7303 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
| Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 7304 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 7305 | } else { |
| 7306 | locations->SetOut(Location::RequiresRegister()); |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 7307 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 7308 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7309 | // Rely on the pResolveString to save everything. |
| Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 7310 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 7311 | } else { |
| 7312 | // For non-Baker read barrier we have a temp-clobbering call. |
| 7313 | } |
| 7314 | } |
| Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 7315 | } |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 7316 | } |
| 7317 | |
| Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7318 | Label* CodeGeneratorX86::NewJitRootStringPatch(const DexFile& dex_file, |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7319 | dex::StringIndex string_index, |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7320 | Handle<mirror::String> handle) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7321 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7322 | // Add a patch entry and return the label. |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7323 | jit_string_patches_.emplace_back(&dex_file, string_index.index_); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7324 | PatchInfo<Label>* info = &jit_string_patches_.back(); |
| 7325 | return &info->label; |
| 7326 | } |
| 7327 | |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7328 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 7329 | // move. |
| 7330 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
| Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 7331 | LocationSummary* locations = load->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7332 | Location out_loc = locations->Out(); |
| 7333 | Register out = out_loc.AsRegister<Register>(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7334 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7335 | switch (load->GetLoadKind()) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7336 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 7337 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 7338 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7339 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 7340 | __ leal(out, Address(method_address, CodeGeneratorX86::kPlaceholder32BitOffset)); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7341 | codegen_->RecordBootImageStringPatch(load); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7342 | return; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7343 | } |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7344 | case HLoadString::LoadKind::kBootImageRelRo: { |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7345 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 7346 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 7347 | __ movl(out, Address(method_address, CodeGeneratorX86::kPlaceholder32BitOffset)); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7348 | codegen_->RecordBootImageRelRoPatch(load->InputAt(0)->AsX86ComputeBaseMethodAddress(), |
| Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 7349 | CodeGenerator::GetBootImageOffset(load)); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7350 | return; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7351 | } |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7352 | case HLoadString::LoadKind::kBssEntry: { |
| 7353 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 7354 | Address address = Address(method_address, CodeGeneratorX86::kPlaceholder32BitOffset); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7355 | Label* fixup_label = codegen_->NewStringBssEntryPatch(load); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7356 | // /* GcRoot<mirror::String> */ out = *address /* PC-relative */ |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7357 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
| Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 7358 | // No need for memory fence, thanks to the x86 memory model. |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7359 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadStringSlowPathX86(load); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7360 | codegen_->AddSlowPath(slow_path); |
| 7361 | __ testl(out, out); |
| 7362 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 7363 | __ Bind(slow_path->GetExitLabel()); |
| 7364 | return; |
| 7365 | } |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7366 | case HLoadString::LoadKind::kJitBootImageAddress: { |
| 7367 | uint32_t address = reinterpret_cast32<uint32_t>(load->GetString().Get()); |
| 7368 | DCHECK_NE(address, 0u); |
| 7369 | __ movl(out, Immediate(address)); |
| 7370 | return; |
| 7371 | } |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7372 | case HLoadString::LoadKind::kJitTableAddress: { |
| Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 7373 | Address address = Address::Absolute(CodeGeneratorX86::kPlaceholder32BitOffset); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7374 | Label* fixup_label = codegen_->NewJitRootStringPatch( |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7375 | load->GetDexFile(), load->GetStringIndex(), load->GetString()); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7376 | // /* GcRoot<mirror::String> */ out = *address |
| 7377 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
| 7378 | return; |
| 7379 | } |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7380 | default: |
| Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 7381 | break; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7382 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7383 | |
| Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 7384 | // 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] | 7385 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 7386 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
| Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7387 | __ movl(calling_convention.GetRegisterAt(0), Immediate(load->GetStringIndex().index_)); |
| Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 7388 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 7389 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 7390 | } |
| 7391 | |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7392 | static Address GetExceptionTlsAddress() { |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7393 | return Address::Absolute(Thread::ExceptionOffset<kX86PointerSize>().Int32Value()); |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7394 | } |
| 7395 | |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7396 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 7397 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7398 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7399 | locations->SetOut(Location::RequiresRegister()); |
| 7400 | } |
| 7401 | |
| 7402 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7403 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 7404 | } |
| 7405 | |
| 7406 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7407 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7408 | } |
| 7409 | |
| 7410 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 7411 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7412 | } |
| 7413 | |
| 7414 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7415 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 7416 | instruction, LocationSummary::kCallOnMainOnly); |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7417 | InvokeRuntimeCallingConvention calling_convention; |
| 7418 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 7419 | } |
| 7420 | |
| 7421 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 7422 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7423 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7424 | } |
| 7425 | |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7426 | // Temp is used for read barrier. |
| 7427 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 7428 | if (kEmitCompilerReadBarrier && |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7429 | !kUseBakerReadBarrier && |
| 7430 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7431 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7432 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 7433 | return 1; |
| 7434 | } |
| 7435 | return 0; |
| 7436 | } |
| 7437 | |
| Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 7438 | // Interface case has 2 temps, one for holding the number of interfaces, one for the current |
| 7439 | // interface pointer, the current interface is compared in memory. |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7440 | // The other checks have one temp for loading the object's class. |
| 7441 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 7442 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7443 | return 2; |
| 7444 | } |
| 7445 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7446 | } |
| 7447 | |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7448 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7449 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7450 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7451 | bool baker_read_barrier_slow_path = false; |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7452 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7453 | case TypeCheckKind::kExactCheck: |
| 7454 | case TypeCheckKind::kAbstractClassCheck: |
| 7455 | case TypeCheckKind::kClassHierarchyCheck: |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7456 | case TypeCheckKind::kArrayObjectCheck: { |
| 7457 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 7458 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 7459 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7460 | break; |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7461 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7462 | case TypeCheckKind::kArrayCheck: |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7463 | case TypeCheckKind::kUnresolvedCheck: |
| 7464 | case TypeCheckKind::kInterfaceCheck: |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7465 | call_kind = LocationSummary::kCallOnSlowPath; |
| 7466 | break; |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7467 | case TypeCheckKind::kBitstringCheck: |
| 7468 | break; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7469 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7470 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7471 | LocationSummary* locations = |
| 7472 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7473 | if (baker_read_barrier_slow_path) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 7474 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7475 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7476 | locations->SetInAt(0, Location::RequiresRegister()); |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7477 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 7478 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 7479 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 7480 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 7481 | } else { |
| 7482 | locations->SetInAt(1, Location::Any()); |
| 7483 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7484 | // Note that TypeCheckSlowPathX86 uses this "out" register too. |
| 7485 | locations->SetOut(Location::RequiresRegister()); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7486 | // When read barriers are enabled, we need a temporary register for some cases. |
| 7487 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7488 | } |
| 7489 | |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7490 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7491 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7492 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7493 | Location obj_loc = locations->InAt(0); |
| 7494 | Register obj = obj_loc.AsRegister<Register>(); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7495 | Location cls = locations->InAt(1); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7496 | Location out_loc = locations->Out(); |
| 7497 | Register out = out_loc.AsRegister<Register>(); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7498 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 7499 | DCHECK_LE(num_temps, 1u); |
| 7500 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7501 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7502 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7503 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7504 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7505 | SlowPathCode* slow_path = nullptr; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7506 | NearLabel done, zero; |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7507 | |
| 7508 | // Return 0 if `obj` is null. |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7509 | // Avoid null check if we know obj is not null. |
| 7510 | if (instruction->MustDoNullCheck()) { |
| 7511 | __ testl(obj, obj); |
| 7512 | __ j(kEqual, &zero); |
| 7513 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7514 | |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7515 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7516 | case TypeCheckKind::kExactCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7517 | ReadBarrierOption read_barrier_option = |
| 7518 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7519 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7520 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7521 | out_loc, |
| 7522 | obj_loc, |
| 7523 | class_offset, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7524 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7525 | if (cls.IsRegister()) { |
| 7526 | __ cmpl(out, cls.AsRegister<Register>()); |
| 7527 | } else { |
| 7528 | DCHECK(cls.IsStackSlot()) << cls; |
| 7529 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 7530 | } |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7531 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7532 | // Classes must be equal for the instanceof to succeed. |
| 7533 | __ j(kNotEqual, &zero); |
| 7534 | __ movl(out, Immediate(1)); |
| 7535 | __ jmp(&done); |
| 7536 | break; |
| 7537 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7538 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7539 | case TypeCheckKind::kAbstractClassCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7540 | ReadBarrierOption read_barrier_option = |
| 7541 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7542 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7543 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7544 | out_loc, |
| 7545 | obj_loc, |
| 7546 | class_offset, |
| 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 | // If the class is abstract, we eagerly fetch the super class of the |
| 7549 | // object to avoid doing a comparison we know will fail. |
| 7550 | NearLabel loop; |
| 7551 | __ Bind(&loop); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7552 | // /* HeapReference<Class> */ out = out->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7553 | GenerateReferenceLoadOneRegister(instruction, |
| 7554 | out_loc, |
| 7555 | super_offset, |
| 7556 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7557 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7558 | __ testl(out, out); |
| 7559 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7560 | __ j(kEqual, &done); |
| 7561 | if (cls.IsRegister()) { |
| 7562 | __ cmpl(out, cls.AsRegister<Register>()); |
| 7563 | } else { |
| 7564 | DCHECK(cls.IsStackSlot()) << cls; |
| 7565 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 7566 | } |
| 7567 | __ j(kNotEqual, &loop); |
| 7568 | __ movl(out, Immediate(1)); |
| 7569 | if (zero.IsLinked()) { |
| 7570 | __ jmp(&done); |
| 7571 | } |
| 7572 | break; |
| 7573 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7574 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7575 | case TypeCheckKind::kClassHierarchyCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7576 | ReadBarrierOption read_barrier_option = |
| 7577 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7578 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7579 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7580 | out_loc, |
| 7581 | obj_loc, |
| 7582 | class_offset, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7583 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7584 | // Walk over the class hierarchy to find a match. |
| 7585 | NearLabel loop, success; |
| 7586 | __ Bind(&loop); |
| 7587 | if (cls.IsRegister()) { |
| 7588 | __ cmpl(out, cls.AsRegister<Register>()); |
| 7589 | } else { |
| 7590 | DCHECK(cls.IsStackSlot()) << cls; |
| 7591 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 7592 | } |
| 7593 | __ j(kEqual, &success); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7594 | // /* HeapReference<Class> */ out = out->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7595 | GenerateReferenceLoadOneRegister(instruction, |
| 7596 | out_loc, |
| 7597 | super_offset, |
| 7598 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7599 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7600 | __ testl(out, out); |
| 7601 | __ j(kNotEqual, &loop); |
| 7602 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7603 | __ jmp(&done); |
| 7604 | __ Bind(&success); |
| 7605 | __ movl(out, Immediate(1)); |
| 7606 | if (zero.IsLinked()) { |
| 7607 | __ jmp(&done); |
| 7608 | } |
| 7609 | break; |
| 7610 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7611 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7612 | case TypeCheckKind::kArrayObjectCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7613 | ReadBarrierOption read_barrier_option = |
| 7614 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7615 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7616 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7617 | out_loc, |
| 7618 | obj_loc, |
| 7619 | class_offset, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7620 | read_barrier_option); |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7621 | // Do an exact check. |
| 7622 | NearLabel exact_check; |
| 7623 | if (cls.IsRegister()) { |
| 7624 | __ cmpl(out, cls.AsRegister<Register>()); |
| 7625 | } else { |
| 7626 | DCHECK(cls.IsStackSlot()) << cls; |
| 7627 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 7628 | } |
| 7629 | __ j(kEqual, &exact_check); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7630 | // 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] | 7631 | // /* HeapReference<Class> */ out = out->component_type_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7632 | GenerateReferenceLoadOneRegister(instruction, |
| 7633 | out_loc, |
| 7634 | component_offset, |
| 7635 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7636 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7637 | __ testl(out, out); |
| 7638 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7639 | __ j(kEqual, &done); |
| 7640 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 7641 | __ j(kNotEqual, &zero); |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7642 | __ Bind(&exact_check); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7643 | __ movl(out, Immediate(1)); |
| 7644 | __ jmp(&done); |
| 7645 | break; |
| 7646 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7647 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7648 | case TypeCheckKind::kArrayCheck: { |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7649 | // No read barrier since the slow path will retry upon failure. |
| 7650 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7651 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7652 | out_loc, |
| 7653 | obj_loc, |
| 7654 | class_offset, |
| 7655 | kWithoutReadBarrier); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7656 | if (cls.IsRegister()) { |
| 7657 | __ cmpl(out, cls.AsRegister<Register>()); |
| 7658 | } else { |
| 7659 | DCHECK(cls.IsStackSlot()) << cls; |
| 7660 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 7661 | } |
| 7662 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7663 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7664 | instruction, /* is_fatal= */ false); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7665 | codegen_->AddSlowPath(slow_path); |
| 7666 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 7667 | __ movl(out, Immediate(1)); |
| 7668 | if (zero.IsLinked()) { |
| 7669 | __ jmp(&done); |
| 7670 | } |
| 7671 | break; |
| 7672 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7673 | |
| Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 7674 | case TypeCheckKind::kUnresolvedCheck: |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7675 | case TypeCheckKind::kInterfaceCheck: { |
| 7676 | // 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] | 7677 | // into the slow path for the unresolved and interface check |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7678 | // cases. |
| 7679 | // |
| 7680 | // We cannot directly call the InstanceofNonTrivial runtime |
| 7681 | // entry point without resorting to a type checking slow path |
| 7682 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 7683 | // require to assign fixed registers for the inputs of this |
| 7684 | // HInstanceOf instruction (following the runtime calling |
| 7685 | // convention), which might be cluttered by the potential first |
| 7686 | // read barrier emission at the beginning of this method. |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7687 | // |
| 7688 | // TODO: Introduce a new runtime entry point taking the object |
| 7689 | // to test (instead of its class) as argument, and let it deal |
| 7690 | // with the read barrier issues. This will let us refactor this |
| 7691 | // case of the `switch` code as it was previously (with a direct |
| 7692 | // call to the runtime not using a type checking slow path). |
| 7693 | // This should also be beneficial for the other cases above. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7694 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7695 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7696 | instruction, /* is_fatal= */ false); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7697 | codegen_->AddSlowPath(slow_path); |
| 7698 | __ jmp(slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7699 | if (zero.IsLinked()) { |
| 7700 | __ jmp(&done); |
| 7701 | } |
| 7702 | break; |
| 7703 | } |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7704 | |
| 7705 | case TypeCheckKind::kBitstringCheck: { |
| 7706 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7707 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7708 | out_loc, |
| 7709 | obj_loc, |
| 7710 | class_offset, |
| 7711 | kWithoutReadBarrier); |
| 7712 | |
| 7713 | GenerateBitstringTypeCheckCompare(instruction, out); |
| 7714 | __ j(kNotEqual, &zero); |
| 7715 | __ movl(out, Immediate(1)); |
| 7716 | __ jmp(&done); |
| 7717 | break; |
| 7718 | } |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7719 | } |
| 7720 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7721 | if (zero.IsLinked()) { |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7722 | __ Bind(&zero); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7723 | __ xorl(out, out); |
| 7724 | } |
| 7725 | |
| 7726 | if (done.IsLinked()) { |
| 7727 | __ Bind(&done); |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7728 | } |
| 7729 | |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7730 | if (slow_path != nullptr) { |
| 7731 | __ Bind(slow_path->GetExitLabel()); |
| 7732 | } |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7733 | } |
| 7734 | |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7735 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7736 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7737 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7738 | LocationSummary* locations = |
| 7739 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7740 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7741 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 7742 | // Require a register for the interface check since there is a loop that compares the class to |
| 7743 | // a memory address. |
| 7744 | locations->SetInAt(1, Location::RequiresRegister()); |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7745 | } else if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 7746 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 7747 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 7748 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7749 | } else { |
| 7750 | locations->SetInAt(1, Location::Any()); |
| 7751 | } |
| Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 7752 | // 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] | 7753 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
| 7754 | } |
| 7755 | |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7756 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7757 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7758 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7759 | Location obj_loc = locations->InAt(0); |
| 7760 | Register obj = obj_loc.AsRegister<Register>(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7761 | Location cls = locations->InAt(1); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7762 | Location temp_loc = locations->GetTemp(0); |
| 7763 | Register temp = temp_loc.AsRegister<Register>(); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7764 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 7765 | DCHECK_GE(num_temps, 1u); |
| 7766 | DCHECK_LE(num_temps, 2u); |
| 7767 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 7768 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7769 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7770 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7771 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 7772 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 7773 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 7774 | const uint32_t object_array_data_offset = |
| 7775 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7776 | |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7777 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7778 | SlowPathCode* type_check_slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7779 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
| 7780 | instruction, is_type_check_slow_path_fatal); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7781 | codegen_->AddSlowPath(type_check_slow_path); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7782 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7783 | NearLabel done; |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7784 | // Avoid null check if we know obj is not null. |
| 7785 | if (instruction->MustDoNullCheck()) { |
| 7786 | __ testl(obj, obj); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7787 | __ j(kEqual, &done); |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7788 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7789 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7790 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7791 | case TypeCheckKind::kExactCheck: |
| 7792 | case TypeCheckKind::kArrayCheck: { |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7793 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7794 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7795 | temp_loc, |
| 7796 | obj_loc, |
| 7797 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7798 | kWithoutReadBarrier); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7799 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7800 | if (cls.IsRegister()) { |
| 7801 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 7802 | } else { |
| 7803 | DCHECK(cls.IsStackSlot()) << cls; |
| 7804 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 7805 | } |
| 7806 | // Jump to slow path for throwing the exception or doing a |
| 7807 | // more involved array check. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7808 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7809 | break; |
| 7810 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7811 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7812 | case TypeCheckKind::kAbstractClassCheck: { |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7813 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7814 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7815 | temp_loc, |
| 7816 | obj_loc, |
| 7817 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7818 | kWithoutReadBarrier); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7819 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7820 | // If the class is abstract, we eagerly fetch the super class of the |
| 7821 | // object to avoid doing a comparison we know will fail. |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7822 | NearLabel loop; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7823 | __ Bind(&loop); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7824 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7825 | GenerateReferenceLoadOneRegister(instruction, |
| 7826 | temp_loc, |
| 7827 | super_offset, |
| 7828 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7829 | kWithoutReadBarrier); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7830 | |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7831 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 7832 | // exception. |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7833 | __ testl(temp, temp); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7834 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7835 | |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7836 | // Otherwise, compare the classes |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7837 | if (cls.IsRegister()) { |
| 7838 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 7839 | } else { |
| 7840 | DCHECK(cls.IsStackSlot()) << cls; |
| 7841 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 7842 | } |
| 7843 | __ j(kNotEqual, &loop); |
| 7844 | break; |
| 7845 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7846 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7847 | case TypeCheckKind::kClassHierarchyCheck: { |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7848 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7849 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7850 | temp_loc, |
| 7851 | obj_loc, |
| 7852 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7853 | kWithoutReadBarrier); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7854 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7855 | // Walk over the class hierarchy to find a match. |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7856 | NearLabel loop; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7857 | __ Bind(&loop); |
| 7858 | if (cls.IsRegister()) { |
| 7859 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 7860 | } else { |
| 7861 | DCHECK(cls.IsStackSlot()) << cls; |
| 7862 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 7863 | } |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7864 | __ j(kEqual, &done); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7865 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7866 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7867 | GenerateReferenceLoadOneRegister(instruction, |
| 7868 | temp_loc, |
| 7869 | super_offset, |
| 7870 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7871 | kWithoutReadBarrier); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7872 | |
| 7873 | // If the class reference currently in `temp` is not null, jump |
| 7874 | // back at the beginning of the loop. |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7875 | __ testl(temp, temp); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7876 | __ j(kNotZero, &loop); |
| 7877 | // Otherwise, jump to the slow path to throw the exception.; |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7878 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7879 | break; |
| 7880 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7881 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7882 | case TypeCheckKind::kArrayObjectCheck: { |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7883 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7884 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7885 | temp_loc, |
| 7886 | obj_loc, |
| 7887 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7888 | kWithoutReadBarrier); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7889 | |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7890 | // Do an exact check. |
| 7891 | if (cls.IsRegister()) { |
| 7892 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 7893 | } else { |
| 7894 | DCHECK(cls.IsStackSlot()) << cls; |
| 7895 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 7896 | } |
| 7897 | __ j(kEqual, &done); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7898 | |
| 7899 | // 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] | 7900 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7901 | GenerateReferenceLoadOneRegister(instruction, |
| 7902 | temp_loc, |
| 7903 | component_offset, |
| 7904 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7905 | kWithoutReadBarrier); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7906 | |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7907 | // If the component type is null (i.e. the object not an array), jump to the slow path to |
| 7908 | // throw the exception. Otherwise proceed with the check. |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7909 | __ testl(temp, temp); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7910 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7911 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7912 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7913 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7914 | break; |
| 7915 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7916 | |
| Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 7917 | case TypeCheckKind::kUnresolvedCheck: |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7918 | // 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] | 7919 | // We cannot directly call the CheckCast runtime entry point |
| 7920 | // without resorting to a type checking slow path here (i.e. by |
| 7921 | // calling InvokeRuntime directly), as it would require to |
| 7922 | // assign fixed registers for the inputs of this HInstanceOf |
| 7923 | // instruction (following the runtime calling convention), which |
| 7924 | // might be cluttered by the potential first read barrier |
| 7925 | // emission at the beginning of this method. |
| 7926 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7927 | break; |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7928 | |
| 7929 | case TypeCheckKind::kInterfaceCheck: { |
| Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 7930 | // Fast path for the interface check. Try to avoid read barriers to improve the fast path. |
| 7931 | // We can not get false positives by doing this. |
| 7932 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7933 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7934 | temp_loc, |
| 7935 | obj_loc, |
| 7936 | class_offset, |
| 7937 | kWithoutReadBarrier); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7938 | |
| Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 7939 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 7940 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7941 | temp_loc, |
| 7942 | temp_loc, |
| 7943 | iftable_offset, |
| 7944 | kWithoutReadBarrier); |
| 7945 | // Iftable is never null. |
| 7946 | __ movl(maybe_temp2_loc.AsRegister<Register>(), Address(temp, array_length_offset)); |
| 7947 | // Maybe poison the `cls` for direct comparison with memory. |
| 7948 | __ MaybePoisonHeapReference(cls.AsRegister<Register>()); |
| 7949 | // Loop through the iftable and check if any class matches. |
| 7950 | NearLabel start_loop; |
| 7951 | __ Bind(&start_loop); |
| 7952 | // Need to subtract first to handle the empty array case. |
| 7953 | __ subl(maybe_temp2_loc.AsRegister<Register>(), Immediate(2)); |
| 7954 | __ j(kNegative, type_check_slow_path->GetEntryLabel()); |
| 7955 | // Go to next interface if the classes do not match. |
| 7956 | __ cmpl(cls.AsRegister<Register>(), |
| 7957 | CodeGeneratorX86::ArrayAddress(temp, |
| 7958 | maybe_temp2_loc, |
| 7959 | TIMES_4, |
| 7960 | object_array_data_offset)); |
| 7961 | __ j(kNotEqual, &start_loop); |
| 7962 | // If `cls` was poisoned above, unpoison it. |
| 7963 | __ MaybeUnpoisonHeapReference(cls.AsRegister<Register>()); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7964 | break; |
| 7965 | } |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7966 | |
| 7967 | case TypeCheckKind::kBitstringCheck: { |
| 7968 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7969 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7970 | temp_loc, |
| 7971 | obj_loc, |
| 7972 | class_offset, |
| 7973 | kWithoutReadBarrier); |
| 7974 | |
| 7975 | GenerateBitstringTypeCheckCompare(instruction, temp); |
| 7976 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
| 7977 | break; |
| 7978 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7979 | } |
| 7980 | __ Bind(&done); |
| 7981 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7982 | __ Bind(type_check_slow_path->GetExitLabel()); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7983 | } |
| 7984 | |
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7985 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7986 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 7987 | instruction, LocationSummary::kCallOnMainOnly); |
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7988 | InvokeRuntimeCallingConvention calling_convention; |
| 7989 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 7990 | } |
| 7991 | |
| 7992 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 7993 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject |
| 7994 | : kQuickUnlockObject, |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 7995 | instruction, |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 7996 | instruction->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7997 | if (instruction->IsEnter()) { |
| 7998 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 7999 | } else { |
| 8000 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 8001 | } |
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 8002 | } |
| 8003 | |
| Shalini Salomi Bodapati | dd121f6 | 2018-10-26 15:03:53 +0530 | [diff] [blame] | 8004 | void LocationsBuilderX86::VisitX86AndNot(HX86AndNot* instruction) { |
| 8005 | DCHECK(codegen_->GetInstructionSetFeatures().HasAVX2()); |
| 8006 | DCHECK(DataType::IsIntOrLongType(instruction->GetType())) << instruction->GetType(); |
| 8007 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| 8008 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8009 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8010 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8011 | } |
| 8012 | |
| 8013 | void InstructionCodeGeneratorX86::VisitX86AndNot(HX86AndNot* instruction) { |
| 8014 | LocationSummary* locations = instruction->GetLocations(); |
| 8015 | Location first = locations->InAt(0); |
| 8016 | Location second = locations->InAt(1); |
| 8017 | Location dest = locations->Out(); |
| 8018 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
| 8019 | __ andn(dest.AsRegister<Register>(), |
| 8020 | first.AsRegister<Register>(), |
| 8021 | second.AsRegister<Register>()); |
| 8022 | } else { |
| 8023 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
| 8024 | __ andn(dest.AsRegisterPairLow<Register>(), |
| 8025 | first.AsRegisterPairLow<Register>(), |
| 8026 | second.AsRegisterPairLow<Register>()); |
| 8027 | __ andn(dest.AsRegisterPairHigh<Register>(), |
| 8028 | first.AsRegisterPairHigh<Register>(), |
| 8029 | second.AsRegisterPairHigh<Register>()); |
| 8030 | } |
| 8031 | } |
| 8032 | |
| 8033 | void LocationsBuilderX86::VisitX86MaskOrResetLeastSetBit(HX86MaskOrResetLeastSetBit* instruction) { |
| 8034 | DCHECK(codegen_->GetInstructionSetFeatures().HasAVX2()); |
| 8035 | DCHECK(instruction->GetType() == DataType::Type::kInt32) << instruction->GetType(); |
| 8036 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| 8037 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8038 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8039 | } |
| 8040 | |
| 8041 | void InstructionCodeGeneratorX86::VisitX86MaskOrResetLeastSetBit( |
| 8042 | HX86MaskOrResetLeastSetBit* instruction) { |
| 8043 | LocationSummary* locations = instruction->GetLocations(); |
| 8044 | Location src = locations->InAt(0); |
| 8045 | Location dest = locations->Out(); |
| 8046 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
| 8047 | switch (instruction->GetOpKind()) { |
| 8048 | case HInstruction::kAnd: |
| 8049 | __ blsr(dest.AsRegister<Register>(), src.AsRegister<Register>()); |
| 8050 | break; |
| 8051 | case HInstruction::kXor: |
| 8052 | __ blsmsk(dest.AsRegister<Register>(), src.AsRegister<Register>()); |
| 8053 | break; |
| 8054 | default: |
| 8055 | LOG(FATAL) << "Unreachable"; |
| 8056 | } |
| 8057 | } |
| 8058 | |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8059 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 8060 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 8061 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 8062 | |
| 8063 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 8064 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8065 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8066 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 |
| 8067 | || instruction->GetResultType() == DataType::Type::kInt64); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8068 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8069 | locations->SetInAt(1, Location::Any()); |
| 8070 | locations->SetOut(Location::SameAsFirstInput()); |
| 8071 | } |
| 8072 | |
| 8073 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 8074 | HandleBitwiseOperation(instruction); |
| 8075 | } |
| 8076 | |
| 8077 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 8078 | HandleBitwiseOperation(instruction); |
| 8079 | } |
| 8080 | |
| 8081 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 8082 | HandleBitwiseOperation(instruction); |
| 8083 | } |
| 8084 | |
| 8085 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 8086 | LocationSummary* locations = instruction->GetLocations(); |
| 8087 | Location first = locations->InAt(0); |
| 8088 | Location second = locations->InAt(1); |
| 8089 | DCHECK(first.Equals(locations->Out())); |
| 8090 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8091 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8092 | if (second.IsRegister()) { |
| 8093 | if (instruction->IsAnd()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 8094 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8095 | } else if (instruction->IsOr()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 8096 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8097 | } else { |
| 8098 | DCHECK(instruction->IsXor()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 8099 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8100 | } |
| 8101 | } else if (second.IsConstant()) { |
| 8102 | if (instruction->IsAnd()) { |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 8103 | __ andl(first.AsRegister<Register>(), |
| 8104 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8105 | } else if (instruction->IsOr()) { |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 8106 | __ orl(first.AsRegister<Register>(), |
| 8107 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8108 | } else { |
| 8109 | DCHECK(instruction->IsXor()); |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 8110 | __ xorl(first.AsRegister<Register>(), |
| 8111 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8112 | } |
| 8113 | } else { |
| 8114 | if (instruction->IsAnd()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 8115 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8116 | } else if (instruction->IsOr()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 8117 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8118 | } else { |
| 8119 | DCHECK(instruction->IsXor()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 8120 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8121 | } |
| 8122 | } |
| 8123 | } else { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8124 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8125 | if (second.IsRegisterPair()) { |
| 8126 | if (instruction->IsAnd()) { |
| 8127 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 8128 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 8129 | } else if (instruction->IsOr()) { |
| 8130 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 8131 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 8132 | } else { |
| 8133 | DCHECK(instruction->IsXor()); |
| 8134 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 8135 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 8136 | } |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 8137 | } else if (second.IsDoubleStackSlot()) { |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8138 | if (instruction->IsAnd()) { |
| 8139 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 8140 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 8141 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 8142 | } else if (instruction->IsOr()) { |
| 8143 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 8144 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 8145 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 8146 | } else { |
| 8147 | DCHECK(instruction->IsXor()); |
| 8148 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 8149 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 8150 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 8151 | } |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 8152 | } else { |
| 8153 | DCHECK(second.IsConstant()) << second; |
| 8154 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 8155 | int32_t low_value = Low32Bits(value); |
| 8156 | int32_t high_value = High32Bits(value); |
| 8157 | Immediate low(low_value); |
| 8158 | Immediate high(high_value); |
| 8159 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 8160 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 8161 | if (instruction->IsAnd()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 8162 | if (low_value == 0) { |
| 8163 | __ xorl(first_low, first_low); |
| 8164 | } else if (low_value != -1) { |
| 8165 | __ andl(first_low, low); |
| 8166 | } |
| 8167 | if (high_value == 0) { |
| 8168 | __ xorl(first_high, first_high); |
| 8169 | } else if (high_value != -1) { |
| 8170 | __ andl(first_high, high); |
| 8171 | } |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 8172 | } else if (instruction->IsOr()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 8173 | if (low_value != 0) { |
| 8174 | __ orl(first_low, low); |
| 8175 | } |
| 8176 | if (high_value != 0) { |
| 8177 | __ orl(first_high, high); |
| 8178 | } |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 8179 | } else { |
| 8180 | DCHECK(instruction->IsXor()); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 8181 | if (low_value != 0) { |
| 8182 | __ xorl(first_low, low); |
| 8183 | } |
| 8184 | if (high_value != 0) { |
| 8185 | __ xorl(first_high, high); |
| 8186 | } |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 8187 | } |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8188 | } |
| 8189 | } |
| 8190 | } |
| 8191 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 8192 | void InstructionCodeGeneratorX86::GenerateReferenceLoadOneRegister( |
| 8193 | HInstruction* instruction, |
| 8194 | Location out, |
| 8195 | uint32_t offset, |
| 8196 | Location maybe_temp, |
| 8197 | ReadBarrierOption read_barrier_option) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8198 | Register out_reg = out.AsRegister<Register>(); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 8199 | if (read_barrier_option == kWithReadBarrier) { |
| 8200 | CHECK(kEmitCompilerReadBarrier); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8201 | if (kUseBakerReadBarrier) { |
| 8202 | // Load with fast path based Baker's read barrier. |
| 8203 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8204 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8205 | instruction, out, out_reg, offset, /* needs_null_check= */ false); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8206 | } else { |
| 8207 | // Load with slow path based read barrier. |
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 8208 | // Save the value of `out` into `maybe_temp` before overwriting it |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8209 | // in the following move operation, as we will need it for the |
| 8210 | // read barrier below. |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 8211 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 8212 | __ movl(maybe_temp.AsRegister<Register>(), out_reg); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8213 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8214 | __ movl(out_reg, Address(out_reg, offset)); |
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 8215 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8216 | } |
| 8217 | } else { |
| 8218 | // Plain load with no read barrier. |
| 8219 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8220 | __ movl(out_reg, Address(out_reg, offset)); |
| 8221 | __ MaybeUnpoisonHeapReference(out_reg); |
| 8222 | } |
| 8223 | } |
| 8224 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 8225 | void InstructionCodeGeneratorX86::GenerateReferenceLoadTwoRegisters( |
| 8226 | HInstruction* instruction, |
| 8227 | Location out, |
| 8228 | Location obj, |
| 8229 | uint32_t offset, |
| 8230 | ReadBarrierOption read_barrier_option) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8231 | Register out_reg = out.AsRegister<Register>(); |
| 8232 | Register obj_reg = obj.AsRegister<Register>(); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 8233 | if (read_barrier_option == kWithReadBarrier) { |
| 8234 | CHECK(kEmitCompilerReadBarrier); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8235 | if (kUseBakerReadBarrier) { |
| 8236 | // Load with fast path based Baker's read barrier. |
| 8237 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8238 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8239 | instruction, out, obj_reg, offset, /* needs_null_check= */ false); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8240 | } else { |
| 8241 | // Load with slow path based read barrier. |
| 8242 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8243 | __ movl(out_reg, Address(obj_reg, offset)); |
| 8244 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 8245 | } |
| 8246 | } else { |
| 8247 | // Plain load with no read barrier. |
| 8248 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8249 | __ movl(out_reg, Address(obj_reg, offset)); |
| 8250 | __ MaybeUnpoisonHeapReference(out_reg); |
| 8251 | } |
| 8252 | } |
| 8253 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 8254 | void InstructionCodeGeneratorX86::GenerateGcRootFieldLoad( |
| 8255 | HInstruction* instruction, |
| 8256 | Location root, |
| 8257 | const Address& address, |
| 8258 | Label* fixup_label, |
| 8259 | ReadBarrierOption read_barrier_option) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8260 | Register root_reg = root.AsRegister<Register>(); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 8261 | if (read_barrier_option == kWithReadBarrier) { |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 8262 | DCHECK(kEmitCompilerReadBarrier); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8263 | if (kUseBakerReadBarrier) { |
| 8264 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 8265 | // Baker's read barrier are used: |
| 8266 | // |
| Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 8267 | // root = obj.field; |
| 8268 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 8269 | // if (temp != null) { |
| 8270 | // root = temp(root) |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8271 | // } |
| 8272 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8273 | // /* GcRoot<mirror::Object> */ root = *address |
| 8274 | __ movl(root_reg, address); |
| 8275 | if (fixup_label != nullptr) { |
| 8276 | __ Bind(fixup_label); |
| 8277 | } |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8278 | static_assert( |
| 8279 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 8280 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 8281 | "have different sizes."); |
| 8282 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 8283 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 8284 | "have different sizes."); |
| 8285 | |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 8286 | // Slow path marking the GC root `root`. |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8287 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathX86( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8288 | instruction, root, /* unpoison_ref_before_marking= */ false); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8289 | codegen_->AddSlowPath(slow_path); |
| 8290 | |
| Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 8291 | // Test the entrypoint (`Thread::Current()->pReadBarrierMarkReg ## root.reg()`). |
| 8292 | const int32_t entry_point_offset = |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 8293 | Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(root.reg()); |
| Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 8294 | __ fs()->cmpl(Address::Absolute(entry_point_offset), Immediate(0)); |
| 8295 | // The entrypoint is null when the GC is not marking. |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8296 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 8297 | __ Bind(slow_path->GetExitLabel()); |
| 8298 | } else { |
| 8299 | // GC root loaded through a slow path for read barriers other |
| 8300 | // than Baker's. |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8301 | // /* GcRoot<mirror::Object>* */ root = address |
| 8302 | __ leal(root_reg, address); |
| 8303 | if (fixup_label != nullptr) { |
| 8304 | __ Bind(fixup_label); |
| 8305 | } |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8306 | // /* mirror::Object* */ root = root->Read() |
| 8307 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 8308 | } |
| 8309 | } else { |
| 8310 | // Plain GC root load with no read barrier. |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8311 | // /* GcRoot<mirror::Object> */ root = *address |
| 8312 | __ movl(root_reg, address); |
| 8313 | if (fixup_label != nullptr) { |
| 8314 | __ Bind(fixup_label); |
| 8315 | } |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 8316 | // Note that GC roots are not affected by heap poisoning, thus we |
| 8317 | // do not have to unpoison `root_reg` here. |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8318 | } |
| 8319 | } |
| 8320 | |
| 8321 | void CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8322 | Location ref, |
| 8323 | Register obj, |
| 8324 | uint32_t offset, |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8325 | bool needs_null_check) { |
| 8326 | DCHECK(kEmitCompilerReadBarrier); |
| 8327 | DCHECK(kUseBakerReadBarrier); |
| 8328 | |
| 8329 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 8330 | Address src(obj, offset); |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 8331 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8332 | } |
| 8333 | |
| 8334 | void CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8335 | Location ref, |
| 8336 | Register obj, |
| 8337 | uint32_t data_offset, |
| 8338 | Location index, |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8339 | bool needs_null_check) { |
| 8340 | DCHECK(kEmitCompilerReadBarrier); |
| 8341 | DCHECK(kUseBakerReadBarrier); |
| 8342 | |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 8343 | static_assert( |
| 8344 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 8345 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8346 | // /* HeapReference<Object> */ ref = |
| 8347 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8348 | Address src = CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset); |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 8349 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8350 | } |
| 8351 | |
| 8352 | void CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8353 | Location ref, |
| 8354 | Register obj, |
| 8355 | const Address& src, |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 8356 | bool needs_null_check, |
| 8357 | bool always_update_field, |
| 8358 | Register* temp) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8359 | DCHECK(kEmitCompilerReadBarrier); |
| 8360 | DCHECK(kUseBakerReadBarrier); |
| 8361 | |
| 8362 | // In slow path based read barriers, the read barrier call is |
| 8363 | // inserted after the original load. However, in fast path based |
| 8364 | // Baker's read barriers, we need to perform the load of |
| 8365 | // mirror::Object::monitor_ *before* the original reference load. |
| 8366 | // This load-load ordering is required by the read barrier. |
| 8367 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 8368 | // |
| 8369 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 8370 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 8371 | // HeapReference<Object> ref = *src; // Original reference load. |
| Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 8372 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8373 | // if (is_gray) { |
| 8374 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 8375 | // } |
| 8376 | // |
| 8377 | // Note: the original implementation in ReadBarrier::Barrier is |
| 8378 | // slightly more complex as: |
| 8379 | // - it implements the load-load fence using a data dependency on |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 8380 | // the high-bits of rb_state, which are expected to be all zeroes |
| 8381 | // (we use CodeGeneratorX86::GenerateMemoryBarrier instead here, |
| 8382 | // which is a no-op thanks to the x86 memory model); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8383 | // - it performs additional checks that we do not do here for |
| 8384 | // performance reasons. |
| 8385 | |
| 8386 | Register ref_reg = ref.AsRegister<Register>(); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8387 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 8388 | |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 8389 | // 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] | 8390 | static_assert(ReadBarrier::NonGrayState() == 0, "Expecting non-gray to have value 0"); |
| Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 8391 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 8392 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 8393 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 8394 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 8395 | |
| Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 8396 | // if (rb_state == ReadBarrier::GrayState()) |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 8397 | // ref = ReadBarrier::Mark(ref); |
| 8398 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 8399 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8400 | if (needs_null_check) { |
| 8401 | MaybeRecordImplicitNullCheck(instruction); |
| 8402 | } |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8403 | |
| 8404 | // Load fence to prevent load-load reordering. |
| 8405 | // Note that this is a no-op, thanks to the x86 memory model. |
| 8406 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 8407 | |
| 8408 | // The actual reference load. |
| 8409 | // /* HeapReference<Object> */ ref = *src |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 8410 | __ movl(ref_reg, src); // Flags are unaffected. |
| 8411 | |
| 8412 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 8413 | // Slow path marking the object `ref` when it is gray. |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 8414 | SlowPathCode* slow_path; |
| 8415 | if (always_update_field) { |
| 8416 | DCHECK(temp != nullptr); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8417 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkAndUpdateFieldSlowPathX86( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8418 | instruction, ref, obj, src, /* unpoison_ref_before_marking= */ true, *temp); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 8419 | } else { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8420 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkSlowPathX86( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8421 | instruction, ref, /* unpoison_ref_before_marking= */ true); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 8422 | } |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 8423 | AddSlowPath(slow_path); |
| 8424 | |
| 8425 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 8426 | __ j(kNotZero, slow_path->GetEntryLabel()); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8427 | |
| 8428 | // Object* ref = ref_addr->AsMirrorPtr() |
| 8429 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 8430 | |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8431 | __ Bind(slow_path->GetExitLabel()); |
| 8432 | } |
| 8433 | |
| 8434 | void CodeGeneratorX86::GenerateReadBarrierSlow(HInstruction* instruction, |
| 8435 | Location out, |
| 8436 | Location ref, |
| 8437 | Location obj, |
| 8438 | uint32_t offset, |
| 8439 | Location index) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8440 | DCHECK(kEmitCompilerReadBarrier); |
| 8441 | |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8442 | // Insert a slow path based read barrier *after* the reference load. |
| 8443 | // |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8444 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 8445 | // reference will be carried out by the runtime within the slow |
| 8446 | // path. |
| 8447 | // |
| 8448 | // Note that `ref` currently does not get unpoisoned (when heap |
| 8449 | // poisoning is enabled), which is alright as the `ref` argument is |
| 8450 | // not used by the artReadBarrierSlow entry point. |
| 8451 | // |
| 8452 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8453 | SlowPathCode* slow_path = new (GetScopedAllocator()) |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8454 | ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); |
| 8455 | AddSlowPath(slow_path); |
| 8456 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8457 | __ jmp(slow_path->GetEntryLabel()); |
| 8458 | __ Bind(slow_path->GetExitLabel()); |
| 8459 | } |
| 8460 | |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8461 | void CodeGeneratorX86::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 8462 | Location out, |
| 8463 | Location ref, |
| 8464 | Location obj, |
| 8465 | uint32_t offset, |
| 8466 | Location index) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8467 | if (kEmitCompilerReadBarrier) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8468 | // Baker's read barriers shall be handled by the fast path |
| 8469 | // (CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier). |
| 8470 | DCHECK(!kUseBakerReadBarrier); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8471 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 8472 | // by the runtime within the slow path. |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8473 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8474 | } else if (kPoisonHeapReferences) { |
| 8475 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 8476 | } |
| 8477 | } |
| 8478 | |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8479 | void CodeGeneratorX86::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 8480 | Location out, |
| 8481 | Location root) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8482 | DCHECK(kEmitCompilerReadBarrier); |
| 8483 | |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8484 | // Insert a slow path based read barrier *after* the GC root load. |
| 8485 | // |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8486 | // Note that GC roots are not affected by heap poisoning, so we do |
| 8487 | // not need to do anything special for this here. |
| 8488 | SlowPathCode* slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8489 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathX86(instruction, out, root); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8490 | AddSlowPath(slow_path); |
| 8491 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8492 | __ jmp(slow_path->GetEntryLabel()); |
| 8493 | __ Bind(slow_path->GetExitLabel()); |
| 8494 | } |
| 8495 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 8496 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8497 | // Nothing to do, this should be removed during prepare for register allocator. |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8498 | LOG(FATAL) << "Unreachable"; |
| 8499 | } |
| 8500 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 8501 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8502 | // Nothing to do, this should be removed during prepare for register allocator. |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8503 | LOG(FATAL) << "Unreachable"; |
| 8504 | } |
| 8505 | |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8506 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 8507 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 8508 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8509 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8510 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8511 | } |
| 8512 | |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8513 | void InstructionCodeGeneratorX86::GenPackedSwitchWithCompares(Register value_reg, |
| 8514 | int32_t lower_bound, |
| 8515 | uint32_t num_entries, |
| 8516 | HBasicBlock* switch_block, |
| 8517 | HBasicBlock* default_block) { |
| 8518 | // Figure out the correct compare values and jump conditions. |
| 8519 | // Handle the first compare/branch as a special case because it might |
| 8520 | // jump to the default case. |
| 8521 | DCHECK_GT(num_entries, 2u); |
| 8522 | Condition first_condition; |
| 8523 | uint32_t index; |
| 8524 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 8525 | if (lower_bound != 0) { |
| 8526 | first_condition = kLess; |
| 8527 | __ cmpl(value_reg, Immediate(lower_bound)); |
| 8528 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 8529 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8530 | |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8531 | index = 1; |
| 8532 | } else { |
| 8533 | // Handle all the compare/jumps below. |
| 8534 | first_condition = kBelow; |
| 8535 | index = 0; |
| 8536 | } |
| 8537 | |
| 8538 | // Handle the rest of the compare/jumps. |
| 8539 | for (; index + 1 < num_entries; index += 2) { |
| 8540 | int32_t compare_to_value = lower_bound + index + 1; |
| 8541 | __ cmpl(value_reg, Immediate(compare_to_value)); |
| 8542 | // Jump to successors[index] if value < case_value[index]. |
| 8543 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 8544 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 8545 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 8546 | } |
| 8547 | |
| 8548 | if (index != num_entries) { |
| 8549 | // There are an odd number of entries. Handle the last one. |
| 8550 | DCHECK_EQ(index + 1, num_entries); |
| 8551 | __ cmpl(value_reg, Immediate(lower_bound + index)); |
| 8552 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8553 | } |
| 8554 | |
| 8555 | // And the default for any other value. |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8556 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
| 8557 | __ jmp(codegen_->GetLabelOf(default_block)); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8558 | } |
| 8559 | } |
| 8560 | |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8561 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 8562 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 8563 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 8564 | LocationSummary* locations = switch_instr->GetLocations(); |
| 8565 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 8566 | |
| 8567 | GenPackedSwitchWithCompares(value_reg, |
| 8568 | lower_bound, |
| 8569 | num_entries, |
| 8570 | switch_instr->GetBlock(), |
| 8571 | switch_instr->GetDefaultBlock()); |
| 8572 | } |
| 8573 | |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8574 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 8575 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8576 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8577 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8578 | |
| 8579 | // Constant area pointer. |
| 8580 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8581 | |
| 8582 | // And the temporary we need. |
| 8583 | locations->AddTemp(Location::RequiresRegister()); |
| 8584 | } |
| 8585 | |
| 8586 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 8587 | int32_t lower_bound = switch_instr->GetStartValue(); |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8588 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8589 | LocationSummary* locations = switch_instr->GetLocations(); |
| 8590 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 8591 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 8592 | |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8593 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 8594 | GenPackedSwitchWithCompares(value_reg, |
| 8595 | lower_bound, |
| 8596 | num_entries, |
| 8597 | switch_instr->GetBlock(), |
| 8598 | default_block); |
| 8599 | return; |
| 8600 | } |
| 8601 | |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8602 | // Optimizing has a jump area. |
| 8603 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 8604 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 8605 | |
| 8606 | // Remove the bias, if needed. |
| 8607 | if (lower_bound != 0) { |
| 8608 | __ leal(temp_reg, Address(value_reg, -lower_bound)); |
| 8609 | value_reg = temp_reg; |
| 8610 | } |
| 8611 | |
| 8612 | // Is the value in range? |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8613 | DCHECK_GE(num_entries, 1u); |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8614 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 8615 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| 8616 | |
| 8617 | // We are in the range of the table. |
| 8618 | // Load (target-constant_area) from the jump table, indexing by the value. |
| 8619 | __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); |
| 8620 | |
| 8621 | // Compute the actual target address by adding in constant_area. |
| 8622 | __ addl(temp_reg, constant_area); |
| 8623 | |
| 8624 | // And jump. |
| 8625 | __ jmp(temp_reg); |
| 8626 | } |
| 8627 | |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8628 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 8629 | HX86ComputeBaseMethodAddress* insn) { |
| 8630 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8631 | new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8632 | locations->SetOut(Location::RequiresRegister()); |
| 8633 | } |
| 8634 | |
| 8635 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 8636 | HX86ComputeBaseMethodAddress* insn) { |
| 8637 | LocationSummary* locations = insn->GetLocations(); |
| 8638 | Register reg = locations->Out().AsRegister<Register>(); |
| 8639 | |
| 8640 | // Generate call to next instruction. |
| 8641 | Label next_instruction; |
| 8642 | __ call(&next_instruction); |
| 8643 | __ Bind(&next_instruction); |
| 8644 | |
| 8645 | // Remember this offset for later use with constant area. |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8646 | codegen_->AddMethodAddressOffset(insn, GetAssembler()->CodeSize()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8647 | |
| 8648 | // Grab the return address off the stack. |
| 8649 | __ popl(reg); |
| 8650 | } |
| 8651 | |
| 8652 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 8653 | HX86LoadFromConstantTable* insn) { |
| 8654 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8655 | new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8656 | |
| 8657 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8658 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 8659 | |
| 8660 | // 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] | 8661 | if (insn->IsEmittedAtUseSite()) { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8662 | return; |
| 8663 | } |
| 8664 | |
| 8665 | switch (insn->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8666 | case DataType::Type::kFloat32: |
| 8667 | case DataType::Type::kFloat64: |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8668 | locations->SetOut(Location::RequiresFpuRegister()); |
| 8669 | break; |
| 8670 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8671 | case DataType::Type::kInt32: |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8672 | locations->SetOut(Location::RequiresRegister()); |
| 8673 | break; |
| 8674 | |
| 8675 | default: |
| 8676 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 8677 | } |
| 8678 | } |
| 8679 | |
| 8680 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 8681 | if (insn->IsEmittedAtUseSite()) { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8682 | return; |
| 8683 | } |
| 8684 | |
| 8685 | LocationSummary* locations = insn->GetLocations(); |
| 8686 | Location out = locations->Out(); |
| 8687 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 8688 | HConstant *value = insn->GetConstant(); |
| 8689 | |
| 8690 | switch (insn->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8691 | case DataType::Type::kFloat32: |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8692 | __ movss(out.AsFpuRegister<XmmRegister>(), |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8693 | codegen_->LiteralFloatAddress( |
| 8694 | value->AsFloatConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8695 | break; |
| 8696 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8697 | case DataType::Type::kFloat64: |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8698 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8699 | codegen_->LiteralDoubleAddress( |
| 8700 | value->AsDoubleConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8701 | break; |
| 8702 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8703 | case DataType::Type::kInt32: |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8704 | __ movl(out.AsRegister<Register>(), |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8705 | codegen_->LiteralInt32Address( |
| 8706 | value->AsIntConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8707 | break; |
| 8708 | |
| 8709 | default: |
| 8710 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 8711 | } |
| 8712 | } |
| 8713 | |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8714 | /** |
| 8715 | * Class to handle late fixup of offsets into constant area. |
| 8716 | */ |
| Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 8717 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8718 | public: |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8719 | RIPFixup(CodeGeneratorX86& codegen, |
| 8720 | HX86ComputeBaseMethodAddress* base_method_address, |
| 8721 | size_t offset) |
| 8722 | : codegen_(&codegen), |
| 8723 | base_method_address_(base_method_address), |
| 8724 | offset_into_constant_area_(offset) {} |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8725 | |
| 8726 | protected: |
| 8727 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 8728 | |
| 8729 | CodeGeneratorX86* codegen_; |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8730 | HX86ComputeBaseMethodAddress* base_method_address_; |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8731 | |
| 8732 | private: |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8733 | void Process(const MemoryRegion& region, int pos) override { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8734 | // Patch the correct offset for the instruction. The place to patch is the |
| 8735 | // last 4 bytes of the instruction. |
| 8736 | // The value to patch is the distance from the offset in the constant area |
| 8737 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8738 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8739 | int32_t relative_position = |
| 8740 | constant_offset - codegen_->GetMethodAddressOffset(base_method_address_); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8741 | |
| 8742 | // Patch in the right value. |
| 8743 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 8744 | } |
| 8745 | |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8746 | // Location in constant area that the fixup refers to. |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8747 | int32_t offset_into_constant_area_; |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8748 | }; |
| 8749 | |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8750 | /** |
| 8751 | * Class to handle late fixup of offsets to a jump table that will be created in the |
| 8752 | * constant area. |
| 8753 | */ |
| 8754 | class JumpTableRIPFixup : public RIPFixup { |
| 8755 | public: |
| 8756 | JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8757 | : RIPFixup(codegen, switch_instr->GetBaseMethodAddress(), static_cast<size_t>(-1)), |
| 8758 | switch_instr_(switch_instr) {} |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8759 | |
| 8760 | void CreateJumpTable() { |
| 8761 | X86Assembler* assembler = codegen_->GetAssembler(); |
| 8762 | |
| 8763 | // Ensure that the reference to the jump table has the correct offset. |
| 8764 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 8765 | SetOffset(offset_in_constant_table); |
| 8766 | |
| 8767 | // The label values in the jump table are computed relative to the |
| 8768 | // instruction addressing the constant area. |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8769 | const int32_t relative_offset = codegen_->GetMethodAddressOffset(base_method_address_); |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8770 | |
| 8771 | // Populate the jump table with the correct values for the jump table. |
| 8772 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 8773 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 8774 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 8775 | // The value that we want is the target offset - the position of the table. |
| 8776 | for (int32_t i = 0; i < num_entries; i++) { |
| 8777 | HBasicBlock* b = successors[i]; |
| 8778 | Label* l = codegen_->GetLabelOf(b); |
| 8779 | DCHECK(l->IsBound()); |
| 8780 | int32_t offset_to_block = l->Position() - relative_offset; |
| 8781 | assembler->AppendInt32(offset_to_block); |
| 8782 | } |
| 8783 | } |
| 8784 | |
| 8785 | private: |
| 8786 | const HX86PackedSwitch* switch_instr_; |
| 8787 | }; |
| 8788 | |
| 8789 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 8790 | // Generate the constant area if needed. |
| 8791 | X86Assembler* assembler = GetAssembler(); |
| jaishank | 20d1c94 | 2019-03-08 15:08:17 +0530 | [diff] [blame] | 8792 | |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8793 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 8794 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 8795 | // byte values. |
| 8796 | assembler->Align(4, 0); |
| 8797 | constant_area_start_ = assembler->CodeSize(); |
| 8798 | |
| 8799 | // Populate any jump tables. |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 8800 | for (JumpTableRIPFixup* jump_table : fixups_to_jump_tables_) { |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8801 | jump_table->CreateJumpTable(); |
| 8802 | } |
| 8803 | |
| 8804 | // And now add the constant area to the generated code. |
| 8805 | assembler->AddConstantArea(); |
| 8806 | } |
| 8807 | |
| 8808 | // And finish up. |
| 8809 | CodeGenerator::Finalize(allocator); |
| 8810 | } |
| 8811 | |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8812 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, |
| 8813 | HX86ComputeBaseMethodAddress* method_base, |
| 8814 | Register reg) { |
| 8815 | AssemblerFixup* fixup = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8816 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddDouble(v)); |
| Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 8817 | return Address(reg, kPlaceholder32BitOffset, fixup); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8818 | } |
| 8819 | |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8820 | Address CodeGeneratorX86::LiteralFloatAddress(float v, |
| 8821 | HX86ComputeBaseMethodAddress* method_base, |
| 8822 | Register reg) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8823 | AssemblerFixup* fixup = |
| 8824 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddFloat(v)); |
| Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 8825 | return Address(reg, kPlaceholder32BitOffset, fixup); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8826 | } |
| 8827 | |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8828 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, |
| 8829 | HX86ComputeBaseMethodAddress* method_base, |
| 8830 | Register reg) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8831 | AssemblerFixup* fixup = |
| 8832 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddInt32(v)); |
| Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 8833 | return Address(reg, kPlaceholder32BitOffset, fixup); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8834 | } |
| 8835 | |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8836 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, |
| 8837 | HX86ComputeBaseMethodAddress* method_base, |
| 8838 | Register reg) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8839 | AssemblerFixup* fixup = |
| 8840 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddInt64(v)); |
| Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 8841 | return Address(reg, kPlaceholder32BitOffset, fixup); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8842 | } |
| 8843 | |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 8844 | void CodeGeneratorX86::Load32BitValue(Register dest, int32_t value) { |
| 8845 | if (value == 0) { |
| 8846 | __ xorl(dest, dest); |
| 8847 | } else { |
| 8848 | __ movl(dest, Immediate(value)); |
| 8849 | } |
| 8850 | } |
| 8851 | |
| 8852 | void CodeGeneratorX86::Compare32BitValue(Register dest, int32_t value) { |
| 8853 | if (value == 0) { |
| 8854 | __ testl(dest, dest); |
| 8855 | } else { |
| 8856 | __ cmpl(dest, Immediate(value)); |
| 8857 | } |
| 8858 | } |
| 8859 | |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8860 | void CodeGeneratorX86::GenerateIntCompare(Location lhs, Location rhs) { |
| 8861 | Register lhs_reg = lhs.AsRegister<Register>(); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8862 | GenerateIntCompare(lhs_reg, rhs); |
| 8863 | } |
| 8864 | |
| 8865 | void CodeGeneratorX86::GenerateIntCompare(Register lhs, Location rhs) { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8866 | if (rhs.IsConstant()) { |
| 8867 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8868 | Compare32BitValue(lhs, value); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8869 | } else if (rhs.IsStackSlot()) { |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8870 | __ cmpl(lhs, Address(ESP, rhs.GetStackIndex())); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8871 | } else { |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8872 | __ cmpl(lhs, rhs.AsRegister<Register>()); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8873 | } |
| 8874 | } |
| 8875 | |
| 8876 | Address CodeGeneratorX86::ArrayAddress(Register obj, |
| 8877 | Location index, |
| 8878 | ScaleFactor scale, |
| 8879 | uint32_t data_offset) { |
| 8880 | return index.IsConstant() ? |
| 8881 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) : |
| 8882 | Address(obj, index.AsRegister<Register>(), scale, data_offset); |
| 8883 | } |
| 8884 | |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8885 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, |
| 8886 | Register reg, |
| 8887 | Register value) { |
| 8888 | // Create a fixup to be used to create and address the jump table. |
| 8889 | JumpTableRIPFixup* table_fixup = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8890 | new (GetGraph()->GetAllocator()) JumpTableRIPFixup(*this, switch_instr); |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8891 | |
| 8892 | // We have to populate the jump tables. |
| 8893 | fixups_to_jump_tables_.push_back(table_fixup); |
| 8894 | |
| 8895 | // 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] | 8896 | return Address(reg, value, TIMES_4, kPlaceholder32BitOffset, table_fixup); |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8897 | } |
| 8898 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8899 | // TODO: target as memory. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8900 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, DataType::Type type) { |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8901 | if (!target.IsValid()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8902 | DCHECK_EQ(type, DataType::Type::kVoid); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8903 | return; |
| 8904 | } |
| 8905 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8906 | DCHECK_NE(type, DataType::Type::kVoid); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8907 | |
| 8908 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 8909 | if (target.Equals(return_loc)) { |
| 8910 | return; |
| 8911 | } |
| 8912 | |
| 8913 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 8914 | // with the else branch. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8915 | if (type == DataType::Type::kInt64) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8916 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8917 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), DataType::Type::kInt32, nullptr); |
| 8918 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), DataType::Type::kInt32, nullptr); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8919 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 8920 | } else { |
| 8921 | // Let the parallel move resolver take care of all of this. |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8922 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8923 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 8924 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 8925 | } |
| 8926 | } |
| 8927 | |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8928 | void CodeGeneratorX86::PatchJitRootUse(uint8_t* code, |
| 8929 | const uint8_t* roots_data, |
| 8930 | const PatchInfo<Label>& info, |
| 8931 | uint64_t index_in_table) const { |
| 8932 | uint32_t code_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 8933 | uintptr_t address = |
| 8934 | 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] | 8935 | using unaligned_uint32_t __attribute__((__aligned__(1))) = uint32_t; |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8936 | reinterpret_cast<unaligned_uint32_t*>(code + code_offset)[0] = |
| 8937 | dchecked_integral_cast<uint32_t>(address); |
| 8938 | } |
| 8939 | |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 8940 | void CodeGeneratorX86::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 8941 | for (const PatchInfo<Label>& info : jit_string_patches_) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8942 | 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] | 8943 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 8944 | PatchJitRootUse(code, roots_data, info, index_in_table); |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8945 | } |
| 8946 | |
| 8947 | for (const PatchInfo<Label>& info : jit_class_patches_) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8948 | 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] | 8949 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 8950 | PatchJitRootUse(code, roots_data, info, index_in_table); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 8951 | } |
| 8952 | } |
| 8953 | |
| xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 8954 | void LocationsBuilderX86::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 8955 | ATTRIBUTE_UNUSED) { |
| 8956 | LOG(FATAL) << "Unreachable"; |
| 8957 | } |
| 8958 | |
| 8959 | void InstructionCodeGeneratorX86::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 8960 | ATTRIBUTE_UNUSED) { |
| 8961 | LOG(FATAL) << "Unreachable"; |
| 8962 | } |
| 8963 | |
| Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 8964 | bool LocationsBuilderX86::CpuHasAvxFeatureFlag() { |
| 8965 | return codegen_->GetInstructionSetFeatures().HasAVX(); |
| 8966 | } |
| 8967 | bool LocationsBuilderX86::CpuHasAvx2FeatureFlag() { |
| 8968 | return codegen_->GetInstructionSetFeatures().HasAVX2(); |
| 8969 | } |
| 8970 | bool InstructionCodeGeneratorX86::CpuHasAvxFeatureFlag() { |
| 8971 | return codegen_->GetInstructionSetFeatures().HasAVX(); |
| 8972 | } |
| 8973 | bool InstructionCodeGeneratorX86::CpuHasAvx2FeatureFlag() { |
| 8974 | return codegen_->GetInstructionSetFeatures().HasAVX2(); |
| 8975 | } |
| 8976 | |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 8977 | #undef __ |
| 8978 | |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 8979 | } // namespace x86 |
| 8980 | } // namespace art |