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" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 23 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 24 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 25 | #include "gc/accounting/card_table.h" |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 26 | #include "gc/space/image_space.h" |
Andreas Gampe | 09659c2 | 2017-09-18 18:23:32 -0700 | [diff] [blame] | 27 | #include "heap_poisoning.h" |
Nicolas Geoffray | 8b8d93d | 2020-09-17 14:30:01 +0100 | [diff] [blame] | 28 | #include "interpreter/mterp/nterp.h" |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 29 | #include "intrinsics.h" |
Ulya Trafimovich | ec696e5 | 2022-01-26 10:21:32 +0000 | [diff] [blame] | 30 | #include "intrinsics_utils.h" |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 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" |
Santiago Aboy Solanes | d422960 | 2023-01-03 16:20:50 +0000 | [diff] [blame] | 38 | #include "optimizing/nodes.h" |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 39 | #include "scoped_thread_state_change-inl.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 40 | #include "thread.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 41 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 42 | #include "utils/stack_checks.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 43 | #include "utils/x86/assembler_x86.h" |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 44 | #include "utils/x86/managed_register_x86.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 45 | |
VladimĂr Marko | 434d968 | 2022-11-04 14:04:17 +0000 | [diff] [blame] | 46 | namespace art HIDDEN { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 47 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 48 | template<class MirrorType> |
| 49 | class GcRoot; |
| 50 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 51 | namespace x86 { |
| 52 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 53 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 54 | static constexpr Register kMethodRegisterArgument = EAX; |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 55 | static constexpr Register kCoreCalleeSaves[] = { EBP, ESI, EDI }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 56 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 57 | static constexpr int kC2ConditionMask = 0x400; |
| 58 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 59 | static constexpr int kFakeReturnRegister = Register(8); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 60 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 61 | static constexpr int64_t kDoubleNaN = INT64_C(0x7FF8000000000000); |
| 62 | static constexpr int32_t kFloatNaN = INT32_C(0x7FC00000); |
| 63 | |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 64 | static RegisterSet OneRegInReferenceOutSaveEverythingCallerSaves() { |
| 65 | InvokeRuntimeCallingConvention calling_convention; |
| 66 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 67 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 68 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 69 | // that the the kPrimNot result register is the same as the first argument register. |
| 70 | return caller_saves; |
| 71 | } |
| 72 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 73 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 74 | #define __ down_cast<X86Assembler*>(codegen->GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 75 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86PointerSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 76 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 77 | class NullCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 78 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 79 | explicit NullCheckSlowPathX86(HNullCheck* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 80 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 81 | void EmitNativeCode(CodeGenerator* codegen) override { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 82 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 83 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 84 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 85 | // Live registers will be restored in the catch block if caught. |
| 86 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 87 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 88 | x86_codegen->InvokeRuntime(kQuickThrowNullPointer, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 89 | instruction_, |
| 90 | instruction_->GetDexPc(), |
| 91 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 92 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 93 | } |
| 94 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 95 | bool IsFatal() const override { return true; } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 96 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 97 | const char* GetDescription() const override { return "NullCheckSlowPathX86"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 98 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 99 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 100 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86); |
| 101 | }; |
| 102 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 103 | class DivZeroCheckSlowPathX86 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 104 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 105 | explicit DivZeroCheckSlowPathX86(HDivZeroCheck* instruction) : SlowPathCode(instruction) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 106 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 107 | void EmitNativeCode(CodeGenerator* codegen) override { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 108 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 109 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 110 | x86_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 111 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 112 | } |
| 113 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 114 | bool IsFatal() const override { return true; } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 115 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 116 | const char* GetDescription() const override { return "DivZeroCheckSlowPathX86"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 117 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 118 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 119 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86); |
| 120 | }; |
| 121 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 122 | class DivRemMinusOneSlowPathX86 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 123 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 124 | DivRemMinusOneSlowPathX86(HInstruction* instruction, Register reg, bool is_div) |
| 125 | : SlowPathCode(instruction), reg_(reg), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 126 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 127 | void EmitNativeCode(CodeGenerator* codegen) override { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 128 | __ Bind(GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 129 | if (is_div_) { |
| 130 | __ negl(reg_); |
| 131 | } else { |
| 132 | __ movl(reg_, Immediate(0)); |
| 133 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 134 | __ jmp(GetExitLabel()); |
| 135 | } |
| 136 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 137 | const char* GetDescription() const override { return "DivRemMinusOneSlowPathX86"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 138 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 139 | private: |
| 140 | Register reg_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 141 | bool is_div_; |
| 142 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 143 | }; |
| 144 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 145 | class BoundsCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 146 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 147 | explicit BoundsCheckSlowPathX86(HBoundsCheck* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 148 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 149 | void EmitNativeCode(CodeGenerator* codegen) override { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 150 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 151 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 152 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 153 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 154 | // Live registers will be restored in the catch block if caught. |
Vladimir Marko | d77cf74 | 2022-04-12 10:46:28 +0100 | [diff] [blame] | 155 | SaveLiveRegisters(codegen, locations); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 156 | } |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 157 | |
Vladimir Marko | d77cf74 | 2022-04-12 10:46:28 +0100 | [diff] [blame] | 158 | Location index_loc = locations->InAt(0); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 159 | Location length_loc = locations->InAt(1); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 160 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | d77cf74 | 2022-04-12 10:46:28 +0100 | [diff] [blame] | 161 | Location index_arg = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 162 | Location length_arg = Location::RegisterLocation(calling_convention.GetRegisterAt(1)); |
| 163 | |
| 164 | // Are we using an array length from memory? |
| 165 | if (!length_loc.IsValid()) { |
| 166 | DCHECK(instruction_->InputAt(1)->IsArrayLength()); |
| 167 | HArrayLength* array_length = instruction_->InputAt(1)->AsArrayLength(); |
| 168 | DCHECK(array_length->IsEmittedAtUseSite()); |
| 169 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 170 | Location array_loc = array_length->GetLocations()->InAt(0); |
Vladimir Marko | d77cf74 | 2022-04-12 10:46:28 +0100 | [diff] [blame] | 171 | if (!index_loc.Equals(length_arg)) { |
| 172 | // The index is not clobbered by loading the length directly to `length_arg`. |
| 173 | __ movl(length_arg.AsRegister<Register>(), |
| 174 | Address(array_loc.AsRegister<Register>(), len_offset)); |
| 175 | x86_codegen->Move32(index_arg, index_loc); |
| 176 | } else if (!array_loc.Equals(index_arg)) { |
| 177 | // The array reference is not clobbered by the index move. |
| 178 | x86_codegen->Move32(index_arg, index_loc); |
| 179 | __ movl(length_arg.AsRegister<Register>(), |
| 180 | Address(array_loc.AsRegister<Register>(), len_offset)); |
| 181 | } else { |
| 182 | // We do not have a temporary we could use, so swap the registers using the |
| 183 | // parallel move resolver and replace the array with the length afterwards. |
| 184 | codegen->EmitParallelMoves( |
| 185 | index_loc, |
| 186 | index_arg, |
| 187 | DataType::Type::kInt32, |
| 188 | array_loc, |
| 189 | length_arg, |
| 190 | DataType::Type::kReference); |
| 191 | __ movl(length_arg.AsRegister<Register>(), |
| 192 | Address(length_arg.AsRegister<Register>(), len_offset)); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 193 | } |
Vladimir Marko | d77cf74 | 2022-04-12 10:46:28 +0100 | [diff] [blame] | 194 | if (mirror::kUseStringCompression && array_length->IsStringLength()) { |
| 195 | __ shrl(length_arg.AsRegister<Register>(), Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 196 | } |
Vladimir Marko | d77cf74 | 2022-04-12 10:46:28 +0100 | [diff] [blame] | 197 | } else { |
| 198 | // We're moving two locations to locations that could overlap, |
| 199 | // so we need a parallel move resolver. |
| 200 | codegen->EmitParallelMoves( |
| 201 | index_loc, |
| 202 | index_arg, |
| 203 | DataType::Type::kInt32, |
| 204 | length_loc, |
| 205 | length_arg, |
| 206 | DataType::Type::kInt32); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 207 | } |
Vladimir Marko | d77cf74 | 2022-04-12 10:46:28 +0100 | [diff] [blame] | 208 | |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 209 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 210 | ? kQuickThrowStringBounds |
| 211 | : kQuickThrowArrayBounds; |
| 212 | x86_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 213 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 214 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 215 | } |
| 216 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 217 | bool IsFatal() const override { return true; } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 218 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 219 | const char* GetDescription() const override { return "BoundsCheckSlowPathX86"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 220 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 221 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 222 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86); |
| 223 | }; |
| 224 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 225 | class SuspendCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 226 | public: |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 227 | SuspendCheckSlowPathX86(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 228 | : SlowPathCode(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 229 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 230 | void EmitNativeCode(CodeGenerator* codegen) override { |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 231 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 232 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 233 | __ Bind(GetEntryLabel()); |
Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 234 | SaveLiveRegisters(codegen, locations); // Only saves full width XMM for SIMD. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 235 | x86_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 236 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 237 | RestoreLiveRegisters(codegen, locations); // Only restores full width XMM for SIMD. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 238 | if (successor_ == nullptr) { |
| 239 | __ jmp(GetReturnLabel()); |
| 240 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 241 | __ jmp(x86_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 242 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 243 | } |
| 244 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 245 | Label* GetReturnLabel() { |
| 246 | DCHECK(successor_ == nullptr); |
| 247 | return &return_label_; |
| 248 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 249 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 250 | HBasicBlock* GetSuccessor() const { |
| 251 | return successor_; |
| 252 | } |
| 253 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 254 | const char* GetDescription() const override { return "SuspendCheckSlowPathX86"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 255 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 256 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 257 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 258 | Label return_label_; |
| 259 | |
| 260 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86); |
| 261 | }; |
| 262 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 263 | class LoadStringSlowPathX86 : public SlowPathCode { |
| 264 | public: |
| 265 | explicit LoadStringSlowPathX86(HLoadString* instruction): SlowPathCode(instruction) {} |
| 266 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 267 | void EmitNativeCode(CodeGenerator* codegen) override { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 268 | LocationSummary* locations = instruction_->GetLocations(); |
| 269 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 270 | |
| 271 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 272 | __ Bind(GetEntryLabel()); |
| 273 | SaveLiveRegisters(codegen, locations); |
| 274 | |
| 275 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 276 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 277 | __ movl(calling_convention.GetRegisterAt(0), Immediate(string_index.index_)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 278 | x86_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 279 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 280 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 281 | RestoreLiveRegisters(codegen, locations); |
| 282 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 283 | __ jmp(GetExitLabel()); |
| 284 | } |
| 285 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 286 | const char* GetDescription() const override { return "LoadStringSlowPathX86"; } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 287 | |
| 288 | private: |
| 289 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86); |
| 290 | }; |
| 291 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 292 | class LoadClassSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 293 | public: |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 294 | LoadClassSlowPathX86(HLoadClass* cls, HInstruction* at) |
| 295 | : SlowPathCode(at), cls_(cls) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 296 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 297 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 298 | } |
| 299 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 300 | void EmitNativeCode(CodeGenerator* codegen) override { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 301 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 302 | Location out = locations->Out(); |
| 303 | const uint32_t dex_pc = instruction_->GetDexPc(); |
| 304 | bool must_resolve_type = instruction_->IsLoadClass() && cls_->MustResolveTypeOnSlowPath(); |
| 305 | bool must_do_clinit = instruction_->IsClinitCheck() || cls_->MustGenerateClinitCheck(); |
| 306 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 307 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 308 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 309 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 310 | |
| 311 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 312 | if (must_resolve_type) { |
Santiago Aboy Solanes | a0232ad | 2021-11-08 17:00:06 +0000 | [diff] [blame] | 313 | DCHECK(IsSameDexFile(cls_->GetDexFile(), x86_codegen->GetGraph()->GetDexFile()) || |
Santiago Aboy Solanes | 69a87e3 | 2022-03-08 16:43:54 +0000 | [diff] [blame] | 314 | x86_codegen->GetCompilerOptions().WithinOatFile(&cls_->GetDexFile()) || |
| 315 | ContainsElement(Runtime::Current()->GetClassLinker()->GetBootClassPath(), |
| 316 | &cls_->GetDexFile())); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 317 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 318 | __ movl(calling_convention.GetRegisterAt(0), Immediate(type_index.index_)); |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 319 | if (cls_->NeedsAccessCheck()) { |
| 320 | CheckEntrypointTypes<kQuickResolveTypeAndVerifyAccess, void*, uint32_t>(); |
| 321 | x86_codegen->InvokeRuntime(kQuickResolveTypeAndVerifyAccess, instruction_, dex_pc, this); |
| 322 | } else { |
| 323 | CheckEntrypointTypes<kQuickResolveType, void*, uint32_t>(); |
| 324 | x86_codegen->InvokeRuntime(kQuickResolveType, instruction_, dex_pc, this); |
| 325 | } |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 326 | // If we also must_do_clinit, the resolved type is now in the correct register. |
| 327 | } else { |
| 328 | DCHECK(must_do_clinit); |
| 329 | Location source = instruction_->IsLoadClass() ? out : locations->InAt(0); |
| 330 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), source); |
| 331 | } |
| 332 | if (must_do_clinit) { |
| 333 | x86_codegen->InvokeRuntime(kQuickInitializeStaticStorage, instruction_, dex_pc, this); |
| 334 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, mirror::Class*>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 335 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 336 | |
| 337 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 338 | if (out.IsValid()) { |
| 339 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 340 | x86_codegen->Move32(out, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 341 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 342 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 343 | __ jmp(GetExitLabel()); |
| 344 | } |
| 345 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 346 | const char* GetDescription() const override { return "LoadClassSlowPathX86"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 347 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 348 | private: |
| 349 | // The class this slow path will load. |
| 350 | HLoadClass* const cls_; |
| 351 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 352 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86); |
| 353 | }; |
| 354 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 355 | class TypeCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 356 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 357 | TypeCheckSlowPathX86(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 358 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 359 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 360 | void EmitNativeCode(CodeGenerator* codegen) override { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 361 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 362 | DCHECK(instruction_->IsCheckCast() |
| 363 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 364 | |
| 365 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 366 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 367 | |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 368 | if (kPoisonHeapReferences && |
| 369 | instruction_->IsCheckCast() && |
| 370 | instruction_->AsCheckCast()->GetTypeCheckKind() == TypeCheckKind::kInterfaceCheck) { |
| 371 | // First, unpoison the `cls` reference that was poisoned for direct memory comparison. |
| 372 | __ UnpoisonHeapReference(locations->InAt(1).AsRegister<Register>()); |
| 373 | } |
| 374 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 375 | if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 376 | SaveLiveRegisters(codegen, locations); |
| 377 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 378 | |
| 379 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 380 | // move resolver. |
| 381 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 382 | x86_codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 383 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 384 | DataType::Type::kReference, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 385 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 386 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 387 | DataType::Type::kReference); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 388 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 389 | x86_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 390 | instruction_, |
| 391 | instruction_->GetDexPc(), |
| 392 | this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 393 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 394 | } else { |
| 395 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 396 | x86_codegen->InvokeRuntime(kQuickCheckInstanceOf, |
| 397 | instruction_, |
| 398 | instruction_->GetDexPc(), |
| 399 | this); |
| 400 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 401 | } |
| 402 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 403 | if (!is_fatal_) { |
| 404 | if (instruction_->IsInstanceOf()) { |
| 405 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 406 | } |
| 407 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 408 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 409 | __ jmp(GetExitLabel()); |
| 410 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 411 | } |
| 412 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 413 | const char* GetDescription() const override { return "TypeCheckSlowPathX86"; } |
| 414 | bool IsFatal() const override { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 415 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 416 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 417 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 418 | |
| 419 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86); |
| 420 | }; |
| 421 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 422 | class DeoptimizationSlowPathX86 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 423 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 424 | explicit DeoptimizationSlowPathX86(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 425 | : SlowPathCode(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 426 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 427 | void EmitNativeCode(CodeGenerator* codegen) override { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 428 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 429 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 430 | LocationSummary* locations = instruction_->GetLocations(); |
| 431 | SaveLiveRegisters(codegen, locations); |
| 432 | InvokeRuntimeCallingConvention calling_convention; |
| 433 | x86_codegen->Load32BitValue( |
| 434 | calling_convention.GetRegisterAt(0), |
| 435 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 436 | x86_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 437 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 438 | } |
| 439 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 440 | const char* GetDescription() const override { return "DeoptimizationSlowPathX86"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 441 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 442 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 443 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86); |
| 444 | }; |
| 445 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 446 | class ArraySetSlowPathX86 : public SlowPathCode { |
| 447 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 448 | explicit ArraySetSlowPathX86(HInstruction* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 449 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 450 | void EmitNativeCode(CodeGenerator* codegen) override { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 451 | LocationSummary* locations = instruction_->GetLocations(); |
| 452 | __ Bind(GetEntryLabel()); |
| 453 | SaveLiveRegisters(codegen, locations); |
| 454 | |
| 455 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 456 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 457 | parallel_move.AddMove( |
| 458 | locations->InAt(0), |
| 459 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 460 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 461 | nullptr); |
| 462 | parallel_move.AddMove( |
| 463 | locations->InAt(1), |
| 464 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 465 | DataType::Type::kInt32, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 466 | nullptr); |
| 467 | parallel_move.AddMove( |
| 468 | locations->InAt(2), |
| 469 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 470 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 471 | nullptr); |
| 472 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 473 | |
| 474 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 475 | x86_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 476 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 477 | RestoreLiveRegisters(codegen, locations); |
| 478 | __ jmp(GetExitLabel()); |
| 479 | } |
| 480 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 481 | const char* GetDescription() const override { return "ArraySetSlowPathX86"; } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 482 | |
| 483 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 484 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86); |
| 485 | }; |
| 486 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 487 | // Slow path marking an object reference `ref` during a read |
| 488 | // barrier. The field `obj.field` in the object `obj` holding this |
| 489 | // reference does not get updated by this slow path after marking (see |
| 490 | // ReadBarrierMarkAndUpdateFieldSlowPathX86 below for that). |
| 491 | // |
| 492 | // This means that after the execution of this slow path, `ref` will |
| 493 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 494 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 495 | // probably still be a from-space reference (unless it gets updated by |
| 496 | // another thread, or if another thread installed another object |
| 497 | // reference (different from `ref`) in `obj.field`). |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 498 | class ReadBarrierMarkSlowPathX86 : public SlowPathCode { |
| 499 | public: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 500 | ReadBarrierMarkSlowPathX86(HInstruction* instruction, |
| 501 | Location ref, |
| 502 | bool unpoison_ref_before_marking) |
| 503 | : SlowPathCode(instruction), |
| 504 | ref_(ref), |
| 505 | unpoison_ref_before_marking_(unpoison_ref_before_marking) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 506 | DCHECK(gUseReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 507 | } |
| 508 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 509 | const char* GetDescription() const override { return "ReadBarrierMarkSlowPathX86"; } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 510 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 511 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 512 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 513 | Register ref_reg = ref_.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 514 | DCHECK(locations->CanCall()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 515 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 516 | DCHECK(instruction_->IsInstanceFieldGet() || |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 517 | instruction_->IsPredicatedInstanceFieldGet() || |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 518 | instruction_->IsStaticFieldGet() || |
| 519 | instruction_->IsArrayGet() || |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 520 | instruction_->IsArraySet() || |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 521 | instruction_->IsLoadClass() || |
| 522 | instruction_->IsLoadString() || |
| 523 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 524 | instruction_->IsCheckCast() || |
Andra Danciu | 1ca6f32 | 2020-08-12 08:58:07 +0000 | [diff] [blame] | 525 | (instruction_->IsInvoke() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 526 | << "Unexpected instruction in read barrier marking slow path: " |
| 527 | << instruction_->DebugName(); |
| 528 | |
| 529 | __ Bind(GetEntryLabel()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 530 | if (unpoison_ref_before_marking_) { |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 531 | // Object* ref = ref_addr->AsMirrorPtr() |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 532 | __ MaybeUnpoisonHeapReference(ref_reg); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 533 | } |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 534 | // No need to save live registers; it's taken care of by the |
| 535 | // entrypoint. Also, there is no need to update the stack mask, |
| 536 | // as this runtime call will not trigger a garbage collection. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 537 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 538 | DCHECK_NE(ref_reg, ESP); |
| 539 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 540 | // "Compact" slow path, saving two moves. |
| 541 | // |
| 542 | // Instead of using the standard runtime calling convention (input |
| 543 | // and output in EAX): |
| 544 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 545 | // EAX <- ref |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 546 | // EAX <- ReadBarrierMark(EAX) |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 547 | // ref <- EAX |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 548 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 549 | // we just use rX (the register containing `ref`) as input and output |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 550 | // of a dedicated entrypoint: |
| 551 | // |
| 552 | // rX <- ReadBarrierMarkRegX(rX) |
| 553 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 554 | int32_t entry_point_offset = Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(ref_reg); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 555 | // This runtime call does not require a stack map. |
| 556 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 557 | __ jmp(GetExitLabel()); |
| 558 | } |
| 559 | |
| 560 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 561 | // The location (register) of the marked object reference. |
| 562 | const Location ref_; |
| 563 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 564 | const bool unpoison_ref_before_marking_; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 565 | |
| 566 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86); |
| 567 | }; |
| 568 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 569 | // Slow path marking an object reference `ref` during a read barrier, |
| 570 | // and if needed, atomically updating the field `obj.field` in the |
| 571 | // object `obj` holding this reference after marking (contrary to |
| 572 | // ReadBarrierMarkSlowPathX86 above, which never tries to update |
| 573 | // `obj.field`). |
| 574 | // |
| 575 | // This means that after the execution of this slow path, both `ref` |
| 576 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 577 | // hold the same to-space reference (unless another thread installed |
| 578 | // another object reference (different from `ref`) in `obj.field`). |
| 579 | class ReadBarrierMarkAndUpdateFieldSlowPathX86 : public SlowPathCode { |
| 580 | public: |
| 581 | ReadBarrierMarkAndUpdateFieldSlowPathX86(HInstruction* instruction, |
| 582 | Location ref, |
| 583 | Register obj, |
| 584 | const Address& field_addr, |
| 585 | bool unpoison_ref_before_marking, |
| 586 | Register temp) |
| 587 | : SlowPathCode(instruction), |
| 588 | ref_(ref), |
| 589 | obj_(obj), |
| 590 | field_addr_(field_addr), |
| 591 | unpoison_ref_before_marking_(unpoison_ref_before_marking), |
| 592 | temp_(temp) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 593 | DCHECK(gUseReadBarrier); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 594 | } |
| 595 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 596 | const char* GetDescription() const override { return "ReadBarrierMarkAndUpdateFieldSlowPathX86"; } |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 597 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 598 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 599 | LocationSummary* locations = instruction_->GetLocations(); |
| 600 | Register ref_reg = ref_.AsRegister<Register>(); |
| 601 | DCHECK(locations->CanCall()); |
| 602 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
Andra Danciu | 5e13d45 | 2020-09-08 14:35:09 +0000 | [diff] [blame] | 603 | DCHECK((instruction_->IsInvoke() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 604 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 605 | << instruction_->DebugName(); |
Ulya Trafimovich | ec696e5 | 2022-01-26 10:21:32 +0000 | [diff] [blame] | 606 | HInvoke* invoke = instruction_->AsInvoke(); |
| 607 | DCHECK(IsUnsafeCASObject(invoke) || IsVarHandleCASFamily(invoke)) << invoke->GetIntrinsic(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 608 | |
| 609 | __ Bind(GetEntryLabel()); |
| 610 | if (unpoison_ref_before_marking_) { |
| 611 | // Object* ref = ref_addr->AsMirrorPtr() |
| 612 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 613 | } |
| 614 | |
| 615 | // Save the old (unpoisoned) reference. |
| 616 | __ movl(temp_, ref_reg); |
| 617 | |
| 618 | // No need to save live registers; it's taken care of by the |
| 619 | // entrypoint. Also, there is no need to update the stack mask, |
| 620 | // as this runtime call will not trigger a garbage collection. |
| 621 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 622 | DCHECK_NE(ref_reg, ESP); |
| 623 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
| 624 | // "Compact" slow path, saving two moves. |
| 625 | // |
| 626 | // Instead of using the standard runtime calling convention (input |
| 627 | // and output in EAX): |
| 628 | // |
| 629 | // EAX <- ref |
| 630 | // EAX <- ReadBarrierMark(EAX) |
| 631 | // ref <- EAX |
| 632 | // |
| 633 | // we just use rX (the register containing `ref`) as input and output |
| 634 | // of a dedicated entrypoint: |
| 635 | // |
| 636 | // rX <- ReadBarrierMarkRegX(rX) |
| 637 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 638 | int32_t entry_point_offset = Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(ref_reg); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 639 | // This runtime call does not require a stack map. |
| 640 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 641 | |
| 642 | // If the new reference is different from the old reference, |
| 643 | // update the field in the holder (`*field_addr`). |
| 644 | // |
| 645 | // Note that this field could also hold a different object, if |
| 646 | // another thread had concurrently changed it. In that case, the |
| 647 | // LOCK CMPXCHGL instruction in the compare-and-set (CAS) |
| 648 | // operation below would abort the CAS, leaving the field as-is. |
| 649 | NearLabel done; |
| 650 | __ cmpl(temp_, ref_reg); |
| 651 | __ j(kEqual, &done); |
| 652 | |
| 653 | // Update the the holder's field atomically. This may fail if |
| 654 | // mutator updates before us, but it's OK. This is achieved |
| 655 | // using a strong compare-and-set (CAS) operation with relaxed |
| 656 | // memory synchronization ordering, where the expected value is |
| 657 | // the old reference and the desired value is the new reference. |
| 658 | // This operation is implemented with a 32-bit LOCK CMPXLCHG |
| 659 | // instruction, which requires the expected value (the old |
| 660 | // reference) to be in EAX. Save EAX beforehand, and move the |
| 661 | // expected value (stored in `temp_`) into EAX. |
| 662 | __ pushl(EAX); |
| 663 | __ movl(EAX, temp_); |
| 664 | |
| 665 | // Convenience aliases. |
| 666 | Register base = obj_; |
| 667 | Register expected = EAX; |
| 668 | Register value = ref_reg; |
| 669 | |
| 670 | bool base_equals_value = (base == value); |
| 671 | if (kPoisonHeapReferences) { |
| 672 | if (base_equals_value) { |
| 673 | // If `base` and `value` are the same register location, move |
| 674 | // `value` to a temporary register. This way, poisoning |
| 675 | // `value` won't invalidate `base`. |
| 676 | value = temp_; |
| 677 | __ movl(value, base); |
| 678 | } |
| 679 | |
| 680 | // Check that the register allocator did not assign the location |
| 681 | // of `expected` (EAX) to `value` nor to `base`, so that heap |
| 682 | // poisoning (when enabled) works as intended below. |
| 683 | // - If `value` were equal to `expected`, both references would |
| 684 | // be poisoned twice, meaning they would not be poisoned at |
| 685 | // all, as heap poisoning uses address negation. |
| 686 | // - If `base` were equal to `expected`, poisoning `expected` |
| 687 | // would invalidate `base`. |
| 688 | DCHECK_NE(value, expected); |
| 689 | DCHECK_NE(base, expected); |
| 690 | |
| 691 | __ PoisonHeapReference(expected); |
| 692 | __ PoisonHeapReference(value); |
| 693 | } |
| 694 | |
| 695 | __ LockCmpxchgl(field_addr_, value); |
| 696 | |
| 697 | // If heap poisoning is enabled, we need to unpoison the values |
| 698 | // that were poisoned earlier. |
| 699 | if (kPoisonHeapReferences) { |
| 700 | if (base_equals_value) { |
| 701 | // `value` has been moved to a temporary register, no need |
| 702 | // to unpoison it. |
| 703 | } else { |
| 704 | __ UnpoisonHeapReference(value); |
| 705 | } |
| 706 | // No need to unpoison `expected` (EAX), as it is be overwritten below. |
| 707 | } |
| 708 | |
| 709 | // Restore EAX. |
| 710 | __ popl(EAX); |
| 711 | |
| 712 | __ Bind(&done); |
| 713 | __ jmp(GetExitLabel()); |
| 714 | } |
| 715 | |
| 716 | private: |
| 717 | // The location (register) of the marked object reference. |
| 718 | const Location ref_; |
| 719 | // The register containing the object holding the marked object reference field. |
| 720 | const Register obj_; |
| 721 | // The address of the marked reference field. The base of this address must be `obj_`. |
| 722 | const Address field_addr_; |
| 723 | |
| 724 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 725 | const bool unpoison_ref_before_marking_; |
| 726 | |
| 727 | const Register temp_; |
| 728 | |
| 729 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathX86); |
| 730 | }; |
| 731 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 732 | // Slow path generating a read barrier for a heap reference. |
| 733 | class ReadBarrierForHeapReferenceSlowPathX86 : public SlowPathCode { |
| 734 | public: |
| 735 | ReadBarrierForHeapReferenceSlowPathX86(HInstruction* instruction, |
| 736 | Location out, |
| 737 | Location ref, |
| 738 | Location obj, |
| 739 | uint32_t offset, |
| 740 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 741 | : SlowPathCode(instruction), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 742 | out_(out), |
| 743 | ref_(ref), |
| 744 | obj_(obj), |
| 745 | offset_(offset), |
| 746 | index_(index) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 747 | DCHECK(gUseReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 748 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 749 | // has been overwritten by (or after) the heap object reference load |
| 750 | // to be instrumented, e.g.: |
| 751 | // |
| 752 | // __ movl(out, Address(out, offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 753 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 754 | // |
| 755 | // In that case, we have lost the information about the original |
| 756 | // object, and the emitted read barrier cannot work properly. |
| 757 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 758 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 759 | } |
| 760 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 761 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 762 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 763 | LocationSummary* locations = instruction_->GetLocations(); |
| 764 | Register reg_out = out_.AsRegister<Register>(); |
| 765 | DCHECK(locations->CanCall()); |
| 766 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 767 | DCHECK(instruction_->IsInstanceFieldGet() || |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 768 | instruction_->IsPredicatedInstanceFieldGet() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 769 | instruction_->IsStaticFieldGet() || |
| 770 | instruction_->IsArrayGet() || |
| 771 | instruction_->IsInstanceOf() || |
| 772 | instruction_->IsCheckCast() || |
Vladimir Marko | 94d2c81 | 2020-11-05 10:04:45 +0000 | [diff] [blame] | 773 | (instruction_->IsInvoke() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 774 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 775 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 776 | |
| 777 | __ Bind(GetEntryLabel()); |
| 778 | SaveLiveRegisters(codegen, locations); |
| 779 | |
| 780 | // We may have to change the index's value, but as `index_` is a |
| 781 | // constant member (like other "inputs" of this slow path), |
| 782 | // introduce a copy of it, `index`. |
| 783 | Location index = index_; |
| 784 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 785 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 786 | if (instruction_->IsArrayGet()) { |
| 787 | // Compute the actual memory offset and store it in `index`. |
| 788 | Register index_reg = index_.AsRegister<Register>(); |
| 789 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 790 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 791 | // We are about to change the value of `index_reg` (see the |
| 792 | // calls to art::x86::X86Assembler::shll and |
| 793 | // art::x86::X86Assembler::AddImmediate below), but it has |
| 794 | // not been saved by the previous call to |
| 795 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 796 | // callee-save register -- |
| 797 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 798 | // callee-save registers, as it has been designed with the |
| 799 | // assumption that callee-save registers are supposed to be |
| 800 | // handled by the called function. So, as a callee-save |
| 801 | // register, `index_reg` _would_ eventually be saved onto |
| 802 | // the stack, but it would be too late: we would have |
| 803 | // changed its value earlier. Therefore, we manually save |
| 804 | // it here into another freely available register, |
| 805 | // `free_reg`, chosen of course among the caller-save |
| 806 | // registers (as a callee-save `free_reg` register would |
| 807 | // exhibit the same problem). |
| 808 | // |
| 809 | // Note we could have requested a temporary register from |
| 810 | // the register allocator instead; but we prefer not to, as |
| 811 | // this is a slow path, and we know we can find a |
| 812 | // caller-save register that is available. |
| 813 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 814 | __ movl(free_reg, index_reg); |
| 815 | index_reg = free_reg; |
| 816 | index = Location::RegisterLocation(index_reg); |
| 817 | } else { |
| 818 | // The initial register stored in `index_` has already been |
| 819 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 820 | // (as it is not a callee-save register), so we can freely |
| 821 | // use it. |
| 822 | } |
| 823 | // Shifting the index value contained in `index_reg` by the scale |
| 824 | // factor (2) cannot overflow in practice, as the runtime is |
| 825 | // unable to allocate object arrays with a size larger than |
| 826 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 827 | __ shll(index_reg, Immediate(TIMES_4)); |
| 828 | static_assert( |
| 829 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 830 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 831 | __ AddImmediate(index_reg, Immediate(offset_)); |
| 832 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 833 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 834 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 835 | // (as in the case of ArrayGet), as it is actually an offset |
| 836 | // to an object field within an object. |
| 837 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 838 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 839 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
Sorin Basca | 2f01e8e | 2021-06-18 06:44:07 +0000 | [diff] [blame] | 840 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile) || |
| 841 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kJdkUnsafeGetObject) || |
Sorin Basca | 4a4696a | 2021-10-09 07:14:40 +0000 | [diff] [blame] | 842 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kJdkUnsafeGetObjectVolatile) || |
| 843 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kJdkUnsafeGetObjectAcquire)) |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 844 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 845 | DCHECK_EQ(offset_, 0U); |
| 846 | DCHECK(index_.IsRegisterPair()); |
| 847 | // UnsafeGet's offset location is a register pair, the low |
| 848 | // part contains the correct offset. |
| 849 | index = index_.ToLow(); |
| 850 | } |
| 851 | } |
| 852 | |
| 853 | // We're moving two or three locations to locations that could |
| 854 | // overlap, so we need a parallel move resolver. |
| 855 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 856 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 857 | parallel_move.AddMove(ref_, |
| 858 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 859 | DataType::Type::kReference, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 860 | nullptr); |
| 861 | parallel_move.AddMove(obj_, |
| 862 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 863 | DataType::Type::kReference, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 864 | nullptr); |
| 865 | if (index.IsValid()) { |
| 866 | parallel_move.AddMove(index, |
| 867 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 868 | DataType::Type::kInt32, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 869 | nullptr); |
| 870 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 871 | } else { |
| 872 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 873 | __ movl(calling_convention.GetRegisterAt(2), Immediate(offset_)); |
| 874 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 875 | x86_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 876 | CheckEntrypointTypes< |
| 877 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 878 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 879 | |
| 880 | RestoreLiveRegisters(codegen, locations); |
| 881 | __ jmp(GetExitLabel()); |
| 882 | } |
| 883 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 884 | const char* GetDescription() const override { return "ReadBarrierForHeapReferenceSlowPathX86"; } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 885 | |
| 886 | private: |
| 887 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 888 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 889 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 890 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 891 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 892 | return static_cast<Register>(i); |
| 893 | } |
| 894 | } |
| 895 | // We shall never fail to find a free caller-save register, as |
| 896 | // there are more than two core caller-save registers on x86 |
| 897 | // (meaning it is possible to find one which is different from |
| 898 | // `ref` and `obj`). |
| 899 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 900 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 901 | UNREACHABLE(); |
| 902 | } |
| 903 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 904 | const Location out_; |
| 905 | const Location ref_; |
| 906 | const Location obj_; |
| 907 | const uint32_t offset_; |
| 908 | // An additional location containing an index to an array. |
| 909 | // Only used for HArrayGet and the UnsafeGetObject & |
| 910 | // UnsafeGetObjectVolatile intrinsics. |
| 911 | const Location index_; |
| 912 | |
| 913 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86); |
| 914 | }; |
| 915 | |
| 916 | // Slow path generating a read barrier for a GC root. |
| 917 | class ReadBarrierForRootSlowPathX86 : public SlowPathCode { |
| 918 | public: |
| 919 | ReadBarrierForRootSlowPathX86(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 920 | : SlowPathCode(instruction), out_(out), root_(root) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 921 | DCHECK(gUseReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 922 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 923 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 924 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 925 | LocationSummary* locations = instruction_->GetLocations(); |
| 926 | Register reg_out = out_.AsRegister<Register>(); |
| 927 | DCHECK(locations->CanCall()); |
| 928 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 929 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 930 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 931 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 932 | |
| 933 | __ Bind(GetEntryLabel()); |
| 934 | SaveLiveRegisters(codegen, locations); |
| 935 | |
| 936 | InvokeRuntimeCallingConvention calling_convention; |
| 937 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 938 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 939 | x86_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 940 | instruction_, |
| 941 | instruction_->GetDexPc(), |
| 942 | this); |
| 943 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 944 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 945 | |
| 946 | RestoreLiveRegisters(codegen, locations); |
| 947 | __ jmp(GetExitLabel()); |
| 948 | } |
| 949 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 950 | const char* GetDescription() const override { return "ReadBarrierForRootSlowPathX86"; } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 951 | |
| 952 | private: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 953 | const Location out_; |
| 954 | const Location root_; |
| 955 | |
| 956 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86); |
| 957 | }; |
| 958 | |
Mythri Alle | 5097f83 | 2021-11-02 14:52:30 +0000 | [diff] [blame] | 959 | class MethodEntryExitHooksSlowPathX86 : public SlowPathCode { |
| 960 | public: |
| 961 | explicit MethodEntryExitHooksSlowPathX86(HInstruction* instruction) : SlowPathCode(instruction) {} |
| 962 | |
| 963 | void EmitNativeCode(CodeGenerator* codegen) override { |
| 964 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 965 | LocationSummary* locations = instruction_->GetLocations(); |
| 966 | QuickEntrypointEnum entry_point = |
| 967 | (instruction_->IsMethodEntryHook()) ? kQuickMethodEntryHook : kQuickMethodExitHook; |
| 968 | __ Bind(GetEntryLabel()); |
| 969 | SaveLiveRegisters(codegen, locations); |
Mythri Alle | bab6beb | 2022-10-21 13:28:05 +0000 | [diff] [blame] | 970 | if (instruction_->IsMethodExitHook()) { |
| 971 | __ movl(EBX, Immediate(codegen->GetFrameSize())); |
| 972 | } |
Mythri Alle | 5097f83 | 2021-11-02 14:52:30 +0000 | [diff] [blame] | 973 | x86_codegen->InvokeRuntime(entry_point, instruction_, instruction_->GetDexPc(), this); |
| 974 | RestoreLiveRegisters(codegen, locations); |
| 975 | __ jmp(GetExitLabel()); |
| 976 | } |
| 977 | |
| 978 | const char* GetDescription() const override { |
| 979 | return "MethodEntryExitHooksSlowPath"; |
| 980 | } |
| 981 | |
| 982 | private: |
| 983 | DISALLOW_COPY_AND_ASSIGN(MethodEntryExitHooksSlowPathX86); |
| 984 | }; |
| 985 | |
Nicolas Geoffray | 9e59890 | 2021-11-19 14:53:07 +0000 | [diff] [blame] | 986 | class CompileOptimizedSlowPathX86 : public SlowPathCode { |
| 987 | public: |
| 988 | CompileOptimizedSlowPathX86() : SlowPathCode(/* instruction= */ nullptr) {} |
| 989 | |
| 990 | void EmitNativeCode(CodeGenerator* codegen) override { |
| 991 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 992 | __ Bind(GetEntryLabel()); |
| 993 | x86_codegen->GenerateInvokeRuntime( |
| 994 | GetThreadOffset<kX86PointerSize>(kQuickCompileOptimized).Int32Value()); |
| 995 | __ jmp(GetExitLabel()); |
| 996 | } |
| 997 | |
| 998 | const char* GetDescription() const override { |
| 999 | return "CompileOptimizedSlowPath"; |
| 1000 | } |
| 1001 | |
| 1002 | private: |
| 1003 | DISALLOW_COPY_AND_ASSIGN(CompileOptimizedSlowPathX86); |
| 1004 | }; |
| 1005 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1006 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 1007 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 1008 | #define __ down_cast<X86Assembler*>(GetAssembler())-> // NOLINT |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1009 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1010 | inline Condition X86Condition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1011 | switch (cond) { |
| 1012 | case kCondEQ: return kEqual; |
| 1013 | case kCondNE: return kNotEqual; |
| 1014 | case kCondLT: return kLess; |
| 1015 | case kCondLE: return kLessEqual; |
| 1016 | case kCondGT: return kGreater; |
| 1017 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1018 | case kCondB: return kBelow; |
| 1019 | case kCondBE: return kBelowEqual; |
| 1020 | case kCondA: return kAbove; |
| 1021 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1022 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1023 | LOG(FATAL) << "Unreachable"; |
| 1024 | UNREACHABLE(); |
| 1025 | } |
| 1026 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1027 | // Maps signed condition to unsigned condition and FP condition to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1028 | inline Condition X86UnsignedOrFPCondition(IfCondition cond) { |
| 1029 | switch (cond) { |
| 1030 | case kCondEQ: return kEqual; |
| 1031 | case kCondNE: return kNotEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1032 | // Signed to unsigned, and FP to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1033 | case kCondLT: return kBelow; |
| 1034 | case kCondLE: return kBelowEqual; |
| 1035 | case kCondGT: return kAbove; |
| 1036 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1037 | // Unsigned remain unchanged. |
| 1038 | case kCondB: return kBelow; |
| 1039 | case kCondBE: return kBelowEqual; |
| 1040 | case kCondA: return kAbove; |
| 1041 | case kCondAE: return kAboveEqual; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1042 | } |
| 1043 | LOG(FATAL) << "Unreachable"; |
| 1044 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1045 | } |
| 1046 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1047 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1048 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1049 | } |
| 1050 | |
| 1051 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1052 | stream << XmmRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1053 | } |
| 1054 | |
Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 1055 | const X86InstructionSetFeatures& CodeGeneratorX86::GetInstructionSetFeatures() const { |
| 1056 | return *GetCompilerOptions().GetInstructionSetFeatures()->AsX86InstructionSetFeatures(); |
| 1057 | } |
| 1058 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1059 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1060 | __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); |
| 1061 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1062 | } |
| 1063 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1064 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1065 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); |
| 1066 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1067 | } |
| 1068 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1069 | size_t CodeGeneratorX86::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1070 | if (GetGraph()->HasSIMD()) { |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 1071 | __ movups(Address(ESP, stack_index), XmmRegister(reg_id)); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1072 | } else { |
| 1073 | __ movsd(Address(ESP, stack_index), XmmRegister(reg_id)); |
| 1074 | } |
Artem Serov | 6a0b657 | 2019-07-26 20:38:37 +0100 | [diff] [blame] | 1075 | return GetSlowPathFPWidth(); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1076 | } |
| 1077 | |
| 1078 | size_t CodeGeneratorX86::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1079 | if (GetGraph()->HasSIMD()) { |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 1080 | __ movups(XmmRegister(reg_id), Address(ESP, stack_index)); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1081 | } else { |
| 1082 | __ movsd(XmmRegister(reg_id), Address(ESP, stack_index)); |
| 1083 | } |
Artem Serov | 6a0b657 | 2019-07-26 20:38:37 +0100 | [diff] [blame] | 1084 | return GetSlowPathFPWidth(); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1085 | } |
| 1086 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1087 | void CodeGeneratorX86::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1088 | HInstruction* instruction, |
| 1089 | uint32_t dex_pc, |
| 1090 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1091 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1092 | GenerateInvokeRuntime(GetThreadOffset<kX86PointerSize>(entrypoint).Int32Value()); |
| 1093 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1094 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1095 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 1096 | } |
| 1097 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1098 | void CodeGeneratorX86::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1099 | HInstruction* instruction, |
| 1100 | SlowPathCode* slow_path) { |
| 1101 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1102 | GenerateInvokeRuntime(entry_point_offset); |
| 1103 | } |
| 1104 | |
| 1105 | void CodeGeneratorX86::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1106 | __ fs()->call(Address::Absolute(entry_point_offset)); |
| 1107 | } |
| 1108 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1109 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1110 | const CompilerOptions& compiler_options, |
| 1111 | OptimizingCompilerStats* stats) |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1112 | : CodeGenerator(graph, |
| 1113 | kNumberOfCpuRegisters, |
| 1114 | kNumberOfXmmRegisters, |
| 1115 | kNumberOfRegisterPairs, |
| 1116 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1117 | arraysize(kCoreCalleeSaves)) |
| 1118 | | (1 << kFakeReturnRegister), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1119 | 0, |
| 1120 | compiler_options, |
| 1121 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1122 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1123 | location_builder_(graph, this), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1124 | instruction_visitor_(graph, this), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1125 | move_resolver_(graph->GetAllocator(), this), |
Shalini Salomi Bodapati | 6545ee3 | 2021-11-02 20:01:06 +0530 | [diff] [blame] | 1126 | assembler_(graph->GetAllocator(), |
| 1127 | compiler_options.GetInstructionSetFeatures()->AsX86InstructionSetFeatures()), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1128 | boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1129 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1130 | boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1131 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 1132 | public_type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1133 | package_type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1134 | boot_image_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1135 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 1136 | boot_image_jni_entrypoint_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 1137 | boot_image_other_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1138 | jit_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1139 | jit_class_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1140 | constant_area_start_(-1), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1141 | fixups_to_jump_tables_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1142 | method_address_offset_(std::less<uint32_t>(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1143 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1144 | // Use a fake return address register to mimic Quick. |
| 1145 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1146 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1147 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1148 | void CodeGeneratorX86::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1149 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1150 | blocked_core_registers_[ESP] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1151 | } |
| 1152 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1153 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1154 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1155 | assembler_(codegen->GetAssembler()), |
| 1156 | codegen_(codegen) {} |
| 1157 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1158 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1159 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1160 | } |
| 1161 | |
Mythri Alle | 5097f83 | 2021-11-02 14:52:30 +0000 | [diff] [blame] | 1162 | void SetInForReturnValue(HInstruction* ret, LocationSummary* locations) { |
| 1163 | switch (ret->InputAt(0)->GetType()) { |
| 1164 | case DataType::Type::kReference: |
| 1165 | case DataType::Type::kBool: |
| 1166 | case DataType::Type::kUint8: |
| 1167 | case DataType::Type::kInt8: |
| 1168 | case DataType::Type::kUint16: |
| 1169 | case DataType::Type::kInt16: |
| 1170 | case DataType::Type::kInt32: |
| 1171 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 1172 | break; |
| 1173 | |
| 1174 | case DataType::Type::kInt64: |
| 1175 | locations->SetInAt(0, Location::RegisterPairLocation(EAX, EDX)); |
| 1176 | break; |
| 1177 | |
| 1178 | case DataType::Type::kFloat32: |
| 1179 | case DataType::Type::kFloat64: |
| 1180 | locations->SetInAt(0, Location::FpuRegisterLocation(XMM0)); |
| 1181 | break; |
| 1182 | |
| 1183 | case DataType::Type::kVoid: |
| 1184 | locations->SetInAt(0, Location::NoLocation()); |
| 1185 | break; |
| 1186 | |
| 1187 | default: |
| 1188 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
| 1189 | } |
| 1190 | } |
| 1191 | |
| 1192 | void LocationsBuilderX86::VisitMethodExitHook(HMethodExitHook* method_hook) { |
| 1193 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
| 1194 | LocationSummary(method_hook, LocationSummary::kCallOnSlowPath); |
| 1195 | SetInForReturnValue(method_hook, locations); |
| 1196 | } |
| 1197 | |
| 1198 | void InstructionCodeGeneratorX86::GenerateMethodEntryExitHook(HInstruction* instruction) { |
| 1199 | SlowPathCode* slow_path = |
| 1200 | new (codegen_->GetScopedAllocator()) MethodEntryExitHooksSlowPathX86(instruction); |
| 1201 | codegen_->AddSlowPath(slow_path); |
| 1202 | |
Mythri Alle | 5eff6b3 | 2022-11-04 10:57:53 +0000 | [diff] [blame] | 1203 | if (instruction->IsMethodExitHook()) { |
| 1204 | // Check if we are required to check if the caller needs a deoptimization. Strictly speaking it |
| 1205 | // would be sufficient to check if CheckCallerForDeopt bit is set. Though it is faster to check |
| 1206 | // if it is just non-zero. kCHA bit isn't used in debuggable runtimes as cha optimization is |
| 1207 | // disabled in debuggable runtime. The other bit is used when this method itself requires a |
| 1208 | // deoptimization due to redefinition. So it is safe to just check for non-zero value here. |
| 1209 | __ cmpl(Address(ESP, codegen_->GetStackOffsetOfShouldDeoptimizeFlag()), Immediate(0)); |
| 1210 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 1211 | } |
| 1212 | |
Mythri Alle | 5097f83 | 2021-11-02 14:52:30 +0000 | [diff] [blame] | 1213 | uint64_t address = reinterpret_cast64<uint64_t>(Runtime::Current()->GetInstrumentation()); |
Mythri Alle | 5b263ae | 2022-10-21 15:07:44 +0000 | [diff] [blame] | 1214 | MemberOffset offset = instruction->IsMethodExitHook() ? |
Mythri Alle | 5eff6b3 | 2022-11-04 10:57:53 +0000 | [diff] [blame] | 1215 | instrumentation::Instrumentation::HaveMethodExitListenersOffset() : |
Mythri Alle | 5b263ae | 2022-10-21 15:07:44 +0000 | [diff] [blame] | 1216 | instrumentation::Instrumentation::HaveMethodEntryListenersOffset(); |
| 1217 | __ cmpb(Address::Absolute(address + offset.Int32Value()), Immediate(0)); |
Mythri Alle | 9575c12 | 2021-11-12 12:04:41 +0000 | [diff] [blame] | 1218 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
Mythri Alle | 5097f83 | 2021-11-02 14:52:30 +0000 | [diff] [blame] | 1219 | __ Bind(slow_path->GetExitLabel()); |
| 1220 | } |
| 1221 | |
| 1222 | void InstructionCodeGeneratorX86::VisitMethodExitHook(HMethodExitHook* instruction) { |
| 1223 | DCHECK(codegen_->GetCompilerOptions().IsJitCompiler() && GetGraph()->IsDebuggable()); |
| 1224 | DCHECK(codegen_->RequiresCurrentMethod()); |
| 1225 | GenerateMethodEntryExitHook(instruction); |
| 1226 | } |
| 1227 | |
| 1228 | void LocationsBuilderX86::VisitMethodEntryHook(HMethodEntryHook* method_hook) { |
| 1229 | new (GetGraph()->GetAllocator()) LocationSummary(method_hook, LocationSummary::kCallOnSlowPath); |
| 1230 | } |
| 1231 | |
| 1232 | void InstructionCodeGeneratorX86::VisitMethodEntryHook(HMethodEntryHook* instruction) { |
| 1233 | DCHECK(codegen_->GetCompilerOptions().IsJitCompiler() && GetGraph()->IsDebuggable()); |
| 1234 | DCHECK(codegen_->RequiresCurrentMethod()); |
| 1235 | GenerateMethodEntryExitHook(instruction); |
| 1236 | } |
| 1237 | |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1238 | void CodeGeneratorX86::MaybeIncrementHotness(bool is_frame_entry) { |
| 1239 | if (GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 1240 | Register reg = EAX; |
| 1241 | if (is_frame_entry) { |
| 1242 | reg = kMethodRegisterArgument; |
| 1243 | } else { |
| 1244 | __ pushl(EAX); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1245 | __ cfi().AdjustCFAOffset(4); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1246 | __ movl(EAX, Address(ESP, kX86WordSize)); |
| 1247 | } |
| 1248 | NearLabel overflow; |
| 1249 | __ cmpw(Address(reg, ArtMethod::HotnessCountOffset().Int32Value()), |
Nicolas Geoffray | 61673dc | 2021-11-06 13:58:31 +0000 | [diff] [blame] | 1250 | Immediate(interpreter::kNterpHotnessValue)); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1251 | __ j(kEqual, &overflow); |
Nicolas Geoffray | 61673dc | 2021-11-06 13:58:31 +0000 | [diff] [blame] | 1252 | __ addw(Address(reg, ArtMethod::HotnessCountOffset().Int32Value()), Immediate(-1)); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1253 | __ Bind(&overflow); |
| 1254 | if (!is_frame_entry) { |
| 1255 | __ popl(EAX); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1256 | __ cfi().AdjustCFAOffset(-4); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1257 | } |
| 1258 | } |
| 1259 | |
| 1260 | if (GetGraph()->IsCompilingBaseline() && !Runtime::Current()->IsAotCompiler()) { |
Nicolas Geoffray | 9e59890 | 2021-11-19 14:53:07 +0000 | [diff] [blame] | 1261 | SlowPathCode* slow_path = new (GetScopedAllocator()) CompileOptimizedSlowPathX86(); |
| 1262 | AddSlowPath(slow_path); |
| 1263 | ProfilingInfo* info = GetGraph()->GetProfilingInfo(); |
| 1264 | DCHECK(info != nullptr); |
| 1265 | uint32_t address = reinterpret_cast32<uint32_t>(info) + |
| 1266 | ProfilingInfo::BaselineHotnessCountOffset().Int32Value(); |
| 1267 | DCHECK(!HasEmptyFrame()); |
| 1268 | // With multiple threads, this can overflow. This is OK, we will eventually get to see |
| 1269 | // it reaching 0. Also, at this point we have no register available to look |
| 1270 | // at the counter directly. |
| 1271 | __ addw(Address::Absolute(address), Immediate(-1)); |
| 1272 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 1273 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1274 | } |
| 1275 | } |
| 1276 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1277 | void CodeGeneratorX86::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1278 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
Nicolas Geoffray | ab3f8d2 | 2022-07-23 15:49:51 +0000 | [diff] [blame] | 1279 | |
| 1280 | // Check if we need to generate the clinit check. We will jump to the |
| 1281 | // resolution stub if the class is not initialized and the executing thread is |
| 1282 | // not the thread initializing it. |
| 1283 | // We do this before constructing the frame to get the correct stack trace if |
| 1284 | // an exception is thrown. |
| 1285 | if (GetCompilerOptions().ShouldCompileWithClinitCheck(GetGraph()->GetArtMethod())) { |
| 1286 | NearLabel continue_execution, resolution; |
| 1287 | // We'll use EBP as temporary. |
| 1288 | __ pushl(EBP); |
| 1289 | // Check if we're visibly initialized. |
| 1290 | |
| 1291 | // We don't emit a read barrier here to save on code size. We rely on the |
| 1292 | // resolution trampoline to do a suspend check before re-entering this code. |
| 1293 | __ movl(EBP, Address(kMethodRegisterArgument, ArtMethod::DeclaringClassOffset().Int32Value())); |
| 1294 | __ cmpb(Address(EBP, status_byte_offset), Immediate(shifted_visibly_initialized_value)); |
| 1295 | __ j(kAboveEqual, &continue_execution); |
| 1296 | |
| 1297 | // Check if we're initializing and the thread initializing is the one |
| 1298 | // executing the code. |
| 1299 | __ cmpb(Address(EBP, status_byte_offset), Immediate(shifted_initializing_value)); |
| 1300 | __ j(kBelow, &resolution); |
| 1301 | |
| 1302 | __ movl(EBP, Address(EBP, mirror::Class::ClinitThreadIdOffset().Int32Value())); |
| 1303 | __ fs()->cmpl(EBP, Address::Absolute(Thread::TidOffset<kX86PointerSize>().Int32Value())); |
| 1304 | __ j(kEqual, &continue_execution); |
| 1305 | __ Bind(&resolution); |
| 1306 | |
| 1307 | __ popl(EBP); |
| 1308 | // Jump to the resolution stub. |
| 1309 | ThreadOffset32 entrypoint_offset = |
| 1310 | GetThreadOffset<kX86PointerSize>(kQuickQuickResolutionTrampoline); |
| 1311 | __ fs()->jmp(Address::Absolute(entrypoint_offset)); |
| 1312 | |
| 1313 | __ Bind(&continue_execution); |
| 1314 | __ popl(EBP); |
| 1315 | } |
| 1316 | |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1317 | __ Bind(&frame_entry_label_); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1318 | bool skip_overflow_check = |
| 1319 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1320 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 1321 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1322 | if (!skip_overflow_check) { |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1323 | size_t reserved_bytes = GetStackOverflowReservedBytes(InstructionSet::kX86); |
| 1324 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(reserved_bytes))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1325 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 1326 | } |
| 1327 | |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1328 | if (!HasEmptyFrame()) { |
| 1329 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 1330 | Register reg = kCoreCalleeSaves[i]; |
| 1331 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1332 | __ pushl(reg); |
| 1333 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 1334 | __ cfi().RelOffset(DWARFReg(reg), 0); |
| 1335 | } |
| 1336 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1337 | |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1338 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1339 | IncreaseFrame(adjust); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1340 | // Save the current method if we need it. Note that we do not |
| 1341 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1342 | // in the SSA graph. |
| 1343 | if (RequiresCurrentMethod()) { |
| 1344 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
| 1345 | } |
| 1346 | |
| 1347 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1348 | // Initialize should_deoptimize flag to 0. |
| 1349 | __ movl(Address(ESP, GetStackOffsetOfShouldDeoptimizeFlag()), Immediate(0)); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1350 | } |
| 1351 | } |
| 1352 | |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1353 | MaybeIncrementHotness(/* is_frame_entry= */ true); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1354 | } |
| 1355 | |
| 1356 | void CodeGeneratorX86::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1357 | __ cfi().RememberState(); |
| 1358 | if (!HasEmptyFrame()) { |
| 1359 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1360 | DecreaseFrame(adjust); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1361 | |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1362 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1363 | Register reg = kCoreCalleeSaves[i]; |
| 1364 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1365 | __ popl(reg); |
| 1366 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 1367 | __ cfi().Restore(DWARFReg(reg)); |
| 1368 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1369 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1370 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1371 | __ ret(); |
| 1372 | __ cfi().RestoreState(); |
| 1373 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1374 | } |
| 1375 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1376 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 1377 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1378 | } |
| 1379 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1380 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(DataType::Type type) const { |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1381 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1382 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1383 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1384 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1385 | case DataType::Type::kInt8: |
| 1386 | case DataType::Type::kUint16: |
| 1387 | case DataType::Type::kInt16: |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1388 | case DataType::Type::kUint32: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1389 | case DataType::Type::kInt32: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1390 | return Location::RegisterLocation(EAX); |
| 1391 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1392 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1393 | case DataType::Type::kInt64: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1394 | return Location::RegisterPairLocation(EAX, EDX); |
| 1395 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1396 | case DataType::Type::kVoid: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1397 | return Location::NoLocation(); |
| 1398 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1399 | case DataType::Type::kFloat64: |
| 1400 | case DataType::Type::kFloat32: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1401 | return Location::FpuRegisterLocation(XMM0); |
| 1402 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1403 | |
| 1404 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1405 | } |
| 1406 | |
| 1407 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 1408 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1409 | } |
| 1410 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1411 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(DataType::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1412 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1413 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1414 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1415 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1416 | case DataType::Type::kInt8: |
| 1417 | case DataType::Type::kUint16: |
| 1418 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1419 | case DataType::Type::kInt32: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1420 | uint32_t index = gp_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1421 | stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1422 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1423 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1424 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1425 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1426 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1427 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1428 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1429 | case DataType::Type::kInt64: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1430 | uint32_t index = gp_index_; |
| 1431 | gp_index_ += 2; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1432 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1433 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1434 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 1435 | calling_convention.GetRegisterPairAt(index)); |
| 1436 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1437 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1438 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1439 | } |
| 1440 | } |
| 1441 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1442 | case DataType::Type::kFloat32: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1443 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1444 | stack_index_++; |
| 1445 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1446 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1447 | } else { |
| 1448 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1449 | } |
| 1450 | } |
| 1451 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1452 | case DataType::Type::kFloat64: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1453 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1454 | stack_index_ += 2; |
| 1455 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1456 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1457 | } else { |
| 1458 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1459 | } |
| 1460 | } |
| 1461 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1462 | case DataType::Type::kUint32: |
| 1463 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1464 | case DataType::Type::kVoid: |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1465 | LOG(FATAL) << "Unexpected parameter type " << type; |
Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 1466 | UNREACHABLE(); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1467 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1468 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1469 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1470 | |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 1471 | Location CriticalNativeCallingConventionVisitorX86::GetNextLocation(DataType::Type type) { |
| 1472 | DCHECK_NE(type, DataType::Type::kReference); |
| 1473 | |
| 1474 | Location location; |
| 1475 | if (DataType::Is64BitType(type)) { |
| 1476 | location = Location::DoubleStackSlot(stack_offset_); |
| 1477 | stack_offset_ += 2 * kFramePointerSize; |
| 1478 | } else { |
| 1479 | location = Location::StackSlot(stack_offset_); |
| 1480 | stack_offset_ += kFramePointerSize; |
| 1481 | } |
| 1482 | if (for_register_allocation_) { |
| 1483 | location = Location::Any(); |
| 1484 | } |
| 1485 | return location; |
| 1486 | } |
| 1487 | |
| 1488 | Location CriticalNativeCallingConventionVisitorX86::GetReturnLocation(DataType::Type type) const { |
| 1489 | // We perform conversion to the managed ABI return register after the call if needed. |
| 1490 | InvokeDexCallingConventionVisitorX86 dex_calling_convention; |
| 1491 | return dex_calling_convention.GetReturnLocation(type); |
| 1492 | } |
| 1493 | |
| 1494 | Location CriticalNativeCallingConventionVisitorX86::GetMethodLocation() const { |
| 1495 | // Pass the method in the hidden argument EAX. |
| 1496 | return Location::RegisterLocation(EAX); |
| 1497 | } |
| 1498 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1499 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 1500 | if (source.Equals(destination)) { |
| 1501 | return; |
| 1502 | } |
| 1503 | if (destination.IsRegister()) { |
| 1504 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1505 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1506 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1507 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
Andra Danciu | 5e13d45 | 2020-09-08 14:35:09 +0000 | [diff] [blame] | 1508 | } else if (source.IsConstant()) { |
| 1509 | int32_t value = GetInt32ValueOf(source.GetConstant()); |
| 1510 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1511 | } else { |
| 1512 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1513 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1514 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1515 | } else if (destination.IsFpuRegister()) { |
| 1516 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1517 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1518 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1519 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1520 | } else { |
| 1521 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1522 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1523 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1524 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1525 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1526 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1527 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1528 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1529 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1530 | } else if (source.IsConstant()) { |
| 1531 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1532 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1533 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1534 | } else { |
| 1535 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1536 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 1537 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1538 | } |
| 1539 | } |
| 1540 | } |
| 1541 | |
| 1542 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 1543 | if (source.Equals(destination)) { |
| 1544 | return; |
| 1545 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1546 | if (destination.IsRegisterPair()) { |
| 1547 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1548 | EmitParallelMoves( |
| 1549 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1550 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1551 | DataType::Type::kInt32, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1552 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1553 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1554 | DataType::Type::kInt32); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1555 | } else if (source.IsFpuRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1556 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 1557 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 1558 | __ psrlq(src_reg, Immediate(32)); |
| 1559 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1560 | } else { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1561 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1562 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1563 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 1564 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1565 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 1566 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1567 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1568 | if (source.IsFpuRegister()) { |
| 1569 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 1570 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1571 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1572 | } else if (source.IsRegisterPair()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1573 | size_t elem_size = DataType::Size(DataType::Type::kInt32); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1574 | // Push the 2 source registers to the stack. |
| 1575 | __ pushl(source.AsRegisterPairHigh<Register>()); |
| 1576 | __ cfi().AdjustCFAOffset(elem_size); |
| 1577 | __ pushl(source.AsRegisterPairLow<Register>()); |
| 1578 | __ cfi().AdjustCFAOffset(elem_size); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1579 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 1580 | // And remove the temporary stack space we allocated. |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1581 | DecreaseFrame(2 * elem_size); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1582 | } else { |
| 1583 | LOG(FATAL) << "Unimplemented"; |
| 1584 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1585 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1586 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1587 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1588 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1589 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1590 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1591 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1592 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1593 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1594 | } else if (source.IsConstant()) { |
| 1595 | HConstant* constant = source.GetConstant(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1596 | DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant()); |
| 1597 | int64_t value = GetInt64ValueOf(constant); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1598 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1599 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
| 1600 | Immediate(High32Bits(value))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1601 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1602 | DCHECK(source.IsDoubleStackSlot()) << source; |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1603 | EmitParallelMoves( |
| 1604 | Location::StackSlot(source.GetStackIndex()), |
| 1605 | Location::StackSlot(destination.GetStackIndex()), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1606 | DataType::Type::kInt32, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1607 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1608 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1609 | DataType::Type::kInt32); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1610 | } |
| 1611 | } |
| 1612 | } |
| 1613 | |
Andra Danciu | 1ca6f32 | 2020-08-12 08:58:07 +0000 | [diff] [blame] | 1614 | static Address CreateAddress(Register base, |
| 1615 | Register index = Register::kNoRegister, |
| 1616 | ScaleFactor scale = TIMES_1, |
| 1617 | int32_t disp = 0) { |
| 1618 | if (index == Register::kNoRegister) { |
| 1619 | return Address(base, disp); |
| 1620 | } |
| 1621 | |
| 1622 | return Address(base, index, scale, disp); |
| 1623 | } |
| 1624 | |
Andra Danciu | d0f71f2 | 2020-09-17 09:00:15 +0000 | [diff] [blame] | 1625 | void CodeGeneratorX86::LoadFromMemoryNoBarrier(DataType::Type dst_type, |
| 1626 | Location dst, |
| 1627 | Address src, |
Ulya Trafimovich | 322eced | 2021-06-02 15:39:36 +0100 | [diff] [blame] | 1628 | HInstruction* instr, |
Andra Danciu | d0f71f2 | 2020-09-17 09:00:15 +0000 | [diff] [blame] | 1629 | XmmRegister temp, |
| 1630 | bool is_atomic_load) { |
Andra Danciu | 1ca6f32 | 2020-08-12 08:58:07 +0000 | [diff] [blame] | 1631 | switch (dst_type) { |
| 1632 | case DataType::Type::kBool: |
| 1633 | case DataType::Type::kUint8: |
| 1634 | __ movzxb(dst.AsRegister<Register>(), src); |
| 1635 | break; |
| 1636 | case DataType::Type::kInt8: |
| 1637 | __ movsxb(dst.AsRegister<Register>(), src); |
| 1638 | break; |
| 1639 | case DataType::Type::kInt16: |
| 1640 | __ movsxw(dst.AsRegister<Register>(), src); |
| 1641 | break; |
| 1642 | case DataType::Type::kUint16: |
| 1643 | __ movzxw(dst.AsRegister<Register>(), src); |
| 1644 | break; |
| 1645 | case DataType::Type::kInt32: |
Andra Danciu | 1ca6f32 | 2020-08-12 08:58:07 +0000 | [diff] [blame] | 1646 | __ movl(dst.AsRegister<Register>(), src); |
| 1647 | break; |
Andra Danciu | d0f71f2 | 2020-09-17 09:00:15 +0000 | [diff] [blame] | 1648 | case DataType::Type::kInt64: { |
| 1649 | if (is_atomic_load) { |
| 1650 | __ movsd(temp, src); |
Ulya Trafimovich | 322eced | 2021-06-02 15:39:36 +0100 | [diff] [blame] | 1651 | if (instr != nullptr) { |
| 1652 | MaybeRecordImplicitNullCheck(instr); |
| 1653 | } |
Andra Danciu | d0f71f2 | 2020-09-17 09:00:15 +0000 | [diff] [blame] | 1654 | __ movd(dst.AsRegisterPairLow<Register>(), temp); |
| 1655 | __ psrlq(temp, Immediate(32)); |
| 1656 | __ movd(dst.AsRegisterPairHigh<Register>(), temp); |
| 1657 | } else { |
| 1658 | DCHECK_NE(src.GetBaseRegister(), dst.AsRegisterPairLow<Register>()); |
Ulya Trafimovich | 893e2ed | 2021-06-10 16:18:12 +0100 | [diff] [blame] | 1659 | Address src_high = Address::displace(src, kX86WordSize); |
Andra Danciu | d0f71f2 | 2020-09-17 09:00:15 +0000 | [diff] [blame] | 1660 | __ movl(dst.AsRegisterPairLow<Register>(), src); |
Ulya Trafimovich | 322eced | 2021-06-02 15:39:36 +0100 | [diff] [blame] | 1661 | if (instr != nullptr) { |
| 1662 | MaybeRecordImplicitNullCheck(instr); |
| 1663 | } |
Andra Danciu | d0f71f2 | 2020-09-17 09:00:15 +0000 | [diff] [blame] | 1664 | __ movl(dst.AsRegisterPairHigh<Register>(), src_high); |
| 1665 | } |
Andra Danciu | 1ca6f32 | 2020-08-12 08:58:07 +0000 | [diff] [blame] | 1666 | break; |
| 1667 | } |
| 1668 | case DataType::Type::kFloat32: |
| 1669 | __ movss(dst.AsFpuRegister<XmmRegister>(), src); |
| 1670 | break; |
| 1671 | case DataType::Type::kFloat64: |
| 1672 | __ movsd(dst.AsFpuRegister<XmmRegister>(), src); |
| 1673 | break; |
Andra Danciu | 1ca6f32 | 2020-08-12 08:58:07 +0000 | [diff] [blame] | 1674 | case DataType::Type::kReference: |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 1675 | DCHECK(!gUseReadBarrier); |
Andra Danciu | d0f71f2 | 2020-09-17 09:00:15 +0000 | [diff] [blame] | 1676 | __ movl(dst.AsRegister<Register>(), src); |
| 1677 | __ MaybeUnpoisonHeapReference(dst.AsRegister<Register>()); |
| 1678 | break; |
| 1679 | default: |
Andra Danciu | 1ca6f32 | 2020-08-12 08:58:07 +0000 | [diff] [blame] | 1680 | LOG(FATAL) << "Unreachable type " << dst_type; |
| 1681 | } |
Ulya Trafimovich | 322eced | 2021-06-02 15:39:36 +0100 | [diff] [blame] | 1682 | if (instr != nullptr && dst_type != DataType::Type::kInt64) { |
| 1683 | // kInt64 needs special handling that is done in the above switch. |
| 1684 | MaybeRecordImplicitNullCheck(instr); |
| 1685 | } |
Andra Danciu | 1ca6f32 | 2020-08-12 08:58:07 +0000 | [diff] [blame] | 1686 | } |
| 1687 | |
Andra Danciu | 73c3180 | 2020-09-01 13:17:05 +0000 | [diff] [blame] | 1688 | void CodeGeneratorX86::MoveToMemory(DataType::Type src_type, |
| 1689 | Location src, |
| 1690 | Register dst_base, |
| 1691 | Register dst_index, |
| 1692 | ScaleFactor dst_scale, |
| 1693 | int32_t dst_disp) { |
| 1694 | DCHECK(dst_base != Register::kNoRegister); |
| 1695 | Address dst = CreateAddress(dst_base, dst_index, dst_scale, dst_disp); |
| 1696 | |
| 1697 | switch (src_type) { |
| 1698 | case DataType::Type::kBool: |
| 1699 | case DataType::Type::kUint8: |
| 1700 | case DataType::Type::kInt8: { |
| 1701 | if (src.IsConstant()) { |
| 1702 | __ movb(dst, Immediate(CodeGenerator::GetInt8ValueOf(src.GetConstant()))); |
| 1703 | } else { |
| 1704 | __ movb(dst, src.AsRegister<ByteRegister>()); |
| 1705 | } |
| 1706 | break; |
| 1707 | } |
| 1708 | case DataType::Type::kUint16: |
| 1709 | case DataType::Type::kInt16: { |
| 1710 | if (src.IsConstant()) { |
| 1711 | __ movw(dst, Immediate(CodeGenerator::GetInt16ValueOf(src.GetConstant()))); |
| 1712 | } else { |
| 1713 | __ movw(dst, src.AsRegister<Register>()); |
| 1714 | } |
| 1715 | break; |
| 1716 | } |
| 1717 | case DataType::Type::kUint32: |
| 1718 | case DataType::Type::kInt32: { |
| 1719 | if (src.IsConstant()) { |
| 1720 | int32_t v = CodeGenerator::GetInt32ValueOf(src.GetConstant()); |
| 1721 | __ movl(dst, Immediate(v)); |
| 1722 | } else { |
| 1723 | __ movl(dst, src.AsRegister<Register>()); |
| 1724 | } |
| 1725 | break; |
| 1726 | } |
| 1727 | case DataType::Type::kUint64: |
| 1728 | case DataType::Type::kInt64: { |
| 1729 | Address dst_next_4_bytes = CreateAddress(dst_base, dst_index, dst_scale, dst_disp + 4); |
| 1730 | if (src.IsConstant()) { |
| 1731 | int64_t v = CodeGenerator::GetInt64ValueOf(src.GetConstant()); |
| 1732 | __ movl(dst, Immediate(Low32Bits(v))); |
| 1733 | __ movl(dst_next_4_bytes, Immediate(High32Bits(v))); |
| 1734 | } else { |
| 1735 | __ movl(dst, src.AsRegisterPairLow<Register>()); |
| 1736 | __ movl(dst_next_4_bytes, src.AsRegisterPairHigh<Register>()); |
| 1737 | } |
| 1738 | break; |
| 1739 | } |
| 1740 | case DataType::Type::kFloat32: { |
| 1741 | if (src.IsConstant()) { |
| 1742 | int32_t v = CodeGenerator::GetInt32ValueOf(src.GetConstant()); |
| 1743 | __ movl(dst, Immediate(v)); |
| 1744 | } else { |
| 1745 | __ movss(dst, src.AsFpuRegister<XmmRegister>()); |
| 1746 | } |
| 1747 | break; |
| 1748 | } |
| 1749 | case DataType::Type::kFloat64: { |
| 1750 | Address dst_next_4_bytes = CreateAddress(dst_base, dst_index, dst_scale, dst_disp + 4); |
| 1751 | if (src.IsConstant()) { |
| 1752 | int64_t v = CodeGenerator::GetInt64ValueOf(src.GetConstant()); |
| 1753 | __ movl(dst, Immediate(Low32Bits(v))); |
| 1754 | __ movl(dst_next_4_bytes, Immediate(High32Bits(v))); |
| 1755 | } else { |
| 1756 | __ movsd(dst, src.AsFpuRegister<XmmRegister>()); |
| 1757 | } |
| 1758 | break; |
| 1759 | } |
| 1760 | case DataType::Type::kVoid: |
| 1761 | case DataType::Type::kReference: |
| 1762 | LOG(FATAL) << "Unreachable type " << src_type; |
| 1763 | } |
| 1764 | } |
| 1765 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1766 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { |
| 1767 | DCHECK(location.IsRegister()); |
| 1768 | __ movl(location.AsRegister<Register>(), Immediate(value)); |
| 1769 | } |
| 1770 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1771 | void CodeGeneratorX86::MoveLocation(Location dst, Location src, DataType::Type dst_type) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1772 | HParallelMove move(GetGraph()->GetAllocator()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1773 | if (dst_type == DataType::Type::kInt64 && !src.IsConstant() && !src.IsFpuRegister()) { |
| 1774 | move.AddMove(src.ToLow(), dst.ToLow(), DataType::Type::kInt32, nullptr); |
| 1775 | move.AddMove(src.ToHigh(), dst.ToHigh(), DataType::Type::kInt32, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1776 | } else { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1777 | move.AddMove(src, dst, dst_type, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1778 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1779 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1780 | } |
| 1781 | |
| 1782 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1783 | if (location.IsRegister()) { |
| 1784 | locations->AddTemp(location); |
| 1785 | } else if (location.IsRegisterPair()) { |
| 1786 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1787 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1788 | } else { |
| 1789 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1790 | } |
| 1791 | } |
| 1792 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1793 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 1794 | if (successor->IsExitBlock()) { |
| 1795 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 1796 | return; // no code needed |
| 1797 | } |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1798 | |
| 1799 | HBasicBlock* block = got->GetBlock(); |
| 1800 | HInstruction* previous = got->GetPrevious(); |
| 1801 | |
| 1802 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1803 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1804 | codegen_->MaybeIncrementHotness(/* is_frame_entry= */ false); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1805 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1806 | return; |
| 1807 | } |
| 1808 | |
| 1809 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1810 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1811 | } |
| 1812 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1813 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1814 | } |
| 1815 | } |
| 1816 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1817 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 1818 | got->SetLocations(nullptr); |
| 1819 | } |
| 1820 | |
| 1821 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 1822 | HandleGoto(got, got->GetSuccessor()); |
| 1823 | } |
| 1824 | |
| 1825 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1826 | try_boundary->SetLocations(nullptr); |
| 1827 | } |
| 1828 | |
| 1829 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1830 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1831 | if (!successor->IsExitBlock()) { |
| 1832 | HandleGoto(try_boundary, successor); |
| 1833 | } |
| 1834 | } |
| 1835 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1836 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1837 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1838 | } |
| 1839 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1840 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1841 | } |
| 1842 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1843 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1844 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1845 | LabelType* true_label, |
| 1846 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1847 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1848 | __ j(kUnordered, true_label); |
| 1849 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1850 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1851 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1852 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1853 | } |
| 1854 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1855 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1856 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1857 | LabelType* true_label, |
| 1858 | LabelType* false_label) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1859 | LocationSummary* locations = cond->GetLocations(); |
| 1860 | Location left = locations->InAt(0); |
| 1861 | Location right = locations->InAt(1); |
| 1862 | IfCondition if_cond = cond->GetCondition(); |
| 1863 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1864 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1865 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1866 | IfCondition true_high_cond = if_cond; |
| 1867 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1868 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); // unsigned on lower part |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1869 | |
| 1870 | // Set the conditions for the test, remembering that == needs to be |
| 1871 | // decided using the low words. |
| 1872 | switch (if_cond) { |
| 1873 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1874 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1875 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1876 | break; |
| 1877 | case kCondLT: |
| 1878 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1879 | break; |
| 1880 | case kCondLE: |
| 1881 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1882 | break; |
| 1883 | case kCondGT: |
| 1884 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1885 | break; |
| 1886 | case kCondGE: |
| 1887 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1888 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1889 | case kCondB: |
| 1890 | false_high_cond = kCondA; |
| 1891 | break; |
| 1892 | case kCondBE: |
| 1893 | true_high_cond = kCondB; |
| 1894 | break; |
| 1895 | case kCondA: |
| 1896 | false_high_cond = kCondB; |
| 1897 | break; |
| 1898 | case kCondAE: |
| 1899 | true_high_cond = kCondA; |
| 1900 | break; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1901 | } |
| 1902 | |
| 1903 | if (right.IsConstant()) { |
| 1904 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1905 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1906 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1907 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1908 | codegen_->Compare32BitValue(left_high, val_high); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1909 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1910 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1911 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1912 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1913 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1914 | __ j(X86Condition(true_high_cond), true_label); |
| 1915 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1916 | } |
| 1917 | // Must be equal high, so compare the lows. |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1918 | codegen_->Compare32BitValue(left_low, val_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1919 | } else if (right.IsRegisterPair()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1920 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1921 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1922 | |
| 1923 | __ cmpl(left_high, right_high); |
| 1924 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1925 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1926 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1927 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1928 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1929 | __ j(X86Condition(true_high_cond), true_label); |
| 1930 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1931 | } |
| 1932 | // Must be equal high, so compare the lows. |
| 1933 | __ cmpl(left_low, right_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1934 | } else { |
| 1935 | DCHECK(right.IsDoubleStackSlot()); |
| 1936 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
| 1937 | if (if_cond == kCondNE) { |
| 1938 | __ j(X86Condition(true_high_cond), true_label); |
| 1939 | } else if (if_cond == kCondEQ) { |
| 1940 | __ j(X86Condition(false_high_cond), false_label); |
| 1941 | } else { |
| 1942 | __ j(X86Condition(true_high_cond), true_label); |
| 1943 | __ j(X86Condition(false_high_cond), false_label); |
| 1944 | } |
| 1945 | // Must be equal high, so compare the lows. |
| 1946 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1947 | } |
| 1948 | // The last comparison might be unsigned. |
| 1949 | __ j(final_condition, true_label); |
| 1950 | } |
| 1951 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1952 | void InstructionCodeGeneratorX86::GenerateFPCompare(Location lhs, |
| 1953 | Location rhs, |
| 1954 | HInstruction* insn, |
| 1955 | bool is_double) { |
| 1956 | HX86LoadFromConstantTable* const_area = insn->InputAt(1)->AsX86LoadFromConstantTable(); |
| 1957 | if (is_double) { |
| 1958 | if (rhs.IsFpuRegister()) { |
| 1959 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1960 | } else if (const_area != nullptr) { |
| 1961 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1962 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), |
| 1963 | codegen_->LiteralDoubleAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1964 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 1965 | const_area->GetBaseMethodAddress(), |
| 1966 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1967 | } else { |
| 1968 | DCHECK(rhs.IsDoubleStackSlot()); |
| 1969 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1970 | } |
| 1971 | } else { |
| 1972 | if (rhs.IsFpuRegister()) { |
| 1973 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1974 | } else if (const_area != nullptr) { |
| 1975 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1976 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), |
| 1977 | codegen_->LiteralFloatAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1978 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 1979 | const_area->GetBaseMethodAddress(), |
| 1980 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1981 | } else { |
| 1982 | DCHECK(rhs.IsStackSlot()); |
| 1983 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1984 | } |
| 1985 | } |
| 1986 | } |
| 1987 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1988 | template<class LabelType> |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1989 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1990 | LabelType* true_target_in, |
| 1991 | LabelType* false_target_in) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1992 | // Generated branching requires both targets to be explicit. If either of the |
| 1993 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1994 | LabelType fallthrough_target; |
| 1995 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1996 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1997 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1998 | LocationSummary* locations = condition->GetLocations(); |
| 1999 | Location left = locations->InAt(0); |
| 2000 | Location right = locations->InAt(1); |
| 2001 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2002 | DataType::Type type = condition->InputAt(0)->GetType(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2003 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2004 | case DataType::Type::kInt64: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2005 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 2006 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2007 | case DataType::Type::kFloat32: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2008 | GenerateFPCompare(left, right, condition, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2009 | GenerateFPJumps(condition, true_target, false_target); |
| 2010 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2011 | case DataType::Type::kFloat64: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2012 | GenerateFPCompare(left, right, condition, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2013 | GenerateFPJumps(condition, true_target, false_target); |
| 2014 | break; |
| 2015 | default: |
| 2016 | LOG(FATAL) << "Unexpected compare type " << type; |
| 2017 | } |
| 2018 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2019 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2020 | __ jmp(false_target); |
| 2021 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2022 | |
| 2023 | if (fallthrough_target.IsLinked()) { |
| 2024 | __ Bind(&fallthrough_target); |
| 2025 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2026 | } |
| 2027 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2028 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 2029 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 2030 | // are set only strictly before `branch`. We can't use the eflags on long/FP |
| 2031 | // conditions if they are materialized due to the complex branching. |
| 2032 | return cond->IsCondition() && |
| 2033 | cond->GetNext() == branch && |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2034 | cond->InputAt(0)->GetType() != DataType::Type::kInt64 && |
| 2035 | !DataType::IsFloatingPointType(cond->InputAt(0)->GetType()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2036 | } |
| 2037 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 2038 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2039 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2040 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 2041 | LabelType* true_target, |
| 2042 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2043 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 2044 | |
| 2045 | if (true_target == nullptr && false_target == nullptr) { |
| 2046 | // Nothing to do. The code always falls through. |
| 2047 | return; |
| 2048 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2049 | // Constant condition, statically compared against "true" (integer value 1). |
| 2050 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2051 | if (true_target != nullptr) { |
| 2052 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 2053 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2054 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2055 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2056 | if (false_target != nullptr) { |
| 2057 | __ jmp(false_target); |
| 2058 | } |
| 2059 | } |
| 2060 | return; |
| 2061 | } |
| 2062 | |
| 2063 | // The following code generates these patterns: |
| 2064 | // (1) true_target == nullptr && false_target != nullptr |
| 2065 | // - opposite condition true => branch to false_target |
| 2066 | // (2) true_target != nullptr && false_target == nullptr |
| 2067 | // - condition true => branch to true_target |
| 2068 | // (3) true_target != nullptr && false_target != nullptr |
| 2069 | // - condition true => branch to true_target |
| 2070 | // - branch to false_target |
| 2071 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 2072 | if (AreEflagsSetFrom(cond, instruction)) { |
| 2073 | if (true_target == nullptr) { |
| 2074 | __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 2075 | } else { |
| 2076 | __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); |
| 2077 | } |
| 2078 | } else { |
| 2079 | // Materialized condition, compare against 0. |
| 2080 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 2081 | if (lhs.IsRegister()) { |
| 2082 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 2083 | } else { |
| 2084 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 2085 | } |
| 2086 | if (true_target == nullptr) { |
| 2087 | __ j(kEqual, false_target); |
| 2088 | } else { |
| 2089 | __ j(kNotEqual, true_target); |
| 2090 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2091 | } |
| 2092 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2093 | // Condition has not been materialized, use its inputs as the comparison and |
| 2094 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 2095 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2096 | |
| 2097 | // If this is a long or FP comparison that has been folded into |
| 2098 | // the HCondition, generate the comparison directly. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2099 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 2100 | if (type == DataType::Type::kInt64 || DataType::IsFloatingPointType(type)) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2101 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 2102 | return; |
| 2103 | } |
| 2104 | |
| 2105 | Location lhs = condition->GetLocations()->InAt(0); |
| 2106 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2107 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition). |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 2108 | codegen_->GenerateIntCompare(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2109 | if (true_target == nullptr) { |
| 2110 | __ j(X86Condition(condition->GetOppositeCondition()), false_target); |
| 2111 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 2112 | __ j(X86Condition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2113 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2114 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2115 | |
| 2116 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 2117 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 2118 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2119 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2120 | } |
| 2121 | } |
| 2122 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2123 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2124 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2125 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2126 | locations->SetInAt(0, Location::Any()); |
| 2127 | } |
| 2128 | } |
| 2129 | |
| 2130 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2131 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 2132 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 2133 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 2134 | nullptr : codegen_->GetLabelOf(true_successor); |
| 2135 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 2136 | nullptr : codegen_->GetLabelOf(false_successor); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2137 | GenerateTestAndBranch(if_instr, /* condition_input_index= */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2138 | } |
| 2139 | |
| 2140 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2141 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2142 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 2143 | InvokeRuntimeCallingConvention calling_convention; |
| 2144 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 2145 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2146 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2147 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2148 | locations->SetInAt(0, Location::Any()); |
| 2149 | } |
| 2150 | } |
| 2151 | |
| 2152 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 2153 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2154 | GenerateTestAndBranch<Label>(deoptimize, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2155 | /* condition_input_index= */ 0, |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2156 | slow_path->GetEntryLabel(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2157 | /* false_target= */ nullptr); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2158 | } |
| 2159 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 2160 | void LocationsBuilderX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2161 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 2162 | LocationSummary(flag, LocationSummary::kNoCall); |
| 2163 | locations->SetOut(Location::RequiresRegister()); |
| 2164 | } |
| 2165 | |
| 2166 | void InstructionCodeGeneratorX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 2167 | __ movl(flag->GetLocations()->Out().AsRegister<Register>(), |
| 2168 | Address(ESP, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 2169 | } |
| 2170 | |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2171 | static bool SelectCanUseCMOV(HSelect* select) { |
| 2172 | // There are no conditional move instructions for XMMs. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2173 | if (DataType::IsFloatingPointType(select->GetType())) { |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2174 | return false; |
| 2175 | } |
| 2176 | |
| 2177 | // A FP condition doesn't generate the single CC that we need. |
| 2178 | // In 32 bit mode, a long condition doesn't generate a single CC either. |
| 2179 | HInstruction* condition = select->GetCondition(); |
| 2180 | if (condition->IsCondition()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2181 | DataType::Type compare_type = condition->InputAt(0)->GetType(); |
| 2182 | if (compare_type == DataType::Type::kInt64 || |
| 2183 | DataType::IsFloatingPointType(compare_type)) { |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2184 | return false; |
| 2185 | } |
| 2186 | } |
| 2187 | |
| 2188 | // We can generate a CMOV for this Select. |
| 2189 | return true; |
| 2190 | } |
| 2191 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2192 | void LocationsBuilderX86::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2193 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2194 | if (DataType::IsFloatingPointType(select->GetType())) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2195 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2196 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2197 | } else { |
| 2198 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2199 | if (SelectCanUseCMOV(select)) { |
| 2200 | if (select->InputAt(1)->IsConstant()) { |
| 2201 | // Cmov can't handle a constant value. |
| 2202 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2203 | } else { |
| 2204 | locations->SetInAt(1, Location::Any()); |
| 2205 | } |
| 2206 | } else { |
| 2207 | locations->SetInAt(1, Location::Any()); |
| 2208 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2209 | } |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2210 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 2211 | locations->SetInAt(2, Location::RequiresRegister()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2212 | } |
| 2213 | locations->SetOut(Location::SameAsFirstInput()); |
| 2214 | } |
| 2215 | |
| 2216 | void InstructionCodeGeneratorX86::VisitSelect(HSelect* select) { |
| 2217 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2218 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 2219 | if (SelectCanUseCMOV(select)) { |
| 2220 | // If both the condition and the source types are integer, we can generate |
| 2221 | // a CMOV to implement Select. |
| 2222 | |
| 2223 | HInstruction* select_condition = select->GetCondition(); |
| 2224 | Condition cond = kNotEqual; |
| 2225 | |
| 2226 | // Figure out how to test the 'condition'. |
| 2227 | if (select_condition->IsCondition()) { |
| 2228 | HCondition* condition = select_condition->AsCondition(); |
| 2229 | if (!condition->IsEmittedAtUseSite()) { |
| 2230 | // This was a previously materialized condition. |
| 2231 | // Can we use the existing condition code? |
| 2232 | if (AreEflagsSetFrom(condition, select)) { |
| 2233 | // Materialization was the previous instruction. Condition codes are right. |
| 2234 | cond = X86Condition(condition->GetCondition()); |
| 2235 | } else { |
| 2236 | // No, we have to recreate the condition code. |
| 2237 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 2238 | __ testl(cond_reg, cond_reg); |
| 2239 | } |
| 2240 | } else { |
| 2241 | // We can't handle FP or long here. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2242 | DCHECK_NE(condition->InputAt(0)->GetType(), DataType::Type::kInt64); |
| 2243 | DCHECK(!DataType::IsFloatingPointType(condition->InputAt(0)->GetType())); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2244 | LocationSummary* cond_locations = condition->GetLocations(); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2245 | codegen_->GenerateIntCompare(cond_locations->InAt(0), cond_locations->InAt(1)); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2246 | cond = X86Condition(condition->GetCondition()); |
| 2247 | } |
| 2248 | } else { |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 2249 | // Must be a Boolean condition, which needs to be compared to 0. |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2250 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 2251 | __ testl(cond_reg, cond_reg); |
| 2252 | } |
| 2253 | |
| 2254 | // If the condition is true, overwrite the output, which already contains false. |
| 2255 | Location false_loc = locations->InAt(0); |
| 2256 | Location true_loc = locations->InAt(1); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2257 | if (select->GetType() == DataType::Type::kInt64) { |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2258 | // 64 bit conditional move. |
| 2259 | Register false_high = false_loc.AsRegisterPairHigh<Register>(); |
| 2260 | Register false_low = false_loc.AsRegisterPairLow<Register>(); |
| 2261 | if (true_loc.IsRegisterPair()) { |
| 2262 | __ cmovl(cond, false_high, true_loc.AsRegisterPairHigh<Register>()); |
| 2263 | __ cmovl(cond, false_low, true_loc.AsRegisterPairLow<Register>()); |
| 2264 | } else { |
| 2265 | __ cmovl(cond, false_high, Address(ESP, true_loc.GetHighStackIndex(kX86WordSize))); |
| 2266 | __ cmovl(cond, false_low, Address(ESP, true_loc.GetStackIndex())); |
| 2267 | } |
| 2268 | } else { |
| 2269 | // 32 bit conditional move. |
| 2270 | Register false_reg = false_loc.AsRegister<Register>(); |
| 2271 | if (true_loc.IsRegister()) { |
| 2272 | __ cmovl(cond, false_reg, true_loc.AsRegister<Register>()); |
| 2273 | } else { |
| 2274 | __ cmovl(cond, false_reg, Address(ESP, true_loc.GetStackIndex())); |
| 2275 | } |
| 2276 | } |
| 2277 | } else { |
| 2278 | NearLabel false_target; |
| 2279 | GenerateTestAndBranch<NearLabel>( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2280 | select, /* condition_input_index= */ 2, /* true_target= */ nullptr, &false_target); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2281 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 2282 | __ Bind(&false_target); |
| 2283 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2284 | } |
| 2285 | |
Santiago Aboy Solanes | caf9b65 | 2022-06-24 10:03:30 +0100 | [diff] [blame] | 2286 | void LocationsBuilderX86::VisitNop(HNop* nop) { |
| 2287 | new (GetGraph()->GetAllocator()) LocationSummary(nop); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 2288 | } |
| 2289 | |
Santiago Aboy Solanes | caf9b65 | 2022-06-24 10:03:30 +0100 | [diff] [blame] | 2290 | void InstructionCodeGeneratorX86::VisitNop(HNop*) { |
| 2291 | // The environment recording already happened in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 2292 | } |
| 2293 | |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 2294 | void CodeGeneratorX86::IncreaseFrame(size_t adjustment) { |
| 2295 | __ subl(ESP, Immediate(adjustment)); |
| 2296 | __ cfi().AdjustCFAOffset(adjustment); |
| 2297 | } |
| 2298 | |
| 2299 | void CodeGeneratorX86::DecreaseFrame(size_t adjustment) { |
| 2300 | __ addl(ESP, Immediate(adjustment)); |
| 2301 | __ cfi().AdjustCFAOffset(-adjustment); |
| 2302 | } |
| 2303 | |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 2304 | void CodeGeneratorX86::GenerateNop() { |
| 2305 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 2306 | } |
| 2307 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2308 | void LocationsBuilderX86::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2309 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2310 | new (GetGraph()->GetAllocator()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2311 | // Handle the long/FP comparisons made in instruction simplification. |
| 2312 | switch (cond->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2313 | case DataType::Type::kInt64: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2314 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 2315 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2316 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2317 | locations->SetOut(Location::RequiresRegister()); |
| 2318 | } |
| 2319 | break; |
| 2320 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2321 | case DataType::Type::kFloat32: |
| 2322 | case DataType::Type::kFloat64: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2323 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2324 | if (cond->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2325 | DCHECK(cond->InputAt(1)->IsEmittedAtUseSite()); |
| 2326 | } else if (cond->InputAt(1)->IsConstant()) { |
| 2327 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2328 | } else { |
| 2329 | locations->SetInAt(1, Location::Any()); |
| 2330 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2331 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2332 | locations->SetOut(Location::RequiresRegister()); |
| 2333 | } |
| 2334 | break; |
| 2335 | } |
| 2336 | default: |
| 2337 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2338 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2339 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2340 | // We need a byte register. |
| 2341 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 2342 | } |
| 2343 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2344 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2345 | } |
| 2346 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2347 | void InstructionCodeGeneratorX86::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2348 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2349 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2350 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2351 | |
| 2352 | LocationSummary* locations = cond->GetLocations(); |
| 2353 | Location lhs = locations->InAt(0); |
| 2354 | Location rhs = locations->InAt(1); |
| 2355 | Register reg = locations->Out().AsRegister<Register>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 2356 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2357 | |
| 2358 | switch (cond->InputAt(0)->GetType()) { |
| 2359 | default: { |
| 2360 | // Integer case. |
| 2361 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 2362 | // Clear output register: setb only sets the low byte. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2363 | __ xorl(reg, reg); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2364 | codegen_->GenerateIntCompare(lhs, rhs); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2365 | __ setb(X86Condition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2366 | return; |
| 2367 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2368 | case DataType::Type::kInt64: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2369 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 2370 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2371 | case DataType::Type::kFloat32: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2372 | GenerateFPCompare(lhs, rhs, cond, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2373 | GenerateFPJumps(cond, &true_label, &false_label); |
| 2374 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2375 | case DataType::Type::kFloat64: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2376 | GenerateFPCompare(lhs, rhs, cond, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2377 | GenerateFPJumps(cond, &true_label, &false_label); |
| 2378 | break; |
| 2379 | } |
| 2380 | |
| 2381 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2382 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2383 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2384 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2385 | __ Bind(&false_label); |
| 2386 | __ xorl(reg, reg); |
| 2387 | __ jmp(&done_label); |
| 2388 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2389 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2390 | __ Bind(&true_label); |
| 2391 | __ movl(reg, Immediate(1)); |
| 2392 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2393 | } |
| 2394 | |
| 2395 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2396 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2397 | } |
| 2398 | |
| 2399 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2400 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2401 | } |
| 2402 | |
| 2403 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2404 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2405 | } |
| 2406 | |
| 2407 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2408 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2409 | } |
| 2410 | |
| 2411 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2412 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2413 | } |
| 2414 | |
| 2415 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2416 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2417 | } |
| 2418 | |
| 2419 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2420 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2421 | } |
| 2422 | |
| 2423 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2424 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2425 | } |
| 2426 | |
| 2427 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2428 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2429 | } |
| 2430 | |
| 2431 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2432 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2433 | } |
| 2434 | |
| 2435 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2436 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2437 | } |
| 2438 | |
| 2439 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2440 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2441 | } |
| 2442 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2443 | void LocationsBuilderX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2444 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2445 | } |
| 2446 | |
| 2447 | void InstructionCodeGeneratorX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2448 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2449 | } |
| 2450 | |
| 2451 | void LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2452 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2453 | } |
| 2454 | |
| 2455 | void InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2456 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2457 | } |
| 2458 | |
| 2459 | void LocationsBuilderX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2460 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2461 | } |
| 2462 | |
| 2463 | void InstructionCodeGeneratorX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2464 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2465 | } |
| 2466 | |
| 2467 | void LocationsBuilderX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2468 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2469 | } |
| 2470 | |
| 2471 | void InstructionCodeGeneratorX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2472 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2473 | } |
| 2474 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2475 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2476 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2477 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2478 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2479 | } |
| 2480 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2481 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2482 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2483 | } |
| 2484 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2485 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 2486 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2487 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2488 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2489 | } |
| 2490 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2491 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2492 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2493 | } |
| 2494 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2495 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2496 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2497 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2498 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2499 | } |
| 2500 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2501 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2502 | // Will be generated at use site. |
| 2503 | } |
| 2504 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2505 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 2506 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2507 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2508 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2509 | } |
| 2510 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2511 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2512 | // Will be generated at use site. |
| 2513 | } |
| 2514 | |
| 2515 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2516 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2517 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2518 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2519 | } |
| 2520 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2521 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2522 | // Will be generated at use site. |
| 2523 | } |
| 2524 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2525 | void LocationsBuilderX86::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 2526 | constructor_fence->SetLocations(nullptr); |
| 2527 | } |
| 2528 | |
| 2529 | void InstructionCodeGeneratorX86::VisitConstructorFence( |
| 2530 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 2531 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 2532 | } |
| 2533 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2534 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2535 | memory_barrier->SetLocations(nullptr); |
| 2536 | } |
| 2537 | |
| 2538 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 2539 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2540 | } |
| 2541 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2542 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2543 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2544 | } |
| 2545 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2546 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2547 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2548 | } |
| 2549 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2550 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2551 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2552 | new (GetGraph()->GetAllocator()) LocationSummary(ret, LocationSummary::kNoCall); |
Mythri Alle | 5097f83 | 2021-11-02 14:52:30 +0000 | [diff] [blame] | 2553 | SetInForReturnValue(ret, locations); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2554 | } |
| 2555 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2556 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 57cacb7 | 2019-12-08 22:07:08 +0000 | [diff] [blame] | 2557 | switch (ret->InputAt(0)->GetType()) { |
| 2558 | case DataType::Type::kReference: |
| 2559 | case DataType::Type::kBool: |
| 2560 | case DataType::Type::kUint8: |
| 2561 | case DataType::Type::kInt8: |
| 2562 | case DataType::Type::kUint16: |
| 2563 | case DataType::Type::kInt16: |
| 2564 | case DataType::Type::kInt32: |
| 2565 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
| 2566 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2567 | |
Nicolas Geoffray | 57cacb7 | 2019-12-08 22:07:08 +0000 | [diff] [blame] | 2568 | case DataType::Type::kInt64: |
| 2569 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 2570 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
| 2571 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2572 | |
Nicolas Geoffray | 57cacb7 | 2019-12-08 22:07:08 +0000 | [diff] [blame] | 2573 | case DataType::Type::kFloat32: |
| 2574 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
| 2575 | if (GetGraph()->IsCompilingOsr()) { |
| 2576 | // To simplify callers of an OSR method, we put the return value in both |
| 2577 | // floating point and core registers. |
| 2578 | __ movd(EAX, XMM0); |
| 2579 | } |
| 2580 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2581 | |
Nicolas Geoffray | 57cacb7 | 2019-12-08 22:07:08 +0000 | [diff] [blame] | 2582 | case DataType::Type::kFloat64: |
| 2583 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
| 2584 | if (GetGraph()->IsCompilingOsr()) { |
| 2585 | // To simplify callers of an OSR method, we put the return value in both |
| 2586 | // floating point and core registers. |
| 2587 | __ movd(EAX, XMM0); |
| 2588 | // Use XMM1 as temporary register to not clobber XMM0. |
| 2589 | __ movaps(XMM1, XMM0); |
| 2590 | __ psrlq(XMM1, Immediate(32)); |
| 2591 | __ movd(EDX, XMM1); |
| 2592 | } |
| 2593 | break; |
| 2594 | |
| 2595 | default: |
| 2596 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2597 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2598 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2599 | } |
| 2600 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2601 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2602 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2603 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2604 | // the method_idx. |
| 2605 | HandleInvoke(invoke); |
| 2606 | } |
| 2607 | |
| 2608 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2609 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2610 | } |
| 2611 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2612 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2613 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2614 | // art::PrepareForRegisterAllocation. |
| 2615 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2616 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2617 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2618 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 2619 | if (invoke->GetLocations()->CanCall() && |
| 2620 | invoke->HasPcRelativeMethodLoadKind() && |
| 2621 | invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()).IsInvalid()) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 2622 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2623 | } |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2624 | return; |
| 2625 | } |
| 2626 | |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 2627 | if (invoke->GetCodePtrLocation() == CodePtrLocation::kCallCriticalNative) { |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 2628 | CriticalNativeCallingConventionVisitorX86 calling_convention_visitor( |
| 2629 | /*for_register_allocation=*/ true); |
| 2630 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 2631 | } else { |
| 2632 | HandleInvoke(invoke); |
| 2633 | } |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2634 | |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 2635 | // 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] | 2636 | if (invoke->HasPcRelativeMethodLoadKind()) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2637 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2638 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2639 | } |
| 2640 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2641 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 2642 | if (invoke->GetLocations()->Intrinsified()) { |
| 2643 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 2644 | intrinsic.Dispatch(invoke); |
| 2645 | return true; |
| 2646 | } |
| 2647 | return false; |
| 2648 | } |
| 2649 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2650 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2651 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2652 | // art::PrepareForRegisterAllocation. |
| 2653 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2654 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2655 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2656 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2657 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2658 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2659 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2660 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2661 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2662 | } |
| 2663 | |
| 2664 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 2665 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 2666 | if (intrinsic.TryDispatch(invoke)) { |
| 2667 | return; |
| 2668 | } |
| 2669 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2670 | HandleInvoke(invoke); |
Nicolas Geoffray | 9b5271e | 2019-12-04 14:39:46 +0000 | [diff] [blame] | 2671 | |
| 2672 | if (GetGraph()->IsCompilingBaseline() && !Runtime::Current()->IsAotCompiler()) { |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2673 | // Add one temporary for inline cache update. |
| 2674 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(EBP)); |
| 2675 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2676 | } |
| 2677 | |
| 2678 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2679 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2680 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2681 | } |
| 2682 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2683 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2684 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2685 | return; |
| 2686 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2687 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2688 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2689 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2690 | } |
| 2691 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2692 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2693 | // This call to HandleInvoke allocates a temporary (core) register |
| 2694 | // which is also used to transfer the hidden argument from FP to |
| 2695 | // core register. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2696 | HandleInvoke(invoke); |
| 2697 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2698 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2699 | |
Nicolas Geoffray | 9b5271e | 2019-12-04 14:39:46 +0000 | [diff] [blame] | 2700 | if (GetGraph()->IsCompilingBaseline() && !Runtime::Current()->IsAotCompiler()) { |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2701 | // Add one temporary for inline cache update. |
| 2702 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(EBP)); |
| 2703 | } |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 2704 | |
| 2705 | // For PC-relative load kinds the invoke has an extra input, the PC-relative address base. |
| 2706 | if (IsPcRelativeMethodLoadKind(invoke->GetHiddenArgumentLoadKind())) { |
| 2707 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| 2708 | } |
| 2709 | |
| 2710 | if (invoke->GetHiddenArgumentLoadKind() == MethodLoadKind::kRecursive) { |
| 2711 | invoke->GetLocations()->SetInAt(invoke->GetNumberOfArguments() - 1, |
| 2712 | Location::RequiresRegister()); |
| 2713 | } |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2714 | } |
| 2715 | |
| 2716 | void CodeGeneratorX86::MaybeGenerateInlineCacheCheck(HInstruction* instruction, Register klass) { |
| 2717 | DCHECK_EQ(EAX, klass); |
Nicolas Geoffray | 17a39ba | 2019-11-27 20:57:48 +0000 | [diff] [blame] | 2718 | // We know the destination of an intrinsic, so no need to record inline |
| 2719 | // caches (also the intrinsic location builder doesn't request an additional |
| 2720 | // temporary). |
| 2721 | if (!instruction->GetLocations()->Intrinsified() && |
Nicolas Geoffray | 9b5271e | 2019-12-04 14:39:46 +0000 | [diff] [blame] | 2722 | GetGraph()->IsCompilingBaseline() && |
Nicolas Geoffray | 17a39ba | 2019-11-27 20:57:48 +0000 | [diff] [blame] | 2723 | !Runtime::Current()->IsAotCompiler()) { |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2724 | DCHECK(!instruction->GetEnvironment()->IsFromInlinedInvoke()); |
Nicolas Geoffray | 9e59890 | 2021-11-19 14:53:07 +0000 | [diff] [blame] | 2725 | ProfilingInfo* info = GetGraph()->GetProfilingInfo(); |
| 2726 | DCHECK(info != nullptr); |
| 2727 | InlineCache* cache = info->GetInlineCache(instruction->GetDexPc()); |
| 2728 | uint32_t address = reinterpret_cast32<uint32_t>(cache); |
| 2729 | if (kIsDebugBuild) { |
| 2730 | uint32_t temp_index = instruction->GetLocations()->GetTempCount() - 1u; |
| 2731 | CHECK_EQ(EBP, instruction->GetLocations()->GetTemp(temp_index).AsRegister<Register>()); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2732 | } |
Nicolas Geoffray | 9e59890 | 2021-11-19 14:53:07 +0000 | [diff] [blame] | 2733 | Register temp = EBP; |
| 2734 | NearLabel done; |
| 2735 | __ movl(temp, Immediate(address)); |
| 2736 | // Fast path for a monomorphic cache. |
| 2737 | __ cmpl(klass, Address(temp, InlineCache::ClassesOffset().Int32Value())); |
| 2738 | __ j(kEqual, &done); |
| 2739 | GenerateInvokeRuntime(GetThreadOffset<kX86PointerSize>(kQuickUpdateInlineCache).Int32Value()); |
| 2740 | __ Bind(&done); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2741 | } |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2742 | } |
| 2743 | |
| 2744 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2745 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2746 | LocationSummary* locations = invoke->GetLocations(); |
| 2747 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2748 | XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2749 | Location receiver = locations->InAt(0); |
| 2750 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2751 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2752 | // Set the hidden argument. This is safe to do this here, as XMM7 |
| 2753 | // won't be modified thereafter, before the `call` instruction. |
| 2754 | DCHECK_EQ(XMM7, hidden_reg); |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 2755 | if (invoke->GetHiddenArgumentLoadKind() == MethodLoadKind::kRecursive) { |
| 2756 | __ movd(hidden_reg, locations->InAt(invoke->GetNumberOfArguments() - 1).AsRegister<Register>()); |
Nicolas Geoffray | d6bd107 | 2020-11-30 18:42:01 +0000 | [diff] [blame] | 2757 | } else if (invoke->GetHiddenArgumentLoadKind() != MethodLoadKind::kRuntimeCall) { |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 2758 | codegen_->LoadMethod(invoke->GetHiddenArgumentLoadKind(), locations->GetTemp(0), invoke); |
| 2759 | __ movd(hidden_reg, temp); |
| 2760 | } |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2761 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2762 | if (receiver.IsStackSlot()) { |
| 2763 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2764 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2765 | __ movl(temp, Address(temp, class_offset)); |
| 2766 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2767 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2768 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2769 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2770 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2771 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2772 | // emit a read barrier for the previous class reference load. |
| 2773 | // However this is not required in practice, as this is an |
| 2774 | // intermediate/temporary reference and because the current |
| 2775 | // concurrent copying collector keeps the from-space memory |
| 2776 | // intact/accessible until the end of the marking phase (the |
| 2777 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2778 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2779 | |
| 2780 | codegen_->MaybeGenerateInlineCacheCheck(invoke, temp); |
| 2781 | |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2782 | // temp = temp->GetAddressOfIMT() |
| 2783 | __ movl(temp, |
| 2784 | Address(temp, mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2785 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2786 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2787 | invoke->GetImtIndex(), kX86PointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2788 | __ movl(temp, Address(temp, method_offset)); |
Nicolas Geoffray | d6bd107 | 2020-11-30 18:42:01 +0000 | [diff] [blame] | 2789 | if (invoke->GetHiddenArgumentLoadKind() == MethodLoadKind::kRuntimeCall) { |
| 2790 | // We pass the method from the IMT in case of a conflict. This will ensure |
| 2791 | // we go into the runtime to resolve the actual method. |
| 2792 | __ movd(hidden_reg, temp); |
| 2793 | } |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2794 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2795 | __ call(Address(temp, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2796 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2797 | |
| 2798 | DCHECK(!codegen_->IsLeafMethod()); |
| 2799 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2800 | } |
| 2801 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2802 | void LocationsBuilderX86::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 2803 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 2804 | if (intrinsic.TryDispatch(invoke)) { |
| 2805 | return; |
| 2806 | } |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2807 | HandleInvoke(invoke); |
| 2808 | } |
| 2809 | |
| 2810 | void InstructionCodeGeneratorX86::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 2811 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2812 | return; |
| 2813 | } |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2814 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 2815 | } |
| 2816 | |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 2817 | void LocationsBuilderX86::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 2818 | HandleInvoke(invoke); |
| 2819 | } |
| 2820 | |
| 2821 | void InstructionCodeGeneratorX86::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 2822 | codegen_->GenerateInvokeCustomCall(invoke); |
| 2823 | } |
| 2824 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2825 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 2826 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2827 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2828 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2829 | case DataType::Type::kInt32: |
| 2830 | case DataType::Type::kInt64: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2831 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2832 | locations->SetOut(Location::SameAsFirstInput()); |
| 2833 | break; |
| 2834 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2835 | case DataType::Type::kFloat32: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2836 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2837 | locations->SetOut(Location::SameAsFirstInput()); |
| 2838 | locations->AddTemp(Location::RequiresRegister()); |
| 2839 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2840 | break; |
| 2841 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2842 | case DataType::Type::kFloat64: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2843 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2844 | locations->SetOut(Location::SameAsFirstInput()); |
| 2845 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2846 | break; |
| 2847 | |
| 2848 | default: |
| 2849 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2850 | } |
| 2851 | } |
| 2852 | |
| 2853 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 2854 | LocationSummary* locations = neg->GetLocations(); |
| 2855 | Location out = locations->Out(); |
| 2856 | Location in = locations->InAt(0); |
| 2857 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2858 | case DataType::Type::kInt32: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2859 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2860 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2861 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2862 | break; |
| 2863 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2864 | case DataType::Type::kInt64: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2865 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2866 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2867 | __ negl(out.AsRegisterPairLow<Register>()); |
| 2868 | // Negation is similar to subtraction from zero. The least |
| 2869 | // significant byte triggers a borrow when it is different from |
| 2870 | // zero; to take it into account, add 1 to the most significant |
| 2871 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 2872 | // operation. |
| 2873 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2874 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 2875 | break; |
| 2876 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2877 | case DataType::Type::kFloat32: { |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2878 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2879 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 2880 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2881 | // Implement float negation with an exclusive or with value |
| 2882 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2883 | // single-precision floating-point number). |
| 2884 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 2885 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2886 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2887 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2888 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2889 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2890 | case DataType::Type::kFloat64: { |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2891 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2892 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2893 | // Implement double negation with an exclusive or with value |
| 2894 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 2895 | // a double-precision floating-point number). |
| 2896 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2897 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2898 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2899 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2900 | |
| 2901 | default: |
| 2902 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2903 | } |
| 2904 | } |
| 2905 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2906 | void LocationsBuilderX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2907 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2908 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2909 | DCHECK(DataType::IsFloatingPointType(neg->GetType())); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2910 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2911 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2912 | locations->SetOut(Location::SameAsFirstInput()); |
| 2913 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2914 | } |
| 2915 | |
| 2916 | void InstructionCodeGeneratorX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2917 | LocationSummary* locations = neg->GetLocations(); |
| 2918 | Location out = locations->Out(); |
| 2919 | DCHECK(locations->InAt(0).Equals(out)); |
| 2920 | |
| 2921 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 2922 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2923 | if (neg->GetType() == DataType::Type::kFloat32) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 2924 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x80000000), |
| 2925 | neg->GetBaseMethodAddress(), |
| 2926 | constant_area)); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2927 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| 2928 | } else { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 2929 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000), |
| 2930 | neg->GetBaseMethodAddress(), |
| 2931 | constant_area)); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2932 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| 2933 | } |
| 2934 | } |
| 2935 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2936 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2937 | DataType::Type result_type = conversion->GetResultType(); |
| 2938 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2939 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 2940 | << input_type << " -> " << result_type; |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2941 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2942 | // The float-to-long and double-to-long type conversions rely on a |
| 2943 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2944 | LocationSummary::CallKind call_kind = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2945 | ((input_type == DataType::Type::kFloat32 || input_type == DataType::Type::kFloat64) |
| 2946 | && result_type == DataType::Type::kInt64) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2947 | ? LocationSummary::kCallOnMainOnly |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2948 | : LocationSummary::kNoCall; |
| 2949 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2950 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, call_kind); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2951 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2952 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2953 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2954 | case DataType::Type::kInt8: |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2955 | switch (input_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2956 | case DataType::Type::kUint8: |
| 2957 | case DataType::Type::kInt8: |
| 2958 | case DataType::Type::kUint16: |
| 2959 | case DataType::Type::kInt16: |
| 2960 | case DataType::Type::kInt32: |
| 2961 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 2962 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2963 | // the validation of the linear scan implementation |
| 2964 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2965 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2966 | case DataType::Type::kInt64: { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2967 | HInstruction* input = conversion->InputAt(0); |
| 2968 | Location input_location = input->IsConstant() |
| 2969 | ? Location::ConstantLocation(input->AsConstant()) |
| 2970 | : Location::RegisterPairLocation(EAX, EDX); |
| 2971 | locations->SetInAt(0, input_location); |
| 2972 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2973 | // the validation of the linear scan implementation |
| 2974 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2975 | break; |
| 2976 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2977 | |
| 2978 | default: |
| 2979 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2980 | << " to " << result_type; |
| 2981 | } |
| 2982 | break; |
| 2983 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2984 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2985 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2986 | DCHECK(DataType::IsIntegralType(input_type)) << input_type; |
| 2987 | locations->SetInAt(0, Location::Any()); |
| 2988 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2989 | break; |
| 2990 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2991 | case DataType::Type::kInt32: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2992 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2993 | case DataType::Type::kInt64: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2994 | locations->SetInAt(0, Location::Any()); |
| 2995 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2996 | break; |
| 2997 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2998 | case DataType::Type::kFloat32: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2999 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3000 | locations->SetOut(Location::RequiresRegister()); |
| 3001 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3002 | break; |
| 3003 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3004 | case DataType::Type::kFloat64: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3005 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3006 | locations->SetOut(Location::RequiresRegister()); |
| 3007 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3008 | break; |
| 3009 | |
| 3010 | default: |
| 3011 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3012 | << " to " << result_type; |
| 3013 | } |
| 3014 | break; |
| 3015 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3016 | case DataType::Type::kInt64: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3017 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3018 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3019 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3020 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3021 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3022 | case DataType::Type::kInt16: |
| 3023 | case DataType::Type::kInt32: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3024 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 3025 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3026 | break; |
| 3027 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3028 | case DataType::Type::kFloat32: |
| 3029 | case DataType::Type::kFloat64: { |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 3030 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 3031 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 3032 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 3033 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 3034 | // The runtime helper puts the result in EAX, EDX. |
| 3035 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 3036 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 3037 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3038 | |
| 3039 | default: |
| 3040 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3041 | << " to " << result_type; |
| 3042 | } |
| 3043 | break; |
| 3044 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3045 | case DataType::Type::kFloat32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3046 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3047 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3048 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3049 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3050 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3051 | case DataType::Type::kInt16: |
| 3052 | case DataType::Type::kInt32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3053 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3054 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3055 | break; |
| 3056 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3057 | case DataType::Type::kInt64: |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3058 | locations->SetInAt(0, Location::Any()); |
| 3059 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3060 | break; |
| 3061 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3062 | case DataType::Type::kFloat64: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3063 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3064 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3065 | break; |
| 3066 | |
| 3067 | default: |
| 3068 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3069 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3070 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3071 | break; |
| 3072 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3073 | case DataType::Type::kFloat64: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3074 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3075 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3076 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3077 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3078 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3079 | case DataType::Type::kInt16: |
| 3080 | case DataType::Type::kInt32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3081 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3082 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3083 | break; |
| 3084 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3085 | case DataType::Type::kInt64: |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3086 | locations->SetInAt(0, Location::Any()); |
| 3087 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3088 | break; |
| 3089 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3090 | case DataType::Type::kFloat32: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3091 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3092 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3093 | break; |
| 3094 | |
| 3095 | default: |
| 3096 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3097 | << " to " << result_type; |
| 3098 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3099 | break; |
| 3100 | |
| 3101 | default: |
| 3102 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3103 | << " to " << result_type; |
| 3104 | } |
| 3105 | } |
| 3106 | |
| 3107 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 3108 | LocationSummary* locations = conversion->GetLocations(); |
| 3109 | Location out = locations->Out(); |
| 3110 | Location in = locations->InAt(0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3111 | DataType::Type result_type = conversion->GetResultType(); |
| 3112 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3113 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 3114 | << input_type << " -> " << result_type; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3115 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3116 | case DataType::Type::kUint8: |
| 3117 | switch (input_type) { |
| 3118 | case DataType::Type::kInt8: |
| 3119 | case DataType::Type::kUint16: |
| 3120 | case DataType::Type::kInt16: |
| 3121 | case DataType::Type::kInt32: |
| 3122 | if (in.IsRegister()) { |
| 3123 | __ movzxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
| 3124 | } else { |
| 3125 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 3126 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 3127 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint8_t>(value))); |
| 3128 | } |
| 3129 | break; |
| 3130 | case DataType::Type::kInt64: |
| 3131 | if (in.IsRegisterPair()) { |
| 3132 | __ movzxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 3133 | } else { |
| 3134 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 3135 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3136 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint8_t>(value))); |
| 3137 | } |
| 3138 | break; |
| 3139 | |
| 3140 | default: |
| 3141 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3142 | << " to " << result_type; |
| 3143 | } |
| 3144 | break; |
| 3145 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3146 | case DataType::Type::kInt8: |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3147 | switch (input_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3148 | case DataType::Type::kUint8: |
| 3149 | case DataType::Type::kUint16: |
| 3150 | case DataType::Type::kInt16: |
| 3151 | case DataType::Type::kInt32: |
| 3152 | if (in.IsRegister()) { |
| 3153 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
| 3154 | } else { |
| 3155 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 3156 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 3157 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 3158 | } |
| 3159 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3160 | case DataType::Type::kInt64: |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3161 | if (in.IsRegisterPair()) { |
| 3162 | __ movsxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 3163 | } else { |
| 3164 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 3165 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3166 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 3167 | } |
| 3168 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3169 | |
| 3170 | default: |
| 3171 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3172 | << " to " << result_type; |
| 3173 | } |
| 3174 | break; |
| 3175 | |
| 3176 | case DataType::Type::kUint16: |
| 3177 | switch (input_type) { |
| 3178 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3179 | case DataType::Type::kInt16: |
| 3180 | case DataType::Type::kInt32: |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 3181 | if (in.IsRegister()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3182 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
| 3183 | } else if (in.IsStackSlot()) { |
| 3184 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 3185 | } else { |
| 3186 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 3187 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3188 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
| 3189 | } |
| 3190 | break; |
| 3191 | case DataType::Type::kInt64: |
| 3192 | if (in.IsRegisterPair()) { |
| 3193 | __ movzxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 3194 | } else if (in.IsDoubleStackSlot()) { |
| 3195 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 3196 | } else { |
| 3197 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 3198 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3199 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 3200 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3201 | break; |
| 3202 | |
| 3203 | default: |
| 3204 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3205 | << " to " << result_type; |
| 3206 | } |
| 3207 | break; |
| 3208 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3209 | case DataType::Type::kInt16: |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3210 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3211 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3212 | case DataType::Type::kInt32: |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3213 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3214 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3215 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3216 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3217 | } else { |
| 3218 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 3219 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3220 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3221 | } |
| 3222 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3223 | case DataType::Type::kInt64: |
| 3224 | if (in.IsRegisterPair()) { |
| 3225 | __ movsxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 3226 | } else if (in.IsDoubleStackSlot()) { |
| 3227 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 3228 | } else { |
| 3229 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 3230 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3231 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
| 3232 | } |
| 3233 | break; |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3234 | |
| 3235 | default: |
| 3236 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3237 | << " to " << result_type; |
| 3238 | } |
| 3239 | break; |
| 3240 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3241 | case DataType::Type::kInt32: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3242 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3243 | case DataType::Type::kInt64: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3244 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3245 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3246 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3247 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3248 | } else { |
| 3249 | DCHECK(in.IsConstant()); |
| 3250 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 3251 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3252 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3253 | } |
| 3254 | break; |
| 3255 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3256 | case DataType::Type::kFloat32: { |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 3257 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 3258 | Register output = out.AsRegister<Register>(); |
| 3259 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3260 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 3261 | |
| 3262 | __ movl(output, Immediate(kPrimIntMax)); |
| 3263 | // temp = int-to-float(output) |
| 3264 | __ cvtsi2ss(temp, output); |
| 3265 | // if input >= temp goto done |
| 3266 | __ comiss(input, temp); |
| 3267 | __ j(kAboveEqual, &done); |
| 3268 | // if input == NaN goto nan |
| 3269 | __ j(kUnordered, &nan); |
| 3270 | // output = float-to-int-truncate(input) |
| 3271 | __ cvttss2si(output, input); |
| 3272 | __ jmp(&done); |
| 3273 | __ Bind(&nan); |
| 3274 | // output = 0 |
| 3275 | __ xorl(output, output); |
| 3276 | __ Bind(&done); |
| 3277 | break; |
| 3278 | } |
| 3279 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3280 | case DataType::Type::kFloat64: { |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3281 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 3282 | Register output = out.AsRegister<Register>(); |
| 3283 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3284 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3285 | |
| 3286 | __ movl(output, Immediate(kPrimIntMax)); |
| 3287 | // temp = int-to-double(output) |
| 3288 | __ cvtsi2sd(temp, output); |
| 3289 | // if input >= temp goto done |
| 3290 | __ comisd(input, temp); |
| 3291 | __ j(kAboveEqual, &done); |
| 3292 | // if input == NaN goto nan |
| 3293 | __ j(kUnordered, &nan); |
| 3294 | // output = double-to-int-truncate(input) |
| 3295 | __ cvttsd2si(output, input); |
| 3296 | __ jmp(&done); |
| 3297 | __ Bind(&nan); |
| 3298 | // output = 0 |
| 3299 | __ xorl(output, output); |
| 3300 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3301 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3302 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3303 | |
| 3304 | default: |
| 3305 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3306 | << " to " << result_type; |
| 3307 | } |
| 3308 | break; |
| 3309 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3310 | case DataType::Type::kInt64: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3311 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3312 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3313 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3314 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3315 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3316 | case DataType::Type::kInt16: |
| 3317 | case DataType::Type::kInt32: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3318 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 3319 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3320 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3321 | __ cdq(); |
| 3322 | break; |
| 3323 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3324 | case DataType::Type::kFloat32: |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3325 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3326 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3327 | break; |
| 3328 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3329 | case DataType::Type::kFloat64: |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3330 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3331 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3332 | break; |
| 3333 | |
| 3334 | default: |
| 3335 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3336 | << " to " << result_type; |
| 3337 | } |
| 3338 | break; |
| 3339 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3340 | case DataType::Type::kFloat32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3341 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3342 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3343 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3344 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3345 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3346 | case DataType::Type::kInt16: |
| 3347 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3348 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3349 | break; |
| 3350 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3351 | case DataType::Type::kInt64: { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3352 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3353 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3354 | // Create stack space for the call to |
| 3355 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 3356 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3357 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3358 | adjustment = DataType::Size(DataType::Type::kInt64); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 3359 | codegen_->IncreaseFrame(adjustment); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3360 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3361 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3362 | // Load the value to the FP stack, using temporaries if needed. |
| 3363 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 3364 | |
| 3365 | if (out.IsStackSlot()) { |
| 3366 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 3367 | } else { |
| 3368 | __ fstps(Address(ESP, 0)); |
| 3369 | Location stack_temp = Location::StackSlot(0); |
| 3370 | codegen_->Move32(out, stack_temp); |
| 3371 | } |
| 3372 | |
| 3373 | // Remove the temporary stack space we allocated. |
| 3374 | if (adjustment != 0) { |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 3375 | codegen_->DecreaseFrame(adjustment); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3376 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3377 | break; |
| 3378 | } |
| 3379 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3380 | case DataType::Type::kFloat64: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3381 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3382 | break; |
| 3383 | |
| 3384 | default: |
| 3385 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3386 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3387 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3388 | break; |
| 3389 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3390 | case DataType::Type::kFloat64: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3391 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3392 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3393 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3394 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3395 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3396 | case DataType::Type::kInt16: |
| 3397 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3398 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3399 | break; |
| 3400 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3401 | case DataType::Type::kInt64: { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3402 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3403 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3404 | // Create stack space for the call to |
| 3405 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 3406 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3407 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3408 | adjustment = DataType::Size(DataType::Type::kInt64); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 3409 | codegen_->IncreaseFrame(adjustment); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3410 | } |
| 3411 | |
| 3412 | // Load the value to the FP stack, using temporaries if needed. |
| 3413 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 3414 | |
| 3415 | if (out.IsDoubleStackSlot()) { |
| 3416 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 3417 | } else { |
| 3418 | __ fstpl(Address(ESP, 0)); |
| 3419 | Location stack_temp = Location::DoubleStackSlot(0); |
| 3420 | codegen_->Move64(out, stack_temp); |
| 3421 | } |
| 3422 | |
| 3423 | // Remove the temporary stack space we allocated. |
| 3424 | if (adjustment != 0) { |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 3425 | codegen_->DecreaseFrame(adjustment); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3426 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3427 | break; |
| 3428 | } |
| 3429 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3430 | case DataType::Type::kFloat32: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3431 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3432 | break; |
| 3433 | |
| 3434 | default: |
| 3435 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3436 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3437 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3438 | break; |
| 3439 | |
| 3440 | default: |
| 3441 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3442 | << " to " << result_type; |
| 3443 | } |
| 3444 | } |
| 3445 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3446 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3447 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3448 | new (GetGraph()->GetAllocator()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3449 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3450 | case DataType::Type::kInt32: { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3451 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3452 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 3453 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3454 | break; |
| 3455 | } |
| 3456 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3457 | case DataType::Type::kInt64: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3458 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3459 | locations->SetInAt(1, Location::Any()); |
| 3460 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3461 | break; |
| 3462 | } |
| 3463 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3464 | case DataType::Type::kFloat32: |
| 3465 | case DataType::Type::kFloat64: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3466 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3467 | if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3468 | DCHECK(add->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3469 | } else if (add->InputAt(1)->IsConstant()) { |
| 3470 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3471 | } else { |
| 3472 | locations->SetInAt(1, Location::Any()); |
| 3473 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3474 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3475 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3476 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3477 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3478 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3479 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 3480 | UNREACHABLE(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3481 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3482 | } |
| 3483 | |
| 3484 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 3485 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3486 | Location first = locations->InAt(0); |
| 3487 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3488 | Location out = locations->Out(); |
| 3489 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3490 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3491 | case DataType::Type::kInt32: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3492 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3493 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3494 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 3495 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 3496 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3497 | } else { |
| 3498 | __ leal(out.AsRegister<Register>(), Address( |
| 3499 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 3500 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3501 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3502 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3503 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3504 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 3505 | } else { |
| 3506 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 3507 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3508 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3509 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3510 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3511 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3512 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3513 | } |
| 3514 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3515 | case DataType::Type::kInt64: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3516 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3517 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3518 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3519 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3520 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 3521 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3522 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3523 | } else { |
| 3524 | DCHECK(second.IsConstant()) << second; |
| 3525 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3526 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 3527 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3528 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3529 | break; |
| 3530 | } |
| 3531 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3532 | case DataType::Type::kFloat32: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3533 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3534 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3535 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3536 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3537 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3538 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 3539 | codegen_->LiteralFloatAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3540 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3541 | const_area->GetBaseMethodAddress(), |
| 3542 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3543 | } else { |
| 3544 | DCHECK(second.IsStackSlot()); |
| 3545 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3546 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3547 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3548 | } |
| 3549 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3550 | case DataType::Type::kFloat64: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3551 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3552 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3553 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3554 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3555 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3556 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 3557 | codegen_->LiteralDoubleAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3558 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3559 | const_area->GetBaseMethodAddress(), |
| 3560 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3561 | } else { |
| 3562 | DCHECK(second.IsDoubleStackSlot()); |
| 3563 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3564 | } |
| 3565 | break; |
| 3566 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3567 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3568 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3569 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3570 | } |
| 3571 | } |
| 3572 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3573 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3574 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3575 | new (GetGraph()->GetAllocator()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3576 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3577 | case DataType::Type::kInt32: |
| 3578 | case DataType::Type::kInt64: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3579 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3580 | locations->SetInAt(1, Location::Any()); |
| 3581 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3582 | break; |
| 3583 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3584 | case DataType::Type::kFloat32: |
| 3585 | case DataType::Type::kFloat64: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3586 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3587 | if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3588 | DCHECK(sub->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3589 | } else if (sub->InputAt(1)->IsConstant()) { |
| 3590 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3591 | } else { |
| 3592 | locations->SetInAt(1, Location::Any()); |
| 3593 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3594 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3595 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3596 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3597 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3598 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3599 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3600 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3601 | } |
| 3602 | |
| 3603 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 3604 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3605 | Location first = locations->InAt(0); |
| 3606 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3607 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3608 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3609 | case DataType::Type::kInt32: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3610 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3611 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3612 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3613 | __ subl(first.AsRegister<Register>(), |
| 3614 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3615 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3616 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3617 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3618 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3619 | } |
| 3620 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3621 | case DataType::Type::kInt64: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3622 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3623 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3624 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3625 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3626 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3627 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 3628 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3629 | } else { |
| 3630 | DCHECK(second.IsConstant()) << second; |
| 3631 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3632 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 3633 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3634 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3635 | break; |
| 3636 | } |
| 3637 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3638 | case DataType::Type::kFloat32: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3639 | if (second.IsFpuRegister()) { |
| 3640 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3641 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3642 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3643 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3644 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3645 | codegen_->LiteralFloatAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3646 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3647 | const_area->GetBaseMethodAddress(), |
| 3648 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3649 | } else { |
| 3650 | DCHECK(second.IsStackSlot()); |
| 3651 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3652 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3653 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3654 | } |
| 3655 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3656 | case DataType::Type::kFloat64: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3657 | if (second.IsFpuRegister()) { |
| 3658 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3659 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3660 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3661 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3662 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3663 | codegen_->LiteralDoubleAddress( |
| 3664 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3665 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3666 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3667 | } else { |
| 3668 | DCHECK(second.IsDoubleStackSlot()); |
| 3669 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3670 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3671 | break; |
| 3672 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3673 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3674 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3675 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3676 | } |
| 3677 | } |
| 3678 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3679 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 3680 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3681 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3682 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3683 | case DataType::Type::kInt32: |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3684 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3685 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3686 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3687 | // Can use 3 operand multiply. |
| 3688 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3689 | } else { |
| 3690 | locations->SetOut(Location::SameAsFirstInput()); |
| 3691 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3692 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3693 | case DataType::Type::kInt64: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3694 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3695 | locations->SetInAt(1, Location::Any()); |
| 3696 | locations->SetOut(Location::SameAsFirstInput()); |
| 3697 | // Needed for imul on 32bits with 64bits output. |
| 3698 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 3699 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 3700 | break; |
| 3701 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3702 | case DataType::Type::kFloat32: |
| 3703 | case DataType::Type::kFloat64: { |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3704 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3705 | if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3706 | DCHECK(mul->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3707 | } else if (mul->InputAt(1)->IsConstant()) { |
| 3708 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3709 | } else { |
| 3710 | locations->SetInAt(1, Location::Any()); |
| 3711 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3712 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3713 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3714 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3715 | |
| 3716 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3717 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3718 | } |
| 3719 | } |
| 3720 | |
| 3721 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 3722 | LocationSummary* locations = mul->GetLocations(); |
| 3723 | Location first = locations->InAt(0); |
| 3724 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3725 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3726 | |
| 3727 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3728 | case DataType::Type::kInt32: |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3729 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3730 | // problems where the output may not be the same as the first operand. |
| 3731 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3732 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3733 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 3734 | } else if (second.IsRegister()) { |
| 3735 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3736 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3737 | } else { |
| 3738 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3739 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3740 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3741 | } |
| 3742 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3743 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3744 | case DataType::Type::kInt64: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3745 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 3746 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3747 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 3748 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3749 | |
| 3750 | DCHECK_EQ(EAX, eax); |
| 3751 | DCHECK_EQ(EDX, edx); |
| 3752 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3753 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3754 | // output: in1 |
| 3755 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3756 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3757 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3758 | if (second.IsConstant()) { |
| 3759 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3760 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3761 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3762 | int32_t low_value = Low32Bits(value); |
| 3763 | int32_t high_value = High32Bits(value); |
| 3764 | Immediate low(low_value); |
| 3765 | Immediate high(high_value); |
| 3766 | |
| 3767 | __ movl(eax, high); |
| 3768 | // eax <- in1.lo * in2.hi |
| 3769 | __ imull(eax, in1_lo); |
| 3770 | // in1.hi <- in1.hi * in2.lo |
| 3771 | __ imull(in1_hi, low); |
| 3772 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3773 | __ addl(in1_hi, eax); |
| 3774 | // move in2_lo to eax to prepare for double precision |
| 3775 | __ movl(eax, low); |
| 3776 | // edx:eax <- in1.lo * in2.lo |
| 3777 | __ mull(in1_lo); |
| 3778 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3779 | __ addl(in1_hi, edx); |
| 3780 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3781 | __ movl(in1_lo, eax); |
| 3782 | } else if (second.IsRegisterPair()) { |
| 3783 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3784 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3785 | |
| 3786 | __ movl(eax, in2_hi); |
| 3787 | // eax <- in1.lo * in2.hi |
| 3788 | __ imull(eax, in1_lo); |
| 3789 | // in1.hi <- in1.hi * in2.lo |
| 3790 | __ imull(in1_hi, in2_lo); |
| 3791 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3792 | __ addl(in1_hi, eax); |
| 3793 | // move in1_lo to eax to prepare for double precision |
| 3794 | __ movl(eax, in1_lo); |
| 3795 | // edx:eax <- in1.lo * in2.lo |
| 3796 | __ mull(in2_lo); |
| 3797 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3798 | __ addl(in1_hi, edx); |
| 3799 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3800 | __ movl(in1_lo, eax); |
| 3801 | } else { |
| 3802 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 3803 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 3804 | Address in2_lo(ESP, second.GetStackIndex()); |
| 3805 | |
| 3806 | __ movl(eax, in2_hi); |
| 3807 | // eax <- in1.lo * in2.hi |
| 3808 | __ imull(eax, in1_lo); |
| 3809 | // in1.hi <- in1.hi * in2.lo |
| 3810 | __ imull(in1_hi, in2_lo); |
| 3811 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3812 | __ addl(in1_hi, eax); |
| 3813 | // move in1_lo to eax to prepare for double precision |
| 3814 | __ movl(eax, in1_lo); |
| 3815 | // edx:eax <- in1.lo * in2.lo |
| 3816 | __ mull(in2_lo); |
| 3817 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3818 | __ addl(in1_hi, edx); |
| 3819 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3820 | __ movl(in1_lo, eax); |
| 3821 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3822 | |
| 3823 | break; |
| 3824 | } |
| 3825 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3826 | case DataType::Type::kFloat32: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3827 | DCHECK(first.Equals(locations->Out())); |
| 3828 | if (second.IsFpuRegister()) { |
| 3829 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3830 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3831 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3832 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3833 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3834 | codegen_->LiteralFloatAddress( |
| 3835 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3836 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3837 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3838 | } else { |
| 3839 | DCHECK(second.IsStackSlot()); |
| 3840 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3841 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3842 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3843 | } |
| 3844 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3845 | case DataType::Type::kFloat64: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3846 | DCHECK(first.Equals(locations->Out())); |
| 3847 | if (second.IsFpuRegister()) { |
| 3848 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3849 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3850 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3851 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3852 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3853 | codegen_->LiteralDoubleAddress( |
| 3854 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3855 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3856 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3857 | } else { |
| 3858 | DCHECK(second.IsDoubleStackSlot()); |
| 3859 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3860 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3861 | break; |
| 3862 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3863 | |
| 3864 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3865 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3866 | } |
| 3867 | } |
| 3868 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3869 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 3870 | uint32_t temp_offset, |
| 3871 | uint32_t stack_adjustment, |
| 3872 | bool is_fp, |
| 3873 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3874 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3875 | DCHECK(!is_wide); |
| 3876 | if (is_fp) { |
| 3877 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3878 | } else { |
| 3879 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3880 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3881 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3882 | DCHECK(is_wide); |
| 3883 | if (is_fp) { |
| 3884 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3885 | } else { |
| 3886 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3887 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3888 | } else { |
| 3889 | // 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] | 3890 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3891 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3892 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3893 | if (is_fp) { |
| 3894 | __ flds(Address(ESP, temp_offset)); |
| 3895 | } else { |
| 3896 | __ filds(Address(ESP, temp_offset)); |
| 3897 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3898 | } else { |
| 3899 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3900 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3901 | if (is_fp) { |
| 3902 | __ fldl(Address(ESP, temp_offset)); |
| 3903 | } else { |
| 3904 | __ fildl(Address(ESP, temp_offset)); |
| 3905 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3906 | } |
| 3907 | } |
| 3908 | } |
| 3909 | |
| 3910 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3911 | DataType::Type type = rem->GetResultType(); |
| 3912 | bool is_float = type == DataType::Type::kFloat32; |
| 3913 | size_t elem_size = DataType::Size(type); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3914 | LocationSummary* locations = rem->GetLocations(); |
| 3915 | Location first = locations->InAt(0); |
| 3916 | Location second = locations->InAt(1); |
| 3917 | Location out = locations->Out(); |
| 3918 | |
| 3919 | // Create stack space for 2 elements. |
| 3920 | // TODO: enhance register allocator to ask for stack temporaries. |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 3921 | codegen_->IncreaseFrame(2 * elem_size); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3922 | |
| 3923 | // 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] | 3924 | const bool is_wide = !is_float; |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3925 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp= */ true, is_wide); |
| 3926 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp= */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3927 | |
| 3928 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3929 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3930 | __ Bind(&retry); |
| 3931 | __ fprem(); |
| 3932 | |
| 3933 | // Move FP status to AX. |
| 3934 | __ fstsw(); |
| 3935 | |
| 3936 | // And see if the argument reduction is complete. This is signaled by the |
| 3937 | // C2 FPU flag bit set to 0. |
| 3938 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 3939 | __ j(kNotEqual, &retry); |
| 3940 | |
| 3941 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3942 | // Store FP top of stack to real stack. |
| 3943 | if (is_float) { |
| 3944 | __ fsts(Address(ESP, 0)); |
| 3945 | } else { |
| 3946 | __ fstl(Address(ESP, 0)); |
| 3947 | } |
| 3948 | |
| 3949 | // Pop the 2 items from the FP stack. |
| 3950 | __ fucompp(); |
| 3951 | |
| 3952 | // Load the value from the stack into an XMM register. |
| 3953 | DCHECK(out.IsFpuRegister()) << out; |
| 3954 | if (is_float) { |
| 3955 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3956 | } else { |
| 3957 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3958 | } |
| 3959 | |
| 3960 | // And remove the temporary stack space we allocated. |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 3961 | codegen_->DecreaseFrame(2 * elem_size); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3962 | } |
| 3963 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3964 | |
| 3965 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3966 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3967 | |
| 3968 | LocationSummary* locations = instruction->GetLocations(); |
| 3969 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3970 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3971 | |
| 3972 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3973 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3974 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3975 | |
| 3976 | DCHECK(imm == 1 || imm == -1); |
| 3977 | |
| 3978 | if (instruction->IsRem()) { |
| 3979 | __ xorl(out_register, out_register); |
| 3980 | } else { |
| 3981 | __ movl(out_register, input_register); |
| 3982 | if (imm == -1) { |
| 3983 | __ negl(out_register); |
| 3984 | } |
| 3985 | } |
| 3986 | } |
| 3987 | |
Shalini Salomi Bodapati | a66784b | 2018-11-06 13:05:44 +0530 | [diff] [blame] | 3988 | void InstructionCodeGeneratorX86::RemByPowerOfTwo(HRem* instruction) { |
| 3989 | LocationSummary* locations = instruction->GetLocations(); |
| 3990 | Location second = locations->InAt(1); |
| 3991 | |
| 3992 | Register out = locations->Out().AsRegister<Register>(); |
| 3993 | Register numerator = locations->InAt(0).AsRegister<Register>(); |
| 3994 | |
| 3995 | int32_t imm = Int64FromConstant(second.GetConstant()); |
| 3996 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3997 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
| 3998 | |
| 3999 | Register tmp = locations->GetTemp(0).AsRegister<Register>(); |
| 4000 | NearLabel done; |
| 4001 | __ movl(out, numerator); |
| 4002 | __ andl(out, Immediate(abs_imm-1)); |
| 4003 | __ j(Condition::kZero, &done); |
| 4004 | __ leal(tmp, Address(out, static_cast<int32_t>(~(abs_imm-1)))); |
| 4005 | __ testl(numerator, numerator); |
| 4006 | __ cmovl(Condition::kLess, out, tmp); |
| 4007 | __ Bind(&done); |
| 4008 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4009 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 4010 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4011 | LocationSummary* locations = instruction->GetLocations(); |
| 4012 | |
| 4013 | Register out_register = locations->Out().AsRegister<Register>(); |
| 4014 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 4015 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4016 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 4017 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4018 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4019 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 4020 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4021 | __ leal(num, Address(input_register, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4022 | __ testl(input_register, input_register); |
| 4023 | __ cmovl(kGreaterEqual, num, input_register); |
| 4024 | int shift = CTZ(imm); |
| 4025 | __ sarl(num, Immediate(shift)); |
| 4026 | |
| 4027 | if (imm < 0) { |
| 4028 | __ negl(num); |
| 4029 | } |
| 4030 | |
| 4031 | __ movl(out_register, num); |
| 4032 | } |
| 4033 | |
| 4034 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 4035 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 4036 | |
| 4037 | LocationSummary* locations = instruction->GetLocations(); |
| 4038 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 4039 | |
| 4040 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 4041 | Register out = locations->Out().AsRegister<Register>(); |
| 4042 | Register num; |
| 4043 | Register edx; |
| 4044 | |
| 4045 | if (instruction->IsDiv()) { |
| 4046 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 4047 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 4048 | } else { |
| 4049 | edx = locations->Out().AsRegister<Register>(); |
| 4050 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 4051 | } |
| 4052 | |
| 4053 | DCHECK_EQ(EAX, eax); |
| 4054 | DCHECK_EQ(EDX, edx); |
| 4055 | if (instruction->IsDiv()) { |
| 4056 | DCHECK_EQ(EAX, out); |
| 4057 | } else { |
| 4058 | DCHECK_EQ(EDX, out); |
| 4059 | } |
| 4060 | |
| 4061 | int64_t magic; |
| 4062 | int shift; |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4063 | CalculateMagicAndShiftForDivRem(imm, /* is_long= */ false, &magic, &shift); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4064 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4065 | // Save the numerator. |
| 4066 | __ movl(num, eax); |
| 4067 | |
| 4068 | // EAX = magic |
| 4069 | __ movl(eax, Immediate(magic)); |
| 4070 | |
| 4071 | // EDX:EAX = magic * numerator |
| 4072 | __ imull(num); |
| 4073 | |
| 4074 | if (imm > 0 && magic < 0) { |
| 4075 | // EDX += num |
| 4076 | __ addl(edx, num); |
| 4077 | } else if (imm < 0 && magic > 0) { |
| 4078 | __ subl(edx, num); |
| 4079 | } |
| 4080 | |
| 4081 | // Shift if needed. |
| 4082 | if (shift != 0) { |
| 4083 | __ sarl(edx, Immediate(shift)); |
| 4084 | } |
| 4085 | |
| 4086 | // EDX += 1 if EDX < 0 |
| 4087 | __ movl(eax, edx); |
| 4088 | __ shrl(edx, Immediate(31)); |
| 4089 | __ addl(edx, eax); |
| 4090 | |
| 4091 | if (instruction->IsRem()) { |
| 4092 | __ movl(eax, num); |
| 4093 | __ imull(edx, Immediate(imm)); |
| 4094 | __ subl(eax, edx); |
| 4095 | __ movl(edx, eax); |
| 4096 | } else { |
| 4097 | __ movl(eax, edx); |
| 4098 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4099 | } |
| 4100 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4101 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 4102 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 4103 | |
| 4104 | LocationSummary* locations = instruction->GetLocations(); |
| 4105 | Location out = locations->Out(); |
| 4106 | Location first = locations->InAt(0); |
| 4107 | Location second = locations->InAt(1); |
| 4108 | bool is_div = instruction->IsDiv(); |
| 4109 | |
| 4110 | switch (instruction->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4111 | case DataType::Type::kInt32: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4112 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 4113 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4114 | |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 4115 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 4116 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4117 | |
| 4118 | if (imm == 0) { |
| 4119 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 4120 | } else if (imm == 1 || imm == -1) { |
| 4121 | DivRemOneOrMinusOne(instruction); |
Shalini Salomi Bodapati | a66784b | 2018-11-06 13:05:44 +0530 | [diff] [blame] | 4122 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 4123 | if (is_div) { |
| 4124 | DivByPowerOfTwo(instruction->AsDiv()); |
| 4125 | } else { |
| 4126 | RemByPowerOfTwo(instruction->AsRem()); |
| 4127 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4128 | } else { |
| 4129 | DCHECK(imm <= -2 || imm >= 2); |
| 4130 | GenerateDivRemWithAnyConstant(instruction); |
| 4131 | } |
| 4132 | } else { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4133 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) DivRemMinusOneSlowPathX86( |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 4134 | instruction, out.AsRegister<Register>(), is_div); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4135 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4136 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4137 | Register second_reg = second.AsRegister<Register>(); |
| 4138 | // 0x80000000/-1 triggers an arithmetic exception! |
| 4139 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 4140 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4141 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4142 | __ cmpl(second_reg, Immediate(-1)); |
| 4143 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4144 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4145 | // edx:eax <- sign-extended of eax |
| 4146 | __ cdq(); |
| 4147 | // eax = quotient, edx = remainder |
| 4148 | __ idivl(second_reg); |
| 4149 | __ Bind(slow_path->GetExitLabel()); |
| 4150 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4151 | break; |
| 4152 | } |
| 4153 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4154 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4155 | InvokeRuntimeCallingConvention calling_convention; |
| 4156 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 4157 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 4158 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 4159 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 4160 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 4161 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 4162 | |
| 4163 | if (is_div) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 4164 | codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4165 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4166 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 4167 | codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4168 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4169 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4170 | break; |
| 4171 | } |
| 4172 | |
| 4173 | default: |
| 4174 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 4175 | } |
| 4176 | } |
| 4177 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4178 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4179 | LocationSummary::CallKind call_kind = (div->GetResultType() == DataType::Type::kInt64) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4180 | ? LocationSummary::kCallOnMainOnly |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4181 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4182 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(div, call_kind); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4183 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4184 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4185 | case DataType::Type::kInt32: { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4186 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4187 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4188 | locations->SetOut(Location::SameAsFirstInput()); |
| 4189 | // Intel uses edx:eax as the dividend. |
| 4190 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4191 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 4192 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 4193 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 4194 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4195 | locations->AddTemp(Location::RequiresRegister()); |
| 4196 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4197 | break; |
| 4198 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4199 | case DataType::Type::kInt64: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4200 | InvokeRuntimeCallingConvention calling_convention; |
| 4201 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 4202 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4203 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 4204 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4205 | // Runtime helper puts the result in EAX, EDX. |
| 4206 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4207 | break; |
| 4208 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4209 | case DataType::Type::kFloat32: |
| 4210 | case DataType::Type::kFloat64: { |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4211 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 4212 | if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4213 | DCHECK(div->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 4214 | } else if (div->InputAt(1)->IsConstant()) { |
| 4215 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 4216 | } else { |
| 4217 | locations->SetInAt(1, Location::Any()); |
| 4218 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4219 | locations->SetOut(Location::SameAsFirstInput()); |
| 4220 | break; |
| 4221 | } |
| 4222 | |
| 4223 | default: |
| 4224 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4225 | } |
| 4226 | } |
| 4227 | |
| 4228 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 4229 | LocationSummary* locations = div->GetLocations(); |
| 4230 | Location first = locations->InAt(0); |
| 4231 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4232 | |
| 4233 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4234 | case DataType::Type::kInt32: |
| 4235 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4236 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4237 | break; |
| 4238 | } |
| 4239 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4240 | case DataType::Type::kFloat32: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 4241 | if (second.IsFpuRegister()) { |
| 4242 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 4243 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4244 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 4245 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 4246 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 4247 | codegen_->LiteralFloatAddress( |
| 4248 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4249 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 4250 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 4251 | } else { |
| 4252 | DCHECK(second.IsStackSlot()); |
| 4253 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 4254 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4255 | break; |
| 4256 | } |
| 4257 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4258 | case DataType::Type::kFloat64: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 4259 | if (second.IsFpuRegister()) { |
| 4260 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 4261 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4262 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 4263 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 4264 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 4265 | codegen_->LiteralDoubleAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4266 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 4267 | const_area->GetBaseMethodAddress(), |
| 4268 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 4269 | } else { |
| 4270 | DCHECK(second.IsDoubleStackSlot()); |
| 4271 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 4272 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4273 | break; |
| 4274 | } |
| 4275 | |
| 4276 | default: |
| 4277 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4278 | } |
| 4279 | } |
| 4280 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4281 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4282 | DataType::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4283 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4284 | LocationSummary::CallKind call_kind = (rem->GetResultType() == DataType::Type::kInt64) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4285 | ? LocationSummary::kCallOnMainOnly |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4286 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4287 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4288 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4289 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4290 | case DataType::Type::kInt32: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4291 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4292 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4293 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4294 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 4295 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 4296 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 4297 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4298 | locations->AddTemp(Location::RequiresRegister()); |
| 4299 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4300 | break; |
| 4301 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4302 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4303 | InvokeRuntimeCallingConvention calling_convention; |
| 4304 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 4305 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4306 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 4307 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4308 | // Runtime helper puts the result in EAX, EDX. |
| 4309 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 4310 | break; |
| 4311 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4312 | case DataType::Type::kFloat64: |
| 4313 | case DataType::Type::kFloat32: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 4314 | locations->SetInAt(0, Location::Any()); |
| 4315 | locations->SetInAt(1, Location::Any()); |
| 4316 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4317 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4318 | break; |
| 4319 | } |
| 4320 | |
| 4321 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4322 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4323 | } |
| 4324 | } |
| 4325 | |
| 4326 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4327 | DataType::Type type = rem->GetResultType(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4328 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4329 | case DataType::Type::kInt32: |
| 4330 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4331 | GenerateDivRemIntegral(rem); |
| 4332 | break; |
| 4333 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4334 | case DataType::Type::kFloat32: |
| 4335 | case DataType::Type::kFloat64: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 4336 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4337 | break; |
| 4338 | } |
| 4339 | default: |
| 4340 | LOG(FATAL) << "Unexpected rem type " << type; |
| 4341 | } |
| 4342 | } |
| 4343 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4344 | static void CreateMinMaxLocations(ArenaAllocator* allocator, HBinaryOperation* minmax) { |
| 4345 | LocationSummary* locations = new (allocator) LocationSummary(minmax); |
| 4346 | switch (minmax->GetResultType()) { |
| 4347 | case DataType::Type::kInt32: |
| 4348 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4349 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4350 | locations->SetOut(Location::SameAsFirstInput()); |
| 4351 | break; |
| 4352 | case DataType::Type::kInt64: |
| 4353 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4354 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4355 | locations->SetOut(Location::SameAsFirstInput()); |
| 4356 | // Register to use to perform a long subtract to set cc. |
| 4357 | locations->AddTemp(Location::RequiresRegister()); |
| 4358 | break; |
| 4359 | case DataType::Type::kFloat32: |
| 4360 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4361 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4362 | locations->SetOut(Location::SameAsFirstInput()); |
| 4363 | locations->AddTemp(Location::RequiresRegister()); |
| 4364 | break; |
| 4365 | case DataType::Type::kFloat64: |
| 4366 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4367 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4368 | locations->SetOut(Location::SameAsFirstInput()); |
| 4369 | break; |
| 4370 | default: |
| 4371 | LOG(FATAL) << "Unexpected type for HMinMax " << minmax->GetResultType(); |
| 4372 | } |
| 4373 | } |
| 4374 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4375 | void InstructionCodeGeneratorX86::GenerateMinMaxInt(LocationSummary* locations, |
| 4376 | bool is_min, |
| 4377 | DataType::Type type) { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4378 | Location op1_loc = locations->InAt(0); |
| 4379 | Location op2_loc = locations->InAt(1); |
| 4380 | |
| 4381 | // Shortcut for same input locations. |
| 4382 | if (op1_loc.Equals(op2_loc)) { |
| 4383 | // Can return immediately, as op1_loc == out_loc. |
| 4384 | // Note: if we ever support separate registers, e.g., output into memory, we need to check for |
| 4385 | // a copy here. |
| 4386 | DCHECK(locations->Out().Equals(op1_loc)); |
| 4387 | return; |
| 4388 | } |
| 4389 | |
| 4390 | if (type == DataType::Type::kInt64) { |
| 4391 | // Need to perform a subtract to get the sign right. |
| 4392 | // op1 is already in the same location as the output. |
| 4393 | Location output = locations->Out(); |
| 4394 | Register output_lo = output.AsRegisterPairLow<Register>(); |
| 4395 | Register output_hi = output.AsRegisterPairHigh<Register>(); |
| 4396 | |
| 4397 | Register op2_lo = op2_loc.AsRegisterPairLow<Register>(); |
| 4398 | Register op2_hi = op2_loc.AsRegisterPairHigh<Register>(); |
| 4399 | |
| 4400 | // The comparison is performed by subtracting the second operand from |
| 4401 | // the first operand and then setting the status flags in the same |
| 4402 | // manner as the SUB instruction." |
| 4403 | __ cmpl(output_lo, op2_lo); |
| 4404 | |
| 4405 | // Now use a temp and the borrow to finish the subtraction of op2_hi. |
| 4406 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4407 | __ movl(temp, output_hi); |
| 4408 | __ sbbl(temp, op2_hi); |
| 4409 | |
| 4410 | // Now the condition code is correct. |
| 4411 | Condition cond = is_min ? Condition::kGreaterEqual : Condition::kLess; |
| 4412 | __ cmovl(cond, output_lo, op2_lo); |
| 4413 | __ cmovl(cond, output_hi, op2_hi); |
| 4414 | } else { |
| 4415 | DCHECK_EQ(type, DataType::Type::kInt32); |
| 4416 | Register out = locations->Out().AsRegister<Register>(); |
| 4417 | Register op2 = op2_loc.AsRegister<Register>(); |
| 4418 | |
| 4419 | // (out := op1) |
| 4420 | // out <=? op2 |
| 4421 | // if out is min jmp done |
| 4422 | // out := op2 |
| 4423 | // done: |
| 4424 | |
| 4425 | __ cmpl(out, op2); |
| 4426 | Condition cond = is_min ? Condition::kGreater : Condition::kLess; |
| 4427 | __ cmovl(cond, out, op2); |
| 4428 | } |
| 4429 | } |
| 4430 | |
| 4431 | void InstructionCodeGeneratorX86::GenerateMinMaxFP(LocationSummary* locations, |
| 4432 | bool is_min, |
| 4433 | DataType::Type type) { |
| 4434 | Location op1_loc = locations->InAt(0); |
| 4435 | Location op2_loc = locations->InAt(1); |
| 4436 | Location out_loc = locations->Out(); |
| 4437 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
| 4438 | |
| 4439 | // Shortcut for same input locations. |
| 4440 | if (op1_loc.Equals(op2_loc)) { |
| 4441 | DCHECK(out_loc.Equals(op1_loc)); |
| 4442 | return; |
| 4443 | } |
| 4444 | |
| 4445 | // (out := op1) |
| 4446 | // out <=? op2 |
| 4447 | // if Nan jmp Nan_label |
| 4448 | // if out is min jmp done |
| 4449 | // if op2 is min jmp op2_label |
| 4450 | // handle -0/+0 |
| 4451 | // jmp done |
| 4452 | // Nan_label: |
| 4453 | // out := NaN |
| 4454 | // op2_label: |
| 4455 | // out := op2 |
| 4456 | // done: |
| 4457 | // |
| 4458 | // This removes one jmp, but needs to copy one input (op1) to out. |
| 4459 | // |
| 4460 | // TODO: This is straight from Quick (except literal pool). Make NaN an out-of-line slowpath? |
| 4461 | |
| 4462 | XmmRegister op2 = op2_loc.AsFpuRegister<XmmRegister>(); |
| 4463 | |
| 4464 | NearLabel nan, done, op2_label; |
| 4465 | if (type == DataType::Type::kFloat64) { |
| 4466 | __ ucomisd(out, op2); |
| 4467 | } else { |
| 4468 | DCHECK_EQ(type, DataType::Type::kFloat32); |
| 4469 | __ ucomiss(out, op2); |
| 4470 | } |
| 4471 | |
| 4472 | __ j(Condition::kParityEven, &nan); |
| 4473 | |
| 4474 | __ j(is_min ? Condition::kAbove : Condition::kBelow, &op2_label); |
| 4475 | __ j(is_min ? Condition::kBelow : Condition::kAbove, &done); |
| 4476 | |
| 4477 | // Handle 0.0/-0.0. |
| 4478 | if (is_min) { |
| 4479 | if (type == DataType::Type::kFloat64) { |
| 4480 | __ orpd(out, op2); |
| 4481 | } else { |
| 4482 | __ orps(out, op2); |
| 4483 | } |
| 4484 | } else { |
| 4485 | if (type == DataType::Type::kFloat64) { |
| 4486 | __ andpd(out, op2); |
| 4487 | } else { |
| 4488 | __ andps(out, op2); |
| 4489 | } |
| 4490 | } |
| 4491 | __ jmp(&done); |
| 4492 | |
| 4493 | // NaN handling. |
| 4494 | __ Bind(&nan); |
| 4495 | if (type == DataType::Type::kFloat64) { |
| 4496 | // TODO: Use a constant from the constant table (requires extra input). |
| 4497 | __ LoadLongConstant(out, kDoubleNaN); |
| 4498 | } else { |
| 4499 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 4500 | __ movl(constant, Immediate(kFloatNaN)); |
| 4501 | __ movd(out, constant); |
| 4502 | } |
| 4503 | __ jmp(&done); |
| 4504 | |
| 4505 | // out := op2; |
| 4506 | __ Bind(&op2_label); |
| 4507 | if (type == DataType::Type::kFloat64) { |
| 4508 | __ movsd(out, op2); |
| 4509 | } else { |
| 4510 | __ movss(out, op2); |
| 4511 | } |
| 4512 | |
| 4513 | // Done. |
| 4514 | __ Bind(&done); |
| 4515 | } |
| 4516 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4517 | void InstructionCodeGeneratorX86::GenerateMinMax(HBinaryOperation* minmax, bool is_min) { |
| 4518 | DataType::Type type = minmax->GetResultType(); |
| 4519 | switch (type) { |
| 4520 | case DataType::Type::kInt32: |
| 4521 | case DataType::Type::kInt64: |
| 4522 | GenerateMinMaxInt(minmax->GetLocations(), is_min, type); |
| 4523 | break; |
| 4524 | case DataType::Type::kFloat32: |
| 4525 | case DataType::Type::kFloat64: |
| 4526 | GenerateMinMaxFP(minmax->GetLocations(), is_min, type); |
| 4527 | break; |
| 4528 | default: |
| 4529 | LOG(FATAL) << "Unexpected type for HMinMax " << type; |
| 4530 | } |
| 4531 | } |
| 4532 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4533 | void LocationsBuilderX86::VisitMin(HMin* min) { |
| 4534 | CreateMinMaxLocations(GetGraph()->GetAllocator(), min); |
| 4535 | } |
| 4536 | |
| 4537 | void InstructionCodeGeneratorX86::VisitMin(HMin* min) { |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4538 | GenerateMinMax(min, /*is_min*/ true); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4539 | } |
| 4540 | |
| 4541 | void LocationsBuilderX86::VisitMax(HMax* max) { |
| 4542 | CreateMinMaxLocations(GetGraph()->GetAllocator(), max); |
| 4543 | } |
| 4544 | |
| 4545 | void InstructionCodeGeneratorX86::VisitMax(HMax* max) { |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4546 | GenerateMinMax(max, /*is_min*/ false); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4547 | } |
| 4548 | |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 4549 | void LocationsBuilderX86::VisitAbs(HAbs* abs) { |
| 4550 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 4551 | switch (abs->GetResultType()) { |
| 4552 | case DataType::Type::kInt32: |
| 4553 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 4554 | locations->SetOut(Location::SameAsFirstInput()); |
| 4555 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 4556 | break; |
| 4557 | case DataType::Type::kInt64: |
| 4558 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4559 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4560 | locations->AddTemp(Location::RequiresRegister()); |
| 4561 | break; |
| 4562 | case DataType::Type::kFloat32: |
| 4563 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4564 | locations->SetOut(Location::SameAsFirstInput()); |
| 4565 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4566 | locations->AddTemp(Location::RequiresRegister()); |
| 4567 | break; |
| 4568 | case DataType::Type::kFloat64: |
| 4569 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4570 | locations->SetOut(Location::SameAsFirstInput()); |
| 4571 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4572 | break; |
| 4573 | default: |
| 4574 | LOG(FATAL) << "Unexpected type for HAbs " << abs->GetResultType(); |
| 4575 | } |
| 4576 | } |
| 4577 | |
| 4578 | void InstructionCodeGeneratorX86::VisitAbs(HAbs* abs) { |
| 4579 | LocationSummary* locations = abs->GetLocations(); |
| 4580 | switch (abs->GetResultType()) { |
| 4581 | case DataType::Type::kInt32: { |
| 4582 | Register out = locations->Out().AsRegister<Register>(); |
| 4583 | DCHECK_EQ(out, EAX); |
| 4584 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4585 | DCHECK_EQ(temp, EDX); |
| 4586 | // Sign extend EAX into EDX. |
| 4587 | __ cdq(); |
| 4588 | // XOR EAX with sign. |
| 4589 | __ xorl(EAX, EDX); |
| 4590 | // Subtract out sign to correct. |
| 4591 | __ subl(EAX, EDX); |
| 4592 | // The result is in EAX. |
| 4593 | break; |
| 4594 | } |
| 4595 | case DataType::Type::kInt64: { |
| 4596 | Location input = locations->InAt(0); |
| 4597 | Register input_lo = input.AsRegisterPairLow<Register>(); |
| 4598 | Register input_hi = input.AsRegisterPairHigh<Register>(); |
| 4599 | Location output = locations->Out(); |
| 4600 | Register output_lo = output.AsRegisterPairLow<Register>(); |
| 4601 | Register output_hi = output.AsRegisterPairHigh<Register>(); |
| 4602 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4603 | // Compute the sign into the temporary. |
| 4604 | __ movl(temp, input_hi); |
| 4605 | __ sarl(temp, Immediate(31)); |
| 4606 | // Store the sign into the output. |
| 4607 | __ movl(output_lo, temp); |
| 4608 | __ movl(output_hi, temp); |
| 4609 | // XOR the input to the output. |
| 4610 | __ xorl(output_lo, input_lo); |
| 4611 | __ xorl(output_hi, input_hi); |
| 4612 | // Subtract the sign. |
| 4613 | __ subl(output_lo, temp); |
| 4614 | __ sbbl(output_hi, temp); |
| 4615 | break; |
| 4616 | } |
| 4617 | case DataType::Type::kFloat32: { |
| 4618 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4619 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4620 | Register constant = locations->GetTemp(1).AsRegister<Register>(); |
| 4621 | __ movl(constant, Immediate(INT32_C(0x7FFFFFFF))); |
| 4622 | __ movd(temp, constant); |
| 4623 | __ andps(out, temp); |
| 4624 | break; |
| 4625 | } |
| 4626 | case DataType::Type::kFloat64: { |
| 4627 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4628 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4629 | // TODO: Use a constant from the constant table (requires extra input). |
| 4630 | __ LoadLongConstant(temp, INT64_C(0x7FFFFFFFFFFFFFFF)); |
| 4631 | __ andpd(out, temp); |
| 4632 | break; |
| 4633 | } |
| 4634 | default: |
| 4635 | LOG(FATAL) << "Unexpected type for HAbs " << abs->GetResultType(); |
| 4636 | } |
| 4637 | } |
| 4638 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4639 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4640 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4641 | switch (instruction->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4642 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4643 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4644 | case DataType::Type::kInt8: |
| 4645 | case DataType::Type::kUint16: |
| 4646 | case DataType::Type::kInt16: |
| 4647 | case DataType::Type::kInt32: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4648 | locations->SetInAt(0, Location::Any()); |
| 4649 | break; |
| 4650 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4651 | case DataType::Type::kInt64: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4652 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 4653 | if (!instruction->IsConstant()) { |
| 4654 | locations->AddTemp(Location::RequiresRegister()); |
| 4655 | } |
| 4656 | break; |
| 4657 | } |
| 4658 | default: |
| 4659 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 4660 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4661 | } |
| 4662 | |
| 4663 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4664 | SlowPathCode* slow_path = |
| 4665 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathX86(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4666 | codegen_->AddSlowPath(slow_path); |
| 4667 | |
| 4668 | LocationSummary* locations = instruction->GetLocations(); |
| 4669 | Location value = locations->InAt(0); |
| 4670 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4671 | switch (instruction->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4672 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4673 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4674 | case DataType::Type::kInt8: |
| 4675 | case DataType::Type::kUint16: |
| 4676 | case DataType::Type::kInt16: |
| 4677 | case DataType::Type::kInt32: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4678 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4679 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4680 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4681 | } else if (value.IsStackSlot()) { |
| 4682 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 4683 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4684 | } else { |
| 4685 | DCHECK(value.IsConstant()) << value; |
| 4686 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4687 | __ jmp(slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4688 | } |
| 4689 | } |
| 4690 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4691 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4692 | case DataType::Type::kInt64: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4693 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4694 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4695 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 4696 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 4697 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4698 | } else { |
| 4699 | DCHECK(value.IsConstant()) << value; |
| 4700 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 4701 | __ jmp(slow_path->GetEntryLabel()); |
| 4702 | } |
| 4703 | } |
| 4704 | break; |
| 4705 | } |
| 4706 | default: |
| 4707 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4708 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4709 | } |
| 4710 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4711 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 4712 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4713 | |
| 4714 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4715 | new (GetGraph()->GetAllocator()) LocationSummary(op, LocationSummary::kNoCall); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4716 | |
| 4717 | switch (op->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4718 | case DataType::Type::kInt32: |
| 4719 | case DataType::Type::kInt64: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4720 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4721 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4722 | // The shift count needs to be in CL or a constant. |
| 4723 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4724 | locations->SetOut(Location::SameAsFirstInput()); |
| 4725 | break; |
| 4726 | } |
| 4727 | default: |
| 4728 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 4729 | } |
| 4730 | } |
| 4731 | |
| 4732 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 4733 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4734 | |
| 4735 | LocationSummary* locations = op->GetLocations(); |
| 4736 | Location first = locations->InAt(0); |
| 4737 | Location second = locations->InAt(1); |
| 4738 | DCHECK(first.Equals(locations->Out())); |
| 4739 | |
| 4740 | switch (op->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4741 | case DataType::Type::kInt32: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4742 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4743 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4744 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4745 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4746 | DCHECK_EQ(ECX, second_reg); |
| 4747 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4748 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4749 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4750 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4751 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4752 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4753 | } |
| 4754 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4755 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4756 | if (shift == 0) { |
| 4757 | return; |
| 4758 | } |
| 4759 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4760 | if (op->IsShl()) { |
| 4761 | __ shll(first_reg, imm); |
| 4762 | } else if (op->IsShr()) { |
| 4763 | __ sarl(first_reg, imm); |
| 4764 | } else { |
| 4765 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4766 | } |
| 4767 | } |
| 4768 | break; |
| 4769 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4770 | case DataType::Type::kInt64: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4771 | if (second.IsRegister()) { |
| 4772 | Register second_reg = second.AsRegister<Register>(); |
| 4773 | DCHECK_EQ(ECX, second_reg); |
| 4774 | if (op->IsShl()) { |
| 4775 | GenerateShlLong(first, second_reg); |
| 4776 | } else if (op->IsShr()) { |
| 4777 | GenerateShrLong(first, second_reg); |
| 4778 | } else { |
| 4779 | GenerateUShrLong(first, second_reg); |
| 4780 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4781 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4782 | // Shift by a constant. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4783 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4784 | // Nothing to do if the shift is 0, as the input is already the output. |
| 4785 | if (shift != 0) { |
| 4786 | if (op->IsShl()) { |
| 4787 | GenerateShlLong(first, shift); |
| 4788 | } else if (op->IsShr()) { |
| 4789 | GenerateShrLong(first, shift); |
| 4790 | } else { |
| 4791 | GenerateUShrLong(first, shift); |
| 4792 | } |
| 4793 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4794 | } |
| 4795 | break; |
| 4796 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4797 | default: |
| 4798 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 4799 | } |
| 4800 | } |
| 4801 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4802 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 4803 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4804 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 4805 | if (shift == 1) { |
| 4806 | // This is just an addition. |
| 4807 | __ addl(low, low); |
| 4808 | __ adcl(high, high); |
| 4809 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4810 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 4811 | codegen_->EmitParallelMoves( |
| 4812 | loc.ToLow(), |
| 4813 | loc.ToHigh(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4814 | DataType::Type::kInt32, |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4815 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 4816 | loc.ToLow(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4817 | DataType::Type::kInt32); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4818 | } else if (shift > 32) { |
| 4819 | // Low part becomes 0. High part is low part << (shift-32). |
| 4820 | __ movl(high, low); |
| 4821 | __ shll(high, Immediate(shift - 32)); |
| 4822 | __ xorl(low, low); |
| 4823 | } else { |
| 4824 | // Between 1 and 31. |
| 4825 | __ shld(high, low, Immediate(shift)); |
| 4826 | __ shll(low, Immediate(shift)); |
| 4827 | } |
| 4828 | } |
| 4829 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4830 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4831 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4832 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 4833 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 4834 | __ testl(shifter, Immediate(32)); |
| 4835 | __ j(kEqual, &done); |
| 4836 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 4837 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 4838 | __ Bind(&done); |
| 4839 | } |
| 4840 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4841 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 4842 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4843 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 4844 | if (shift == 32) { |
| 4845 | // Need to copy the sign. |
| 4846 | DCHECK_NE(low, high); |
| 4847 | __ movl(low, high); |
| 4848 | __ sarl(high, Immediate(31)); |
| 4849 | } else if (shift > 32) { |
| 4850 | DCHECK_NE(low, high); |
| 4851 | // High part becomes sign. Low part is shifted by shift - 32. |
| 4852 | __ movl(low, high); |
| 4853 | __ sarl(high, Immediate(31)); |
| 4854 | __ sarl(low, Immediate(shift - 32)); |
| 4855 | } else { |
| 4856 | // Between 1 and 31. |
| 4857 | __ shrd(low, high, Immediate(shift)); |
| 4858 | __ sarl(high, Immediate(shift)); |
| 4859 | } |
| 4860 | } |
| 4861 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4862 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4863 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4864 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4865 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4866 | __ testl(shifter, Immediate(32)); |
| 4867 | __ j(kEqual, &done); |
| 4868 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4869 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 4870 | __ Bind(&done); |
| 4871 | } |
| 4872 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4873 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 4874 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4875 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 4876 | if (shift == 32) { |
| 4877 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 4878 | codegen_->EmitParallelMoves( |
| 4879 | loc.ToHigh(), |
| 4880 | loc.ToLow(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4881 | DataType::Type::kInt32, |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4882 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 4883 | loc.ToHigh(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4884 | DataType::Type::kInt32); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4885 | } else if (shift > 32) { |
| 4886 | // Low part is high >> (shift - 32). High part becomes 0. |
| 4887 | __ movl(low, high); |
| 4888 | __ shrl(low, Immediate(shift - 32)); |
| 4889 | __ xorl(high, high); |
| 4890 | } else { |
| 4891 | // Between 1 and 31. |
| 4892 | __ shrd(low, high, Immediate(shift)); |
| 4893 | __ shrl(high, Immediate(shift)); |
| 4894 | } |
| 4895 | } |
| 4896 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4897 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4898 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4899 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4900 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4901 | __ testl(shifter, Immediate(32)); |
| 4902 | __ j(kEqual, &done); |
| 4903 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4904 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 4905 | __ Bind(&done); |
| 4906 | } |
| 4907 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4908 | void LocationsBuilderX86::VisitRor(HRor* ror) { |
| 4909 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4910 | new (GetGraph()->GetAllocator()) LocationSummary(ror, LocationSummary::kNoCall); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4911 | |
| 4912 | switch (ror->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4913 | case DataType::Type::kInt64: |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4914 | // Add the temporary needed. |
| 4915 | locations->AddTemp(Location::RequiresRegister()); |
| 4916 | FALLTHROUGH_INTENDED; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4917 | case DataType::Type::kInt32: |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4918 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4919 | // The shift count needs to be in CL (unless it is a constant). |
| 4920 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); |
| 4921 | locations->SetOut(Location::SameAsFirstInput()); |
| 4922 | break; |
| 4923 | default: |
| 4924 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4925 | UNREACHABLE(); |
| 4926 | } |
| 4927 | } |
| 4928 | |
| 4929 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { |
| 4930 | LocationSummary* locations = ror->GetLocations(); |
| 4931 | Location first = locations->InAt(0); |
| 4932 | Location second = locations->InAt(1); |
| 4933 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4934 | if (ror->GetResultType() == DataType::Type::kInt32) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4935 | Register first_reg = first.AsRegister<Register>(); |
| 4936 | if (second.IsRegister()) { |
| 4937 | Register second_reg = second.AsRegister<Register>(); |
| 4938 | __ rorl(first_reg, second_reg); |
| 4939 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4940 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4941 | __ rorl(first_reg, imm); |
| 4942 | } |
| 4943 | return; |
| 4944 | } |
| 4945 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4946 | DCHECK_EQ(ror->GetResultType(), DataType::Type::kInt64); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4947 | Register first_reg_lo = first.AsRegisterPairLow<Register>(); |
| 4948 | Register first_reg_hi = first.AsRegisterPairHigh<Register>(); |
| 4949 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 4950 | if (second.IsRegister()) { |
| 4951 | Register second_reg = second.AsRegister<Register>(); |
| 4952 | DCHECK_EQ(second_reg, ECX); |
| 4953 | __ movl(temp_reg, first_reg_hi); |
| 4954 | __ shrd(first_reg_hi, first_reg_lo, second_reg); |
| 4955 | __ shrd(first_reg_lo, temp_reg, second_reg); |
| 4956 | __ movl(temp_reg, first_reg_hi); |
| 4957 | __ testl(second_reg, Immediate(32)); |
| 4958 | __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); |
| 4959 | __ cmovl(kNotEqual, first_reg_lo, temp_reg); |
| 4960 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4961 | int32_t shift_amt = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4962 | if (shift_amt == 0) { |
| 4963 | // Already fine. |
| 4964 | return; |
| 4965 | } |
| 4966 | if (shift_amt == 32) { |
| 4967 | // Just swap. |
| 4968 | __ movl(temp_reg, first_reg_lo); |
| 4969 | __ movl(first_reg_lo, first_reg_hi); |
| 4970 | __ movl(first_reg_hi, temp_reg); |
| 4971 | return; |
| 4972 | } |
| 4973 | |
| 4974 | Immediate imm(shift_amt); |
| 4975 | // Save the constents of the low value. |
| 4976 | __ movl(temp_reg, first_reg_lo); |
| 4977 | |
| 4978 | // Shift right into low, feeding bits from high. |
| 4979 | __ shrd(first_reg_lo, first_reg_hi, imm); |
| 4980 | |
| 4981 | // Shift right into high, feeding bits from the original low. |
| 4982 | __ shrd(first_reg_hi, temp_reg, imm); |
| 4983 | |
| 4984 | // Swap if needed. |
| 4985 | if (shift_amt > 32) { |
| 4986 | __ movl(temp_reg, first_reg_lo); |
| 4987 | __ movl(first_reg_lo, first_reg_hi); |
| 4988 | __ movl(first_reg_hi, temp_reg); |
| 4989 | } |
| 4990 | } |
| 4991 | } |
| 4992 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4993 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 4994 | HandleShift(shl); |
| 4995 | } |
| 4996 | |
| 4997 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 4998 | HandleShift(shl); |
| 4999 | } |
| 5000 | |
| 5001 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 5002 | HandleShift(shr); |
| 5003 | } |
| 5004 | |
| 5005 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 5006 | HandleShift(shr); |
| 5007 | } |
| 5008 | |
| 5009 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 5010 | HandleShift(ushr); |
| 5011 | } |
| 5012 | |
| 5013 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 5014 | HandleShift(ushr); |
| 5015 | } |
| 5016 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 5017 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5018 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5019 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5020 | locations->SetOut(Location::RegisterLocation(EAX)); |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 5021 | InvokeRuntimeCallingConvention calling_convention; |
| 5022 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 5023 | } |
| 5024 | |
| 5025 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 5026 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
| 5027 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| 5028 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 5029 | } |
| 5030 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 5031 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5032 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5033 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 5034 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 5035 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5036 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5037 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 5038 | } |
| 5039 | |
| 5040 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 5041 | // Note: if heap poisoning is enabled, the entry point takes care of poisoning the reference. |
| 5042 | QuickEntrypointEnum entrypoint = CodeGenerator::GetArrayAllocationEntrypoint(instruction); |
Nicolas Geoffray | d095844 | 2017-01-30 14:57:16 +0000 | [diff] [blame] | 5043 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5044 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 5045 | DCHECK(!codegen_->IsLeafMethod()); |
| 5046 | } |
| 5047 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5048 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5049 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5050 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 5051 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 5052 | if (location.IsStackSlot()) { |
| 5053 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5054 | } else if (location.IsDoubleStackSlot()) { |
| 5055 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5056 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 5057 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5058 | } |
| 5059 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5060 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 5061 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 5062 | } |
| 5063 | |
| 5064 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 5065 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5066 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5067 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 5068 | } |
| 5069 | |
| 5070 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5071 | } |
| 5072 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5073 | void LocationsBuilderX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 5074 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5075 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5076 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5077 | locations->SetOut(Location::RequiresRegister()); |
| 5078 | } |
| 5079 | |
| 5080 | void InstructionCodeGeneratorX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 5081 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5082 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 5083 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5084 | instruction->GetIndex(), kX86PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 5085 | __ movl(locations->Out().AsRegister<Register>(), |
| 5086 | Address(locations->InAt(0).AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5087 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 5088 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 5089 | instruction->GetIndex(), kX86PointerSize)); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 5090 | __ movl(locations->Out().AsRegister<Register>(), |
| 5091 | Address(locations->InAt(0).AsRegister<Register>(), |
| 5092 | mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
| 5093 | // temp = temp->GetImtEntryAt(method_offset); |
| 5094 | __ movl(locations->Out().AsRegister<Register>(), |
| 5095 | Address(locations->Out().AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5096 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5097 | } |
| 5098 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 5099 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5100 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5101 | new (GetGraph()->GetAllocator()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 5102 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5103 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5104 | } |
| 5105 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 5106 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 5107 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 5108 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 5109 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 5110 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 5111 | switch (not_->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5112 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5113 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 5114 | break; |
| 5115 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5116 | case DataType::Type::kInt64: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 5117 | __ notl(out.AsRegisterPairLow<Register>()); |
| 5118 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 5119 | break; |
| 5120 | |
| 5121 | default: |
| 5122 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 5123 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5124 | } |
| 5125 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5126 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 5127 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5128 | new (GetGraph()->GetAllocator()) LocationSummary(bool_not, LocationSummary::kNoCall); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5129 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5130 | locations->SetOut(Location::SameAsFirstInput()); |
| 5131 | } |
| 5132 | |
| 5133 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5134 | LocationSummary* locations = bool_not->GetLocations(); |
| 5135 | Location in = locations->InAt(0); |
| 5136 | Location out = locations->Out(); |
| 5137 | DCHECK(in.Equals(out)); |
| 5138 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 5139 | } |
| 5140 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5141 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5142 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5143 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5144 | switch (compare->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5145 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5146 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5147 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5148 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5149 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5150 | case DataType::Type::kInt32: |
| 5151 | case DataType::Type::kInt64: { |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5152 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5153 | locations->SetInAt(1, Location::Any()); |
| 5154 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5155 | break; |
| 5156 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5157 | case DataType::Type::kFloat32: |
| 5158 | case DataType::Type::kFloat64: { |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5159 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 5160 | if (compare->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 5161 | DCHECK(compare->InputAt(1)->IsEmittedAtUseSite()); |
| 5162 | } else if (compare->InputAt(1)->IsConstant()) { |
| 5163 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 5164 | } else { |
| 5165 | locations->SetInAt(1, Location::Any()); |
| 5166 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5167 | locations->SetOut(Location::RequiresRegister()); |
| 5168 | break; |
| 5169 | } |
| 5170 | default: |
| 5171 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 5172 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5173 | } |
| 5174 | |
| 5175 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5176 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5177 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5178 | Location left = locations->InAt(0); |
| 5179 | Location right = locations->InAt(1); |
| 5180 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 5181 | NearLabel less, greater, done; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5182 | Condition less_cond = kLess; |
| 5183 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5184 | switch (compare->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5185 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5186 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5187 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5188 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5189 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5190 | case DataType::Type::kInt32: { |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 5191 | codegen_->GenerateIntCompare(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5192 | break; |
| 5193 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5194 | case DataType::Type::kInt64: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5195 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 5196 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 5197 | int32_t val_low = 0; |
| 5198 | int32_t val_high = 0; |
| 5199 | bool right_is_const = false; |
| 5200 | |
| 5201 | if (right.IsConstant()) { |
| 5202 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 5203 | right_is_const = true; |
| 5204 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 5205 | val_low = Low32Bits(val); |
| 5206 | val_high = High32Bits(val); |
| 5207 | } |
| 5208 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5209 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5210 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5211 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5212 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5213 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5214 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5215 | codegen_->Compare32BitValue(left_high, val_high); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5216 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5217 | __ j(kLess, &less); // Signed compare. |
| 5218 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5219 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5220 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5221 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5222 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5223 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5224 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5225 | codegen_->Compare32BitValue(left_low, val_low); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5226 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5227 | less_cond = kBelow; // for CF (unsigned). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5228 | break; |
| 5229 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5230 | case DataType::Type::kFloat32: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 5231 | GenerateFPCompare(left, right, compare, false); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5232 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5233 | less_cond = kBelow; // for CF (floats). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5234 | break; |
| 5235 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5236 | case DataType::Type::kFloat64: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 5237 | GenerateFPCompare(left, right, compare, true); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5238 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5239 | less_cond = kBelow; // for CF (floats). |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5240 | break; |
| 5241 | } |
| 5242 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5243 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5244 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5245 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5246 | __ movl(out, Immediate(0)); |
| 5247 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5248 | __ j(less_cond, &less); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5249 | |
| 5250 | __ Bind(&greater); |
| 5251 | __ movl(out, Immediate(1)); |
| 5252 | __ jmp(&done); |
| 5253 | |
| 5254 | __ Bind(&less); |
| 5255 | __ movl(out, Immediate(-1)); |
| 5256 | |
| 5257 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5258 | } |
| 5259 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 5260 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5261 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5262 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5263 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 5264 | locations->SetInAt(i, Location::Any()); |
| 5265 | } |
| 5266 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 5267 | } |
| 5268 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5269 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5270 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 5271 | } |
| 5272 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5273 | void CodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5274 | /* |
| 5275 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 5276 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 5277 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 5278 | */ |
| 5279 | switch (kind) { |
| 5280 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 5281 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5282 | break; |
| 5283 | } |
| 5284 | case MemBarrierKind::kAnyStore: |
| 5285 | case MemBarrierKind::kLoadAny: |
| 5286 | case MemBarrierKind::kStoreStore: { |
| 5287 | // nop |
| 5288 | break; |
| 5289 | } |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 5290 | case MemBarrierKind::kNTStoreStore: |
| 5291 | // Non-Temporal Store/Store needs an explicit fence. |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5292 | MemoryFence(/* non-temporal= */ true); |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 5293 | break; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 5294 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5295 | } |
| 5296 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5297 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( |
| 5298 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | bdb2ecc | 2018-09-18 14:33:55 +0100 | [diff] [blame] | 5299 | ArtMethod* method ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 5300 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5301 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5302 | |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5303 | Register CodeGeneratorX86::GetInvokeExtraParameter(HInvoke* invoke, Register temp) { |
| 5304 | if (invoke->IsInvokeStaticOrDirect()) { |
| 5305 | return GetInvokeStaticOrDirectExtraParameter(invoke->AsInvokeStaticOrDirect(), temp); |
| 5306 | } |
| 5307 | DCHECK(invoke->IsInvokeInterface()); |
| 5308 | Location location = |
| 5309 | invoke->GetLocations()->InAt(invoke->AsInvokeInterface()->GetSpecialInputIndex()); |
| 5310 | return location.AsRegister<Register>(); |
| 5311 | } |
| 5312 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 5313 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 5314 | Register temp) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 5315 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 5316 | if (!invoke->GetLocations()->Intrinsified()) { |
| 5317 | return location.AsRegister<Register>(); |
| 5318 | } |
| 5319 | // For intrinsics we allow any location, so it may be on the stack. |
| 5320 | if (!location.IsRegister()) { |
| 5321 | __ movl(temp, Address(ESP, location.GetStackIndex())); |
| 5322 | return temp; |
| 5323 | } |
| 5324 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 5325 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 5326 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 5327 | // simple and more robust approach rather that trying to determine if that's the case. |
| 5328 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
Vladimir Marko | 4ee8e29 | 2017-06-02 15:39:30 +0000 | [diff] [blame] | 5329 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 5330 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 5331 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 5332 | __ movl(temp, Address(ESP, stack_offset)); |
| 5333 | return temp; |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 5334 | } |
| 5335 | return location.AsRegister<Register>(); |
| 5336 | } |
| 5337 | |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5338 | void CodeGeneratorX86::LoadMethod(MethodLoadKind load_kind, Location temp, HInvoke* invoke) { |
| 5339 | switch (load_kind) { |
| 5340 | case MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 5341 | DCHECK(GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()); |
| 5342 | Register base_reg = GetInvokeExtraParameter(invoke, temp.AsRegister<Register>()); |
| 5343 | __ leal(temp.AsRegister<Register>(), |
| 5344 | Address(base_reg, CodeGeneratorX86::kPlaceholder32BitOffset)); |
| 5345 | RecordBootImageMethodPatch(invoke); |
| 5346 | break; |
| 5347 | } |
| 5348 | case MethodLoadKind::kBootImageRelRo: { |
| 5349 | size_t index = invoke->IsInvokeInterface() |
| 5350 | ? invoke->AsInvokeInterface()->GetSpecialInputIndex() |
| 5351 | : invoke->AsInvokeStaticOrDirect()->GetSpecialInputIndex(); |
| 5352 | Register base_reg = GetInvokeExtraParameter(invoke, temp.AsRegister<Register>()); |
| 5353 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kPlaceholder32BitOffset)); |
| 5354 | RecordBootImageRelRoPatch( |
| 5355 | invoke->InputAt(index)->AsX86ComputeBaseMethodAddress(), |
| 5356 | GetBootImageOffset(invoke)); |
| 5357 | break; |
| 5358 | } |
| 5359 | case MethodLoadKind::kBssEntry: { |
| 5360 | Register base_reg = GetInvokeExtraParameter(invoke, temp.AsRegister<Register>()); |
| 5361 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kPlaceholder32BitOffset)); |
| 5362 | RecordMethodBssEntryPatch(invoke); |
| 5363 | // No need for memory fence, thanks to the x86 memory model. |
| 5364 | break; |
| 5365 | } |
| 5366 | case MethodLoadKind::kJitDirectAddress: { |
| 5367 | __ movl(temp.AsRegister<Register>(), |
| 5368 | Immediate(reinterpret_cast32<uint32_t>(invoke->GetResolvedMethod()))); |
| 5369 | break; |
| 5370 | } |
| 5371 | case MethodLoadKind::kRuntimeCall: { |
| 5372 | // Test situation, don't do anything. |
| 5373 | break; |
| 5374 | } |
| 5375 | default: { |
| 5376 | LOG(FATAL) << "Load kind should have already been handled " << load_kind; |
| 5377 | UNREACHABLE(); |
| 5378 | } |
| 5379 | } |
| 5380 | } |
| 5381 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5382 | void CodeGeneratorX86::GenerateStaticOrDirectCall( |
| 5383 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5384 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 5385 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 5386 | case MethodLoadKind::kStringInit: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5387 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5388 | uint32_t offset = |
| 5389 | GetThreadOffset<kX86PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 5390 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5391 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5392 | } |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5393 | case MethodLoadKind::kRecursive: { |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 5394 | callee_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5395 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5396 | } |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 5397 | case MethodLoadKind::kRuntimeCall: { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5398 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 5399 | return; // No code pointer retrieval; the runtime performs the call directly. |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 5400 | } |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 5401 | case MethodLoadKind::kBootImageLinkTimePcRelative: |
| 5402 | // For kCallCriticalNative we skip loading the method and do the call directly. |
| 5403 | if (invoke->GetCodePtrLocation() == CodePtrLocation::kCallCriticalNative) { |
| 5404 | break; |
| 5405 | } |
| 5406 | FALLTHROUGH_INTENDED; |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5407 | default: { |
| 5408 | LoadMethod(invoke->GetMethodLoadKind(), callee_method, invoke); |
| 5409 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5410 | } |
| 5411 | |
| 5412 | switch (invoke->GetCodePtrLocation()) { |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 5413 | case CodePtrLocation::kCallSelf: |
Nicolas Geoffray | 282795c | 2021-09-24 18:16:41 +0100 | [diff] [blame] | 5414 | DCHECK(!GetGraph()->HasShouldDeoptimizeFlag()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5415 | __ call(GetFrameEntryLabel()); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 5416 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5417 | break; |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 5418 | case CodePtrLocation::kCallCriticalNative: { |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 5419 | size_t out_frame_size = |
| 5420 | PrepareCriticalNativeCall<CriticalNativeCallingConventionVisitorX86, |
| 5421 | kNativeStackAlignment, |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 5422 | GetCriticalNativeDirectCallFrameSize>(invoke); |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 5423 | if (invoke->GetMethodLoadKind() == MethodLoadKind::kBootImageLinkTimePcRelative) { |
| 5424 | DCHECK(GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()); |
| 5425 | Register base_reg = GetInvokeExtraParameter(invoke, temp.AsRegister<Register>()); |
| 5426 | __ call(Address(base_reg, CodeGeneratorX86::kPlaceholder32BitOffset)); |
| 5427 | RecordBootImageJniEntrypointPatch(invoke); |
| 5428 | } else { |
| 5429 | // (callee_method + offset_of_jni_entry_point)() |
| 5430 | __ call(Address(callee_method.AsRegister<Register>(), |
| 5431 | ArtMethod::EntryPointFromJniOffset(kX86PointerSize).Int32Value())); |
| 5432 | } |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 5433 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 5434 | if (out_frame_size == 0u && DataType::IsFloatingPointType(invoke->GetType())) { |
| 5435 | // Create space for conversion. |
| 5436 | out_frame_size = 8u; |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 5437 | IncreaseFrame(out_frame_size); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 5438 | } |
| 5439 | // Zero-/sign-extend or move the result when needed due to native and managed ABI mismatch. |
| 5440 | switch (invoke->GetType()) { |
| 5441 | case DataType::Type::kBool: |
| 5442 | __ movzxb(EAX, AL); |
| 5443 | break; |
| 5444 | case DataType::Type::kInt8: |
| 5445 | __ movsxb(EAX, AL); |
| 5446 | break; |
| 5447 | case DataType::Type::kUint16: |
| 5448 | __ movzxw(EAX, EAX); |
| 5449 | break; |
| 5450 | case DataType::Type::kInt16: |
| 5451 | __ movsxw(EAX, EAX); |
| 5452 | break; |
| 5453 | case DataType::Type::kFloat32: |
| 5454 | __ fstps(Address(ESP, 0)); |
| 5455 | __ movss(XMM0, Address(ESP, 0)); |
| 5456 | break; |
| 5457 | case DataType::Type::kFloat64: |
| 5458 | __ fstpl(Address(ESP, 0)); |
| 5459 | __ movsd(XMM0, Address(ESP, 0)); |
| 5460 | break; |
| 5461 | case DataType::Type::kInt32: |
| 5462 | case DataType::Type::kInt64: |
| 5463 | case DataType::Type::kVoid: |
| 5464 | break; |
| 5465 | default: |
| 5466 | DCHECK(false) << invoke->GetType(); |
| 5467 | break; |
| 5468 | } |
| 5469 | if (out_frame_size != 0u) { |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 5470 | DecreaseFrame(out_frame_size); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 5471 | } |
| 5472 | break; |
| 5473 | } |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 5474 | case CodePtrLocation::kCallArtMethod: |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5475 | // (callee_method + offset_of_quick_compiled_code)() |
| 5476 | __ call(Address(callee_method.AsRegister<Register>(), |
| 5477 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5478 | kX86PointerSize).Int32Value())); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 5479 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5480 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 5481 | } |
| 5482 | |
| 5483 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 5484 | } |
| 5485 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5486 | void CodeGeneratorX86::GenerateVirtualCall( |
| 5487 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5488 | Register temp = temp_in.AsRegister<Register>(); |
| 5489 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 5490 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 5491 | |
| 5492 | // Use the calling convention instead of the location of the receiver, as |
| 5493 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 5494 | // slow path, the arguments have been moved to the right place, so here we are |
| 5495 | // guaranteed that the receiver is the first register of the calling convention. |
| 5496 | InvokeDexCallingConvention calling_convention; |
| 5497 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5498 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5499 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 5500 | __ movl(temp, Address(receiver, class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5501 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5502 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 5503 | // emit a read barrier for the previous class reference load. |
| 5504 | // However this is not required in practice, as this is an |
| 5505 | // intermediate/temporary reference and because the current |
| 5506 | // concurrent copying collector keeps the from-space memory |
| 5507 | // intact/accessible until the end of the marking phase (the |
| 5508 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5509 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 5510 | |
| 5511 | MaybeGenerateInlineCacheCheck(invoke, temp); |
| 5512 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5513 | // temp = temp->GetMethodAt(method_offset); |
| 5514 | __ movl(temp, Address(temp, method_offset)); |
| 5515 | // call temp->GetEntryPoint(); |
| 5516 | __ call(Address( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5517 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5518 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5519 | } |
| 5520 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5521 | void CodeGeneratorX86::RecordBootImageIntrinsicPatch(HX86ComputeBaseMethodAddress* method_address, |
| 5522 | uint32_t intrinsic_data) { |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5523 | boot_image_other_patches_.emplace_back( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5524 | method_address, /* target_dex_file= */ nullptr, intrinsic_data); |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5525 | __ Bind(&boot_image_other_patches_.back().label); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5526 | } |
| 5527 | |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 5528 | void CodeGeneratorX86::RecordBootImageRelRoPatch(HX86ComputeBaseMethodAddress* method_address, |
| 5529 | uint32_t boot_image_offset) { |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5530 | boot_image_other_patches_.emplace_back( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5531 | method_address, /* target_dex_file= */ nullptr, boot_image_offset); |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5532 | __ Bind(&boot_image_other_patches_.back().label); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 5533 | } |
| 5534 | |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5535 | void CodeGeneratorX86::RecordBootImageMethodPatch(HInvoke* invoke) { |
| 5536 | size_t index = invoke->IsInvokeInterface() |
| 5537 | ? invoke->AsInvokeInterface()->GetSpecialInputIndex() |
| 5538 | : invoke->AsInvokeStaticOrDirect()->GetSpecialInputIndex(); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5539 | HX86ComputeBaseMethodAddress* method_address = |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5540 | invoke->InputAt(index)->AsX86ComputeBaseMethodAddress(); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5541 | boot_image_method_patches_.emplace_back( |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 5542 | method_address, |
| 5543 | invoke->GetResolvedMethodReference().dex_file, |
| 5544 | invoke->GetResolvedMethodReference().index); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5545 | __ Bind(&boot_image_method_patches_.back().label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5546 | } |
| 5547 | |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5548 | void CodeGeneratorX86::RecordMethodBssEntryPatch(HInvoke* invoke) { |
| 5549 | size_t index = invoke->IsInvokeInterface() |
| 5550 | ? invoke->AsInvokeInterface()->GetSpecialInputIndex() |
| 5551 | : invoke->AsInvokeStaticOrDirect()->GetSpecialInputIndex(); |
Santiago Aboy Solanes | a0232ad | 2021-11-08 17:00:06 +0000 | [diff] [blame] | 5552 | DCHECK(IsSameDexFile(GetGraph()->GetDexFile(), *invoke->GetMethodReference().dex_file) || |
Santiago Aboy Solanes | 69a87e3 | 2022-03-08 16:43:54 +0000 | [diff] [blame] | 5553 | GetCompilerOptions().WithinOatFile(invoke->GetMethodReference().dex_file) || |
| 5554 | ContainsElement(Runtime::Current()->GetClassLinker()->GetBootClassPath(), |
| 5555 | invoke->GetMethodReference().dex_file)); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5556 | HX86ComputeBaseMethodAddress* method_address = |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5557 | invoke->InputAt(index)->AsX86ComputeBaseMethodAddress(); |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5558 | // 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] | 5559 | method_bss_entry_patches_.emplace_back( |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 5560 | method_address, |
| 5561 | invoke->GetMethodReference().dex_file, |
| 5562 | invoke->GetMethodReference().index); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5563 | __ Bind(&method_bss_entry_patches_.back().label); |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5564 | } |
| 5565 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5566 | void CodeGeneratorX86::RecordBootImageTypePatch(HLoadClass* load_class) { |
| 5567 | HX86ComputeBaseMethodAddress* method_address = |
| 5568 | load_class->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 5569 | boot_image_type_patches_.emplace_back( |
| 5570 | method_address, &load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5571 | __ Bind(&boot_image_type_patches_.back().label); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5572 | } |
| 5573 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5574 | Label* CodeGeneratorX86::NewTypeBssEntryPatch(HLoadClass* load_class) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5575 | HX86ComputeBaseMethodAddress* method_address = |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 5576 | load_class->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5577 | ArenaDeque<X86PcRelativePatchInfo>* patches = nullptr; |
| 5578 | switch (load_class->GetLoadKind()) { |
| 5579 | case HLoadClass::LoadKind::kBssEntry: |
| 5580 | patches = &type_bss_entry_patches_; |
| 5581 | break; |
| 5582 | case HLoadClass::LoadKind::kBssEntryPublic: |
| 5583 | patches = &public_type_bss_entry_patches_; |
| 5584 | break; |
| 5585 | case HLoadClass::LoadKind::kBssEntryPackage: |
| 5586 | patches = &package_type_bss_entry_patches_; |
| 5587 | break; |
| 5588 | default: |
| 5589 | LOG(FATAL) << "Unexpected load kind: " << load_class->GetLoadKind(); |
| 5590 | UNREACHABLE(); |
| 5591 | } |
| 5592 | patches->emplace_back( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5593 | method_address, &load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5594 | return &patches->back().label; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5595 | } |
| 5596 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5597 | void CodeGeneratorX86::RecordBootImageStringPatch(HLoadString* load_string) { |
| 5598 | HX86ComputeBaseMethodAddress* method_address = |
| 5599 | load_string->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 5600 | boot_image_string_patches_.emplace_back( |
| 5601 | method_address, &load_string->GetDexFile(), load_string->GetStringIndex().index_); |
| 5602 | __ Bind(&boot_image_string_patches_.back().label); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5603 | } |
| 5604 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5605 | Label* CodeGeneratorX86::NewStringBssEntryPatch(HLoadString* load_string) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5606 | HX86ComputeBaseMethodAddress* method_address = |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 5607 | load_string->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5608 | string_bss_entry_patches_.emplace_back( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5609 | method_address, &load_string->GetDexFile(), load_string->GetStringIndex().index_); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5610 | return &string_bss_entry_patches_.back().label; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5611 | } |
| 5612 | |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 5613 | void CodeGeneratorX86::RecordBootImageJniEntrypointPatch(HInvokeStaticOrDirect* invoke) { |
| 5614 | HX86ComputeBaseMethodAddress* method_address = |
| 5615 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
| 5616 | boot_image_jni_entrypoint_patches_.emplace_back( |
| 5617 | method_address, |
| 5618 | invoke->GetResolvedMethodReference().dex_file, |
| 5619 | invoke->GetResolvedMethodReference().index); |
| 5620 | __ Bind(&boot_image_jni_entrypoint_patches_.back().label); |
| 5621 | } |
| 5622 | |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5623 | void CodeGeneratorX86::LoadBootImageAddress(Register reg, |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5624 | uint32_t boot_image_reference, |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5625 | HInvokeStaticOrDirect* invoke) { |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5626 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5627 | HX86ComputeBaseMethodAddress* method_address = |
| 5628 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
| 5629 | DCHECK(method_address != nullptr); |
| 5630 | Register method_address_reg = |
| 5631 | invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()).AsRegister<Register>(); |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 5632 | __ leal(reg, Address(method_address_reg, CodeGeneratorX86::kPlaceholder32BitOffset)); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5633 | RecordBootImageIntrinsicPatch(method_address, boot_image_reference); |
Vladimir Marko | a2da9b9 | 2018-10-10 14:21:55 +0100 | [diff] [blame] | 5634 | } else if (GetCompilerOptions().GetCompilePic()) { |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5635 | HX86ComputeBaseMethodAddress* method_address = |
| 5636 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
| 5637 | DCHECK(method_address != nullptr); |
| 5638 | Register method_address_reg = |
| 5639 | invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()).AsRegister<Register>(); |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 5640 | __ movl(reg, Address(method_address_reg, CodeGeneratorX86::kPlaceholder32BitOffset)); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5641 | RecordBootImageRelRoPatch(method_address, boot_image_reference); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5642 | } else { |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 5643 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5644 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 5645 | DCHECK(!heap->GetBootImageSpaces().empty()); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5646 | const uint8_t* address = heap->GetBootImageSpaces()[0]->Begin() + boot_image_reference; |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5647 | __ movl(reg, Immediate(dchecked_integral_cast<uint32_t>(reinterpret_cast<uintptr_t>(address)))); |
| 5648 | } |
| 5649 | } |
| 5650 | |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 5651 | void CodeGeneratorX86::LoadIntrinsicDeclaringClass(Register reg, HInvokeStaticOrDirect* invoke) { |
| 5652 | DCHECK_NE(invoke->GetIntrinsic(), Intrinsics::kNone); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5653 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5654 | // Load the class the same way as for HLoadClass::LoadKind::kBootImageLinkTimePcRelative. |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5655 | HX86ComputeBaseMethodAddress* method_address = |
| 5656 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
| 5657 | DCHECK(method_address != nullptr); |
| 5658 | Register method_address_reg = |
| 5659 | invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()).AsRegister<Register>(); |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 5660 | __ leal(reg, Address(method_address_reg, CodeGeneratorX86::kPlaceholder32BitOffset)); |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 5661 | MethodReference target_method = invoke->GetResolvedMethodReference(); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5662 | dex::TypeIndex type_idx = target_method.dex_file->GetMethodId(target_method.index).class_idx_; |
| 5663 | boot_image_type_patches_.emplace_back(method_address, target_method.dex_file, type_idx.index_); |
| 5664 | __ Bind(&boot_image_type_patches_.back().label); |
| 5665 | } else { |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 5666 | uint32_t boot_image_offset = GetBootImageOffsetOfIntrinsicDeclaringClass(invoke); |
| 5667 | LoadBootImageAddress(reg, boot_image_offset, invoke); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5668 | } |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5669 | } |
| 5670 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5671 | // The label points to the end of the "movl" or another instruction but the literal offset |
| 5672 | // for method patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 5673 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
| 5674 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5675 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5676 | inline void CodeGeneratorX86::EmitPcRelativeLinkerPatches( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 5677 | const ArenaDeque<X86PcRelativePatchInfo>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5678 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 5679 | for (const X86PcRelativePatchInfo& info : infos) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5680 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5681 | linker_patches->push_back(Factory(literal_offset, |
| 5682 | info.target_dex_file, |
| 5683 | GetMethodAddressOffset(info.method_address), |
| 5684 | info.offset_or_index)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5685 | } |
| 5686 | } |
| 5687 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5688 | template <linker::LinkerPatch (*Factory)(size_t, uint32_t, uint32_t)> |
| 5689 | linker::LinkerPatch NoDexFileAdapter(size_t literal_offset, |
| 5690 | const DexFile* target_dex_file, |
| 5691 | uint32_t pc_insn_offset, |
| 5692 | uint32_t boot_image_offset) { |
| 5693 | DCHECK(target_dex_file == nullptr); // Unused for these patches, should be null. |
| 5694 | return Factory(literal_offset, pc_insn_offset, boot_image_offset); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 5695 | } |
| 5696 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5697 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5698 | DCHECK(linker_patches->empty()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 5699 | size_t size = |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5700 | boot_image_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5701 | method_bss_entry_patches_.size() + |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5702 | boot_image_type_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5703 | type_bss_entry_patches_.size() + |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5704 | public_type_bss_entry_patches_.size() + |
| 5705 | package_type_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5706 | boot_image_string_patches_.size() + |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5707 | string_bss_entry_patches_.size() + |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 5708 | boot_image_jni_entrypoint_patches_.size() + |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5709 | boot_image_other_patches_.size(); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 5710 | linker_patches->reserve(size); |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 5711 | if (GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5712 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
| 5713 | boot_image_method_patches_, linker_patches); |
| 5714 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
| 5715 | boot_image_type_patches_, linker_patches); |
| 5716 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5717 | boot_image_string_patches_, linker_patches); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5718 | } else { |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5719 | DCHECK(boot_image_method_patches_.empty()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5720 | DCHECK(boot_image_type_patches_.empty()); |
| 5721 | DCHECK(boot_image_string_patches_.empty()); |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5722 | } |
| 5723 | if (GetCompilerOptions().IsBootImage()) { |
| 5724 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::IntrinsicReferencePatch>>( |
| 5725 | boot_image_other_patches_, linker_patches); |
| 5726 | } else { |
| 5727 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::DataBimgRelRoPatch>>( |
| 5728 | boot_image_other_patches_, linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5729 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5730 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 5731 | method_bss_entry_patches_, linker_patches); |
| 5732 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 5733 | type_bss_entry_patches_, linker_patches); |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5734 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::PublicTypeBssEntryPatch>( |
| 5735 | public_type_bss_entry_patches_, linker_patches); |
| 5736 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::PackageTypeBssEntryPatch>( |
| 5737 | package_type_bss_entry_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5738 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 5739 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 5740 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeJniEntrypointPatch>( |
| 5741 | boot_image_jni_entrypoint_patches_, linker_patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5742 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5743 | } |
| 5744 | |
Santiago Aboy Solanes | d422960 | 2023-01-03 16:20:50 +0000 | [diff] [blame] | 5745 | void CodeGeneratorX86::MarkGCCard( |
| 5746 | Register temp, Register card, Register object, Register value, bool emit_null_check) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 5747 | NearLabel is_null; |
Santiago Aboy Solanes | d422960 | 2023-01-03 16:20:50 +0000 | [diff] [blame] | 5748 | if (emit_null_check) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5749 | __ testl(value, value); |
| 5750 | __ j(kEqual, &is_null); |
| 5751 | } |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5752 | // Load the address of the card table into `card`. |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5753 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86PointerSize>().Int32Value())); |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5754 | // Calculate the offset (in the card table) of the card corresponding to |
| 5755 | // `object`. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5756 | __ movl(temp, object); |
| 5757 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5758 | // Write the `art::gc::accounting::CardTable::kCardDirty` value into the |
| 5759 | // `object`'s card. |
| 5760 | // |
| 5761 | // Register `card` contains the address of the card table. Note that the card |
| 5762 | // table's base is biased during its creation so that it always starts at an |
| 5763 | // address whose least-significant byte is equal to `kCardDirty` (see |
| 5764 | // art::gc::accounting::CardTable::Create). Therefore the MOVB instruction |
| 5765 | // below writes the `kCardDirty` (byte) value into the `object`'s card |
| 5766 | // (located at `card + object >> kCardShift`). |
| 5767 | // |
| 5768 | // This dual use of the value in register `card` (1. to calculate the location |
| 5769 | // of the card to mark; and 2. to load the `kCardDirty` value) saves a load |
| 5770 | // (no need to explicitly load `kCardDirty` as an immediate value). |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 5771 | __ movb(Address(temp, card, TIMES_1, 0), |
| 5772 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Santiago Aboy Solanes | d422960 | 2023-01-03 16:20:50 +0000 | [diff] [blame] | 5773 | if (emit_null_check) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5774 | __ Bind(&is_null); |
| 5775 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5776 | } |
| 5777 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5778 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 5779 | DCHECK(instruction->IsInstanceFieldGet() || |
| 5780 | instruction->IsStaticFieldGet() || |
| 5781 | instruction->IsPredicatedInstanceFieldGet()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5782 | |
| 5783 | bool object_field_get_with_read_barrier = |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 5784 | gUseReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 5785 | bool is_predicated = instruction->IsPredicatedInstanceFieldGet(); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5786 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5787 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 5788 | gUseReadBarrier |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5789 | ? LocationSummary::kCallOnSlowPath |
| 5790 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5791 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5792 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5793 | } |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 5794 | // receiver_input |
| 5795 | locations->SetInAt(is_predicated ? 1 : 0, Location::RequiresRegister()); |
| 5796 | if (is_predicated) { |
| 5797 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
| 5798 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5799 | } else { |
| 5800 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5801 | } |
| 5802 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5803 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 5804 | locations->SetOut(is_predicated ? Location::SameAsFirstInput() |
| 5805 | : Location::RequiresFpuRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5806 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5807 | // The output overlaps in case of long: we don't want the low move |
| 5808 | // to overwrite the object's location. Likewise, in the case of |
| 5809 | // an object field get with read barriers enabled, we do not want |
| 5810 | // the move to overwrite the object's location, as we need it to emit |
| 5811 | // the read barrier. |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 5812 | locations->SetOut(is_predicated ? Location::SameAsFirstInput() : Location::RequiresRegister(), |
| 5813 | (object_field_get_with_read_barrier || |
| 5814 | instruction->GetType() == DataType::Type::kInt64 || |
| 5815 | is_predicated) |
| 5816 | ? Location::kOutputOverlap |
| 5817 | : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5818 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5819 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5820 | if (field_info.IsVolatile() && (field_info.GetFieldType() == DataType::Type::kInt64)) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5821 | // Long values can be loaded atomically into an XMM using movsd. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5822 | // So we use an XMM register as a temp to achieve atomicity (first |
| 5823 | // load the temp into the XMM and then copy the XMM into the |
| 5824 | // output, 32 bits at a time). |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5825 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 5826 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5827 | } |
| 5828 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5829 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 5830 | const FieldInfo& field_info) { |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 5831 | DCHECK(instruction->IsInstanceFieldGet() || |
| 5832 | instruction->IsStaticFieldGet() || |
| 5833 | instruction->IsPredicatedInstanceFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5834 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5835 | LocationSummary* locations = instruction->GetLocations(); |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 5836 | Location base_loc = locations->InAt(instruction->IsPredicatedInstanceFieldGet() ? 1 : 0); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5837 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5838 | Location out = locations->Out(); |
| 5839 | bool is_volatile = field_info.IsVolatile(); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5840 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 5841 | DataType::Type load_type = instruction->GetType(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5842 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5843 | |
Ulya Trafimovich | 322eced | 2021-06-02 15:39:36 +0100 | [diff] [blame] | 5844 | if (load_type == DataType::Type::kReference) { |
| 5845 | // /* HeapReference<Object> */ out = *(base + offset) |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 5846 | if (gUseReadBarrier && kUseBakerReadBarrier) { |
Ulya Trafimovich | 322eced | 2021-06-02 15:39:36 +0100 | [diff] [blame] | 5847 | // Note that a potential implicit null check is handled in this |
| 5848 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 5849 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 5850 | instruction, out, base, offset, /* needs_null_check= */ true); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5851 | if (is_volatile) { |
Ulya Trafimovich | 322eced | 2021-06-02 15:39:36 +0100 | [diff] [blame] | 5852 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5853 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5854 | } else { |
Ulya Trafimovich | 322eced | 2021-06-02 15:39:36 +0100 | [diff] [blame] | 5855 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| 5856 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5857 | if (is_volatile) { |
| 5858 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5859 | } |
| 5860 | // If read barriers are enabled, emit read barriers other than |
| 5861 | // Baker's using a slow path (and also unpoison the loaded |
| 5862 | // reference, if heap poisoning is enabled). |
| 5863 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 5864 | } |
| 5865 | } else { |
| 5866 | Address src(base, offset); |
| 5867 | XmmRegister temp = (load_type == DataType::Type::kInt64 && is_volatile) |
| 5868 | ? locations->GetTemp(0).AsFpuRegister<XmmRegister>() |
| 5869 | : kNoXmmRegister; |
| 5870 | codegen_->LoadFromMemoryNoBarrier(load_type, out, src, instruction, temp, is_volatile); |
| 5871 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5872 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5873 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5874 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5875 | } |
| 5876 | |
Santiago Aboy Solanes | d422960 | 2023-01-03 16:20:50 +0000 | [diff] [blame] | 5877 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, |
| 5878 | const FieldInfo& field_info, |
| 5879 | WriteBarrierKind write_barrier_kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5880 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5881 | |
| 5882 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5883 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5884 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5885 | bool is_volatile = field_info.IsVolatile(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5886 | DataType::Type field_type = field_info.GetFieldType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5887 | bool is_byte_type = DataType::Size(field_type) == 1u; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5888 | |
| 5889 | // The register allocator does not support multiple |
| 5890 | // inputs that die at entry with one in a specific register. |
| 5891 | if (is_byte_type) { |
| 5892 | // Ensure the value is in a byte register. |
| 5893 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5894 | } else if (DataType::IsFloatingPointType(field_type)) { |
| 5895 | if (is_volatile && field_type == DataType::Type::kFloat64) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5896 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 5897 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 5898 | } else { |
| 5899 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 5900 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5901 | } else if (is_volatile && field_type == DataType::Type::kInt64) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5902 | // 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] | 5903 | locations->SetInAt(1, Location::RequiresRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5904 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5905 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 5906 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 5907 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 5908 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 5909 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 5910 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 5911 | locations->AddTemp(Location::RequiresFpuRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5912 | } else { |
| 5913 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5914 | |
| 5915 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Santiago Aboy Solanes | d422960 | 2023-01-03 16:20:50 +0000 | [diff] [blame] | 5916 | if (write_barrier_kind != WriteBarrierKind::kDontEmit) { |
| 5917 | locations->AddTemp(Location::RequiresRegister()); |
| 5918 | // Ensure the card is in a byte register. |
| 5919 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 5920 | } else if (kPoisonHeapReferences) { |
| 5921 | locations->AddTemp(Location::RequiresRegister()); |
| 5922 | } |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5923 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5924 | } |
| 5925 | } |
| 5926 | |
| 5927 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5928 | uint32_t value_index, |
| 5929 | DataType::Type field_type, |
| 5930 | Address field_addr, |
| 5931 | Register base, |
| 5932 | bool is_volatile, |
Santiago Aboy Solanes | d422960 | 2023-01-03 16:20:50 +0000 | [diff] [blame] | 5933 | bool value_can_be_null, |
| 5934 | WriteBarrierKind write_barrier_kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5935 | LocationSummary* locations = instruction->GetLocations(); |
Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5936 | Location value = locations->InAt(value_index); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5937 | bool needs_write_barrier = |
Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5938 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(value_index)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5939 | |
| 5940 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5941 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5942 | } |
| 5943 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5944 | bool maybe_record_implicit_null_check_done = false; |
| 5945 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5946 | switch (field_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5947 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5948 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5949 | case DataType::Type::kInt8: { |
Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5950 | if (value.IsConstant()) { |
| 5951 | __ movb(field_addr, Immediate(CodeGenerator::GetInt8ValueOf(value.GetConstant()))); |
| 5952 | } else { |
| 5953 | __ movb(field_addr, value.AsRegister<ByteRegister>()); |
| 5954 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5955 | break; |
| 5956 | } |
| 5957 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5958 | case DataType::Type::kUint16: |
| 5959 | case DataType::Type::kInt16: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5960 | if (value.IsConstant()) { |
Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5961 | __ movw(field_addr, Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5962 | } else { |
Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5963 | __ movw(field_addr, value.AsRegister<Register>()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5964 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5965 | break; |
| 5966 | } |
| 5967 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5968 | case DataType::Type::kInt32: |
| 5969 | case DataType::Type::kReference: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5970 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 5971 | // Note that in the case where `value` is a null reference, |
| 5972 | // we do not enter this block, as the reference does not |
| 5973 | // need poisoning. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5974 | DCHECK_EQ(field_type, DataType::Type::kReference); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5975 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5976 | __ movl(temp, value.AsRegister<Register>()); |
| 5977 | __ PoisonHeapReference(temp); |
Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5978 | __ movl(field_addr, temp); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5979 | } else if (value.IsConstant()) { |
| 5980 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5981 | __ movl(field_addr, Immediate(v)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5982 | } else { |
Nicolas Geoffray | 0397163 | 2016-03-17 10:44:24 +0000 | [diff] [blame] | 5983 | DCHECK(value.IsRegister()) << value; |
Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5984 | __ movl(field_addr, value.AsRegister<Register>()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5985 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5986 | break; |
| 5987 | } |
| 5988 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5989 | case DataType::Type::kInt64: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5990 | if (is_volatile) { |
| 5991 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 5992 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 5993 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 5994 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 5995 | __ punpckldq(temp1, temp2); |
Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5996 | __ movsd(field_addr, temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5997 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5998 | } else if (value.IsConstant()) { |
| 5999 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 6000 | __ movl(field_addr, Immediate(Low32Bits(v))); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6001 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Ulya Trafimovich | 893e2ed | 2021-06-10 16:18:12 +0100 | [diff] [blame] | 6002 | __ movl(Address::displace(field_addr, kX86WordSize), Immediate(High32Bits(v))); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6003 | } else { |
Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 6004 | __ movl(field_addr, value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6005 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Ulya Trafimovich | 893e2ed | 2021-06-10 16:18:12 +0100 | [diff] [blame] | 6006 | __ movl(Address::displace(field_addr, kX86WordSize), value.AsRegisterPairHigh<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6007 | } |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6008 | maybe_record_implicit_null_check_done = true; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6009 | break; |
| 6010 | } |
| 6011 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6012 | case DataType::Type::kFloat32: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6013 | if (value.IsConstant()) { |
| 6014 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 6015 | __ movl(field_addr, Immediate(v)); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6016 | } else { |
Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 6017 | __ movss(field_addr, value.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6018 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6019 | break; |
| 6020 | } |
| 6021 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6022 | case DataType::Type::kFloat64: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6023 | if (value.IsConstant()) { |
Andra Danciu | c992e42 | 2020-09-16 08:12:02 +0000 | [diff] [blame] | 6024 | DCHECK(!is_volatile); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6025 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 6026 | __ movl(field_addr, Immediate(Low32Bits(v))); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6027 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Ulya Trafimovich | 893e2ed | 2021-06-10 16:18:12 +0100 | [diff] [blame] | 6028 | __ movl(Address::displace(field_addr, kX86WordSize), Immediate(High32Bits(v))); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6029 | maybe_record_implicit_null_check_done = true; |
| 6030 | } else { |
Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 6031 | __ movsd(field_addr, value.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6032 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6033 | break; |
| 6034 | } |
| 6035 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 6036 | case DataType::Type::kUint32: |
| 6037 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6038 | case DataType::Type::kVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6039 | LOG(FATAL) << "Unreachable type " << field_type; |
| 6040 | UNREACHABLE(); |
| 6041 | } |
| 6042 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6043 | if (!maybe_record_implicit_null_check_done) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6044 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6045 | } |
| 6046 | |
Santiago Aboy Solanes | d422960 | 2023-01-03 16:20:50 +0000 | [diff] [blame] | 6047 | if (needs_write_barrier && write_barrier_kind != WriteBarrierKind::kDontEmit) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6048 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 6049 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Santiago Aboy Solanes | d422960 | 2023-01-03 16:20:50 +0000 | [diff] [blame] | 6050 | codegen_->MarkGCCard( |
| 6051 | temp, |
| 6052 | card, |
| 6053 | base, |
| 6054 | value.AsRegister<Register>(), |
| 6055 | value_can_be_null && write_barrier_kind == WriteBarrierKind::kEmitWithNullCheck); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6056 | } |
| 6057 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6058 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6059 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6060 | } |
| 6061 | } |
| 6062 | |
Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 6063 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
| 6064 | const FieldInfo& field_info, |
Santiago Aboy Solanes | d422960 | 2023-01-03 16:20:50 +0000 | [diff] [blame] | 6065 | bool value_can_be_null, |
| 6066 | WriteBarrierKind write_barrier_kind) { |
Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 6067 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 6068 | |
| 6069 | LocationSummary* locations = instruction->GetLocations(); |
| 6070 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 6071 | bool is_volatile = field_info.IsVolatile(); |
| 6072 | DataType::Type field_type = field_info.GetFieldType(); |
| 6073 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 6074 | bool is_predicated = |
| 6075 | instruction->IsInstanceFieldSet() && instruction->AsInstanceFieldSet()->GetIsPredicatedSet(); |
Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 6076 | |
| 6077 | Address field_addr(base, offset); |
| 6078 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 6079 | NearLabel pred_is_null; |
| 6080 | if (is_predicated) { |
| 6081 | __ testl(base, base); |
| 6082 | __ j(kEqual, &pred_is_null); |
| 6083 | } |
| 6084 | |
Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 6085 | HandleFieldSet(instruction, |
| 6086 | /* value_index= */ 1, |
| 6087 | field_type, |
| 6088 | field_addr, |
| 6089 | base, |
| 6090 | is_volatile, |
Santiago Aboy Solanes | d422960 | 2023-01-03 16:20:50 +0000 | [diff] [blame] | 6091 | value_can_be_null, |
| 6092 | write_barrier_kind); |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 6093 | |
| 6094 | if (is_predicated) { |
| 6095 | __ Bind(&pred_is_null); |
| 6096 | } |
Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 6097 | } |
| 6098 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6099 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 6100 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6101 | } |
| 6102 | |
| 6103 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 6104 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6105 | } |
| 6106 | |
| 6107 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Santiago Aboy Solanes | d422960 | 2023-01-03 16:20:50 +0000 | [diff] [blame] | 6108 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetWriteBarrierKind()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6109 | } |
| 6110 | |
| 6111 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Santiago Aboy Solanes | d422960 | 2023-01-03 16:20:50 +0000 | [diff] [blame] | 6112 | HandleFieldSet(instruction, |
| 6113 | instruction->GetFieldInfo(), |
| 6114 | instruction->GetValueCanBeNull(), |
| 6115 | instruction->GetWriteBarrierKind()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6116 | } |
| 6117 | |
| 6118 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Santiago Aboy Solanes | d422960 | 2023-01-03 16:20:50 +0000 | [diff] [blame] | 6119 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetWriteBarrierKind()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6120 | } |
| 6121 | |
| 6122 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Santiago Aboy Solanes | d422960 | 2023-01-03 16:20:50 +0000 | [diff] [blame] | 6123 | HandleFieldSet(instruction, |
| 6124 | instruction->GetFieldInfo(), |
| 6125 | instruction->GetValueCanBeNull(), |
| 6126 | instruction->GetWriteBarrierKind()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6127 | } |
| 6128 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 6129 | void LocationsBuilderX86::VisitPredicatedInstanceFieldGet( |
| 6130 | HPredicatedInstanceFieldGet* instruction) { |
| 6131 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6132 | } |
| 6133 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6134 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 6135 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6136 | } |
| 6137 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 6138 | void InstructionCodeGeneratorX86::VisitPredicatedInstanceFieldGet( |
| 6139 | HPredicatedInstanceFieldGet* instruction) { |
| 6140 | NearLabel finish; |
| 6141 | LocationSummary* locations = instruction->GetLocations(); |
| 6142 | Register recv = locations->InAt(1).AsRegister<Register>(); |
| 6143 | __ testl(recv, recv); |
| 6144 | __ j(kZero, &finish); |
| 6145 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6146 | __ Bind(&finish); |
| 6147 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6148 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 6149 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6150 | } |
| 6151 | |
Vladimir Marko | 552a134 | 2017-10-31 10:56:47 +0000 | [diff] [blame] | 6152 | void LocationsBuilderX86::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 6153 | codegen_->CreateStringBuilderAppendLocations(instruction, Location::RegisterLocation(EAX)); |
| 6154 | } |
| 6155 | |
| 6156 | void InstructionCodeGeneratorX86::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 6157 | __ movl(EAX, Immediate(instruction->GetFormat()->GetValue())); |
| 6158 | codegen_->InvokeRuntime(kQuickStringBuilderAppend, instruction, instruction->GetDexPc()); |
| 6159 | } |
| 6160 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6161 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 6162 | HUnresolvedInstanceFieldGet* instruction) { |
| 6163 | FieldAccessCallingConventionX86 calling_convention; |
| 6164 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6165 | instruction, instruction->GetFieldType(), calling_convention); |
| 6166 | } |
| 6167 | |
| 6168 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 6169 | HUnresolvedInstanceFieldGet* instruction) { |
| 6170 | FieldAccessCallingConventionX86 calling_convention; |
| 6171 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6172 | instruction->GetFieldType(), |
| 6173 | instruction->GetFieldIndex(), |
| 6174 | instruction->GetDexPc(), |
| 6175 | calling_convention); |
| 6176 | } |
| 6177 | |
| 6178 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 6179 | HUnresolvedInstanceFieldSet* instruction) { |
| 6180 | FieldAccessCallingConventionX86 calling_convention; |
| 6181 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6182 | instruction, instruction->GetFieldType(), calling_convention); |
| 6183 | } |
| 6184 | |
| 6185 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 6186 | HUnresolvedInstanceFieldSet* instruction) { |
| 6187 | FieldAccessCallingConventionX86 calling_convention; |
| 6188 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6189 | instruction->GetFieldType(), |
| 6190 | instruction->GetFieldIndex(), |
| 6191 | instruction->GetDexPc(), |
| 6192 | calling_convention); |
| 6193 | } |
| 6194 | |
| 6195 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 6196 | HUnresolvedStaticFieldGet* instruction) { |
| 6197 | FieldAccessCallingConventionX86 calling_convention; |
| 6198 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6199 | instruction, instruction->GetFieldType(), calling_convention); |
| 6200 | } |
| 6201 | |
| 6202 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 6203 | HUnresolvedStaticFieldGet* instruction) { |
| 6204 | FieldAccessCallingConventionX86 calling_convention; |
| 6205 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6206 | instruction->GetFieldType(), |
| 6207 | instruction->GetFieldIndex(), |
| 6208 | instruction->GetDexPc(), |
| 6209 | calling_convention); |
| 6210 | } |
| 6211 | |
| 6212 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 6213 | HUnresolvedStaticFieldSet* instruction) { |
| 6214 | FieldAccessCallingConventionX86 calling_convention; |
| 6215 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6216 | instruction, instruction->GetFieldType(), calling_convention); |
| 6217 | } |
| 6218 | |
| 6219 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 6220 | HUnresolvedStaticFieldSet* instruction) { |
| 6221 | FieldAccessCallingConventionX86 calling_convention; |
| 6222 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6223 | instruction->GetFieldType(), |
| 6224 | instruction->GetFieldIndex(), |
| 6225 | instruction->GetDexPc(), |
| 6226 | calling_convention); |
| 6227 | } |
| 6228 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6229 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6230 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 6231 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 6232 | ? Location::RequiresRegister() |
| 6233 | : Location::Any(); |
| 6234 | locations->SetInAt(0, loc); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6235 | } |
| 6236 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6237 | void CodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 6238 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6239 | return; |
| 6240 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 6241 | LocationSummary* locations = instruction->GetLocations(); |
| 6242 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6243 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 6244 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6245 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 6246 | } |
| 6247 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6248 | void CodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6249 | SlowPathCode* slow_path = new (GetScopedAllocator()) NullCheckSlowPathX86(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6250 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6251 | |
| 6252 | LocationSummary* locations = instruction->GetLocations(); |
| 6253 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6254 | |
| 6255 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 6256 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 6257 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6258 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 6259 | } else { |
| 6260 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 6261 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 6262 | __ jmp(slow_path->GetEntryLabel()); |
| 6263 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6264 | } |
| 6265 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6266 | } |
| 6267 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 6268 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6269 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 6270 | } |
| 6271 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6272 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6273 | bool object_array_get_with_read_barrier = |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 6274 | gUseReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 6275 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6276 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 6277 | object_array_get_with_read_barrier |
| 6278 | ? LocationSummary::kCallOnSlowPath |
| 6279 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6280 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6281 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6282 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 6283 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6284 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6285 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 6286 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6287 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6288 | // The output overlaps in case of long: we don't want the low move |
| 6289 | // to overwrite the array's location. Likewise, in the case of an |
| 6290 | // object array get with read barriers enabled, we do not want the |
| 6291 | // move to overwrite the array's location, as we need it to emit |
| 6292 | // the read barrier. |
| 6293 | locations->SetOut( |
| 6294 | Location::RequiresRegister(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6295 | (instruction->GetType() == DataType::Type::kInt64 || object_array_get_with_read_barrier) |
| 6296 | ? Location::kOutputOverlap |
| 6297 | : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 6298 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6299 | } |
| 6300 | |
| 6301 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 6302 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6303 | Location obj_loc = locations->InAt(0); |
| 6304 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6305 | Location index = locations->InAt(1); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6306 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6307 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6308 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6309 | DataType::Type type = instruction->GetType(); |
Ulya Trafimovich | 322eced | 2021-06-02 15:39:36 +0100 | [diff] [blame] | 6310 | if (type == DataType::Type::kReference) { |
| 6311 | static_assert( |
| 6312 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6313 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 6314 | // /* HeapReference<Object> */ out = |
| 6315 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 6316 | if (gUseReadBarrier && kUseBakerReadBarrier) { |
Ulya Trafimovich | 322eced | 2021-06-02 15:39:36 +0100 | [diff] [blame] | 6317 | // Note that a potential implicit null check is handled in this |
| 6318 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 6319 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 6320 | instruction, out_loc, obj, data_offset, index, /* needs_null_check= */ true); |
| 6321 | } else { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6322 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6323 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6324 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Ulya Trafimovich | 322eced | 2021-06-02 15:39:36 +0100 | [diff] [blame] | 6325 | // If read barriers are enabled, emit read barriers other than |
| 6326 | // Baker's using a slow path (and also unpoison the loaded |
| 6327 | // reference, if heap poisoning is enabled). |
| 6328 | if (index.IsConstant()) { |
| 6329 | uint32_t offset = |
| 6330 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 6331 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 6332 | } else { |
| 6333 | codegen_->MaybeGenerateReadBarrierSlow( |
| 6334 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 6335 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6336 | } |
Ulya Trafimovich | 322eced | 2021-06-02 15:39:36 +0100 | [diff] [blame] | 6337 | } else if (type == DataType::Type::kUint16 |
| 6338 | && mirror::kUseStringCompression |
| 6339 | && instruction->IsStringCharAt()) { |
| 6340 | // Branch cases into compressed and uncompressed for each index's type. |
| 6341 | Register out = out_loc.AsRegister<Register>(); |
| 6342 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 6343 | NearLabel done, not_compressed; |
| 6344 | __ testb(Address(obj, count_offset), Immediate(1)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6345 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Ulya Trafimovich | 322eced | 2021-06-02 15:39:36 +0100 | [diff] [blame] | 6346 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 6347 | "Expecting 0=compressed, 1=uncompressed"); |
| 6348 | __ j(kNotZero, ¬_compressed); |
| 6349 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| 6350 | __ jmp(&done); |
| 6351 | __ Bind(¬_compressed); |
| 6352 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 6353 | __ Bind(&done); |
| 6354 | } else { |
Ulya Trafimovich | c8451cb | 2021-06-02 17:35:16 +0100 | [diff] [blame] | 6355 | ScaleFactor scale = CodeGenerator::ScaleFactorForType(type); |
| 6356 | Address src = CodeGeneratorX86::ArrayAddress(obj, index, scale, data_offset); |
Ulya Trafimovich | 322eced | 2021-06-02 15:39:36 +0100 | [diff] [blame] | 6357 | codegen_->LoadFromMemoryNoBarrier(type, out_loc, src, instruction); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6358 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6359 | } |
| 6360 | |
| 6361 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6362 | DataType::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6363 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6364 | bool needs_write_barrier = |
| 6365 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6366 | bool needs_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6367 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6368 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 6369 | instruction, |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6370 | needs_type_check ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 6371 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6372 | bool is_byte_type = DataType::Size(value_type) == 1u; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6373 | // We need the inputs to be different than the output in case of long operation. |
| 6374 | // In case of a byte operation, the register allocator does not support multiple |
| 6375 | // inputs that die at entry with one in a specific register. |
| 6376 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6377 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 6378 | if (is_byte_type) { |
| 6379 | // Ensure the value is in a byte register. |
| 6380 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6381 | } else if (DataType::IsFloatingPointType(value_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6382 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6383 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6384 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 6385 | } |
| 6386 | if (needs_write_barrier) { |
Santiago Aboy Solanes | d422960 | 2023-01-03 16:20:50 +0000 | [diff] [blame] | 6387 | // Used by reference poisoning or emitting write barrier. |
| 6388 | locations->AddTemp(Location::RequiresRegister()); |
| 6389 | if (instruction->GetWriteBarrierKind() != WriteBarrierKind::kDontEmit) { |
| 6390 | // Only used when emitting a write barrier. Ensure the card is in a byte register. |
| 6391 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 6392 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6393 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6394 | } |
| 6395 | |
| 6396 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 6397 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6398 | Location array_loc = locations->InAt(0); |
| 6399 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6400 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 6401 | Location value = locations->InAt(2); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6402 | DataType::Type value_type = instruction->GetComponentType(); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6403 | bool needs_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6404 | bool needs_write_barrier = |
| 6405 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6406 | |
| 6407 | switch (value_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6408 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6409 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6410 | case DataType::Type::kInt8: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6411 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6412 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_1, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6413 | if (value.IsRegister()) { |
| 6414 | __ movb(address, value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6415 | } else { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 6416 | __ movb(address, Immediate(CodeGenerator::GetInt8ValueOf(value.GetConstant()))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6417 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6418 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6419 | break; |
| 6420 | } |
| 6421 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6422 | case DataType::Type::kUint16: |
| 6423 | case DataType::Type::kInt16: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6424 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6425 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_2, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6426 | if (value.IsRegister()) { |
| 6427 | __ movw(address, value.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6428 | } else { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 6429 | __ movw(address, Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6430 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6431 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6432 | break; |
| 6433 | } |
| 6434 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6435 | case DataType::Type::kReference: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6436 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6437 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6438 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6439 | if (!value.IsRegister()) { |
| 6440 | // Just setting null. |
| 6441 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 6442 | DCHECK(value.IsConstant()) << value; |
| 6443 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6444 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6445 | DCHECK(!needs_write_barrier); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6446 | DCHECK(!needs_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6447 | break; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6448 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6449 | |
| 6450 | DCHECK(needs_write_barrier); |
| 6451 | Register register_value = value.AsRegister<Register>(); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6452 | Location temp_loc = locations->GetTemp(0); |
| 6453 | Register temp = temp_loc.AsRegister<Register>(); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6454 | |
| 6455 | bool can_value_be_null = instruction->GetValueCanBeNull(); |
| 6456 | NearLabel do_store; |
| 6457 | if (can_value_be_null) { |
| 6458 | __ testl(register_value, register_value); |
| 6459 | __ j(kEqual, &do_store); |
| 6460 | } |
| 6461 | |
| 6462 | SlowPathCode* slow_path = nullptr; |
| 6463 | if (needs_type_check) { |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6464 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathX86(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6465 | codegen_->AddSlowPath(slow_path); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6466 | |
| 6467 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6468 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6469 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6470 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6471 | // Note that when Baker read barriers are enabled, the type |
| 6472 | // checks are performed without read barriers. This is fine, |
| 6473 | // even in the case where a class object is in the from-space |
| 6474 | // after the flip, as a comparison involving such a type would |
| 6475 | // not produce a false positive; it may of course produce a |
| 6476 | // false negative, in which case we would take the ArraySet |
| 6477 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6478 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6479 | // /* HeapReference<Class> */ temp = array->klass_ |
| 6480 | __ movl(temp, Address(array, class_offset)); |
| 6481 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6482 | __ MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6483 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6484 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 6485 | __ movl(temp, Address(temp, component_offset)); |
| 6486 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 6487 | // nor the object reference in `register_value->klass`, as |
| 6488 | // we are comparing two poisoned references. |
| 6489 | __ cmpl(temp, Address(register_value, class_offset)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6490 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6491 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6492 | NearLabel do_put; |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6493 | __ j(kEqual, &do_put); |
| 6494 | // If heap poisoning is enabled, the `temp` reference has |
| 6495 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6496 | __ MaybeUnpoisonHeapReference(temp); |
| 6497 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6498 | // If heap poisoning is enabled, no need to unpoison the |
| 6499 | // heap reference loaded below, as it is only used for a |
| 6500 | // comparison with null. |
| 6501 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 6502 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6503 | __ Bind(&do_put); |
| 6504 | } else { |
| 6505 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6506 | } |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6507 | } |
| 6508 | |
Santiago Aboy Solanes | d422960 | 2023-01-03 16:20:50 +0000 | [diff] [blame] | 6509 | if (instruction->GetWriteBarrierKind() != WriteBarrierKind::kDontEmit) { |
| 6510 | DCHECK_EQ(instruction->GetWriteBarrierKind(), WriteBarrierKind::kEmitNoNullCheck) |
| 6511 | << " Already null checked so we shouldn't do it again."; |
| 6512 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 6513 | codegen_->MarkGCCard(temp, |
| 6514 | card, |
| 6515 | array, |
| 6516 | value.AsRegister<Register>(), |
| 6517 | /* emit_null_check= */ false); |
| 6518 | } |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6519 | |
| 6520 | if (can_value_be_null) { |
| 6521 | DCHECK(do_store.IsLinked()); |
| 6522 | __ Bind(&do_store); |
| 6523 | } |
| 6524 | |
| 6525 | Register source = register_value; |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6526 | if (kPoisonHeapReferences) { |
| 6527 | __ movl(temp, register_value); |
| 6528 | __ PoisonHeapReference(temp); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6529 | source = temp; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6530 | } |
| 6531 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6532 | __ movl(address, source); |
| 6533 | |
| 6534 | if (can_value_be_null || !needs_type_check) { |
| 6535 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6536 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6537 | |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6538 | if (slow_path != nullptr) { |
| 6539 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6540 | } |
| 6541 | |
| 6542 | break; |
| 6543 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6544 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6545 | case DataType::Type::kInt32: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6546 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6547 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6548 | if (value.IsRegister()) { |
| 6549 | __ movl(address, value.AsRegister<Register>()); |
| 6550 | } else { |
| 6551 | DCHECK(value.IsConstant()) << value; |
| 6552 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 6553 | __ movl(address, Immediate(v)); |
| 6554 | } |
| 6555 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6556 | break; |
| 6557 | } |
| 6558 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6559 | case DataType::Type::kInt64: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6560 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6561 | if (value.IsRegisterPair()) { |
| 6562 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 6563 | value.AsRegisterPairLow<Register>()); |
| 6564 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6565 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 6566 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6567 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6568 | DCHECK(value.IsConstant()); |
| 6569 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
| 6570 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 6571 | Immediate(Low32Bits(val))); |
| 6572 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6573 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 6574 | Immediate(High32Bits(val))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6575 | } |
| 6576 | break; |
| 6577 | } |
| 6578 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6579 | case DataType::Type::kFloat32: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6580 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6581 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6582 | if (value.IsFpuRegister()) { |
| 6583 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 6584 | } else { |
| 6585 | DCHECK(value.IsConstant()); |
| 6586 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 6587 | __ movl(address, Immediate(v)); |
| 6588 | } |
| 6589 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6590 | break; |
| 6591 | } |
| 6592 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6593 | case DataType::Type::kFloat64: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6594 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6595 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6596 | if (value.IsFpuRegister()) { |
| 6597 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 6598 | } else { |
| 6599 | DCHECK(value.IsConstant()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6600 | Address address_hi = |
| 6601 | CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset + kX86WordSize); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6602 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 6603 | __ movl(address, Immediate(Low32Bits(v))); |
| 6604 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6605 | __ movl(address_hi, Immediate(High32Bits(v))); |
| 6606 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6607 | break; |
| 6608 | } |
| 6609 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 6610 | case DataType::Type::kUint32: |
| 6611 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6612 | case DataType::Type::kVoid: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6613 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 6614 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6615 | } |
| 6616 | } |
| 6617 | |
| 6618 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6619 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 6620 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6621 | if (!instruction->IsEmittedAtUseSite()) { |
| 6622 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6623 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6624 | } |
| 6625 | |
| 6626 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6627 | if (instruction->IsEmittedAtUseSite()) { |
| 6628 | return; |
| 6629 | } |
| 6630 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6631 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 6632 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6633 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 6634 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6635 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6636 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6637 | // Mask out most significant bit in case the array is String's array of char. |
| 6638 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6639 | __ shrl(out, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6640 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6641 | } |
| 6642 | |
| 6643 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6644 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6645 | InvokeRuntimeCallingConvention calling_convention; |
| 6646 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6647 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 6648 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 6649 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6650 | HInstruction* length = instruction->InputAt(1); |
| 6651 | if (!length->IsEmittedAtUseSite()) { |
| 6652 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 6653 | } |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6654 | // Need register to see array's length. |
| 6655 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 6656 | locations->AddTemp(Location::RequiresRegister()); |
| 6657 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6658 | } |
| 6659 | |
| 6660 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6661 | const bool is_string_compressed_char_at = |
| 6662 | mirror::kUseStringCompression && instruction->IsStringCharAt(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6663 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 6664 | Location index_loc = locations->InAt(0); |
| 6665 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6666 | SlowPathCode* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6667 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathX86(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6668 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 6669 | if (length_loc.IsConstant()) { |
| 6670 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 6671 | if (index_loc.IsConstant()) { |
| 6672 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 6673 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 6674 | if (index < 0 || index >= length) { |
| 6675 | codegen_->AddSlowPath(slow_path); |
| 6676 | __ jmp(slow_path->GetEntryLabel()); |
| 6677 | } else { |
| 6678 | // Some optimization after BCE may have generated this, and we should not |
| 6679 | // generate a bounds check if it is a valid range. |
| 6680 | } |
| 6681 | return; |
| 6682 | } |
| 6683 | |
| 6684 | // We have to reverse the jump condition because the length is the constant. |
| 6685 | Register index_reg = index_loc.AsRegister<Register>(); |
| 6686 | __ cmpl(index_reg, Immediate(length)); |
| 6687 | codegen_->AddSlowPath(slow_path); |
| 6688 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 6689 | } else { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6690 | HInstruction* array_length = instruction->InputAt(1); |
| 6691 | if (array_length->IsEmittedAtUseSite()) { |
| 6692 | // Address the length field in the array. |
| 6693 | DCHECK(array_length->IsArrayLength()); |
| 6694 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 6695 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 6696 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6697 | if (is_string_compressed_char_at) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6698 | // TODO: if index_loc.IsConstant(), compare twice the index (to compensate for |
| 6699 | // the string compression flag) with the in-memory length and avoid the temporary. |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6700 | Register length_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 6701 | __ movl(length_reg, array_len); |
| 6702 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6703 | __ shrl(length_reg, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6704 | codegen_->GenerateIntCompare(length_reg, index_loc); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6705 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6706 | // Checking bounds for general case: |
| 6707 | // Array of char or string's array with feature compression off. |
| 6708 | if (index_loc.IsConstant()) { |
| 6709 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 6710 | __ cmpl(array_len, Immediate(value)); |
| 6711 | } else { |
| 6712 | __ cmpl(array_len, index_loc.AsRegister<Register>()); |
| 6713 | } |
| 6714 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6715 | } |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 6716 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6717 | codegen_->GenerateIntCompare(length_loc, index_loc); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 6718 | } |
| 6719 | codegen_->AddSlowPath(slow_path); |
| 6720 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 6721 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6722 | } |
| 6723 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6724 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6725 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6726 | } |
| 6727 | |
| 6728 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 6729 | if (instruction->GetNext()->IsSuspendCheck() && |
| 6730 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 6731 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 6732 | // The back edge will generate the suspend check. |
| 6733 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 6734 | } |
| 6735 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6736 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 6737 | } |
| 6738 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6739 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6740 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6741 | instruction, LocationSummary::kCallOnSlowPath); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 6742 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 6743 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 6744 | // registers in full width (since the runtime only saves/restores lower part). |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6745 | locations->SetCustomSlowPathCallerSaves( |
| 6746 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6747 | } |
| 6748 | |
| 6749 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6750 | HBasicBlock* block = instruction->GetBlock(); |
| 6751 | if (block->GetLoopInformation() != nullptr) { |
| 6752 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 6753 | // The back edge will generate the suspend check. |
| 6754 | return; |
| 6755 | } |
| 6756 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 6757 | // The goto will generate the suspend check. |
| 6758 | return; |
| 6759 | } |
| 6760 | GenerateSuspendCheck(instruction, nullptr); |
| 6761 | } |
| 6762 | |
| 6763 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 6764 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6765 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6766 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 6767 | if (slow_path == nullptr) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6768 | slow_path = |
| 6769 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathX86(instruction, successor); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6770 | instruction->SetSlowPath(slow_path); |
| 6771 | codegen_->AddSlowPath(slow_path); |
| 6772 | if (successor != nullptr) { |
| 6773 | DCHECK(successor->IsLoopHeader()); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6774 | } |
| 6775 | } else { |
| 6776 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 6777 | } |
| 6778 | |
Vladimir Marko | 254a858 | 2021-11-29 14:08:37 +0000 | [diff] [blame] | 6779 | __ fs()->testl(Address::Absolute(Thread::ThreadFlagsOffset<kX86PointerSize>().Int32Value()), |
| 6780 | Immediate(Thread::SuspendOrCheckpointRequestFlags())); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6781 | if (successor == nullptr) { |
Vladimir Marko | 254a858 | 2021-11-29 14:08:37 +0000 | [diff] [blame] | 6782 | __ j(kNotZero, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6783 | __ Bind(slow_path->GetReturnLabel()); |
| 6784 | } else { |
Vladimir Marko | 254a858 | 2021-11-29 14:08:37 +0000 | [diff] [blame] | 6785 | __ j(kZero, codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6786 | __ jmp(slow_path->GetEntryLabel()); |
| 6787 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6788 | } |
| 6789 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6790 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 6791 | return codegen_->GetAssembler(); |
| 6792 | } |
| 6793 | |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6794 | void ParallelMoveResolverX86::MoveMemoryToMemory(int dst, int src, int number_of_words) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6795 | ScratchRegisterScope ensure_scratch( |
| 6796 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 6797 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 6798 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6799 | |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6800 | // Now that temp register is available (possibly spilled), move blocks of memory. |
| 6801 | for (int i = 0; i < number_of_words; i++) { |
| 6802 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 6803 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 6804 | stack_offset += kX86WordSize; |
| 6805 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6806 | } |
| 6807 | |
| 6808 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6809 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6810 | Location source = move->GetSource(); |
| 6811 | Location destination = move->GetDestination(); |
| 6812 | |
| 6813 | if (source.IsRegister()) { |
| 6814 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6815 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6816 | } else if (destination.IsFpuRegister()) { |
| 6817 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6818 | } else { |
| 6819 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6820 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6821 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6822 | } else if (source.IsRegisterPair()) { |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 6823 | if (destination.IsRegisterPair()) { |
| 6824 | __ movl(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 6825 | DCHECK_NE(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>()); |
| 6826 | __ movl(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
| 6827 | } else if (destination.IsFpuRegister()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6828 | size_t elem_size = DataType::Size(DataType::Type::kInt32); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 6829 | // Push the 2 source registers to the stack. |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 6830 | __ pushl(source.AsRegisterPairHigh<Register>()); |
| 6831 | __ cfi().AdjustCFAOffset(elem_size); |
| 6832 | __ pushl(source.AsRegisterPairLow<Register>()); |
| 6833 | __ cfi().AdjustCFAOffset(elem_size); |
| 6834 | // Load the destination register. |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6835 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 6836 | // And remove the temporary stack space we allocated. |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 6837 | codegen_->DecreaseFrame(2 * elem_size); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 6838 | } else { |
| 6839 | DCHECK(destination.IsDoubleStackSlot()); |
| 6840 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
| 6841 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
| 6842 | source.AsRegisterPairHigh<Register>()); |
| 6843 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6844 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6845 | if (destination.IsRegister()) { |
| 6846 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
| 6847 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6848 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6849 | } else if (destination.IsRegisterPair()) { |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 6850 | size_t elem_size = DataType::Size(DataType::Type::kInt32); |
| 6851 | // Create stack space for 2 elements. |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 6852 | codegen_->IncreaseFrame(2 * elem_size); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 6853 | // Store the source register. |
| 6854 | __ movsd(Address(ESP, 0), source.AsFpuRegister<XmmRegister>()); |
| 6855 | // And pop the values into destination registers. |
| 6856 | __ popl(destination.AsRegisterPairLow<Register>()); |
| 6857 | __ cfi().AdjustCFAOffset(-elem_size); |
| 6858 | __ popl(destination.AsRegisterPairHigh<Register>()); |
| 6859 | __ cfi().AdjustCFAOffset(-elem_size); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6860 | } else if (destination.IsStackSlot()) { |
| 6861 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6862 | } else if (destination.IsDoubleStackSlot()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6863 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6864 | } else { |
| 6865 | DCHECK(destination.IsSIMDStackSlot()); |
| 6866 | __ movups(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6867 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6868 | } else if (source.IsStackSlot()) { |
| 6869 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6870 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6871 | } else if (destination.IsFpuRegister()) { |
| 6872 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6873 | } else { |
| 6874 | DCHECK(destination.IsStackSlot()); |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6875 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 1); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6876 | } |
| 6877 | } else if (source.IsDoubleStackSlot()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6878 | if (destination.IsRegisterPair()) { |
| 6879 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 6880 | __ movl(destination.AsRegisterPairHigh<Register>(), |
| 6881 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 6882 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6883 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 6884 | } else { |
| 6885 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6886 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 2); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6887 | } |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6888 | } else if (source.IsSIMDStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6889 | if (destination.IsFpuRegister()) { |
| 6890 | __ movups(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 6891 | } else { |
| 6892 | DCHECK(destination.IsSIMDStackSlot()); |
| 6893 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 4); |
| 6894 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 6895 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6896 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 6897 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 6898 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6899 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 6900 | if (value == 0) { |
| 6901 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 6902 | } else { |
| 6903 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 6904 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6905 | } else { |
| 6906 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 6907 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6908 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6909 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6910 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 6911 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6912 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6913 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6914 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 6915 | if (value == 0) { |
| 6916 | // Easy handling of 0.0. |
| 6917 | __ xorps(dest, dest); |
| 6918 | } else { |
| 6919 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6920 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 6921 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 6922 | __ movl(temp, Immediate(value)); |
| 6923 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6924 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6925 | } else { |
| 6926 | DCHECK(destination.IsStackSlot()) << destination; |
| 6927 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 6928 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6929 | } else if (constant->IsLongConstant()) { |
| 6930 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 6931 | int32_t low_value = Low32Bits(value); |
| 6932 | int32_t high_value = High32Bits(value); |
| 6933 | Immediate low(low_value); |
| 6934 | Immediate high(high_value); |
| 6935 | if (destination.IsDoubleStackSlot()) { |
| 6936 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 6937 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 6938 | } else { |
| 6939 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 6940 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 6941 | } |
| 6942 | } else { |
| 6943 | DCHECK(constant->IsDoubleConstant()); |
| 6944 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 6945 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6946 | int32_t low_value = Low32Bits(value); |
| 6947 | int32_t high_value = High32Bits(value); |
| 6948 | Immediate low(low_value); |
| 6949 | Immediate high(high_value); |
| 6950 | if (destination.IsFpuRegister()) { |
| 6951 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 6952 | if (value == 0) { |
| 6953 | // Easy handling of 0.0. |
| 6954 | __ xorpd(dest, dest); |
| 6955 | } else { |
| 6956 | __ pushl(high); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 6957 | __ cfi().AdjustCFAOffset(4); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6958 | __ pushl(low); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 6959 | __ cfi().AdjustCFAOffset(4); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6960 | __ movsd(dest, Address(ESP, 0)); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 6961 | codegen_->DecreaseFrame(8); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6962 | } |
| 6963 | } else { |
| 6964 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6965 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 6966 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 6967 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 6968 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6969 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 6970 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6971 | } |
| 6972 | } |
| 6973 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 6974 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6975 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 6976 | ScratchRegisterScope ensure_scratch( |
| 6977 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 6978 | |
| 6979 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 6980 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 6981 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 6982 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6983 | } |
| 6984 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6985 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6986 | ScratchRegisterScope ensure_scratch( |
| 6987 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 6988 | |
| 6989 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 6990 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 6991 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 6992 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 6993 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6994 | } |
| 6995 | |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6996 | void ParallelMoveResolverX86::Exchange128(XmmRegister reg, int mem) { |
| 6997 | size_t extra_slot = 4 * kX86WordSize; |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 6998 | codegen_->IncreaseFrame(extra_slot); |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6999 | __ movups(Address(ESP, 0), XmmRegister(reg)); |
| 7000 | ExchangeMemory(0, mem + extra_slot, 4); |
| 7001 | __ movups(XmmRegister(reg), Address(ESP, 0)); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 7002 | codegen_->DecreaseFrame(extra_slot); |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 7003 | } |
| 7004 | |
| 7005 | void ParallelMoveResolverX86::ExchangeMemory(int mem1, int mem2, int number_of_words) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 7006 | ScratchRegisterScope ensure_scratch1( |
| 7007 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 7008 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 7009 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 7010 | ScratchRegisterScope ensure_scratch2( |
| 7011 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 7012 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 7013 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 7014 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 7015 | |
| 7016 | // Now that temp registers are available (possibly spilled), exchange blocks of memory. |
| 7017 | for (int i = 0; i < number_of_words; i++) { |
| 7018 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 7019 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 7020 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 7021 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
| 7022 | stack_offset += kX86WordSize; |
| 7023 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 7024 | } |
| 7025 | |
| 7026 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7027 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 7028 | Location source = move->GetSource(); |
| 7029 | Location destination = move->GetDestination(); |
| 7030 | |
| 7031 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 7032 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 7033 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 7034 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 7035 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 7036 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 7037 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7038 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 7039 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7040 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 7041 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 7042 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 1); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 7043 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 7044 | // Use XOR Swap algorithm to avoid a temporary. |
| 7045 | DCHECK_NE(source.reg(), destination.reg()); |
| 7046 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 7047 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 7048 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 7049 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 7050 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 7051 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 7052 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7053 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 7054 | // Take advantage of the 16 bytes in the XMM register. |
| 7055 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 7056 | Address stack(ESP, destination.GetStackIndex()); |
| 7057 | // Load the double into the high doubleword. |
| 7058 | __ movhpd(reg, stack); |
| 7059 | |
| 7060 | // Store the low double into the destination. |
| 7061 | __ movsd(stack, reg); |
| 7062 | |
| 7063 | // Move the high double to the low double. |
| 7064 | __ psrldq(reg, Immediate(8)); |
| 7065 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 7066 | // Take advantage of the 16 bytes in the XMM register. |
| 7067 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 7068 | Address stack(ESP, source.GetStackIndex()); |
| 7069 | // Load the double into the high doubleword. |
| 7070 | __ movhpd(reg, stack); |
| 7071 | |
| 7072 | // Store the low double into the destination. |
| 7073 | __ movsd(stack, reg); |
| 7074 | |
| 7075 | // Move the high double to the low double. |
| 7076 | __ psrldq(reg, Immediate(8)); |
| 7077 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 7078 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 2); |
| 7079 | } else if (source.IsSIMDStackSlot() && destination.IsSIMDStackSlot()) { |
| 7080 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 4); |
| 7081 | } else if (source.IsFpuRegister() && destination.IsSIMDStackSlot()) { |
| 7082 | Exchange128(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 7083 | } else if (destination.IsFpuRegister() && source.IsSIMDStackSlot()) { |
| 7084 | Exchange128(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 7085 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 7086 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 7087 | } |
| 7088 | } |
| 7089 | |
| 7090 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 7091 | __ pushl(static_cast<Register>(reg)); |
| 7092 | } |
| 7093 | |
| 7094 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 7095 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7096 | } |
| 7097 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7098 | HLoadClass::LoadKind CodeGeneratorX86::GetSupportedLoadClassKind( |
| 7099 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7100 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7101 | case HLoadClass::LoadKind::kInvalid: |
| 7102 | LOG(FATAL) << "UNREACHABLE"; |
| 7103 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7104 | case HLoadClass::LoadKind::kReferrersClass: |
| 7105 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7106 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7107 | case HLoadClass::LoadKind::kBootImageRelRo: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7108 | case HLoadClass::LoadKind::kBssEntry: |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 7109 | case HLoadClass::LoadKind::kBssEntryPublic: |
| 7110 | case HLoadClass::LoadKind::kBssEntryPackage: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 7111 | DCHECK(!GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7112 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7113 | case HLoadClass::LoadKind::kJitBootImageAddress: |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7114 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 7115 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7116 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7117 | case HLoadClass::LoadKind::kRuntimeCall: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7118 | break; |
| 7119 | } |
| 7120 | return desired_class_load_kind; |
| 7121 | } |
| 7122 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7123 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7124 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7125 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7126 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7127 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7128 | cls, |
| 7129 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7130 | Location::RegisterLocation(EAX)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7131 | DCHECK_EQ(calling_convention.GetRegisterAt(0), EAX); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7132 | return; |
| 7133 | } |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 7134 | DCHECK_EQ(cls->NeedsAccessCheck(), |
| 7135 | load_kind == HLoadClass::LoadKind::kBssEntryPublic || |
| 7136 | load_kind == HLoadClass::LoadKind::kBssEntryPackage); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7137 | |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 7138 | const bool requires_read_barrier = gUseReadBarrier && !cls->IsInBootImage(); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7139 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7140 | ? LocationSummary::kCallOnSlowPath |
| 7141 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7142 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7143 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 7144 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7145 | } |
| 7146 | |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 7147 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || cls->HasPcRelativeLoadKind()) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7148 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7149 | } |
| 7150 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 7151 | if (call_kind == LocationSummary::kCallOnSlowPath && cls->HasPcRelativeLoadKind()) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 7152 | if (!gUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7153 | // Rely on the type resolution and/or initialization to save everything. |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 7154 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7155 | } else { |
| 7156 | // For non-Baker read barrier we have a temp-clobbering call. |
| 7157 | } |
| 7158 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7159 | } |
| 7160 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7161 | Label* CodeGeneratorX86::NewJitRootClassPatch(const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7162 | dex::TypeIndex type_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7163 | Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7164 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7165 | // Add a patch entry and return the label. |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7166 | jit_class_patches_.emplace_back(&dex_file, type_index.index_); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7167 | PatchInfo<Label>* info = &jit_class_patches_.back(); |
| 7168 | return &info->label; |
| 7169 | } |
| 7170 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7171 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 7172 | // move. |
| 7173 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7174 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7175 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7176 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 7177 | return; |
| 7178 | } |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 7179 | DCHECK_EQ(cls->NeedsAccessCheck(), |
| 7180 | load_kind == HLoadClass::LoadKind::kBssEntryPublic || |
| 7181 | load_kind == HLoadClass::LoadKind::kBssEntryPackage); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 7182 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7183 | LocationSummary* locations = cls->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7184 | Location out_loc = locations->Out(); |
| 7185 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7186 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7187 | bool generate_null_check = false; |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7188 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 7189 | ? kWithoutReadBarrier |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 7190 | : gCompilerReadBarrierOption; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7191 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7192 | case HLoadClass::LoadKind::kReferrersClass: { |
| 7193 | DCHECK(!cls->CanCallRuntime()); |
| 7194 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 7195 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 7196 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 7197 | GenerateGcRootFieldLoad( |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7198 | cls, |
| 7199 | out_loc, |
| 7200 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7201 | /* fixup_label= */ nullptr, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7202 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7203 | break; |
| 7204 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7205 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 7206 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 7207 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7208 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7209 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 7210 | __ leal(out, Address(method_address, CodeGeneratorX86::kPlaceholder32BitOffset)); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7211 | codegen_->RecordBootImageTypePatch(cls); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7212 | break; |
| 7213 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7214 | case HLoadClass::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 7215 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 7216 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 7217 | __ movl(out, Address(method_address, CodeGeneratorX86::kPlaceholder32BitOffset)); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7218 | codegen_->RecordBootImageRelRoPatch(cls->InputAt(0)->AsX86ComputeBaseMethodAddress(), |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 7219 | CodeGenerator::GetBootImageOffset(cls)); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 7220 | break; |
| 7221 | } |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 7222 | case HLoadClass::LoadKind::kBssEntry: |
| 7223 | case HLoadClass::LoadKind::kBssEntryPublic: |
| 7224 | case HLoadClass::LoadKind::kBssEntryPackage: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7225 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 7226 | Address address(method_address, CodeGeneratorX86::kPlaceholder32BitOffset); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7227 | Label* fixup_label = codegen_->NewTypeBssEntryPatch(cls); |
| 7228 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 7229 | // No need for memory fence, thanks to the x86 memory model. |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7230 | generate_null_check = true; |
| 7231 | break; |
| 7232 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7233 | case HLoadClass::LoadKind::kJitBootImageAddress: { |
| 7234 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 7235 | uint32_t address = reinterpret_cast32<uint32_t>(cls->GetClass().Get()); |
| 7236 | DCHECK_NE(address, 0u); |
| 7237 | __ movl(out, Immediate(address)); |
| 7238 | break; |
| 7239 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7240 | case HLoadClass::LoadKind::kJitTableAddress: { |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 7241 | Address address = Address::Absolute(CodeGeneratorX86::kPlaceholder32BitOffset); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7242 | Label* fixup_label = codegen_->NewJitRootClassPatch( |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7243 | cls->GetDexFile(), cls->GetTypeIndex(), cls->GetClass()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7244 | // /* GcRoot<mirror::Class> */ out = *address |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7245 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7246 | break; |
| 7247 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7248 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7249 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7250 | LOG(FATAL) << "UNREACHABLE"; |
| 7251 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7252 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 7253 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7254 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 7255 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 7256 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86(cls, cls); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7257 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 7258 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7259 | if (generate_null_check) { |
| 7260 | __ testl(out, out); |
| 7261 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 7262 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 7263 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7264 | if (cls->MustGenerateClinitCheck()) { |
| 7265 | GenerateClassInitializationCheck(slow_path, out); |
| 7266 | } else { |
| 7267 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 7268 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7269 | } |
| 7270 | } |
| 7271 | |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 7272 | void LocationsBuilderX86::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 7273 | InvokeRuntimeCallingConvention calling_convention; |
| 7274 | Location location = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 7275 | CodeGenerator::CreateLoadMethodHandleRuntimeCallLocationSummary(load, location, location); |
| 7276 | } |
| 7277 | |
| 7278 | void InstructionCodeGeneratorX86::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 7279 | codegen_->GenerateLoadMethodHandleRuntimeCall(load); |
| 7280 | } |
| 7281 | |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 7282 | void LocationsBuilderX86::VisitLoadMethodType(HLoadMethodType* load) { |
| 7283 | InvokeRuntimeCallingConvention calling_convention; |
| 7284 | Location location = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 7285 | CodeGenerator::CreateLoadMethodTypeRuntimeCallLocationSummary(load, location, location); |
| 7286 | } |
| 7287 | |
| 7288 | void InstructionCodeGeneratorX86::VisitLoadMethodType(HLoadMethodType* load) { |
| 7289 | codegen_->GenerateLoadMethodTypeRuntimeCall(load); |
| 7290 | } |
| 7291 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7292 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 7293 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7294 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7295 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7296 | if (check->HasUses()) { |
| 7297 | locations->SetOut(Location::SameAsFirstInput()); |
| 7298 | } |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 7299 | // Rely on the type initialization to save everything we need. |
| 7300 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7301 | } |
| 7302 | |
| 7303 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 7304 | // We assume the class to not be null. |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 7305 | SlowPathCode* slow_path = |
| 7306 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86(check->GetLoadClass(), check); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7307 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 7308 | GenerateClassInitializationCheck(slow_path, |
| 7309 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 7310 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7311 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 7312 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7313 | SlowPathCode* slow_path, Register class_reg) { |
Vladimir Marko | bf12191 | 2019-06-04 13:49:05 +0100 | [diff] [blame] | 7314 | __ cmpb(Address(class_reg, status_byte_offset), Immediate(shifted_visibly_initialized_value)); |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 7315 | __ j(kBelow, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7316 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7317 | } |
| 7318 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7319 | void InstructionCodeGeneratorX86::GenerateBitstringTypeCheckCompare(HTypeCheckInstruction* check, |
| 7320 | Register temp) { |
| 7321 | uint32_t path_to_root = check->GetBitstringPathToRoot(); |
| 7322 | uint32_t mask = check->GetBitstringMask(); |
| 7323 | DCHECK(IsPowerOfTwo(mask + 1)); |
| 7324 | size_t mask_bits = WhichPowerOf2(mask + 1); |
| 7325 | |
| 7326 | if (mask_bits == 16u) { |
| 7327 | // Compare the bitstring in memory. |
| 7328 | __ cmpw(Address(temp, mirror::Class::StatusOffset()), Immediate(path_to_root)); |
| 7329 | } else { |
| 7330 | // /* uint32_t */ temp = temp->status_ |
| 7331 | __ movl(temp, Address(temp, mirror::Class::StatusOffset())); |
| 7332 | // Compare the bitstring bits using SUB. |
| 7333 | __ subl(temp, Immediate(path_to_root)); |
| 7334 | // Shift out bits that do not contribute to the comparison. |
| 7335 | __ shll(temp, Immediate(32u - mask_bits)); |
| 7336 | } |
| 7337 | } |
| 7338 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7339 | HLoadString::LoadKind CodeGeneratorX86::GetSupportedLoadStringKind( |
| 7340 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7341 | switch (desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7342 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7343 | case HLoadString::LoadKind::kBootImageRelRo: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7344 | case HLoadString::LoadKind::kBssEntry: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 7345 | DCHECK(!GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7346 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7347 | case HLoadString::LoadKind::kJitBootImageAddress: |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7348 | case HLoadString::LoadKind::kJitTableAddress: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 7349 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7350 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7351 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7352 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7353 | } |
| 7354 | return desired_string_load_kind; |
| 7355 | } |
| 7356 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 7357 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7358 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7359 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7360 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 7361 | if (load_kind == HLoadString::LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7362 | load_kind == HLoadString::LoadKind::kBootImageRelRo || |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7363 | load_kind == HLoadString::LoadKind::kBssEntry) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7364 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7365 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7366 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 7367 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 7368 | } else { |
| 7369 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 7370 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 7371 | if (!gUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7372 | // Rely on the pResolveString to save everything. |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 7373 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 7374 | } else { |
| 7375 | // For non-Baker read barrier we have a temp-clobbering call. |
| 7376 | } |
| 7377 | } |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 7378 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 7379 | } |
| 7380 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7381 | Label* CodeGeneratorX86::NewJitRootStringPatch(const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7382 | dex::StringIndex string_index, |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7383 | Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7384 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7385 | // Add a patch entry and return the label. |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7386 | jit_string_patches_.emplace_back(&dex_file, string_index.index_); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7387 | PatchInfo<Label>* info = &jit_string_patches_.back(); |
| 7388 | return &info->label; |
| 7389 | } |
| 7390 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7391 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 7392 | // move. |
| 7393 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 7394 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7395 | Location out_loc = locations->Out(); |
| 7396 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7397 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7398 | switch (load->GetLoadKind()) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7399 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 7400 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 7401 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7402 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 7403 | __ leal(out, Address(method_address, CodeGeneratorX86::kPlaceholder32BitOffset)); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7404 | codegen_->RecordBootImageStringPatch(load); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7405 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7406 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7407 | case HLoadString::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7408 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 7409 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 7410 | __ movl(out, Address(method_address, CodeGeneratorX86::kPlaceholder32BitOffset)); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7411 | codegen_->RecordBootImageRelRoPatch(load->InputAt(0)->AsX86ComputeBaseMethodAddress(), |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 7412 | CodeGenerator::GetBootImageOffset(load)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7413 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7414 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7415 | case HLoadString::LoadKind::kBssEntry: { |
| 7416 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 7417 | Address address = Address(method_address, CodeGeneratorX86::kPlaceholder32BitOffset); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7418 | Label* fixup_label = codegen_->NewStringBssEntryPatch(load); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7419 | // /* GcRoot<mirror::String> */ out = *address /* PC-relative */ |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 7420 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, gCompilerReadBarrierOption); |
Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 7421 | // No need for memory fence, thanks to the x86 memory model. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7422 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadStringSlowPathX86(load); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7423 | codegen_->AddSlowPath(slow_path); |
| 7424 | __ testl(out, out); |
| 7425 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 7426 | __ Bind(slow_path->GetExitLabel()); |
| 7427 | return; |
| 7428 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7429 | case HLoadString::LoadKind::kJitBootImageAddress: { |
| 7430 | uint32_t address = reinterpret_cast32<uint32_t>(load->GetString().Get()); |
| 7431 | DCHECK_NE(address, 0u); |
| 7432 | __ movl(out, Immediate(address)); |
| 7433 | return; |
| 7434 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7435 | case HLoadString::LoadKind::kJitTableAddress: { |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 7436 | Address address = Address::Absolute(CodeGeneratorX86::kPlaceholder32BitOffset); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7437 | Label* fixup_label = codegen_->NewJitRootStringPatch( |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7438 | load->GetDexFile(), load->GetStringIndex(), load->GetString()); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7439 | // /* GcRoot<mirror::String> */ out = *address |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 7440 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, gCompilerReadBarrierOption); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7441 | return; |
| 7442 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7443 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 7444 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7445 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7446 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 7447 | // 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] | 7448 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 7449 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7450 | __ movl(calling_convention.GetRegisterAt(0), Immediate(load->GetStringIndex().index_)); |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 7451 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 7452 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 7453 | } |
| 7454 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7455 | static Address GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7456 | return Address::Absolute(Thread::ExceptionOffset<kX86PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7457 | } |
| 7458 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7459 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 7460 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7461 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7462 | locations->SetOut(Location::RequiresRegister()); |
| 7463 | } |
| 7464 | |
| 7465 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7466 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 7467 | } |
| 7468 | |
| 7469 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7470 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7471 | } |
| 7472 | |
| 7473 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 7474 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7475 | } |
| 7476 | |
| 7477 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7478 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 7479 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7480 | InvokeRuntimeCallingConvention calling_convention; |
| 7481 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 7482 | } |
| 7483 | |
| 7484 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 7485 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7486 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7487 | } |
| 7488 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7489 | // Temp is used for read barrier. |
| 7490 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 7491 | if (gUseReadBarrier && |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7492 | !kUseBakerReadBarrier && |
| 7493 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7494 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7495 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 7496 | return 1; |
| 7497 | } |
| 7498 | return 0; |
| 7499 | } |
| 7500 | |
Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 7501 | // Interface case has 2 temps, one for holding the number of interfaces, one for the current |
| 7502 | // interface pointer, the current interface is compared in memory. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7503 | // The other checks have one temp for loading the object's class. |
| 7504 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 7505 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7506 | return 2; |
| 7507 | } |
| 7508 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7509 | } |
| 7510 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7511 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7512 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7513 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7514 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7515 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7516 | case TypeCheckKind::kExactCheck: |
| 7517 | case TypeCheckKind::kAbstractClassCheck: |
| 7518 | case TypeCheckKind::kClassHierarchyCheck: |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7519 | case TypeCheckKind::kArrayObjectCheck: { |
| 7520 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 7521 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 7522 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7523 | break; |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7524 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7525 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7526 | case TypeCheckKind::kUnresolvedCheck: |
| 7527 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7528 | call_kind = LocationSummary::kCallOnSlowPath; |
| 7529 | break; |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7530 | case TypeCheckKind::kBitstringCheck: |
| 7531 | break; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7532 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7533 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7534 | LocationSummary* locations = |
| 7535 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7536 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 7537 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7538 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7539 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7540 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 7541 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 7542 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 7543 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 7544 | } else { |
| 7545 | locations->SetInAt(1, Location::Any()); |
| 7546 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7547 | // Note that TypeCheckSlowPathX86 uses this "out" register too. |
| 7548 | locations->SetOut(Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7549 | // When read barriers are enabled, we need a temporary register for some cases. |
| 7550 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7551 | } |
| 7552 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7553 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7554 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7555 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7556 | Location obj_loc = locations->InAt(0); |
| 7557 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7558 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7559 | Location out_loc = locations->Out(); |
| 7560 | Register out = out_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7561 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 7562 | DCHECK_LE(num_temps, 1u); |
| 7563 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7564 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7565 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7566 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7567 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7568 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7569 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7570 | |
| 7571 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7572 | // Avoid null check if we know obj is not null. |
| 7573 | if (instruction->MustDoNullCheck()) { |
| 7574 | __ testl(obj, obj); |
| 7575 | __ j(kEqual, &zero); |
| 7576 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7577 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7578 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7579 | case TypeCheckKind::kExactCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7580 | ReadBarrierOption read_barrier_option = |
| 7581 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7582 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7583 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7584 | out_loc, |
| 7585 | obj_loc, |
| 7586 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7587 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7588 | if (cls.IsRegister()) { |
| 7589 | __ cmpl(out, cls.AsRegister<Register>()); |
| 7590 | } else { |
| 7591 | DCHECK(cls.IsStackSlot()) << cls; |
| 7592 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 7593 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7594 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7595 | // Classes must be equal for the instanceof to succeed. |
| 7596 | __ j(kNotEqual, &zero); |
| 7597 | __ movl(out, Immediate(1)); |
| 7598 | __ jmp(&done); |
| 7599 | break; |
| 7600 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7601 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7602 | case TypeCheckKind::kAbstractClassCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7603 | ReadBarrierOption read_barrier_option = |
| 7604 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7605 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7606 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7607 | out_loc, |
| 7608 | obj_loc, |
| 7609 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7610 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7611 | // If the class is abstract, we eagerly fetch the super class of the |
| 7612 | // object to avoid doing a comparison we know will fail. |
| 7613 | NearLabel loop; |
| 7614 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7615 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7616 | GenerateReferenceLoadOneRegister(instruction, |
| 7617 | out_loc, |
| 7618 | super_offset, |
| 7619 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7620 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7621 | __ testl(out, out); |
| 7622 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7623 | __ j(kEqual, &done); |
| 7624 | if (cls.IsRegister()) { |
| 7625 | __ cmpl(out, cls.AsRegister<Register>()); |
| 7626 | } else { |
| 7627 | DCHECK(cls.IsStackSlot()) << cls; |
| 7628 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 7629 | } |
| 7630 | __ j(kNotEqual, &loop); |
| 7631 | __ movl(out, Immediate(1)); |
| 7632 | if (zero.IsLinked()) { |
| 7633 | __ jmp(&done); |
| 7634 | } |
| 7635 | break; |
| 7636 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7637 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7638 | case TypeCheckKind::kClassHierarchyCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7639 | ReadBarrierOption read_barrier_option = |
| 7640 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7641 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7642 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7643 | out_loc, |
| 7644 | obj_loc, |
| 7645 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7646 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7647 | // Walk over the class hierarchy to find a match. |
| 7648 | NearLabel loop, success; |
| 7649 | __ Bind(&loop); |
| 7650 | if (cls.IsRegister()) { |
| 7651 | __ cmpl(out, cls.AsRegister<Register>()); |
| 7652 | } else { |
| 7653 | DCHECK(cls.IsStackSlot()) << cls; |
| 7654 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 7655 | } |
| 7656 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7657 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7658 | GenerateReferenceLoadOneRegister(instruction, |
| 7659 | out_loc, |
| 7660 | super_offset, |
| 7661 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7662 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7663 | __ testl(out, out); |
| 7664 | __ j(kNotEqual, &loop); |
| 7665 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7666 | __ jmp(&done); |
| 7667 | __ Bind(&success); |
| 7668 | __ movl(out, Immediate(1)); |
| 7669 | if (zero.IsLinked()) { |
| 7670 | __ jmp(&done); |
| 7671 | } |
| 7672 | break; |
| 7673 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7674 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7675 | case TypeCheckKind::kArrayObjectCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7676 | ReadBarrierOption read_barrier_option = |
| 7677 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7678 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7679 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7680 | out_loc, |
| 7681 | obj_loc, |
| 7682 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7683 | read_barrier_option); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7684 | // Do an exact check. |
| 7685 | NearLabel exact_check; |
| 7686 | if (cls.IsRegister()) { |
| 7687 | __ cmpl(out, cls.AsRegister<Register>()); |
| 7688 | } else { |
| 7689 | DCHECK(cls.IsStackSlot()) << cls; |
| 7690 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 7691 | } |
| 7692 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7693 | // 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] | 7694 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7695 | GenerateReferenceLoadOneRegister(instruction, |
| 7696 | out_loc, |
| 7697 | component_offset, |
| 7698 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7699 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7700 | __ testl(out, out); |
| 7701 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7702 | __ j(kEqual, &done); |
| 7703 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 7704 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7705 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7706 | __ movl(out, Immediate(1)); |
| 7707 | __ jmp(&done); |
| 7708 | break; |
| 7709 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7710 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7711 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7712 | // No read barrier since the slow path will retry upon failure. |
| 7713 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7714 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7715 | out_loc, |
| 7716 | obj_loc, |
| 7717 | class_offset, |
| 7718 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7719 | if (cls.IsRegister()) { |
| 7720 | __ cmpl(out, cls.AsRegister<Register>()); |
| 7721 | } else { |
| 7722 | DCHECK(cls.IsStackSlot()) << cls; |
| 7723 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 7724 | } |
| 7725 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7726 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7727 | instruction, /* is_fatal= */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7728 | codegen_->AddSlowPath(slow_path); |
| 7729 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 7730 | __ movl(out, Immediate(1)); |
| 7731 | if (zero.IsLinked()) { |
| 7732 | __ jmp(&done); |
| 7733 | } |
| 7734 | break; |
| 7735 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7736 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 7737 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7738 | case TypeCheckKind::kInterfaceCheck: { |
| 7739 | // 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] | 7740 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7741 | // cases. |
| 7742 | // |
| 7743 | // We cannot directly call the InstanceofNonTrivial runtime |
| 7744 | // entry point without resorting to a type checking slow path |
| 7745 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 7746 | // require to assign fixed registers for the inputs of this |
| 7747 | // HInstanceOf instruction (following the runtime calling |
| 7748 | // convention), which might be cluttered by the potential first |
| 7749 | // read barrier emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7750 | // |
| 7751 | // TODO: Introduce a new runtime entry point taking the object |
| 7752 | // to test (instead of its class) as argument, and let it deal |
| 7753 | // with the read barrier issues. This will let us refactor this |
| 7754 | // case of the `switch` code as it was previously (with a direct |
| 7755 | // call to the runtime not using a type checking slow path). |
| 7756 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7757 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7758 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7759 | instruction, /* is_fatal= */ false); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7760 | codegen_->AddSlowPath(slow_path); |
| 7761 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7762 | if (zero.IsLinked()) { |
| 7763 | __ jmp(&done); |
| 7764 | } |
| 7765 | break; |
| 7766 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7767 | |
| 7768 | case TypeCheckKind::kBitstringCheck: { |
| 7769 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7770 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7771 | out_loc, |
| 7772 | obj_loc, |
| 7773 | class_offset, |
| 7774 | kWithoutReadBarrier); |
| 7775 | |
| 7776 | GenerateBitstringTypeCheckCompare(instruction, out); |
| 7777 | __ j(kNotEqual, &zero); |
| 7778 | __ movl(out, Immediate(1)); |
| 7779 | __ jmp(&done); |
| 7780 | break; |
| 7781 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7782 | } |
| 7783 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7784 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7785 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7786 | __ xorl(out, out); |
| 7787 | } |
| 7788 | |
| 7789 | if (done.IsLinked()) { |
| 7790 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7791 | } |
| 7792 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7793 | if (slow_path != nullptr) { |
| 7794 | __ Bind(slow_path->GetExitLabel()); |
| 7795 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7796 | } |
| 7797 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7798 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7799 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7800 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7801 | LocationSummary* locations = |
| 7802 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7803 | locations->SetInAt(0, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7804 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 7805 | // Require a register for the interface check since there is a loop that compares the class to |
| 7806 | // a memory address. |
| 7807 | locations->SetInAt(1, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7808 | } else if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 7809 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 7810 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 7811 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7812 | } else { |
| 7813 | locations->SetInAt(1, Location::Any()); |
| 7814 | } |
Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 7815 | // 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] | 7816 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
| 7817 | } |
| 7818 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7819 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7820 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7821 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7822 | Location obj_loc = locations->InAt(0); |
| 7823 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7824 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7825 | Location temp_loc = locations->GetTemp(0); |
| 7826 | Register temp = temp_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7827 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 7828 | DCHECK_GE(num_temps, 1u); |
| 7829 | DCHECK_LE(num_temps, 2u); |
| 7830 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 7831 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7832 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7833 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7834 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 7835 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 7836 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 7837 | const uint32_t object_array_data_offset = |
| 7838 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7839 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7840 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7841 | SlowPathCode* type_check_slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7842 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
| 7843 | instruction, is_type_check_slow_path_fatal); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7844 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7845 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7846 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7847 | // Avoid null check if we know obj is not null. |
| 7848 | if (instruction->MustDoNullCheck()) { |
| 7849 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7850 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7851 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7852 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7853 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7854 | case TypeCheckKind::kExactCheck: |
| 7855 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7856 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7857 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7858 | temp_loc, |
| 7859 | obj_loc, |
| 7860 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7861 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7862 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7863 | if (cls.IsRegister()) { |
| 7864 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 7865 | } else { |
| 7866 | DCHECK(cls.IsStackSlot()) << cls; |
| 7867 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 7868 | } |
| 7869 | // Jump to slow path for throwing the exception or doing a |
| 7870 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7871 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7872 | break; |
| 7873 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7874 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7875 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7876 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7877 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7878 | temp_loc, |
| 7879 | obj_loc, |
| 7880 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7881 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7882 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7883 | // If the class is abstract, we eagerly fetch the super class of the |
| 7884 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7885 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7886 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7887 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7888 | GenerateReferenceLoadOneRegister(instruction, |
| 7889 | temp_loc, |
| 7890 | super_offset, |
| 7891 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7892 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7893 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7894 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 7895 | // exception. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7896 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7897 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7898 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7899 | // Otherwise, compare the classes |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7900 | if (cls.IsRegister()) { |
| 7901 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 7902 | } else { |
| 7903 | DCHECK(cls.IsStackSlot()) << cls; |
| 7904 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 7905 | } |
| 7906 | __ j(kNotEqual, &loop); |
| 7907 | break; |
| 7908 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7909 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7910 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7911 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7912 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7913 | temp_loc, |
| 7914 | obj_loc, |
| 7915 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7916 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7917 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7918 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7919 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7920 | __ Bind(&loop); |
| 7921 | if (cls.IsRegister()) { |
| 7922 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 7923 | } else { |
| 7924 | DCHECK(cls.IsStackSlot()) << cls; |
| 7925 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 7926 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7927 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7928 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7929 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7930 | GenerateReferenceLoadOneRegister(instruction, |
| 7931 | temp_loc, |
| 7932 | super_offset, |
| 7933 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7934 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7935 | |
| 7936 | // If the class reference currently in `temp` is not null, jump |
| 7937 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7938 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7939 | __ j(kNotZero, &loop); |
| 7940 | // Otherwise, jump to the slow path to throw the exception.; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7941 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7942 | break; |
| 7943 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7944 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7945 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7946 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7947 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7948 | temp_loc, |
| 7949 | obj_loc, |
| 7950 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7951 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7952 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7953 | // Do an exact check. |
| 7954 | if (cls.IsRegister()) { |
| 7955 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 7956 | } else { |
| 7957 | DCHECK(cls.IsStackSlot()) << cls; |
| 7958 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 7959 | } |
| 7960 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7961 | |
| 7962 | // 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] | 7963 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7964 | GenerateReferenceLoadOneRegister(instruction, |
| 7965 | temp_loc, |
| 7966 | component_offset, |
| 7967 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7968 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7969 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7970 | // If the component type is null (i.e. the object not an array), jump to the slow path to |
| 7971 | // throw the exception. Otherwise proceed with the check. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7972 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7973 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7974 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7975 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7976 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7977 | break; |
| 7978 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7979 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 7980 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7981 | // 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] | 7982 | // We cannot directly call the CheckCast runtime entry point |
| 7983 | // without resorting to a type checking slow path here (i.e. by |
| 7984 | // calling InvokeRuntime directly), as it would require to |
| 7985 | // assign fixed registers for the inputs of this HInstanceOf |
| 7986 | // instruction (following the runtime calling convention), which |
| 7987 | // might be cluttered by the potential first read barrier |
| 7988 | // emission at the beginning of this method. |
| 7989 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7990 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7991 | |
| 7992 | case TypeCheckKind::kInterfaceCheck: { |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 7993 | // Fast path for the interface check. Try to avoid read barriers to improve the fast path. |
| 7994 | // We can not get false positives by doing this. |
| 7995 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7996 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7997 | temp_loc, |
| 7998 | obj_loc, |
| 7999 | class_offset, |
| 8000 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 8001 | |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 8002 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 8003 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8004 | temp_loc, |
| 8005 | temp_loc, |
| 8006 | iftable_offset, |
| 8007 | kWithoutReadBarrier); |
| 8008 | // Iftable is never null. |
| 8009 | __ movl(maybe_temp2_loc.AsRegister<Register>(), Address(temp, array_length_offset)); |
| 8010 | // Maybe poison the `cls` for direct comparison with memory. |
| 8011 | __ MaybePoisonHeapReference(cls.AsRegister<Register>()); |
| 8012 | // Loop through the iftable and check if any class matches. |
| 8013 | NearLabel start_loop; |
| 8014 | __ Bind(&start_loop); |
| 8015 | // Need to subtract first to handle the empty array case. |
| 8016 | __ subl(maybe_temp2_loc.AsRegister<Register>(), Immediate(2)); |
| 8017 | __ j(kNegative, type_check_slow_path->GetEntryLabel()); |
| 8018 | // Go to next interface if the classes do not match. |
| 8019 | __ cmpl(cls.AsRegister<Register>(), |
| 8020 | CodeGeneratorX86::ArrayAddress(temp, |
| 8021 | maybe_temp2_loc, |
| 8022 | TIMES_4, |
| 8023 | object_array_data_offset)); |
| 8024 | __ j(kNotEqual, &start_loop); |
| 8025 | // If `cls` was poisoned above, unpoison it. |
| 8026 | __ MaybeUnpoisonHeapReference(cls.AsRegister<Register>()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 8027 | break; |
| 8028 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 8029 | |
| 8030 | case TypeCheckKind::kBitstringCheck: { |
| 8031 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 8032 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8033 | temp_loc, |
| 8034 | obj_loc, |
| 8035 | class_offset, |
| 8036 | kWithoutReadBarrier); |
| 8037 | |
| 8038 | GenerateBitstringTypeCheckCompare(instruction, temp); |
| 8039 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
| 8040 | break; |
| 8041 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 8042 | } |
| 8043 | __ Bind(&done); |
| 8044 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8045 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 8046 | } |
| 8047 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 8048 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8049 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 8050 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 8051 | InvokeRuntimeCallingConvention calling_convention; |
| 8052 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 8053 | } |
| 8054 | |
| 8055 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 8056 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject |
| 8057 | : kQuickUnlockObject, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 8058 | instruction, |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 8059 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 8060 | if (instruction->IsEnter()) { |
| 8061 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 8062 | } else { |
| 8063 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 8064 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 8065 | } |
| 8066 | |
Shalini Salomi Bodapati | dd121f6 | 2018-10-26 15:03:53 +0530 | [diff] [blame] | 8067 | void LocationsBuilderX86::VisitX86AndNot(HX86AndNot* instruction) { |
| 8068 | DCHECK(codegen_->GetInstructionSetFeatures().HasAVX2()); |
| 8069 | DCHECK(DataType::IsIntOrLongType(instruction->GetType())) << instruction->GetType(); |
| 8070 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| 8071 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8072 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8073 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8074 | } |
| 8075 | |
| 8076 | void InstructionCodeGeneratorX86::VisitX86AndNot(HX86AndNot* instruction) { |
| 8077 | LocationSummary* locations = instruction->GetLocations(); |
| 8078 | Location first = locations->InAt(0); |
| 8079 | Location second = locations->InAt(1); |
| 8080 | Location dest = locations->Out(); |
| 8081 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
| 8082 | __ andn(dest.AsRegister<Register>(), |
| 8083 | first.AsRegister<Register>(), |
| 8084 | second.AsRegister<Register>()); |
| 8085 | } else { |
| 8086 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
| 8087 | __ andn(dest.AsRegisterPairLow<Register>(), |
| 8088 | first.AsRegisterPairLow<Register>(), |
| 8089 | second.AsRegisterPairLow<Register>()); |
| 8090 | __ andn(dest.AsRegisterPairHigh<Register>(), |
| 8091 | first.AsRegisterPairHigh<Register>(), |
| 8092 | second.AsRegisterPairHigh<Register>()); |
| 8093 | } |
| 8094 | } |
| 8095 | |
| 8096 | void LocationsBuilderX86::VisitX86MaskOrResetLeastSetBit(HX86MaskOrResetLeastSetBit* instruction) { |
| 8097 | DCHECK(codegen_->GetInstructionSetFeatures().HasAVX2()); |
| 8098 | DCHECK(instruction->GetType() == DataType::Type::kInt32) << instruction->GetType(); |
| 8099 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| 8100 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8101 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8102 | } |
| 8103 | |
| 8104 | void InstructionCodeGeneratorX86::VisitX86MaskOrResetLeastSetBit( |
| 8105 | HX86MaskOrResetLeastSetBit* instruction) { |
| 8106 | LocationSummary* locations = instruction->GetLocations(); |
| 8107 | Location src = locations->InAt(0); |
| 8108 | Location dest = locations->Out(); |
| 8109 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
| 8110 | switch (instruction->GetOpKind()) { |
| 8111 | case HInstruction::kAnd: |
| 8112 | __ blsr(dest.AsRegister<Register>(), src.AsRegister<Register>()); |
| 8113 | break; |
| 8114 | case HInstruction::kXor: |
| 8115 | __ blsmsk(dest.AsRegister<Register>(), src.AsRegister<Register>()); |
| 8116 | break; |
| 8117 | default: |
| 8118 | LOG(FATAL) << "Unreachable"; |
| 8119 | } |
| 8120 | } |
| 8121 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8122 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 8123 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 8124 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 8125 | |
| 8126 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 8127 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8128 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8129 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 |
| 8130 | || instruction->GetResultType() == DataType::Type::kInt64); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8131 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8132 | locations->SetInAt(1, Location::Any()); |
| 8133 | locations->SetOut(Location::SameAsFirstInput()); |
| 8134 | } |
| 8135 | |
| 8136 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 8137 | HandleBitwiseOperation(instruction); |
| 8138 | } |
| 8139 | |
| 8140 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 8141 | HandleBitwiseOperation(instruction); |
| 8142 | } |
| 8143 | |
| 8144 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 8145 | HandleBitwiseOperation(instruction); |
| 8146 | } |
| 8147 | |
| 8148 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 8149 | LocationSummary* locations = instruction->GetLocations(); |
| 8150 | Location first = locations->InAt(0); |
| 8151 | Location second = locations->InAt(1); |
| 8152 | DCHECK(first.Equals(locations->Out())); |
| 8153 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8154 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8155 | if (second.IsRegister()) { |
| 8156 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 8157 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8158 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 8159 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8160 | } else { |
| 8161 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 8162 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8163 | } |
| 8164 | } else if (second.IsConstant()) { |
| 8165 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 8166 | __ andl(first.AsRegister<Register>(), |
| 8167 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8168 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 8169 | __ orl(first.AsRegister<Register>(), |
| 8170 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8171 | } else { |
| 8172 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 8173 | __ xorl(first.AsRegister<Register>(), |
| 8174 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8175 | } |
| 8176 | } else { |
| 8177 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 8178 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8179 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 8180 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8181 | } else { |
| 8182 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 8183 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8184 | } |
| 8185 | } |
| 8186 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8187 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8188 | if (second.IsRegisterPair()) { |
| 8189 | if (instruction->IsAnd()) { |
| 8190 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 8191 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 8192 | } else if (instruction->IsOr()) { |
| 8193 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 8194 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 8195 | } else { |
| 8196 | DCHECK(instruction->IsXor()); |
| 8197 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 8198 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 8199 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 8200 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8201 | if (instruction->IsAnd()) { |
| 8202 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 8203 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 8204 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 8205 | } else if (instruction->IsOr()) { |
| 8206 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 8207 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 8208 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 8209 | } else { |
| 8210 | DCHECK(instruction->IsXor()); |
| 8211 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 8212 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 8213 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 8214 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 8215 | } else { |
| 8216 | DCHECK(second.IsConstant()) << second; |
| 8217 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 8218 | int32_t low_value = Low32Bits(value); |
| 8219 | int32_t high_value = High32Bits(value); |
| 8220 | Immediate low(low_value); |
| 8221 | Immediate high(high_value); |
| 8222 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 8223 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 8224 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 8225 | if (low_value == 0) { |
| 8226 | __ xorl(first_low, first_low); |
| 8227 | } else if (low_value != -1) { |
| 8228 | __ andl(first_low, low); |
| 8229 | } |
| 8230 | if (high_value == 0) { |
| 8231 | __ xorl(first_high, first_high); |
| 8232 | } else if (high_value != -1) { |
| 8233 | __ andl(first_high, high); |
| 8234 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 8235 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 8236 | if (low_value != 0) { |
| 8237 | __ orl(first_low, low); |
| 8238 | } |
| 8239 | if (high_value != 0) { |
| 8240 | __ orl(first_high, high); |
| 8241 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 8242 | } else { |
| 8243 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 8244 | if (low_value != 0) { |
| 8245 | __ xorl(first_low, low); |
| 8246 | } |
| 8247 | if (high_value != 0) { |
| 8248 | __ xorl(first_high, high); |
| 8249 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 8250 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8251 | } |
| 8252 | } |
| 8253 | } |
| 8254 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 8255 | void InstructionCodeGeneratorX86::GenerateReferenceLoadOneRegister( |
| 8256 | HInstruction* instruction, |
| 8257 | Location out, |
| 8258 | uint32_t offset, |
| 8259 | Location maybe_temp, |
| 8260 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8261 | Register out_reg = out.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 8262 | if (read_barrier_option == kWithReadBarrier) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 8263 | CHECK(gUseReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8264 | if (kUseBakerReadBarrier) { |
| 8265 | // Load with fast path based Baker's read barrier. |
| 8266 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8267 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8268 | instruction, out, out_reg, offset, /* needs_null_check= */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8269 | } else { |
| 8270 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 8271 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8272 | // in the following move operation, as we will need it for the |
| 8273 | // read barrier below. |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 8274 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 8275 | __ movl(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8276 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8277 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 8278 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8279 | } |
| 8280 | } else { |
| 8281 | // Plain load with no read barrier. |
| 8282 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8283 | __ movl(out_reg, Address(out_reg, offset)); |
| 8284 | __ MaybeUnpoisonHeapReference(out_reg); |
| 8285 | } |
| 8286 | } |
| 8287 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 8288 | void InstructionCodeGeneratorX86::GenerateReferenceLoadTwoRegisters( |
| 8289 | HInstruction* instruction, |
| 8290 | Location out, |
| 8291 | Location obj, |
| 8292 | uint32_t offset, |
| 8293 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8294 | Register out_reg = out.AsRegister<Register>(); |
| 8295 | Register obj_reg = obj.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 8296 | if (read_barrier_option == kWithReadBarrier) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 8297 | CHECK(gUseReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8298 | if (kUseBakerReadBarrier) { |
| 8299 | // Load with fast path based Baker's read barrier. |
| 8300 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8301 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8302 | instruction, out, obj_reg, offset, /* needs_null_check= */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8303 | } else { |
| 8304 | // Load with slow path based read barrier. |
| 8305 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8306 | __ movl(out_reg, Address(obj_reg, offset)); |
| 8307 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 8308 | } |
| 8309 | } else { |
| 8310 | // Plain load with no read barrier. |
| 8311 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8312 | __ movl(out_reg, Address(obj_reg, offset)); |
| 8313 | __ MaybeUnpoisonHeapReference(out_reg); |
| 8314 | } |
| 8315 | } |
| 8316 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 8317 | void InstructionCodeGeneratorX86::GenerateGcRootFieldLoad( |
| 8318 | HInstruction* instruction, |
| 8319 | Location root, |
| 8320 | const Address& address, |
| 8321 | Label* fixup_label, |
| 8322 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8323 | Register root_reg = root.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 8324 | if (read_barrier_option == kWithReadBarrier) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 8325 | DCHECK(gUseReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8326 | if (kUseBakerReadBarrier) { |
| 8327 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 8328 | // Baker's read barrier are used: |
| 8329 | // |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 8330 | // root = obj.field; |
| 8331 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 8332 | // if (temp != null) { |
| 8333 | // root = temp(root) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8334 | // } |
| 8335 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8336 | // /* GcRoot<mirror::Object> */ root = *address |
| 8337 | __ movl(root_reg, address); |
| 8338 | if (fixup_label != nullptr) { |
| 8339 | __ Bind(fixup_label); |
| 8340 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8341 | static_assert( |
| 8342 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 8343 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 8344 | "have different sizes."); |
| 8345 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 8346 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 8347 | "have different sizes."); |
| 8348 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 8349 | // Slow path marking the GC root `root`. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8350 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathX86( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8351 | instruction, root, /* unpoison_ref_before_marking= */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8352 | codegen_->AddSlowPath(slow_path); |
| 8353 | |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 8354 | // Test the entrypoint (`Thread::Current()->pReadBarrierMarkReg ## root.reg()`). |
| 8355 | const int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 8356 | Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(root.reg()); |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 8357 | __ fs()->cmpl(Address::Absolute(entry_point_offset), Immediate(0)); |
| 8358 | // The entrypoint is null when the GC is not marking. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8359 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 8360 | __ Bind(slow_path->GetExitLabel()); |
| 8361 | } else { |
| 8362 | // GC root loaded through a slow path for read barriers other |
| 8363 | // than Baker's. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8364 | // /* GcRoot<mirror::Object>* */ root = address |
| 8365 | __ leal(root_reg, address); |
| 8366 | if (fixup_label != nullptr) { |
| 8367 | __ Bind(fixup_label); |
| 8368 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8369 | // /* mirror::Object* */ root = root->Read() |
| 8370 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 8371 | } |
| 8372 | } else { |
| 8373 | // Plain GC root load with no read barrier. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8374 | // /* GcRoot<mirror::Object> */ root = *address |
| 8375 | __ movl(root_reg, address); |
| 8376 | if (fixup_label != nullptr) { |
| 8377 | __ Bind(fixup_label); |
| 8378 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 8379 | // Note that GC roots are not affected by heap poisoning, thus we |
| 8380 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8381 | } |
| 8382 | } |
| 8383 | |
| 8384 | void CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8385 | Location ref, |
| 8386 | Register obj, |
| 8387 | uint32_t offset, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8388 | bool needs_null_check) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 8389 | DCHECK(gUseReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8390 | DCHECK(kUseBakerReadBarrier); |
| 8391 | |
| 8392 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 8393 | Address src(obj, offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 8394 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8395 | } |
| 8396 | |
| 8397 | void CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8398 | Location ref, |
| 8399 | Register obj, |
| 8400 | uint32_t data_offset, |
| 8401 | Location index, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8402 | bool needs_null_check) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 8403 | DCHECK(gUseReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8404 | DCHECK(kUseBakerReadBarrier); |
| 8405 | |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 8406 | static_assert( |
| 8407 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 8408 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8409 | // /* HeapReference<Object> */ ref = |
| 8410 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8411 | Address src = CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 8412 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8413 | } |
| 8414 | |
| 8415 | void CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8416 | Location ref, |
| 8417 | Register obj, |
| 8418 | const Address& src, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 8419 | bool needs_null_check, |
| 8420 | bool always_update_field, |
| 8421 | Register* temp) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 8422 | DCHECK(gUseReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8423 | DCHECK(kUseBakerReadBarrier); |
| 8424 | |
| 8425 | // In slow path based read barriers, the read barrier call is |
| 8426 | // inserted after the original load. However, in fast path based |
| 8427 | // Baker's read barriers, we need to perform the load of |
| 8428 | // mirror::Object::monitor_ *before* the original reference load. |
| 8429 | // This load-load ordering is required by the read barrier. |
| 8430 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 8431 | // |
| 8432 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 8433 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 8434 | // HeapReference<Object> ref = *src; // Original reference load. |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 8435 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8436 | // if (is_gray) { |
| 8437 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 8438 | // } |
| 8439 | // |
| 8440 | // Note: the original implementation in ReadBarrier::Barrier is |
| 8441 | // slightly more complex as: |
| 8442 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 8443 | // the high-bits of rb_state, which are expected to be all zeroes |
| 8444 | // (we use CodeGeneratorX86::GenerateMemoryBarrier instead here, |
| 8445 | // which is a no-op thanks to the x86 memory model); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8446 | // - it performs additional checks that we do not do here for |
| 8447 | // performance reasons. |
| 8448 | |
| 8449 | Register ref_reg = ref.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8450 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 8451 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 8452 | // 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] | 8453 | static_assert(ReadBarrier::NonGrayState() == 0, "Expecting non-gray to have value 0"); |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 8454 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 8455 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 8456 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 8457 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 8458 | |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 8459 | // if (rb_state == ReadBarrier::GrayState()) |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 8460 | // ref = ReadBarrier::Mark(ref); |
| 8461 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 8462 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8463 | if (needs_null_check) { |
| 8464 | MaybeRecordImplicitNullCheck(instruction); |
| 8465 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8466 | |
| 8467 | // Load fence to prevent load-load reordering. |
| 8468 | // Note that this is a no-op, thanks to the x86 memory model. |
| 8469 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 8470 | |
| 8471 | // The actual reference load. |
| 8472 | // /* HeapReference<Object> */ ref = *src |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 8473 | __ movl(ref_reg, src); // Flags are unaffected. |
| 8474 | |
| 8475 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 8476 | // Slow path marking the object `ref` when it is gray. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 8477 | SlowPathCode* slow_path; |
| 8478 | if (always_update_field) { |
| 8479 | DCHECK(temp != nullptr); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8480 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkAndUpdateFieldSlowPathX86( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8481 | instruction, ref, obj, src, /* unpoison_ref_before_marking= */ true, *temp); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 8482 | } else { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8483 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkSlowPathX86( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8484 | instruction, ref, /* unpoison_ref_before_marking= */ true); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 8485 | } |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 8486 | AddSlowPath(slow_path); |
| 8487 | |
| 8488 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 8489 | __ j(kNotZero, slow_path->GetEntryLabel()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8490 | |
| 8491 | // Object* ref = ref_addr->AsMirrorPtr() |
| 8492 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 8493 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8494 | __ Bind(slow_path->GetExitLabel()); |
| 8495 | } |
| 8496 | |
| 8497 | void CodeGeneratorX86::GenerateReadBarrierSlow(HInstruction* instruction, |
| 8498 | Location out, |
| 8499 | Location ref, |
| 8500 | Location obj, |
| 8501 | uint32_t offset, |
| 8502 | Location index) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 8503 | DCHECK(gUseReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8504 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8505 | // Insert a slow path based read barrier *after* the reference load. |
| 8506 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8507 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 8508 | // reference will be carried out by the runtime within the slow |
| 8509 | // path. |
| 8510 | // |
| 8511 | // Note that `ref` currently does not get unpoisoned (when heap |
| 8512 | // poisoning is enabled), which is alright as the `ref` argument is |
| 8513 | // not used by the artReadBarrierSlow entry point. |
| 8514 | // |
| 8515 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8516 | SlowPathCode* slow_path = new (GetScopedAllocator()) |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8517 | ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); |
| 8518 | AddSlowPath(slow_path); |
| 8519 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8520 | __ jmp(slow_path->GetEntryLabel()); |
| 8521 | __ Bind(slow_path->GetExitLabel()); |
| 8522 | } |
| 8523 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8524 | void CodeGeneratorX86::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 8525 | Location out, |
| 8526 | Location ref, |
| 8527 | Location obj, |
| 8528 | uint32_t offset, |
| 8529 | Location index) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 8530 | if (gUseReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8531 | // Baker's read barriers shall be handled by the fast path |
| 8532 | // (CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier). |
| 8533 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8534 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 8535 | // by the runtime within the slow path. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8536 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8537 | } else if (kPoisonHeapReferences) { |
| 8538 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 8539 | } |
| 8540 | } |
| 8541 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8542 | void CodeGeneratorX86::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 8543 | Location out, |
| 8544 | Location root) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 8545 | DCHECK(gUseReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8546 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8547 | // Insert a slow path based read barrier *after* the GC root load. |
| 8548 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8549 | // Note that GC roots are not affected by heap poisoning, so we do |
| 8550 | // not need to do anything special for this here. |
| 8551 | SlowPathCode* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8552 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathX86(instruction, out, root); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8553 | AddSlowPath(slow_path); |
| 8554 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8555 | __ jmp(slow_path->GetEntryLabel()); |
| 8556 | __ Bind(slow_path->GetExitLabel()); |
| 8557 | } |
| 8558 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 8559 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8560 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8561 | LOG(FATAL) << "Unreachable"; |
| 8562 | } |
| 8563 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 8564 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8565 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8566 | LOG(FATAL) << "Unreachable"; |
| 8567 | } |
| 8568 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8569 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 8570 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 8571 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8572 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8573 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8574 | } |
| 8575 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8576 | void InstructionCodeGeneratorX86::GenPackedSwitchWithCompares(Register value_reg, |
| 8577 | int32_t lower_bound, |
| 8578 | uint32_t num_entries, |
| 8579 | HBasicBlock* switch_block, |
| 8580 | HBasicBlock* default_block) { |
| 8581 | // Figure out the correct compare values and jump conditions. |
| 8582 | // Handle the first compare/branch as a special case because it might |
| 8583 | // jump to the default case. |
| 8584 | DCHECK_GT(num_entries, 2u); |
| 8585 | Condition first_condition; |
| 8586 | uint32_t index; |
| 8587 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 8588 | if (lower_bound != 0) { |
| 8589 | first_condition = kLess; |
| 8590 | __ cmpl(value_reg, Immediate(lower_bound)); |
| 8591 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 8592 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8593 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8594 | index = 1; |
| 8595 | } else { |
| 8596 | // Handle all the compare/jumps below. |
| 8597 | first_condition = kBelow; |
| 8598 | index = 0; |
| 8599 | } |
| 8600 | |
| 8601 | // Handle the rest of the compare/jumps. |
| 8602 | for (; index + 1 < num_entries; index += 2) { |
| 8603 | int32_t compare_to_value = lower_bound + index + 1; |
| 8604 | __ cmpl(value_reg, Immediate(compare_to_value)); |
| 8605 | // Jump to successors[index] if value < case_value[index]. |
| 8606 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 8607 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 8608 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 8609 | } |
| 8610 | |
| 8611 | if (index != num_entries) { |
| 8612 | // There are an odd number of entries. Handle the last one. |
| 8613 | DCHECK_EQ(index + 1, num_entries); |
| 8614 | __ cmpl(value_reg, Immediate(lower_bound + index)); |
| 8615 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8616 | } |
| 8617 | |
| 8618 | // And the default for any other value. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8619 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
| 8620 | __ jmp(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8621 | } |
| 8622 | } |
| 8623 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8624 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 8625 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 8626 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 8627 | LocationSummary* locations = switch_instr->GetLocations(); |
| 8628 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 8629 | |
| 8630 | GenPackedSwitchWithCompares(value_reg, |
| 8631 | lower_bound, |
| 8632 | num_entries, |
| 8633 | switch_instr->GetBlock(), |
| 8634 | switch_instr->GetDefaultBlock()); |
| 8635 | } |
| 8636 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8637 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 8638 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8639 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8640 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8641 | |
| 8642 | // Constant area pointer. |
| 8643 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8644 | |
| 8645 | // And the temporary we need. |
| 8646 | locations->AddTemp(Location::RequiresRegister()); |
| 8647 | } |
| 8648 | |
| 8649 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 8650 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8651 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8652 | LocationSummary* locations = switch_instr->GetLocations(); |
| 8653 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 8654 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 8655 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8656 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 8657 | GenPackedSwitchWithCompares(value_reg, |
| 8658 | lower_bound, |
| 8659 | num_entries, |
| 8660 | switch_instr->GetBlock(), |
| 8661 | default_block); |
| 8662 | return; |
| 8663 | } |
| 8664 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8665 | // Optimizing has a jump area. |
| 8666 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 8667 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 8668 | |
| 8669 | // Remove the bias, if needed. |
| 8670 | if (lower_bound != 0) { |
| 8671 | __ leal(temp_reg, Address(value_reg, -lower_bound)); |
| 8672 | value_reg = temp_reg; |
| 8673 | } |
| 8674 | |
| 8675 | // Is the value in range? |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8676 | DCHECK_GE(num_entries, 1u); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8677 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 8678 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| 8679 | |
| 8680 | // We are in the range of the table. |
| 8681 | // Load (target-constant_area) from the jump table, indexing by the value. |
| 8682 | __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); |
| 8683 | |
| 8684 | // Compute the actual target address by adding in constant_area. |
| 8685 | __ addl(temp_reg, constant_area); |
| 8686 | |
| 8687 | // And jump. |
| 8688 | __ jmp(temp_reg); |
| 8689 | } |
| 8690 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8691 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 8692 | HX86ComputeBaseMethodAddress* insn) { |
| 8693 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8694 | new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8695 | locations->SetOut(Location::RequiresRegister()); |
| 8696 | } |
| 8697 | |
| 8698 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 8699 | HX86ComputeBaseMethodAddress* insn) { |
| 8700 | LocationSummary* locations = insn->GetLocations(); |
| 8701 | Register reg = locations->Out().AsRegister<Register>(); |
| 8702 | |
| 8703 | // Generate call to next instruction. |
| 8704 | Label next_instruction; |
| 8705 | __ call(&next_instruction); |
| 8706 | __ Bind(&next_instruction); |
| 8707 | |
| 8708 | // Remember this offset for later use with constant area. |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8709 | codegen_->AddMethodAddressOffset(insn, GetAssembler()->CodeSize()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8710 | |
| 8711 | // Grab the return address off the stack. |
| 8712 | __ popl(reg); |
| 8713 | } |
| 8714 | |
| 8715 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 8716 | HX86LoadFromConstantTable* insn) { |
| 8717 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8718 | new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8719 | |
| 8720 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8721 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 8722 | |
| 8723 | // 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] | 8724 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8725 | return; |
| 8726 | } |
| 8727 | |
| 8728 | switch (insn->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8729 | case DataType::Type::kFloat32: |
| 8730 | case DataType::Type::kFloat64: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8731 | locations->SetOut(Location::RequiresFpuRegister()); |
| 8732 | break; |
| 8733 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8734 | case DataType::Type::kInt32: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8735 | locations->SetOut(Location::RequiresRegister()); |
| 8736 | break; |
| 8737 | |
| 8738 | default: |
| 8739 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 8740 | } |
| 8741 | } |
| 8742 | |
| 8743 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 8744 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8745 | return; |
| 8746 | } |
| 8747 | |
| 8748 | LocationSummary* locations = insn->GetLocations(); |
| 8749 | Location out = locations->Out(); |
| 8750 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 8751 | HConstant *value = insn->GetConstant(); |
| 8752 | |
| 8753 | switch (insn->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8754 | case DataType::Type::kFloat32: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8755 | __ movss(out.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8756 | codegen_->LiteralFloatAddress( |
| 8757 | value->AsFloatConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8758 | break; |
| 8759 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8760 | case DataType::Type::kFloat64: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8761 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8762 | codegen_->LiteralDoubleAddress( |
| 8763 | value->AsDoubleConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8764 | break; |
| 8765 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8766 | case DataType::Type::kInt32: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8767 | __ movl(out.AsRegister<Register>(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8768 | codegen_->LiteralInt32Address( |
| 8769 | value->AsIntConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8770 | break; |
| 8771 | |
| 8772 | default: |
| 8773 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 8774 | } |
| 8775 | } |
| 8776 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8777 | /** |
| 8778 | * Class to handle late fixup of offsets into constant area. |
| 8779 | */ |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 8780 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8781 | public: |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8782 | RIPFixup(CodeGeneratorX86& codegen, |
| 8783 | HX86ComputeBaseMethodAddress* base_method_address, |
| 8784 | size_t offset) |
| 8785 | : codegen_(&codegen), |
| 8786 | base_method_address_(base_method_address), |
| 8787 | offset_into_constant_area_(offset) {} |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8788 | |
| 8789 | protected: |
| 8790 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 8791 | |
| 8792 | CodeGeneratorX86* codegen_; |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8793 | HX86ComputeBaseMethodAddress* base_method_address_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8794 | |
| 8795 | private: |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8796 | void Process(const MemoryRegion& region, int pos) override { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8797 | // Patch the correct offset for the instruction. The place to patch is the |
| 8798 | // last 4 bytes of the instruction. |
| 8799 | // The value to patch is the distance from the offset in the constant area |
| 8800 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8801 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8802 | int32_t relative_position = |
| 8803 | constant_offset - codegen_->GetMethodAddressOffset(base_method_address_); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8804 | |
| 8805 | // Patch in the right value. |
| 8806 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 8807 | } |
| 8808 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8809 | // Location in constant area that the fixup refers to. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8810 | int32_t offset_into_constant_area_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8811 | }; |
| 8812 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8813 | /** |
| 8814 | * Class to handle late fixup of offsets to a jump table that will be created in the |
| 8815 | * constant area. |
| 8816 | */ |
| 8817 | class JumpTableRIPFixup : public RIPFixup { |
| 8818 | public: |
| 8819 | JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8820 | : RIPFixup(codegen, switch_instr->GetBaseMethodAddress(), static_cast<size_t>(-1)), |
| 8821 | switch_instr_(switch_instr) {} |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8822 | |
| 8823 | void CreateJumpTable() { |
| 8824 | X86Assembler* assembler = codegen_->GetAssembler(); |
| 8825 | |
| 8826 | // Ensure that the reference to the jump table has the correct offset. |
| 8827 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 8828 | SetOffset(offset_in_constant_table); |
| 8829 | |
| 8830 | // The label values in the jump table are computed relative to the |
| 8831 | // instruction addressing the constant area. |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8832 | const int32_t relative_offset = codegen_->GetMethodAddressOffset(base_method_address_); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8833 | |
| 8834 | // Populate the jump table with the correct values for the jump table. |
| 8835 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 8836 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 8837 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 8838 | // The value that we want is the target offset - the position of the table. |
| 8839 | for (int32_t i = 0; i < num_entries; i++) { |
| 8840 | HBasicBlock* b = successors[i]; |
| 8841 | Label* l = codegen_->GetLabelOf(b); |
| 8842 | DCHECK(l->IsBound()); |
| 8843 | int32_t offset_to_block = l->Position() - relative_offset; |
| 8844 | assembler->AppendInt32(offset_to_block); |
| 8845 | } |
| 8846 | } |
| 8847 | |
| 8848 | private: |
| 8849 | const HX86PackedSwitch* switch_instr_; |
| 8850 | }; |
| 8851 | |
| 8852 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 8853 | // Generate the constant area if needed. |
| 8854 | X86Assembler* assembler = GetAssembler(); |
jaishank | 20d1c94 | 2019-03-08 15:08:17 +0530 | [diff] [blame] | 8855 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8856 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 8857 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 8858 | // byte values. |
| 8859 | assembler->Align(4, 0); |
| 8860 | constant_area_start_ = assembler->CodeSize(); |
| 8861 | |
| 8862 | // Populate any jump tables. |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 8863 | for (JumpTableRIPFixup* jump_table : fixups_to_jump_tables_) { |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8864 | jump_table->CreateJumpTable(); |
| 8865 | } |
| 8866 | |
| 8867 | // And now add the constant area to the generated code. |
| 8868 | assembler->AddConstantArea(); |
| 8869 | } |
| 8870 | |
| 8871 | // And finish up. |
| 8872 | CodeGenerator::Finalize(allocator); |
| 8873 | } |
| 8874 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8875 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, |
| 8876 | HX86ComputeBaseMethodAddress* method_base, |
| 8877 | Register reg) { |
| 8878 | AssemblerFixup* fixup = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8879 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddDouble(v)); |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 8880 | return Address(reg, kPlaceholder32BitOffset, fixup); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8881 | } |
| 8882 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8883 | Address CodeGeneratorX86::LiteralFloatAddress(float v, |
| 8884 | HX86ComputeBaseMethodAddress* method_base, |
| 8885 | Register reg) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8886 | AssemblerFixup* fixup = |
| 8887 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddFloat(v)); |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 8888 | return Address(reg, kPlaceholder32BitOffset, fixup); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8889 | } |
| 8890 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8891 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, |
| 8892 | HX86ComputeBaseMethodAddress* method_base, |
| 8893 | Register reg) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8894 | AssemblerFixup* fixup = |
| 8895 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddInt32(v)); |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 8896 | return Address(reg, kPlaceholder32BitOffset, fixup); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8897 | } |
| 8898 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8899 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, |
| 8900 | HX86ComputeBaseMethodAddress* method_base, |
| 8901 | Register reg) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8902 | AssemblerFixup* fixup = |
| 8903 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddInt64(v)); |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 8904 | return Address(reg, kPlaceholder32BitOffset, fixup); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8905 | } |
| 8906 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 8907 | void CodeGeneratorX86::Load32BitValue(Register dest, int32_t value) { |
| 8908 | if (value == 0) { |
| 8909 | __ xorl(dest, dest); |
| 8910 | } else { |
| 8911 | __ movl(dest, Immediate(value)); |
| 8912 | } |
| 8913 | } |
| 8914 | |
| 8915 | void CodeGeneratorX86::Compare32BitValue(Register dest, int32_t value) { |
| 8916 | if (value == 0) { |
| 8917 | __ testl(dest, dest); |
| 8918 | } else { |
| 8919 | __ cmpl(dest, Immediate(value)); |
| 8920 | } |
| 8921 | } |
| 8922 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8923 | void CodeGeneratorX86::GenerateIntCompare(Location lhs, Location rhs) { |
| 8924 | Register lhs_reg = lhs.AsRegister<Register>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8925 | GenerateIntCompare(lhs_reg, rhs); |
| 8926 | } |
| 8927 | |
| 8928 | void CodeGeneratorX86::GenerateIntCompare(Register lhs, Location rhs) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8929 | if (rhs.IsConstant()) { |
| 8930 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8931 | Compare32BitValue(lhs, value); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8932 | } else if (rhs.IsStackSlot()) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8933 | __ cmpl(lhs, Address(ESP, rhs.GetStackIndex())); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8934 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8935 | __ cmpl(lhs, rhs.AsRegister<Register>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8936 | } |
| 8937 | } |
| 8938 | |
| 8939 | Address CodeGeneratorX86::ArrayAddress(Register obj, |
| 8940 | Location index, |
| 8941 | ScaleFactor scale, |
| 8942 | uint32_t data_offset) { |
| 8943 | return index.IsConstant() ? |
| 8944 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) : |
| 8945 | Address(obj, index.AsRegister<Register>(), scale, data_offset); |
| 8946 | } |
| 8947 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8948 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, |
| 8949 | Register reg, |
| 8950 | Register value) { |
| 8951 | // Create a fixup to be used to create and address the jump table. |
| 8952 | JumpTableRIPFixup* table_fixup = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8953 | new (GetGraph()->GetAllocator()) JumpTableRIPFixup(*this, switch_instr); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8954 | |
| 8955 | // We have to populate the jump tables. |
| 8956 | fixups_to_jump_tables_.push_back(table_fixup); |
| 8957 | |
| 8958 | // 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] | 8959 | return Address(reg, value, TIMES_4, kPlaceholder32BitOffset, table_fixup); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8960 | } |
| 8961 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8962 | // TODO: target as memory. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8963 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, DataType::Type type) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8964 | if (!target.IsValid()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8965 | DCHECK_EQ(type, DataType::Type::kVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8966 | return; |
| 8967 | } |
| 8968 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8969 | DCHECK_NE(type, DataType::Type::kVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8970 | |
| 8971 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 8972 | if (target.Equals(return_loc)) { |
| 8973 | return; |
| 8974 | } |
| 8975 | |
| 8976 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 8977 | // with the else branch. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8978 | if (type == DataType::Type::kInt64) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8979 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8980 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), DataType::Type::kInt32, nullptr); |
| 8981 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), DataType::Type::kInt32, nullptr); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8982 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 8983 | } else { |
| 8984 | // Let the parallel move resolver take care of all of this. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8985 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8986 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 8987 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 8988 | } |
| 8989 | } |
| 8990 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8991 | void CodeGeneratorX86::PatchJitRootUse(uint8_t* code, |
| 8992 | const uint8_t* roots_data, |
| 8993 | const PatchInfo<Label>& info, |
| 8994 | uint64_t index_in_table) const { |
| 8995 | uint32_t code_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 8996 | uintptr_t address = |
| 8997 | 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] | 8998 | using unaligned_uint32_t __attribute__((__aligned__(1))) = uint32_t; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8999 | reinterpret_cast<unaligned_uint32_t*>(code + code_offset)[0] = |
| 9000 | dchecked_integral_cast<uint32_t>(address); |
| 9001 | } |
| 9002 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 9003 | void CodeGeneratorX86::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 9004 | for (const PatchInfo<Label>& info : jit_string_patches_) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9005 | 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] | 9006 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9007 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 9008 | } |
| 9009 | |
| 9010 | for (const PatchInfo<Label>& info : jit_class_patches_) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9011 | 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] | 9012 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9013 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 9014 | } |
| 9015 | } |
| 9016 | |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 9017 | void LocationsBuilderX86::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 9018 | ATTRIBUTE_UNUSED) { |
| 9019 | LOG(FATAL) << "Unreachable"; |
| 9020 | } |
| 9021 | |
| 9022 | void InstructionCodeGeneratorX86::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 9023 | ATTRIBUTE_UNUSED) { |
| 9024 | LOG(FATAL) << "Unreachable"; |
| 9025 | } |
| 9026 | |
Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 9027 | bool LocationsBuilderX86::CpuHasAvxFeatureFlag() { |
| 9028 | return codegen_->GetInstructionSetFeatures().HasAVX(); |
| 9029 | } |
| 9030 | bool LocationsBuilderX86::CpuHasAvx2FeatureFlag() { |
| 9031 | return codegen_->GetInstructionSetFeatures().HasAVX2(); |
| 9032 | } |
| 9033 | bool InstructionCodeGeneratorX86::CpuHasAvxFeatureFlag() { |
| 9034 | return codegen_->GetInstructionSetFeatures().HasAVX(); |
| 9035 | } |
| 9036 | bool InstructionCodeGeneratorX86::CpuHasAvx2FeatureFlag() { |
| 9037 | return codegen_->GetInstructionSetFeatures().HasAVX2(); |
| 9038 | } |
| 9039 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 9040 | #undef __ |
| 9041 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 9042 | } // namespace x86 |
| 9043 | } // namespace art |