Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "code_generator_x86.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 18 | |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 19 | #include "arch/x86/jni_frame_x86.h" |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 20 | #include "art_method-inl.h" |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 21 | #include "class_table.h" |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 22 | #include "code_generator_utils.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 23 | #include "compiled_method.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 24 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 25 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 26 | #include "gc/accounting/card_table.h" |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 27 | #include "gc/space/image_space.h" |
Andreas Gampe | 09659c2 | 2017-09-18 18:23:32 -0700 | [diff] [blame] | 28 | #include "heap_poisoning.h" |
Nicolas Geoffray | 8b8d93d | 2020-09-17 14:30:01 +0100 | [diff] [blame] | 29 | #include "interpreter/mterp/nterp.h" |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 30 | #include "intrinsics.h" |
Ulya Trafimovich | ec696e5 | 2022-01-26 10:21:32 +0000 | [diff] [blame] | 31 | #include "intrinsics_utils.h" |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 32 | #include "intrinsics_x86.h" |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 33 | #include "jit/profiling_info.h" |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 34 | #include "linker/linker_patch.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 35 | #include "lock_word.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 36 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 37 | #include "mirror/class-inl.h" |
Andra Danciu | 52d2c0c | 2020-09-15 14:27:21 +0000 | [diff] [blame] | 38 | #include "mirror/var_handle.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 | |
Vladimir Marko | 0a51605 | 2019-10-14 13:00:44 +0000 | [diff] [blame] | 46 | namespace art { |
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); |
| 970 | x86_codegen->InvokeRuntime(entry_point, instruction_, instruction_->GetDexPc(), this); |
| 971 | RestoreLiveRegisters(codegen, locations); |
| 972 | __ jmp(GetExitLabel()); |
| 973 | } |
| 974 | |
| 975 | const char* GetDescription() const override { |
| 976 | return "MethodEntryExitHooksSlowPath"; |
| 977 | } |
| 978 | |
| 979 | private: |
| 980 | DISALLOW_COPY_AND_ASSIGN(MethodEntryExitHooksSlowPathX86); |
| 981 | }; |
| 982 | |
Nicolas Geoffray | 9e59890 | 2021-11-19 14:53:07 +0000 | [diff] [blame] | 983 | class CompileOptimizedSlowPathX86 : public SlowPathCode { |
| 984 | public: |
| 985 | CompileOptimizedSlowPathX86() : SlowPathCode(/* instruction= */ nullptr) {} |
| 986 | |
| 987 | void EmitNativeCode(CodeGenerator* codegen) override { |
| 988 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 989 | __ Bind(GetEntryLabel()); |
| 990 | x86_codegen->GenerateInvokeRuntime( |
| 991 | GetThreadOffset<kX86PointerSize>(kQuickCompileOptimized).Int32Value()); |
| 992 | __ jmp(GetExitLabel()); |
| 993 | } |
| 994 | |
| 995 | const char* GetDescription() const override { |
| 996 | return "CompileOptimizedSlowPath"; |
| 997 | } |
| 998 | |
| 999 | private: |
| 1000 | DISALLOW_COPY_AND_ASSIGN(CompileOptimizedSlowPathX86); |
| 1001 | }; |
| 1002 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1003 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 1004 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 1005 | #define __ down_cast<X86Assembler*>(GetAssembler())-> // NOLINT |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1006 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1007 | inline Condition X86Condition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1008 | switch (cond) { |
| 1009 | case kCondEQ: return kEqual; |
| 1010 | case kCondNE: return kNotEqual; |
| 1011 | case kCondLT: return kLess; |
| 1012 | case kCondLE: return kLessEqual; |
| 1013 | case kCondGT: return kGreater; |
| 1014 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1015 | case kCondB: return kBelow; |
| 1016 | case kCondBE: return kBelowEqual; |
| 1017 | case kCondA: return kAbove; |
| 1018 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1019 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1020 | LOG(FATAL) << "Unreachable"; |
| 1021 | UNREACHABLE(); |
| 1022 | } |
| 1023 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1024 | // Maps signed condition to unsigned condition and FP condition to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1025 | inline Condition X86UnsignedOrFPCondition(IfCondition cond) { |
| 1026 | switch (cond) { |
| 1027 | case kCondEQ: return kEqual; |
| 1028 | case kCondNE: return kNotEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1029 | // Signed to unsigned, and FP to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1030 | case kCondLT: return kBelow; |
| 1031 | case kCondLE: return kBelowEqual; |
| 1032 | case kCondGT: return kAbove; |
| 1033 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1034 | // Unsigned remain unchanged. |
| 1035 | case kCondB: return kBelow; |
| 1036 | case kCondBE: return kBelowEqual; |
| 1037 | case kCondA: return kAbove; |
| 1038 | case kCondAE: return kAboveEqual; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1039 | } |
| 1040 | LOG(FATAL) << "Unreachable"; |
| 1041 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1042 | } |
| 1043 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1044 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1045 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1046 | } |
| 1047 | |
| 1048 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1049 | stream << XmmRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1050 | } |
| 1051 | |
Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 1052 | const X86InstructionSetFeatures& CodeGeneratorX86::GetInstructionSetFeatures() const { |
| 1053 | return *GetCompilerOptions().GetInstructionSetFeatures()->AsX86InstructionSetFeatures(); |
| 1054 | } |
| 1055 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1056 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1057 | __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); |
| 1058 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1059 | } |
| 1060 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1061 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1062 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); |
| 1063 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1064 | } |
| 1065 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1066 | size_t CodeGeneratorX86::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1067 | if (GetGraph()->HasSIMD()) { |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 1068 | __ movups(Address(ESP, stack_index), XmmRegister(reg_id)); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1069 | } else { |
| 1070 | __ movsd(Address(ESP, stack_index), XmmRegister(reg_id)); |
| 1071 | } |
Artem Serov | 6a0b657 | 2019-07-26 20:38:37 +0100 | [diff] [blame] | 1072 | return GetSlowPathFPWidth(); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1073 | } |
| 1074 | |
| 1075 | size_t CodeGeneratorX86::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1076 | if (GetGraph()->HasSIMD()) { |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 1077 | __ movups(XmmRegister(reg_id), Address(ESP, stack_index)); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1078 | } else { |
| 1079 | __ movsd(XmmRegister(reg_id), Address(ESP, stack_index)); |
| 1080 | } |
Artem Serov | 6a0b657 | 2019-07-26 20:38:37 +0100 | [diff] [blame] | 1081 | return GetSlowPathFPWidth(); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1082 | } |
| 1083 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1084 | void CodeGeneratorX86::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1085 | HInstruction* instruction, |
| 1086 | uint32_t dex_pc, |
| 1087 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1088 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1089 | GenerateInvokeRuntime(GetThreadOffset<kX86PointerSize>(entrypoint).Int32Value()); |
| 1090 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1091 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1092 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 1093 | } |
| 1094 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1095 | void CodeGeneratorX86::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1096 | HInstruction* instruction, |
| 1097 | SlowPathCode* slow_path) { |
| 1098 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1099 | GenerateInvokeRuntime(entry_point_offset); |
| 1100 | } |
| 1101 | |
| 1102 | void CodeGeneratorX86::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1103 | __ fs()->call(Address::Absolute(entry_point_offset)); |
| 1104 | } |
| 1105 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1106 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1107 | const CompilerOptions& compiler_options, |
| 1108 | OptimizingCompilerStats* stats) |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1109 | : CodeGenerator(graph, |
| 1110 | kNumberOfCpuRegisters, |
| 1111 | kNumberOfXmmRegisters, |
| 1112 | kNumberOfRegisterPairs, |
| 1113 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1114 | arraysize(kCoreCalleeSaves)) |
| 1115 | | (1 << kFakeReturnRegister), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1116 | 0, |
| 1117 | compiler_options, |
| 1118 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1119 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1120 | location_builder_(graph, this), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1121 | instruction_visitor_(graph, this), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1122 | move_resolver_(graph->GetAllocator(), this), |
Shalini Salomi Bodapati | 6545ee3 | 2021-11-02 20:01:06 +0530 | [diff] [blame] | 1123 | assembler_(graph->GetAllocator(), |
| 1124 | compiler_options.GetInstructionSetFeatures()->AsX86InstructionSetFeatures()), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1125 | boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1126 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1127 | boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1128 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 1129 | public_type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1130 | package_type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1131 | boot_image_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1132 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 1133 | boot_image_jni_entrypoint_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 1134 | boot_image_other_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1135 | jit_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1136 | jit_class_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1137 | constant_area_start_(-1), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1138 | fixups_to_jump_tables_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1139 | method_address_offset_(std::less<uint32_t>(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1140 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1141 | // Use a fake return address register to mimic Quick. |
| 1142 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1143 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1144 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1145 | void CodeGeneratorX86::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1146 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1147 | blocked_core_registers_[ESP] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1148 | } |
| 1149 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1150 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1151 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1152 | assembler_(codegen->GetAssembler()), |
| 1153 | codegen_(codegen) {} |
| 1154 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1155 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1156 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1157 | } |
| 1158 | |
Mythri Alle | 5097f83 | 2021-11-02 14:52:30 +0000 | [diff] [blame] | 1159 | void SetInForReturnValue(HInstruction* ret, LocationSummary* locations) { |
| 1160 | switch (ret->InputAt(0)->GetType()) { |
| 1161 | case DataType::Type::kReference: |
| 1162 | case DataType::Type::kBool: |
| 1163 | case DataType::Type::kUint8: |
| 1164 | case DataType::Type::kInt8: |
| 1165 | case DataType::Type::kUint16: |
| 1166 | case DataType::Type::kInt16: |
| 1167 | case DataType::Type::kInt32: |
| 1168 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 1169 | break; |
| 1170 | |
| 1171 | case DataType::Type::kInt64: |
| 1172 | locations->SetInAt(0, Location::RegisterPairLocation(EAX, EDX)); |
| 1173 | break; |
| 1174 | |
| 1175 | case DataType::Type::kFloat32: |
| 1176 | case DataType::Type::kFloat64: |
| 1177 | locations->SetInAt(0, Location::FpuRegisterLocation(XMM0)); |
| 1178 | break; |
| 1179 | |
| 1180 | case DataType::Type::kVoid: |
| 1181 | locations->SetInAt(0, Location::NoLocation()); |
| 1182 | break; |
| 1183 | |
| 1184 | default: |
| 1185 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
| 1186 | } |
| 1187 | } |
| 1188 | |
| 1189 | void LocationsBuilderX86::VisitMethodExitHook(HMethodExitHook* method_hook) { |
| 1190 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
| 1191 | LocationSummary(method_hook, LocationSummary::kCallOnSlowPath); |
| 1192 | SetInForReturnValue(method_hook, locations); |
| 1193 | } |
| 1194 | |
| 1195 | void InstructionCodeGeneratorX86::GenerateMethodEntryExitHook(HInstruction* instruction) { |
| 1196 | SlowPathCode* slow_path = |
| 1197 | new (codegen_->GetScopedAllocator()) MethodEntryExitHooksSlowPathX86(instruction); |
| 1198 | codegen_->AddSlowPath(slow_path); |
| 1199 | |
| 1200 | uint64_t address = reinterpret_cast64<uint64_t>(Runtime::Current()->GetInstrumentation()); |
| 1201 | int offset = instrumentation::Instrumentation::NeedsEntryExitHooksOffset().Int32Value(); |
Mythri Alle | 9575c12 | 2021-11-12 12:04:41 +0000 | [diff] [blame] | 1202 | __ cmpb(Address::Absolute(address + offset), Immediate(0)); |
| 1203 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
Mythri Alle | 5097f83 | 2021-11-02 14:52:30 +0000 | [diff] [blame] | 1204 | __ Bind(slow_path->GetExitLabel()); |
| 1205 | } |
| 1206 | |
| 1207 | void InstructionCodeGeneratorX86::VisitMethodExitHook(HMethodExitHook* instruction) { |
| 1208 | DCHECK(codegen_->GetCompilerOptions().IsJitCompiler() && GetGraph()->IsDebuggable()); |
| 1209 | DCHECK(codegen_->RequiresCurrentMethod()); |
| 1210 | GenerateMethodEntryExitHook(instruction); |
| 1211 | } |
| 1212 | |
| 1213 | void LocationsBuilderX86::VisitMethodEntryHook(HMethodEntryHook* method_hook) { |
| 1214 | new (GetGraph()->GetAllocator()) LocationSummary(method_hook, LocationSummary::kCallOnSlowPath); |
| 1215 | } |
| 1216 | |
| 1217 | void InstructionCodeGeneratorX86::VisitMethodEntryHook(HMethodEntryHook* instruction) { |
| 1218 | DCHECK(codegen_->GetCompilerOptions().IsJitCompiler() && GetGraph()->IsDebuggable()); |
| 1219 | DCHECK(codegen_->RequiresCurrentMethod()); |
| 1220 | GenerateMethodEntryExitHook(instruction); |
| 1221 | } |
| 1222 | |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1223 | void CodeGeneratorX86::MaybeIncrementHotness(bool is_frame_entry) { |
| 1224 | if (GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 1225 | Register reg = EAX; |
| 1226 | if (is_frame_entry) { |
| 1227 | reg = kMethodRegisterArgument; |
| 1228 | } else { |
| 1229 | __ pushl(EAX); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1230 | __ cfi().AdjustCFAOffset(4); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1231 | __ movl(EAX, Address(ESP, kX86WordSize)); |
| 1232 | } |
| 1233 | NearLabel overflow; |
| 1234 | __ cmpw(Address(reg, ArtMethod::HotnessCountOffset().Int32Value()), |
Nicolas Geoffray | 61673dc | 2021-11-06 13:58:31 +0000 | [diff] [blame] | 1235 | Immediate(interpreter::kNterpHotnessValue)); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1236 | __ j(kEqual, &overflow); |
Nicolas Geoffray | 61673dc | 2021-11-06 13:58:31 +0000 | [diff] [blame] | 1237 | __ addw(Address(reg, ArtMethod::HotnessCountOffset().Int32Value()), Immediate(-1)); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1238 | __ Bind(&overflow); |
| 1239 | if (!is_frame_entry) { |
| 1240 | __ popl(EAX); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1241 | __ cfi().AdjustCFAOffset(-4); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1242 | } |
| 1243 | } |
| 1244 | |
| 1245 | if (GetGraph()->IsCompilingBaseline() && !Runtime::Current()->IsAotCompiler()) { |
Nicolas Geoffray | 9e59890 | 2021-11-19 14:53:07 +0000 | [diff] [blame] | 1246 | SlowPathCode* slow_path = new (GetScopedAllocator()) CompileOptimizedSlowPathX86(); |
| 1247 | AddSlowPath(slow_path); |
| 1248 | ProfilingInfo* info = GetGraph()->GetProfilingInfo(); |
| 1249 | DCHECK(info != nullptr); |
| 1250 | uint32_t address = reinterpret_cast32<uint32_t>(info) + |
| 1251 | ProfilingInfo::BaselineHotnessCountOffset().Int32Value(); |
| 1252 | DCHECK(!HasEmptyFrame()); |
| 1253 | // With multiple threads, this can overflow. This is OK, we will eventually get to see |
| 1254 | // it reaching 0. Also, at this point we have no register available to look |
| 1255 | // at the counter directly. |
| 1256 | __ addw(Address::Absolute(address), Immediate(-1)); |
| 1257 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 1258 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1259 | } |
| 1260 | } |
| 1261 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1262 | void CodeGeneratorX86::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1263 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
Nicolas Geoffray | ab3f8d2 | 2022-07-23 15:49:51 +0000 | [diff] [blame] | 1264 | |
| 1265 | // Check if we need to generate the clinit check. We will jump to the |
| 1266 | // resolution stub if the class is not initialized and the executing thread is |
| 1267 | // not the thread initializing it. |
| 1268 | // We do this before constructing the frame to get the correct stack trace if |
| 1269 | // an exception is thrown. |
| 1270 | if (GetCompilerOptions().ShouldCompileWithClinitCheck(GetGraph()->GetArtMethod())) { |
| 1271 | NearLabel continue_execution, resolution; |
| 1272 | // We'll use EBP as temporary. |
| 1273 | __ pushl(EBP); |
| 1274 | // Check if we're visibly initialized. |
| 1275 | |
| 1276 | // We don't emit a read barrier here to save on code size. We rely on the |
| 1277 | // resolution trampoline to do a suspend check before re-entering this code. |
| 1278 | __ movl(EBP, Address(kMethodRegisterArgument, ArtMethod::DeclaringClassOffset().Int32Value())); |
| 1279 | __ cmpb(Address(EBP, status_byte_offset), Immediate(shifted_visibly_initialized_value)); |
| 1280 | __ j(kAboveEqual, &continue_execution); |
| 1281 | |
| 1282 | // Check if we're initializing and the thread initializing is the one |
| 1283 | // executing the code. |
| 1284 | __ cmpb(Address(EBP, status_byte_offset), Immediate(shifted_initializing_value)); |
| 1285 | __ j(kBelow, &resolution); |
| 1286 | |
| 1287 | __ movl(EBP, Address(EBP, mirror::Class::ClinitThreadIdOffset().Int32Value())); |
| 1288 | __ fs()->cmpl(EBP, Address::Absolute(Thread::TidOffset<kX86PointerSize>().Int32Value())); |
| 1289 | __ j(kEqual, &continue_execution); |
| 1290 | __ Bind(&resolution); |
| 1291 | |
| 1292 | __ popl(EBP); |
| 1293 | // Jump to the resolution stub. |
| 1294 | ThreadOffset32 entrypoint_offset = |
| 1295 | GetThreadOffset<kX86PointerSize>(kQuickQuickResolutionTrampoline); |
| 1296 | __ fs()->jmp(Address::Absolute(entrypoint_offset)); |
| 1297 | |
| 1298 | __ Bind(&continue_execution); |
| 1299 | __ popl(EBP); |
| 1300 | } |
| 1301 | |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1302 | __ Bind(&frame_entry_label_); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1303 | bool skip_overflow_check = |
| 1304 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1305 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 1306 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1307 | if (!skip_overflow_check) { |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1308 | size_t reserved_bytes = GetStackOverflowReservedBytes(InstructionSet::kX86); |
| 1309 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(reserved_bytes))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1310 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 1311 | } |
| 1312 | |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1313 | if (!HasEmptyFrame()) { |
| 1314 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 1315 | Register reg = kCoreCalleeSaves[i]; |
| 1316 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1317 | __ pushl(reg); |
| 1318 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 1319 | __ cfi().RelOffset(DWARFReg(reg), 0); |
| 1320 | } |
| 1321 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1322 | |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1323 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1324 | IncreaseFrame(adjust); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1325 | // Save the current method if we need it. Note that we do not |
| 1326 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1327 | // in the SSA graph. |
| 1328 | if (RequiresCurrentMethod()) { |
| 1329 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
| 1330 | } |
| 1331 | |
| 1332 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1333 | // Initialize should_deoptimize flag to 0. |
| 1334 | __ movl(Address(ESP, GetStackOffsetOfShouldDeoptimizeFlag()), Immediate(0)); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1335 | } |
| 1336 | } |
| 1337 | |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1338 | MaybeIncrementHotness(/* is_frame_entry= */ true); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1339 | } |
| 1340 | |
| 1341 | void CodeGeneratorX86::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1342 | __ cfi().RememberState(); |
| 1343 | if (!HasEmptyFrame()) { |
| 1344 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1345 | DecreaseFrame(adjust); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1346 | |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1347 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1348 | Register reg = kCoreCalleeSaves[i]; |
| 1349 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1350 | __ popl(reg); |
| 1351 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 1352 | __ cfi().Restore(DWARFReg(reg)); |
| 1353 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1354 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1355 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1356 | __ ret(); |
| 1357 | __ cfi().RestoreState(); |
| 1358 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1359 | } |
| 1360 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1361 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 1362 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1363 | } |
| 1364 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1365 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(DataType::Type type) const { |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1366 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1367 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1368 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1369 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1370 | case DataType::Type::kInt8: |
| 1371 | case DataType::Type::kUint16: |
| 1372 | case DataType::Type::kInt16: |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1373 | case DataType::Type::kUint32: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1374 | case DataType::Type::kInt32: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1375 | return Location::RegisterLocation(EAX); |
| 1376 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1377 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1378 | case DataType::Type::kInt64: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1379 | return Location::RegisterPairLocation(EAX, EDX); |
| 1380 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1381 | case DataType::Type::kVoid: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1382 | return Location::NoLocation(); |
| 1383 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1384 | case DataType::Type::kFloat64: |
| 1385 | case DataType::Type::kFloat32: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1386 | return Location::FpuRegisterLocation(XMM0); |
| 1387 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1388 | |
| 1389 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1390 | } |
| 1391 | |
| 1392 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 1393 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1394 | } |
| 1395 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1396 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(DataType::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1397 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1398 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1399 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1400 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1401 | case DataType::Type::kInt8: |
| 1402 | case DataType::Type::kUint16: |
| 1403 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1404 | case DataType::Type::kInt32: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1405 | uint32_t index = gp_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1406 | stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1407 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1408 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1409 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1410 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1411 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1412 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1413 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1414 | case DataType::Type::kInt64: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1415 | uint32_t index = gp_index_; |
| 1416 | gp_index_ += 2; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1417 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1418 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1419 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 1420 | calling_convention.GetRegisterPairAt(index)); |
| 1421 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1422 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1423 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1424 | } |
| 1425 | } |
| 1426 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1427 | case DataType::Type::kFloat32: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1428 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1429 | stack_index_++; |
| 1430 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1431 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1432 | } else { |
| 1433 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1434 | } |
| 1435 | } |
| 1436 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1437 | case DataType::Type::kFloat64: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1438 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1439 | stack_index_ += 2; |
| 1440 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1441 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1442 | } else { |
| 1443 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1444 | } |
| 1445 | } |
| 1446 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1447 | case DataType::Type::kUint32: |
| 1448 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1449 | case DataType::Type::kVoid: |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1450 | LOG(FATAL) << "Unexpected parameter type " << type; |
Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 1451 | UNREACHABLE(); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1452 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1453 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1454 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1455 | |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 1456 | Location CriticalNativeCallingConventionVisitorX86::GetNextLocation(DataType::Type type) { |
| 1457 | DCHECK_NE(type, DataType::Type::kReference); |
| 1458 | |
| 1459 | Location location; |
| 1460 | if (DataType::Is64BitType(type)) { |
| 1461 | location = Location::DoubleStackSlot(stack_offset_); |
| 1462 | stack_offset_ += 2 * kFramePointerSize; |
| 1463 | } else { |
| 1464 | location = Location::StackSlot(stack_offset_); |
| 1465 | stack_offset_ += kFramePointerSize; |
| 1466 | } |
| 1467 | if (for_register_allocation_) { |
| 1468 | location = Location::Any(); |
| 1469 | } |
| 1470 | return location; |
| 1471 | } |
| 1472 | |
| 1473 | Location CriticalNativeCallingConventionVisitorX86::GetReturnLocation(DataType::Type type) const { |
| 1474 | // We perform conversion to the managed ABI return register after the call if needed. |
| 1475 | InvokeDexCallingConventionVisitorX86 dex_calling_convention; |
| 1476 | return dex_calling_convention.GetReturnLocation(type); |
| 1477 | } |
| 1478 | |
| 1479 | Location CriticalNativeCallingConventionVisitorX86::GetMethodLocation() const { |
| 1480 | // Pass the method in the hidden argument EAX. |
| 1481 | return Location::RegisterLocation(EAX); |
| 1482 | } |
| 1483 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1484 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 1485 | if (source.Equals(destination)) { |
| 1486 | return; |
| 1487 | } |
| 1488 | if (destination.IsRegister()) { |
| 1489 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1490 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1491 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1492 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
Andra Danciu | 5e13d45 | 2020-09-08 14:35:09 +0000 | [diff] [blame] | 1493 | } else if (source.IsConstant()) { |
| 1494 | int32_t value = GetInt32ValueOf(source.GetConstant()); |
| 1495 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1496 | } else { |
| 1497 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1498 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1499 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1500 | } else if (destination.IsFpuRegister()) { |
| 1501 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1502 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1503 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1504 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1505 | } else { |
| 1506 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1507 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1508 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1509 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1510 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1511 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1512 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1513 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1514 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1515 | } else if (source.IsConstant()) { |
| 1516 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1517 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1518 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1519 | } else { |
| 1520 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1521 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 1522 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1523 | } |
| 1524 | } |
| 1525 | } |
| 1526 | |
| 1527 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 1528 | if (source.Equals(destination)) { |
| 1529 | return; |
| 1530 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1531 | if (destination.IsRegisterPair()) { |
| 1532 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1533 | EmitParallelMoves( |
| 1534 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1535 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1536 | DataType::Type::kInt32, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1537 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1538 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1539 | DataType::Type::kInt32); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1540 | } else if (source.IsFpuRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1541 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 1542 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 1543 | __ psrlq(src_reg, Immediate(32)); |
| 1544 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1545 | } else { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1546 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1547 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1548 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 1549 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1550 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 1551 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1552 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1553 | if (source.IsFpuRegister()) { |
| 1554 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 1555 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1556 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1557 | } else if (source.IsRegisterPair()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1558 | size_t elem_size = DataType::Size(DataType::Type::kInt32); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1559 | // Push the 2 source registers to the stack. |
| 1560 | __ pushl(source.AsRegisterPairHigh<Register>()); |
| 1561 | __ cfi().AdjustCFAOffset(elem_size); |
| 1562 | __ pushl(source.AsRegisterPairLow<Register>()); |
| 1563 | __ cfi().AdjustCFAOffset(elem_size); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1564 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 1565 | // And remove the temporary stack space we allocated. |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1566 | DecreaseFrame(2 * elem_size); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1567 | } else { |
| 1568 | LOG(FATAL) << "Unimplemented"; |
| 1569 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1570 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1571 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1572 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1573 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1574 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1575 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1576 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1577 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1578 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1579 | } else if (source.IsConstant()) { |
| 1580 | HConstant* constant = source.GetConstant(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1581 | DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant()); |
| 1582 | int64_t value = GetInt64ValueOf(constant); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1583 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1584 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
| 1585 | Immediate(High32Bits(value))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1586 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1587 | DCHECK(source.IsDoubleStackSlot()) << source; |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1588 | EmitParallelMoves( |
| 1589 | Location::StackSlot(source.GetStackIndex()), |
| 1590 | Location::StackSlot(destination.GetStackIndex()), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1591 | DataType::Type::kInt32, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1592 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1593 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1594 | DataType::Type::kInt32); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1595 | } |
| 1596 | } |
| 1597 | } |
| 1598 | |
Andra Danciu | 1ca6f32 | 2020-08-12 08:58:07 +0000 | [diff] [blame] | 1599 | static Address CreateAddress(Register base, |
| 1600 | Register index = Register::kNoRegister, |
| 1601 | ScaleFactor scale = TIMES_1, |
| 1602 | int32_t disp = 0) { |
| 1603 | if (index == Register::kNoRegister) { |
| 1604 | return Address(base, disp); |
| 1605 | } |
| 1606 | |
| 1607 | return Address(base, index, scale, disp); |
| 1608 | } |
| 1609 | |
Andra Danciu | d0f71f2 | 2020-09-17 09:00:15 +0000 | [diff] [blame] | 1610 | void CodeGeneratorX86::LoadFromMemoryNoBarrier(DataType::Type dst_type, |
| 1611 | Location dst, |
| 1612 | Address src, |
Ulya Trafimovich | 322eced | 2021-06-02 15:39:36 +0100 | [diff] [blame] | 1613 | HInstruction* instr, |
Andra Danciu | d0f71f2 | 2020-09-17 09:00:15 +0000 | [diff] [blame] | 1614 | XmmRegister temp, |
| 1615 | bool is_atomic_load) { |
Andra Danciu | 1ca6f32 | 2020-08-12 08:58:07 +0000 | [diff] [blame] | 1616 | switch (dst_type) { |
| 1617 | case DataType::Type::kBool: |
| 1618 | case DataType::Type::kUint8: |
| 1619 | __ movzxb(dst.AsRegister<Register>(), src); |
| 1620 | break; |
| 1621 | case DataType::Type::kInt8: |
| 1622 | __ movsxb(dst.AsRegister<Register>(), src); |
| 1623 | break; |
| 1624 | case DataType::Type::kInt16: |
| 1625 | __ movsxw(dst.AsRegister<Register>(), src); |
| 1626 | break; |
| 1627 | case DataType::Type::kUint16: |
| 1628 | __ movzxw(dst.AsRegister<Register>(), src); |
| 1629 | break; |
| 1630 | case DataType::Type::kInt32: |
Andra Danciu | 1ca6f32 | 2020-08-12 08:58:07 +0000 | [diff] [blame] | 1631 | __ movl(dst.AsRegister<Register>(), src); |
| 1632 | break; |
Andra Danciu | d0f71f2 | 2020-09-17 09:00:15 +0000 | [diff] [blame] | 1633 | case DataType::Type::kInt64: { |
| 1634 | if (is_atomic_load) { |
| 1635 | __ movsd(temp, src); |
Ulya Trafimovich | 322eced | 2021-06-02 15:39:36 +0100 | [diff] [blame] | 1636 | if (instr != nullptr) { |
| 1637 | MaybeRecordImplicitNullCheck(instr); |
| 1638 | } |
Andra Danciu | d0f71f2 | 2020-09-17 09:00:15 +0000 | [diff] [blame] | 1639 | __ movd(dst.AsRegisterPairLow<Register>(), temp); |
| 1640 | __ psrlq(temp, Immediate(32)); |
| 1641 | __ movd(dst.AsRegisterPairHigh<Register>(), temp); |
| 1642 | } else { |
| 1643 | DCHECK_NE(src.GetBaseRegister(), dst.AsRegisterPairLow<Register>()); |
Ulya Trafimovich | 893e2ed | 2021-06-10 16:18:12 +0100 | [diff] [blame] | 1644 | Address src_high = Address::displace(src, kX86WordSize); |
Andra Danciu | d0f71f2 | 2020-09-17 09:00:15 +0000 | [diff] [blame] | 1645 | __ movl(dst.AsRegisterPairLow<Register>(), src); |
Ulya Trafimovich | 322eced | 2021-06-02 15:39:36 +0100 | [diff] [blame] | 1646 | if (instr != nullptr) { |
| 1647 | MaybeRecordImplicitNullCheck(instr); |
| 1648 | } |
Andra Danciu | d0f71f2 | 2020-09-17 09:00:15 +0000 | [diff] [blame] | 1649 | __ movl(dst.AsRegisterPairHigh<Register>(), src_high); |
| 1650 | } |
Andra Danciu | 1ca6f32 | 2020-08-12 08:58:07 +0000 | [diff] [blame] | 1651 | break; |
| 1652 | } |
| 1653 | case DataType::Type::kFloat32: |
| 1654 | __ movss(dst.AsFpuRegister<XmmRegister>(), src); |
| 1655 | break; |
| 1656 | case DataType::Type::kFloat64: |
| 1657 | __ movsd(dst.AsFpuRegister<XmmRegister>(), src); |
| 1658 | break; |
Andra Danciu | 1ca6f32 | 2020-08-12 08:58:07 +0000 | [diff] [blame] | 1659 | case DataType::Type::kReference: |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 1660 | DCHECK(!gUseReadBarrier); |
Andra Danciu | d0f71f2 | 2020-09-17 09:00:15 +0000 | [diff] [blame] | 1661 | __ movl(dst.AsRegister<Register>(), src); |
| 1662 | __ MaybeUnpoisonHeapReference(dst.AsRegister<Register>()); |
| 1663 | break; |
| 1664 | default: |
Andra Danciu | 1ca6f32 | 2020-08-12 08:58:07 +0000 | [diff] [blame] | 1665 | LOG(FATAL) << "Unreachable type " << dst_type; |
| 1666 | } |
Ulya Trafimovich | 322eced | 2021-06-02 15:39:36 +0100 | [diff] [blame] | 1667 | if (instr != nullptr && dst_type != DataType::Type::kInt64) { |
| 1668 | // kInt64 needs special handling that is done in the above switch. |
| 1669 | MaybeRecordImplicitNullCheck(instr); |
| 1670 | } |
Andra Danciu | 1ca6f32 | 2020-08-12 08:58:07 +0000 | [diff] [blame] | 1671 | } |
| 1672 | |
Andra Danciu | 73c3180 | 2020-09-01 13:17:05 +0000 | [diff] [blame] | 1673 | void CodeGeneratorX86::MoveToMemory(DataType::Type src_type, |
| 1674 | Location src, |
| 1675 | Register dst_base, |
| 1676 | Register dst_index, |
| 1677 | ScaleFactor dst_scale, |
| 1678 | int32_t dst_disp) { |
| 1679 | DCHECK(dst_base != Register::kNoRegister); |
| 1680 | Address dst = CreateAddress(dst_base, dst_index, dst_scale, dst_disp); |
| 1681 | |
| 1682 | switch (src_type) { |
| 1683 | case DataType::Type::kBool: |
| 1684 | case DataType::Type::kUint8: |
| 1685 | case DataType::Type::kInt8: { |
| 1686 | if (src.IsConstant()) { |
| 1687 | __ movb(dst, Immediate(CodeGenerator::GetInt8ValueOf(src.GetConstant()))); |
| 1688 | } else { |
| 1689 | __ movb(dst, src.AsRegister<ByteRegister>()); |
| 1690 | } |
| 1691 | break; |
| 1692 | } |
| 1693 | case DataType::Type::kUint16: |
| 1694 | case DataType::Type::kInt16: { |
| 1695 | if (src.IsConstant()) { |
| 1696 | __ movw(dst, Immediate(CodeGenerator::GetInt16ValueOf(src.GetConstant()))); |
| 1697 | } else { |
| 1698 | __ movw(dst, src.AsRegister<Register>()); |
| 1699 | } |
| 1700 | break; |
| 1701 | } |
| 1702 | case DataType::Type::kUint32: |
| 1703 | case DataType::Type::kInt32: { |
| 1704 | if (src.IsConstant()) { |
| 1705 | int32_t v = CodeGenerator::GetInt32ValueOf(src.GetConstant()); |
| 1706 | __ movl(dst, Immediate(v)); |
| 1707 | } else { |
| 1708 | __ movl(dst, src.AsRegister<Register>()); |
| 1709 | } |
| 1710 | break; |
| 1711 | } |
| 1712 | case DataType::Type::kUint64: |
| 1713 | case DataType::Type::kInt64: { |
| 1714 | Address dst_next_4_bytes = CreateAddress(dst_base, dst_index, dst_scale, dst_disp + 4); |
| 1715 | if (src.IsConstant()) { |
| 1716 | int64_t v = CodeGenerator::GetInt64ValueOf(src.GetConstant()); |
| 1717 | __ movl(dst, Immediate(Low32Bits(v))); |
| 1718 | __ movl(dst_next_4_bytes, Immediate(High32Bits(v))); |
| 1719 | } else { |
| 1720 | __ movl(dst, src.AsRegisterPairLow<Register>()); |
| 1721 | __ movl(dst_next_4_bytes, src.AsRegisterPairHigh<Register>()); |
| 1722 | } |
| 1723 | break; |
| 1724 | } |
| 1725 | case DataType::Type::kFloat32: { |
| 1726 | if (src.IsConstant()) { |
| 1727 | int32_t v = CodeGenerator::GetInt32ValueOf(src.GetConstant()); |
| 1728 | __ movl(dst, Immediate(v)); |
| 1729 | } else { |
| 1730 | __ movss(dst, src.AsFpuRegister<XmmRegister>()); |
| 1731 | } |
| 1732 | break; |
| 1733 | } |
| 1734 | case DataType::Type::kFloat64: { |
| 1735 | Address dst_next_4_bytes = CreateAddress(dst_base, dst_index, dst_scale, dst_disp + 4); |
| 1736 | if (src.IsConstant()) { |
| 1737 | int64_t v = CodeGenerator::GetInt64ValueOf(src.GetConstant()); |
| 1738 | __ movl(dst, Immediate(Low32Bits(v))); |
| 1739 | __ movl(dst_next_4_bytes, Immediate(High32Bits(v))); |
| 1740 | } else { |
| 1741 | __ movsd(dst, src.AsFpuRegister<XmmRegister>()); |
| 1742 | } |
| 1743 | break; |
| 1744 | } |
| 1745 | case DataType::Type::kVoid: |
| 1746 | case DataType::Type::kReference: |
| 1747 | LOG(FATAL) << "Unreachable type " << src_type; |
| 1748 | } |
| 1749 | } |
| 1750 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1751 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { |
| 1752 | DCHECK(location.IsRegister()); |
| 1753 | __ movl(location.AsRegister<Register>(), Immediate(value)); |
| 1754 | } |
| 1755 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1756 | void CodeGeneratorX86::MoveLocation(Location dst, Location src, DataType::Type dst_type) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1757 | HParallelMove move(GetGraph()->GetAllocator()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1758 | if (dst_type == DataType::Type::kInt64 && !src.IsConstant() && !src.IsFpuRegister()) { |
| 1759 | move.AddMove(src.ToLow(), dst.ToLow(), DataType::Type::kInt32, nullptr); |
| 1760 | move.AddMove(src.ToHigh(), dst.ToHigh(), DataType::Type::kInt32, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1761 | } else { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1762 | move.AddMove(src, dst, dst_type, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1763 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1764 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1765 | } |
| 1766 | |
| 1767 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1768 | if (location.IsRegister()) { |
| 1769 | locations->AddTemp(location); |
| 1770 | } else if (location.IsRegisterPair()) { |
| 1771 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1772 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1773 | } else { |
| 1774 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1775 | } |
| 1776 | } |
| 1777 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1778 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 1779 | if (successor->IsExitBlock()) { |
| 1780 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 1781 | return; // no code needed |
| 1782 | } |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1783 | |
| 1784 | HBasicBlock* block = got->GetBlock(); |
| 1785 | HInstruction* previous = got->GetPrevious(); |
| 1786 | |
| 1787 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1788 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1789 | codegen_->MaybeIncrementHotness(/* is_frame_entry= */ false); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1790 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1791 | return; |
| 1792 | } |
| 1793 | |
| 1794 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1795 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1796 | } |
| 1797 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1798 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1799 | } |
| 1800 | } |
| 1801 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1802 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 1803 | got->SetLocations(nullptr); |
| 1804 | } |
| 1805 | |
| 1806 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 1807 | HandleGoto(got, got->GetSuccessor()); |
| 1808 | } |
| 1809 | |
| 1810 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1811 | try_boundary->SetLocations(nullptr); |
| 1812 | } |
| 1813 | |
| 1814 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1815 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1816 | if (!successor->IsExitBlock()) { |
| 1817 | HandleGoto(try_boundary, successor); |
| 1818 | } |
| 1819 | } |
| 1820 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1821 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1822 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1823 | } |
| 1824 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1825 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1826 | } |
| 1827 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1828 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1829 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1830 | LabelType* true_label, |
| 1831 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1832 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1833 | __ j(kUnordered, true_label); |
| 1834 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1835 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1836 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1837 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1838 | } |
| 1839 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1840 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1841 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1842 | LabelType* true_label, |
| 1843 | LabelType* false_label) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1844 | LocationSummary* locations = cond->GetLocations(); |
| 1845 | Location left = locations->InAt(0); |
| 1846 | Location right = locations->InAt(1); |
| 1847 | IfCondition if_cond = cond->GetCondition(); |
| 1848 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1849 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1850 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1851 | IfCondition true_high_cond = if_cond; |
| 1852 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1853 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); // unsigned on lower part |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1854 | |
| 1855 | // Set the conditions for the test, remembering that == needs to be |
| 1856 | // decided using the low words. |
| 1857 | switch (if_cond) { |
| 1858 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1859 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1860 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1861 | break; |
| 1862 | case kCondLT: |
| 1863 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1864 | break; |
| 1865 | case kCondLE: |
| 1866 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1867 | break; |
| 1868 | case kCondGT: |
| 1869 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1870 | break; |
| 1871 | case kCondGE: |
| 1872 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1873 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1874 | case kCondB: |
| 1875 | false_high_cond = kCondA; |
| 1876 | break; |
| 1877 | case kCondBE: |
| 1878 | true_high_cond = kCondB; |
| 1879 | break; |
| 1880 | case kCondA: |
| 1881 | false_high_cond = kCondB; |
| 1882 | break; |
| 1883 | case kCondAE: |
| 1884 | true_high_cond = kCondA; |
| 1885 | break; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1886 | } |
| 1887 | |
| 1888 | if (right.IsConstant()) { |
| 1889 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1890 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1891 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1892 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1893 | codegen_->Compare32BitValue(left_high, val_high); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1894 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1895 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1896 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1897 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1898 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1899 | __ j(X86Condition(true_high_cond), true_label); |
| 1900 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1901 | } |
| 1902 | // Must be equal high, so compare the lows. |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1903 | codegen_->Compare32BitValue(left_low, val_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1904 | } else if (right.IsRegisterPair()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1905 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1906 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1907 | |
| 1908 | __ cmpl(left_high, right_high); |
| 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. |
| 1918 | __ cmpl(left_low, right_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1919 | } else { |
| 1920 | DCHECK(right.IsDoubleStackSlot()); |
| 1921 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
| 1922 | if (if_cond == kCondNE) { |
| 1923 | __ j(X86Condition(true_high_cond), true_label); |
| 1924 | } else if (if_cond == kCondEQ) { |
| 1925 | __ j(X86Condition(false_high_cond), false_label); |
| 1926 | } else { |
| 1927 | __ j(X86Condition(true_high_cond), true_label); |
| 1928 | __ j(X86Condition(false_high_cond), false_label); |
| 1929 | } |
| 1930 | // Must be equal high, so compare the lows. |
| 1931 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1932 | } |
| 1933 | // The last comparison might be unsigned. |
| 1934 | __ j(final_condition, true_label); |
| 1935 | } |
| 1936 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1937 | void InstructionCodeGeneratorX86::GenerateFPCompare(Location lhs, |
| 1938 | Location rhs, |
| 1939 | HInstruction* insn, |
| 1940 | bool is_double) { |
| 1941 | HX86LoadFromConstantTable* const_area = insn->InputAt(1)->AsX86LoadFromConstantTable(); |
| 1942 | if (is_double) { |
| 1943 | if (rhs.IsFpuRegister()) { |
| 1944 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1945 | } else if (const_area != nullptr) { |
| 1946 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1947 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), |
| 1948 | codegen_->LiteralDoubleAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1949 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 1950 | const_area->GetBaseMethodAddress(), |
| 1951 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1952 | } else { |
| 1953 | DCHECK(rhs.IsDoubleStackSlot()); |
| 1954 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1955 | } |
| 1956 | } else { |
| 1957 | if (rhs.IsFpuRegister()) { |
| 1958 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1959 | } else if (const_area != nullptr) { |
| 1960 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1961 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), |
| 1962 | codegen_->LiteralFloatAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1963 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 1964 | const_area->GetBaseMethodAddress(), |
| 1965 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1966 | } else { |
| 1967 | DCHECK(rhs.IsStackSlot()); |
| 1968 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1969 | } |
| 1970 | } |
| 1971 | } |
| 1972 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1973 | template<class LabelType> |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1974 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1975 | LabelType* true_target_in, |
| 1976 | LabelType* false_target_in) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1977 | // Generated branching requires both targets to be explicit. If either of the |
| 1978 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1979 | LabelType fallthrough_target; |
| 1980 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1981 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1982 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1983 | LocationSummary* locations = condition->GetLocations(); |
| 1984 | Location left = locations->InAt(0); |
| 1985 | Location right = locations->InAt(1); |
| 1986 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1987 | DataType::Type type = condition->InputAt(0)->GetType(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1988 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1989 | case DataType::Type::kInt64: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1990 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1991 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1992 | case DataType::Type::kFloat32: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1993 | GenerateFPCompare(left, right, condition, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1994 | GenerateFPJumps(condition, true_target, false_target); |
| 1995 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1996 | case DataType::Type::kFloat64: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1997 | GenerateFPCompare(left, right, condition, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1998 | GenerateFPJumps(condition, true_target, false_target); |
| 1999 | break; |
| 2000 | default: |
| 2001 | LOG(FATAL) << "Unexpected compare type " << type; |
| 2002 | } |
| 2003 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2004 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2005 | __ jmp(false_target); |
| 2006 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2007 | |
| 2008 | if (fallthrough_target.IsLinked()) { |
| 2009 | __ Bind(&fallthrough_target); |
| 2010 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2011 | } |
| 2012 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2013 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 2014 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 2015 | // are set only strictly before `branch`. We can't use the eflags on long/FP |
| 2016 | // conditions if they are materialized due to the complex branching. |
| 2017 | return cond->IsCondition() && |
| 2018 | cond->GetNext() == branch && |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2019 | cond->InputAt(0)->GetType() != DataType::Type::kInt64 && |
| 2020 | !DataType::IsFloatingPointType(cond->InputAt(0)->GetType()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2021 | } |
| 2022 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 2023 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2024 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2025 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 2026 | LabelType* true_target, |
| 2027 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2028 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 2029 | |
| 2030 | if (true_target == nullptr && false_target == nullptr) { |
| 2031 | // Nothing to do. The code always falls through. |
| 2032 | return; |
| 2033 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2034 | // Constant condition, statically compared against "true" (integer value 1). |
| 2035 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2036 | if (true_target != nullptr) { |
| 2037 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 2038 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2039 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2040 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2041 | if (false_target != nullptr) { |
| 2042 | __ jmp(false_target); |
| 2043 | } |
| 2044 | } |
| 2045 | return; |
| 2046 | } |
| 2047 | |
| 2048 | // The following code generates these patterns: |
| 2049 | // (1) true_target == nullptr && false_target != nullptr |
| 2050 | // - opposite condition true => branch to false_target |
| 2051 | // (2) true_target != nullptr && false_target == nullptr |
| 2052 | // - condition true => branch to true_target |
| 2053 | // (3) true_target != nullptr && false_target != nullptr |
| 2054 | // - condition true => branch to true_target |
| 2055 | // - branch to false_target |
| 2056 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 2057 | if (AreEflagsSetFrom(cond, instruction)) { |
| 2058 | if (true_target == nullptr) { |
| 2059 | __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 2060 | } else { |
| 2061 | __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); |
| 2062 | } |
| 2063 | } else { |
| 2064 | // Materialized condition, compare against 0. |
| 2065 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 2066 | if (lhs.IsRegister()) { |
| 2067 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 2068 | } else { |
| 2069 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 2070 | } |
| 2071 | if (true_target == nullptr) { |
| 2072 | __ j(kEqual, false_target); |
| 2073 | } else { |
| 2074 | __ j(kNotEqual, true_target); |
| 2075 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2076 | } |
| 2077 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2078 | // Condition has not been materialized, use its inputs as the comparison and |
| 2079 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 2080 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2081 | |
| 2082 | // If this is a long or FP comparison that has been folded into |
| 2083 | // the HCondition, generate the comparison directly. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2084 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 2085 | if (type == DataType::Type::kInt64 || DataType::IsFloatingPointType(type)) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2086 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 2087 | return; |
| 2088 | } |
| 2089 | |
| 2090 | Location lhs = condition->GetLocations()->InAt(0); |
| 2091 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2092 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition). |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 2093 | codegen_->GenerateIntCompare(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2094 | if (true_target == nullptr) { |
| 2095 | __ j(X86Condition(condition->GetOppositeCondition()), false_target); |
| 2096 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 2097 | __ j(X86Condition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2098 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2099 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2100 | |
| 2101 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 2102 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 2103 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2104 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2105 | } |
| 2106 | } |
| 2107 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2108 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2109 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2110 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2111 | locations->SetInAt(0, Location::Any()); |
| 2112 | } |
| 2113 | } |
| 2114 | |
| 2115 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2116 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 2117 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 2118 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 2119 | nullptr : codegen_->GetLabelOf(true_successor); |
| 2120 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 2121 | nullptr : codegen_->GetLabelOf(false_successor); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2122 | GenerateTestAndBranch(if_instr, /* condition_input_index= */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2123 | } |
| 2124 | |
| 2125 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2126 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2127 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 2128 | InvokeRuntimeCallingConvention calling_convention; |
| 2129 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 2130 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2131 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2132 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2133 | locations->SetInAt(0, Location::Any()); |
| 2134 | } |
| 2135 | } |
| 2136 | |
| 2137 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 2138 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2139 | GenerateTestAndBranch<Label>(deoptimize, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2140 | /* condition_input_index= */ 0, |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2141 | slow_path->GetEntryLabel(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2142 | /* false_target= */ nullptr); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2143 | } |
| 2144 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 2145 | void LocationsBuilderX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2146 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 2147 | LocationSummary(flag, LocationSummary::kNoCall); |
| 2148 | locations->SetOut(Location::RequiresRegister()); |
| 2149 | } |
| 2150 | |
| 2151 | void InstructionCodeGeneratorX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 2152 | __ movl(flag->GetLocations()->Out().AsRegister<Register>(), |
| 2153 | Address(ESP, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 2154 | } |
| 2155 | |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2156 | static bool SelectCanUseCMOV(HSelect* select) { |
| 2157 | // There are no conditional move instructions for XMMs. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2158 | if (DataType::IsFloatingPointType(select->GetType())) { |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2159 | return false; |
| 2160 | } |
| 2161 | |
| 2162 | // A FP condition doesn't generate the single CC that we need. |
| 2163 | // In 32 bit mode, a long condition doesn't generate a single CC either. |
| 2164 | HInstruction* condition = select->GetCondition(); |
| 2165 | if (condition->IsCondition()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2166 | DataType::Type compare_type = condition->InputAt(0)->GetType(); |
| 2167 | if (compare_type == DataType::Type::kInt64 || |
| 2168 | DataType::IsFloatingPointType(compare_type)) { |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2169 | return false; |
| 2170 | } |
| 2171 | } |
| 2172 | |
| 2173 | // We can generate a CMOV for this Select. |
| 2174 | return true; |
| 2175 | } |
| 2176 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2177 | void LocationsBuilderX86::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2178 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2179 | if (DataType::IsFloatingPointType(select->GetType())) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2180 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2181 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2182 | } else { |
| 2183 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2184 | if (SelectCanUseCMOV(select)) { |
| 2185 | if (select->InputAt(1)->IsConstant()) { |
| 2186 | // Cmov can't handle a constant value. |
| 2187 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2188 | } else { |
| 2189 | locations->SetInAt(1, Location::Any()); |
| 2190 | } |
| 2191 | } else { |
| 2192 | locations->SetInAt(1, Location::Any()); |
| 2193 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2194 | } |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2195 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 2196 | locations->SetInAt(2, Location::RequiresRegister()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2197 | } |
| 2198 | locations->SetOut(Location::SameAsFirstInput()); |
| 2199 | } |
| 2200 | |
| 2201 | void InstructionCodeGeneratorX86::VisitSelect(HSelect* select) { |
| 2202 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2203 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 2204 | if (SelectCanUseCMOV(select)) { |
| 2205 | // If both the condition and the source types are integer, we can generate |
| 2206 | // a CMOV to implement Select. |
| 2207 | |
| 2208 | HInstruction* select_condition = select->GetCondition(); |
| 2209 | Condition cond = kNotEqual; |
| 2210 | |
| 2211 | // Figure out how to test the 'condition'. |
| 2212 | if (select_condition->IsCondition()) { |
| 2213 | HCondition* condition = select_condition->AsCondition(); |
| 2214 | if (!condition->IsEmittedAtUseSite()) { |
| 2215 | // This was a previously materialized condition. |
| 2216 | // Can we use the existing condition code? |
| 2217 | if (AreEflagsSetFrom(condition, select)) { |
| 2218 | // Materialization was the previous instruction. Condition codes are right. |
| 2219 | cond = X86Condition(condition->GetCondition()); |
| 2220 | } else { |
| 2221 | // No, we have to recreate the condition code. |
| 2222 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 2223 | __ testl(cond_reg, cond_reg); |
| 2224 | } |
| 2225 | } else { |
| 2226 | // We can't handle FP or long here. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2227 | DCHECK_NE(condition->InputAt(0)->GetType(), DataType::Type::kInt64); |
| 2228 | DCHECK(!DataType::IsFloatingPointType(condition->InputAt(0)->GetType())); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2229 | LocationSummary* cond_locations = condition->GetLocations(); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2230 | codegen_->GenerateIntCompare(cond_locations->InAt(0), cond_locations->InAt(1)); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2231 | cond = X86Condition(condition->GetCondition()); |
| 2232 | } |
| 2233 | } else { |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 2234 | // Must be a Boolean condition, which needs to be compared to 0. |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2235 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 2236 | __ testl(cond_reg, cond_reg); |
| 2237 | } |
| 2238 | |
| 2239 | // If the condition is true, overwrite the output, which already contains false. |
| 2240 | Location false_loc = locations->InAt(0); |
| 2241 | Location true_loc = locations->InAt(1); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2242 | if (select->GetType() == DataType::Type::kInt64) { |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2243 | // 64 bit conditional move. |
| 2244 | Register false_high = false_loc.AsRegisterPairHigh<Register>(); |
| 2245 | Register false_low = false_loc.AsRegisterPairLow<Register>(); |
| 2246 | if (true_loc.IsRegisterPair()) { |
| 2247 | __ cmovl(cond, false_high, true_loc.AsRegisterPairHigh<Register>()); |
| 2248 | __ cmovl(cond, false_low, true_loc.AsRegisterPairLow<Register>()); |
| 2249 | } else { |
| 2250 | __ cmovl(cond, false_high, Address(ESP, true_loc.GetHighStackIndex(kX86WordSize))); |
| 2251 | __ cmovl(cond, false_low, Address(ESP, true_loc.GetStackIndex())); |
| 2252 | } |
| 2253 | } else { |
| 2254 | // 32 bit conditional move. |
| 2255 | Register false_reg = false_loc.AsRegister<Register>(); |
| 2256 | if (true_loc.IsRegister()) { |
| 2257 | __ cmovl(cond, false_reg, true_loc.AsRegister<Register>()); |
| 2258 | } else { |
| 2259 | __ cmovl(cond, false_reg, Address(ESP, true_loc.GetStackIndex())); |
| 2260 | } |
| 2261 | } |
| 2262 | } else { |
| 2263 | NearLabel false_target; |
| 2264 | GenerateTestAndBranch<NearLabel>( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2265 | select, /* condition_input_index= */ 2, /* true_target= */ nullptr, &false_target); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 2266 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 2267 | __ Bind(&false_target); |
| 2268 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2269 | } |
| 2270 | |
Santiago Aboy Solanes | caf9b65 | 2022-06-24 10:03:30 +0100 | [diff] [blame] | 2271 | void LocationsBuilderX86::VisitNop(HNop* nop) { |
| 2272 | new (GetGraph()->GetAllocator()) LocationSummary(nop); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 2273 | } |
| 2274 | |
Santiago Aboy Solanes | caf9b65 | 2022-06-24 10:03:30 +0100 | [diff] [blame] | 2275 | void InstructionCodeGeneratorX86::VisitNop(HNop*) { |
| 2276 | // The environment recording already happened in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 2277 | } |
| 2278 | |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 2279 | void CodeGeneratorX86::IncreaseFrame(size_t adjustment) { |
| 2280 | __ subl(ESP, Immediate(adjustment)); |
| 2281 | __ cfi().AdjustCFAOffset(adjustment); |
| 2282 | } |
| 2283 | |
| 2284 | void CodeGeneratorX86::DecreaseFrame(size_t adjustment) { |
| 2285 | __ addl(ESP, Immediate(adjustment)); |
| 2286 | __ cfi().AdjustCFAOffset(-adjustment); |
| 2287 | } |
| 2288 | |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 2289 | void CodeGeneratorX86::GenerateNop() { |
| 2290 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 2291 | } |
| 2292 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2293 | void LocationsBuilderX86::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2294 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2295 | new (GetGraph()->GetAllocator()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2296 | // Handle the long/FP comparisons made in instruction simplification. |
| 2297 | switch (cond->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2298 | case DataType::Type::kInt64: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2299 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 2300 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2301 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2302 | locations->SetOut(Location::RequiresRegister()); |
| 2303 | } |
| 2304 | break; |
| 2305 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2306 | case DataType::Type::kFloat32: |
| 2307 | case DataType::Type::kFloat64: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2308 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2309 | if (cond->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2310 | DCHECK(cond->InputAt(1)->IsEmittedAtUseSite()); |
| 2311 | } else if (cond->InputAt(1)->IsConstant()) { |
| 2312 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2313 | } else { |
| 2314 | locations->SetInAt(1, Location::Any()); |
| 2315 | } |
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 | } |
| 2321 | default: |
| 2322 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2323 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2324 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2325 | // We need a byte register. |
| 2326 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 2327 | } |
| 2328 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2329 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2330 | } |
| 2331 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2332 | void InstructionCodeGeneratorX86::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2333 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2334 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2335 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2336 | |
| 2337 | LocationSummary* locations = cond->GetLocations(); |
| 2338 | Location lhs = locations->InAt(0); |
| 2339 | Location rhs = locations->InAt(1); |
| 2340 | Register reg = locations->Out().AsRegister<Register>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 2341 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2342 | |
| 2343 | switch (cond->InputAt(0)->GetType()) { |
| 2344 | default: { |
| 2345 | // Integer case. |
| 2346 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 2347 | // Clear output register: setb only sets the low byte. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2348 | __ xorl(reg, reg); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2349 | codegen_->GenerateIntCompare(lhs, rhs); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2350 | __ setb(X86Condition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2351 | return; |
| 2352 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2353 | case DataType::Type::kInt64: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2354 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 2355 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2356 | case DataType::Type::kFloat32: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2357 | GenerateFPCompare(lhs, rhs, cond, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2358 | GenerateFPJumps(cond, &true_label, &false_label); |
| 2359 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2360 | case DataType::Type::kFloat64: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2361 | GenerateFPCompare(lhs, rhs, cond, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2362 | GenerateFPJumps(cond, &true_label, &false_label); |
| 2363 | break; |
| 2364 | } |
| 2365 | |
| 2366 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2367 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2368 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2369 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2370 | __ Bind(&false_label); |
| 2371 | __ xorl(reg, reg); |
| 2372 | __ jmp(&done_label); |
| 2373 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2374 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2375 | __ Bind(&true_label); |
| 2376 | __ movl(reg, Immediate(1)); |
| 2377 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2378 | } |
| 2379 | |
| 2380 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2381 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2382 | } |
| 2383 | |
| 2384 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2385 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2386 | } |
| 2387 | |
| 2388 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2389 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2390 | } |
| 2391 | |
| 2392 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2393 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2394 | } |
| 2395 | |
| 2396 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2397 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2398 | } |
| 2399 | |
| 2400 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2401 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2402 | } |
| 2403 | |
| 2404 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2405 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2406 | } |
| 2407 | |
| 2408 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2409 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2410 | } |
| 2411 | |
| 2412 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2413 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2414 | } |
| 2415 | |
| 2416 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2417 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2418 | } |
| 2419 | |
| 2420 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2421 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2422 | } |
| 2423 | |
| 2424 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2425 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2426 | } |
| 2427 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2428 | void LocationsBuilderX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2429 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2430 | } |
| 2431 | |
| 2432 | void InstructionCodeGeneratorX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2433 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2434 | } |
| 2435 | |
| 2436 | void LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2437 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2438 | } |
| 2439 | |
| 2440 | void InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2441 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2442 | } |
| 2443 | |
| 2444 | void LocationsBuilderX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2445 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2446 | } |
| 2447 | |
| 2448 | void InstructionCodeGeneratorX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2449 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2450 | } |
| 2451 | |
| 2452 | void LocationsBuilderX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2453 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2454 | } |
| 2455 | |
| 2456 | void InstructionCodeGeneratorX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2457 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2458 | } |
| 2459 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2460 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2461 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2462 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2463 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2464 | } |
| 2465 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2466 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2467 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2468 | } |
| 2469 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2470 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 2471 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2472 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2473 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2474 | } |
| 2475 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2476 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2477 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2478 | } |
| 2479 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2480 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2481 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2482 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2483 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2484 | } |
| 2485 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2486 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2487 | // Will be generated at use site. |
| 2488 | } |
| 2489 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2490 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 2491 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2492 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2493 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2494 | } |
| 2495 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2496 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2497 | // Will be generated at use site. |
| 2498 | } |
| 2499 | |
| 2500 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2501 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2502 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2503 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2504 | } |
| 2505 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2506 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2507 | // Will be generated at use site. |
| 2508 | } |
| 2509 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2510 | void LocationsBuilderX86::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 2511 | constructor_fence->SetLocations(nullptr); |
| 2512 | } |
| 2513 | |
| 2514 | void InstructionCodeGeneratorX86::VisitConstructorFence( |
| 2515 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 2516 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 2517 | } |
| 2518 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2519 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2520 | memory_barrier->SetLocations(nullptr); |
| 2521 | } |
| 2522 | |
| 2523 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 2524 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2525 | } |
| 2526 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2527 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2528 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2529 | } |
| 2530 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2531 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2532 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2533 | } |
| 2534 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2535 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2536 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2537 | new (GetGraph()->GetAllocator()) LocationSummary(ret, LocationSummary::kNoCall); |
Mythri Alle | 5097f83 | 2021-11-02 14:52:30 +0000 | [diff] [blame] | 2538 | SetInForReturnValue(ret, locations); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2539 | } |
| 2540 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2541 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 57cacb7 | 2019-12-08 22:07:08 +0000 | [diff] [blame] | 2542 | switch (ret->InputAt(0)->GetType()) { |
| 2543 | case DataType::Type::kReference: |
| 2544 | case DataType::Type::kBool: |
| 2545 | case DataType::Type::kUint8: |
| 2546 | case DataType::Type::kInt8: |
| 2547 | case DataType::Type::kUint16: |
| 2548 | case DataType::Type::kInt16: |
| 2549 | case DataType::Type::kInt32: |
| 2550 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
| 2551 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2552 | |
Nicolas Geoffray | 57cacb7 | 2019-12-08 22:07:08 +0000 | [diff] [blame] | 2553 | case DataType::Type::kInt64: |
| 2554 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 2555 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
| 2556 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2557 | |
Nicolas Geoffray | 57cacb7 | 2019-12-08 22:07:08 +0000 | [diff] [blame] | 2558 | case DataType::Type::kFloat32: |
| 2559 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
| 2560 | if (GetGraph()->IsCompilingOsr()) { |
| 2561 | // To simplify callers of an OSR method, we put the return value in both |
| 2562 | // floating point and core registers. |
| 2563 | __ movd(EAX, XMM0); |
| 2564 | } |
| 2565 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2566 | |
Nicolas Geoffray | 57cacb7 | 2019-12-08 22:07:08 +0000 | [diff] [blame] | 2567 | case DataType::Type::kFloat64: |
| 2568 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
| 2569 | if (GetGraph()->IsCompilingOsr()) { |
| 2570 | // To simplify callers of an OSR method, we put the return value in both |
| 2571 | // floating point and core registers. |
| 2572 | __ movd(EAX, XMM0); |
| 2573 | // Use XMM1 as temporary register to not clobber XMM0. |
| 2574 | __ movaps(XMM1, XMM0); |
| 2575 | __ psrlq(XMM1, Immediate(32)); |
| 2576 | __ movd(EDX, XMM1); |
| 2577 | } |
| 2578 | break; |
| 2579 | |
| 2580 | default: |
| 2581 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2582 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2583 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2584 | } |
| 2585 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2586 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2587 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2588 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2589 | // the method_idx. |
| 2590 | HandleInvoke(invoke); |
| 2591 | } |
| 2592 | |
| 2593 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2594 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2595 | } |
| 2596 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2597 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2598 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2599 | // art::PrepareForRegisterAllocation. |
| 2600 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2601 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2602 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2603 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 2604 | if (invoke->GetLocations()->CanCall() && |
| 2605 | invoke->HasPcRelativeMethodLoadKind() && |
| 2606 | invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()).IsInvalid()) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 2607 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2608 | } |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2609 | return; |
| 2610 | } |
| 2611 | |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 2612 | if (invoke->GetCodePtrLocation() == CodePtrLocation::kCallCriticalNative) { |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 2613 | CriticalNativeCallingConventionVisitorX86 calling_convention_visitor( |
| 2614 | /*for_register_allocation=*/ true); |
| 2615 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 2616 | } else { |
| 2617 | HandleInvoke(invoke); |
| 2618 | } |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2619 | |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 2620 | // 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] | 2621 | if (invoke->HasPcRelativeMethodLoadKind()) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2622 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2623 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2624 | } |
| 2625 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2626 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 2627 | if (invoke->GetLocations()->Intrinsified()) { |
| 2628 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 2629 | intrinsic.Dispatch(invoke); |
| 2630 | return true; |
| 2631 | } |
| 2632 | return false; |
| 2633 | } |
| 2634 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2635 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2636 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2637 | // art::PrepareForRegisterAllocation. |
| 2638 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2639 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2640 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2641 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2642 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2643 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2644 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2645 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2646 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2647 | } |
| 2648 | |
| 2649 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 2650 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 2651 | if (intrinsic.TryDispatch(invoke)) { |
| 2652 | return; |
| 2653 | } |
| 2654 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2655 | HandleInvoke(invoke); |
Nicolas Geoffray | 9b5271e | 2019-12-04 14:39:46 +0000 | [diff] [blame] | 2656 | |
| 2657 | if (GetGraph()->IsCompilingBaseline() && !Runtime::Current()->IsAotCompiler()) { |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2658 | // Add one temporary for inline cache update. |
| 2659 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(EBP)); |
| 2660 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2661 | } |
| 2662 | |
| 2663 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2664 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2665 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2666 | } |
| 2667 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2668 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2669 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2670 | return; |
| 2671 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2672 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2673 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2674 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2675 | } |
| 2676 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2677 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2678 | // This call to HandleInvoke allocates a temporary (core) register |
| 2679 | // which is also used to transfer the hidden argument from FP to |
| 2680 | // core register. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2681 | HandleInvoke(invoke); |
| 2682 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2683 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2684 | |
Nicolas Geoffray | 9b5271e | 2019-12-04 14:39:46 +0000 | [diff] [blame] | 2685 | if (GetGraph()->IsCompilingBaseline() && !Runtime::Current()->IsAotCompiler()) { |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2686 | // Add one temporary for inline cache update. |
| 2687 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(EBP)); |
| 2688 | } |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 2689 | |
| 2690 | // For PC-relative load kinds the invoke has an extra input, the PC-relative address base. |
| 2691 | if (IsPcRelativeMethodLoadKind(invoke->GetHiddenArgumentLoadKind())) { |
| 2692 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| 2693 | } |
| 2694 | |
| 2695 | if (invoke->GetHiddenArgumentLoadKind() == MethodLoadKind::kRecursive) { |
| 2696 | invoke->GetLocations()->SetInAt(invoke->GetNumberOfArguments() - 1, |
| 2697 | Location::RequiresRegister()); |
| 2698 | } |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2699 | } |
| 2700 | |
| 2701 | void CodeGeneratorX86::MaybeGenerateInlineCacheCheck(HInstruction* instruction, Register klass) { |
| 2702 | DCHECK_EQ(EAX, klass); |
Nicolas Geoffray | 17a39ba | 2019-11-27 20:57:48 +0000 | [diff] [blame] | 2703 | // We know the destination of an intrinsic, so no need to record inline |
| 2704 | // caches (also the intrinsic location builder doesn't request an additional |
| 2705 | // temporary). |
| 2706 | if (!instruction->GetLocations()->Intrinsified() && |
Nicolas Geoffray | 9b5271e | 2019-12-04 14:39:46 +0000 | [diff] [blame] | 2707 | GetGraph()->IsCompilingBaseline() && |
Nicolas Geoffray | 17a39ba | 2019-11-27 20:57:48 +0000 | [diff] [blame] | 2708 | !Runtime::Current()->IsAotCompiler()) { |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2709 | DCHECK(!instruction->GetEnvironment()->IsFromInlinedInvoke()); |
Nicolas Geoffray | 9e59890 | 2021-11-19 14:53:07 +0000 | [diff] [blame] | 2710 | ProfilingInfo* info = GetGraph()->GetProfilingInfo(); |
| 2711 | DCHECK(info != nullptr); |
| 2712 | InlineCache* cache = info->GetInlineCache(instruction->GetDexPc()); |
| 2713 | uint32_t address = reinterpret_cast32<uint32_t>(cache); |
| 2714 | if (kIsDebugBuild) { |
| 2715 | uint32_t temp_index = instruction->GetLocations()->GetTempCount() - 1u; |
| 2716 | CHECK_EQ(EBP, instruction->GetLocations()->GetTemp(temp_index).AsRegister<Register>()); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2717 | } |
Nicolas Geoffray | 9e59890 | 2021-11-19 14:53:07 +0000 | [diff] [blame] | 2718 | Register temp = EBP; |
| 2719 | NearLabel done; |
| 2720 | __ movl(temp, Immediate(address)); |
| 2721 | // Fast path for a monomorphic cache. |
| 2722 | __ cmpl(klass, Address(temp, InlineCache::ClassesOffset().Int32Value())); |
| 2723 | __ j(kEqual, &done); |
| 2724 | GenerateInvokeRuntime(GetThreadOffset<kX86PointerSize>(kQuickUpdateInlineCache).Int32Value()); |
| 2725 | __ Bind(&done); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2726 | } |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2727 | } |
| 2728 | |
| 2729 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2730 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2731 | LocationSummary* locations = invoke->GetLocations(); |
| 2732 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2733 | XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2734 | Location receiver = locations->InAt(0); |
| 2735 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2736 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2737 | // Set the hidden argument. This is safe to do this here, as XMM7 |
| 2738 | // won't be modified thereafter, before the `call` instruction. |
| 2739 | DCHECK_EQ(XMM7, hidden_reg); |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 2740 | if (invoke->GetHiddenArgumentLoadKind() == MethodLoadKind::kRecursive) { |
| 2741 | __ movd(hidden_reg, locations->InAt(invoke->GetNumberOfArguments() - 1).AsRegister<Register>()); |
Nicolas Geoffray | d6bd107 | 2020-11-30 18:42:01 +0000 | [diff] [blame] | 2742 | } else if (invoke->GetHiddenArgumentLoadKind() != MethodLoadKind::kRuntimeCall) { |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 2743 | codegen_->LoadMethod(invoke->GetHiddenArgumentLoadKind(), locations->GetTemp(0), invoke); |
| 2744 | __ movd(hidden_reg, temp); |
| 2745 | } |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2746 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2747 | if (receiver.IsStackSlot()) { |
| 2748 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2749 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2750 | __ movl(temp, Address(temp, class_offset)); |
| 2751 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2752 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2753 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2754 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2755 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2756 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2757 | // emit a read barrier for the previous class reference load. |
| 2758 | // However this is not required in practice, as this is an |
| 2759 | // intermediate/temporary reference and because the current |
| 2760 | // concurrent copying collector keeps the from-space memory |
| 2761 | // intact/accessible until the end of the marking phase (the |
| 2762 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2763 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2764 | |
| 2765 | codegen_->MaybeGenerateInlineCacheCheck(invoke, temp); |
| 2766 | |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2767 | // temp = temp->GetAddressOfIMT() |
| 2768 | __ movl(temp, |
| 2769 | Address(temp, mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2770 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2771 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2772 | invoke->GetImtIndex(), kX86PointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2773 | __ movl(temp, Address(temp, method_offset)); |
Nicolas Geoffray | d6bd107 | 2020-11-30 18:42:01 +0000 | [diff] [blame] | 2774 | if (invoke->GetHiddenArgumentLoadKind() == MethodLoadKind::kRuntimeCall) { |
| 2775 | // We pass the method from the IMT in case of a conflict. This will ensure |
| 2776 | // we go into the runtime to resolve the actual method. |
| 2777 | __ movd(hidden_reg, temp); |
| 2778 | } |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2779 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2780 | __ call(Address(temp, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2781 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2782 | |
| 2783 | DCHECK(!codegen_->IsLeafMethod()); |
| 2784 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2785 | } |
| 2786 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2787 | void LocationsBuilderX86::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 2788 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 2789 | if (intrinsic.TryDispatch(invoke)) { |
| 2790 | return; |
| 2791 | } |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2792 | HandleInvoke(invoke); |
| 2793 | } |
| 2794 | |
| 2795 | void InstructionCodeGeneratorX86::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 2796 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2797 | return; |
| 2798 | } |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2799 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 2800 | } |
| 2801 | |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 2802 | void LocationsBuilderX86::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 2803 | HandleInvoke(invoke); |
| 2804 | } |
| 2805 | |
| 2806 | void InstructionCodeGeneratorX86::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 2807 | codegen_->GenerateInvokeCustomCall(invoke); |
| 2808 | } |
| 2809 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2810 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 2811 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2812 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2813 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2814 | case DataType::Type::kInt32: |
| 2815 | case DataType::Type::kInt64: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2816 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2817 | locations->SetOut(Location::SameAsFirstInput()); |
| 2818 | break; |
| 2819 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2820 | case DataType::Type::kFloat32: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2821 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2822 | locations->SetOut(Location::SameAsFirstInput()); |
| 2823 | locations->AddTemp(Location::RequiresRegister()); |
| 2824 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2825 | break; |
| 2826 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2827 | case DataType::Type::kFloat64: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2828 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2829 | locations->SetOut(Location::SameAsFirstInput()); |
| 2830 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2831 | break; |
| 2832 | |
| 2833 | default: |
| 2834 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2835 | } |
| 2836 | } |
| 2837 | |
| 2838 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 2839 | LocationSummary* locations = neg->GetLocations(); |
| 2840 | Location out = locations->Out(); |
| 2841 | Location in = locations->InAt(0); |
| 2842 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2843 | case DataType::Type::kInt32: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2844 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2845 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2846 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2847 | break; |
| 2848 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2849 | case DataType::Type::kInt64: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2850 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2851 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2852 | __ negl(out.AsRegisterPairLow<Register>()); |
| 2853 | // Negation is similar to subtraction from zero. The least |
| 2854 | // significant byte triggers a borrow when it is different from |
| 2855 | // zero; to take it into account, add 1 to the most significant |
| 2856 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 2857 | // operation. |
| 2858 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2859 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 2860 | break; |
| 2861 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2862 | case DataType::Type::kFloat32: { |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2863 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2864 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 2865 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2866 | // Implement float negation with an exclusive or with value |
| 2867 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2868 | // single-precision floating-point number). |
| 2869 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 2870 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2871 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2872 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2873 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2874 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2875 | case DataType::Type::kFloat64: { |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2876 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2877 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2878 | // Implement double negation with an exclusive or with value |
| 2879 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 2880 | // a double-precision floating-point number). |
| 2881 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2882 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2883 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2884 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2885 | |
| 2886 | default: |
| 2887 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2888 | } |
| 2889 | } |
| 2890 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2891 | void LocationsBuilderX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2892 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2893 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2894 | DCHECK(DataType::IsFloatingPointType(neg->GetType())); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2895 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2896 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2897 | locations->SetOut(Location::SameAsFirstInput()); |
| 2898 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2899 | } |
| 2900 | |
| 2901 | void InstructionCodeGeneratorX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2902 | LocationSummary* locations = neg->GetLocations(); |
| 2903 | Location out = locations->Out(); |
| 2904 | DCHECK(locations->InAt(0).Equals(out)); |
| 2905 | |
| 2906 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 2907 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2908 | if (neg->GetType() == DataType::Type::kFloat32) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 2909 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x80000000), |
| 2910 | neg->GetBaseMethodAddress(), |
| 2911 | constant_area)); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2912 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| 2913 | } else { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 2914 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000), |
| 2915 | neg->GetBaseMethodAddress(), |
| 2916 | constant_area)); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2917 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| 2918 | } |
| 2919 | } |
| 2920 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2921 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2922 | DataType::Type result_type = conversion->GetResultType(); |
| 2923 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2924 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 2925 | << input_type << " -> " << result_type; |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2926 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2927 | // The float-to-long and double-to-long type conversions rely on a |
| 2928 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2929 | LocationSummary::CallKind call_kind = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2930 | ((input_type == DataType::Type::kFloat32 || input_type == DataType::Type::kFloat64) |
| 2931 | && result_type == DataType::Type::kInt64) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2932 | ? LocationSummary::kCallOnMainOnly |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2933 | : LocationSummary::kNoCall; |
| 2934 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2935 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, call_kind); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2936 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2937 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2938 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2939 | case DataType::Type::kInt8: |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2940 | switch (input_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2941 | case DataType::Type::kUint8: |
| 2942 | case DataType::Type::kInt8: |
| 2943 | case DataType::Type::kUint16: |
| 2944 | case DataType::Type::kInt16: |
| 2945 | case DataType::Type::kInt32: |
| 2946 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 2947 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2948 | // the validation of the linear scan implementation |
| 2949 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2950 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2951 | case DataType::Type::kInt64: { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2952 | HInstruction* input = conversion->InputAt(0); |
| 2953 | Location input_location = input->IsConstant() |
| 2954 | ? Location::ConstantLocation(input->AsConstant()) |
| 2955 | : Location::RegisterPairLocation(EAX, EDX); |
| 2956 | locations->SetInAt(0, input_location); |
| 2957 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2958 | // the validation of the linear scan implementation |
| 2959 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2960 | break; |
| 2961 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2962 | |
| 2963 | default: |
| 2964 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2965 | << " to " << result_type; |
| 2966 | } |
| 2967 | break; |
| 2968 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2969 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2970 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2971 | DCHECK(DataType::IsIntegralType(input_type)) << input_type; |
| 2972 | locations->SetInAt(0, Location::Any()); |
| 2973 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2974 | break; |
| 2975 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2976 | case DataType::Type::kInt32: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2977 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2978 | case DataType::Type::kInt64: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2979 | locations->SetInAt(0, Location::Any()); |
| 2980 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2981 | break; |
| 2982 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2983 | case DataType::Type::kFloat32: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2984 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2985 | locations->SetOut(Location::RequiresRegister()); |
| 2986 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2987 | break; |
| 2988 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2989 | case DataType::Type::kFloat64: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2990 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2991 | locations->SetOut(Location::RequiresRegister()); |
| 2992 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2993 | break; |
| 2994 | |
| 2995 | default: |
| 2996 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2997 | << " to " << result_type; |
| 2998 | } |
| 2999 | break; |
| 3000 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3001 | case DataType::Type::kInt64: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3002 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3003 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3004 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3005 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3006 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3007 | case DataType::Type::kInt16: |
| 3008 | case DataType::Type::kInt32: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3009 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 3010 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3011 | break; |
| 3012 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3013 | case DataType::Type::kFloat32: |
| 3014 | case DataType::Type::kFloat64: { |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 3015 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 3016 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 3017 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 3018 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 3019 | // The runtime helper puts the result in EAX, EDX. |
| 3020 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 3021 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 3022 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3023 | |
| 3024 | default: |
| 3025 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3026 | << " to " << result_type; |
| 3027 | } |
| 3028 | break; |
| 3029 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3030 | case DataType::Type::kFloat32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3031 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3032 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3033 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3034 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3035 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3036 | case DataType::Type::kInt16: |
| 3037 | case DataType::Type::kInt32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3038 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3039 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3040 | break; |
| 3041 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3042 | case DataType::Type::kInt64: |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3043 | locations->SetInAt(0, Location::Any()); |
| 3044 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3045 | break; |
| 3046 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3047 | case DataType::Type::kFloat64: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3048 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3049 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3050 | break; |
| 3051 | |
| 3052 | default: |
| 3053 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3054 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3055 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3056 | break; |
| 3057 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3058 | case DataType::Type::kFloat64: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3059 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3060 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3061 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3062 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3063 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3064 | case DataType::Type::kInt16: |
| 3065 | case DataType::Type::kInt32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3066 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3067 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3068 | break; |
| 3069 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3070 | case DataType::Type::kInt64: |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3071 | locations->SetInAt(0, Location::Any()); |
| 3072 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3073 | break; |
| 3074 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3075 | case DataType::Type::kFloat32: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3076 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3077 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3078 | break; |
| 3079 | |
| 3080 | default: |
| 3081 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3082 | << " to " << result_type; |
| 3083 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3084 | break; |
| 3085 | |
| 3086 | default: |
| 3087 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3088 | << " to " << result_type; |
| 3089 | } |
| 3090 | } |
| 3091 | |
| 3092 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 3093 | LocationSummary* locations = conversion->GetLocations(); |
| 3094 | Location out = locations->Out(); |
| 3095 | Location in = locations->InAt(0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3096 | DataType::Type result_type = conversion->GetResultType(); |
| 3097 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3098 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 3099 | << input_type << " -> " << result_type; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3100 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3101 | case DataType::Type::kUint8: |
| 3102 | switch (input_type) { |
| 3103 | case DataType::Type::kInt8: |
| 3104 | case DataType::Type::kUint16: |
| 3105 | case DataType::Type::kInt16: |
| 3106 | case DataType::Type::kInt32: |
| 3107 | if (in.IsRegister()) { |
| 3108 | __ movzxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
| 3109 | } else { |
| 3110 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 3111 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 3112 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint8_t>(value))); |
| 3113 | } |
| 3114 | break; |
| 3115 | case DataType::Type::kInt64: |
| 3116 | if (in.IsRegisterPair()) { |
| 3117 | __ movzxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 3118 | } else { |
| 3119 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 3120 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3121 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint8_t>(value))); |
| 3122 | } |
| 3123 | break; |
| 3124 | |
| 3125 | default: |
| 3126 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3127 | << " to " << result_type; |
| 3128 | } |
| 3129 | break; |
| 3130 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3131 | case DataType::Type::kInt8: |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3132 | switch (input_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3133 | case DataType::Type::kUint8: |
| 3134 | case DataType::Type::kUint16: |
| 3135 | case DataType::Type::kInt16: |
| 3136 | case DataType::Type::kInt32: |
| 3137 | if (in.IsRegister()) { |
| 3138 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
| 3139 | } else { |
| 3140 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 3141 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 3142 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 3143 | } |
| 3144 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3145 | case DataType::Type::kInt64: |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3146 | if (in.IsRegisterPair()) { |
| 3147 | __ movsxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 3148 | } else { |
| 3149 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 3150 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3151 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 3152 | } |
| 3153 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3154 | |
| 3155 | default: |
| 3156 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3157 | << " to " << result_type; |
| 3158 | } |
| 3159 | break; |
| 3160 | |
| 3161 | case DataType::Type::kUint16: |
| 3162 | switch (input_type) { |
| 3163 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3164 | case DataType::Type::kInt16: |
| 3165 | case DataType::Type::kInt32: |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 3166 | if (in.IsRegister()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3167 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
| 3168 | } else if (in.IsStackSlot()) { |
| 3169 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 3170 | } else { |
| 3171 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 3172 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3173 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
| 3174 | } |
| 3175 | break; |
| 3176 | case DataType::Type::kInt64: |
| 3177 | if (in.IsRegisterPair()) { |
| 3178 | __ movzxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 3179 | } else if (in.IsDoubleStackSlot()) { |
| 3180 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 3181 | } else { |
| 3182 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 3183 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3184 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 3185 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3186 | break; |
| 3187 | |
| 3188 | default: |
| 3189 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3190 | << " to " << result_type; |
| 3191 | } |
| 3192 | break; |
| 3193 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3194 | case DataType::Type::kInt16: |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3195 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3196 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3197 | case DataType::Type::kInt32: |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3198 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3199 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3200 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3201 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3202 | } else { |
| 3203 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 3204 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3205 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3206 | } |
| 3207 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3208 | case DataType::Type::kInt64: |
| 3209 | if (in.IsRegisterPair()) { |
| 3210 | __ movsxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 3211 | } else if (in.IsDoubleStackSlot()) { |
| 3212 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 3213 | } else { |
| 3214 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 3215 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3216 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
| 3217 | } |
| 3218 | break; |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3219 | |
| 3220 | default: |
| 3221 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3222 | << " to " << result_type; |
| 3223 | } |
| 3224 | break; |
| 3225 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3226 | case DataType::Type::kInt32: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3227 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3228 | case DataType::Type::kInt64: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3229 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3230 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3231 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3232 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3233 | } else { |
| 3234 | DCHECK(in.IsConstant()); |
| 3235 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 3236 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3237 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3238 | } |
| 3239 | break; |
| 3240 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3241 | case DataType::Type::kFloat32: { |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 3242 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 3243 | Register output = out.AsRegister<Register>(); |
| 3244 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3245 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 3246 | |
| 3247 | __ movl(output, Immediate(kPrimIntMax)); |
| 3248 | // temp = int-to-float(output) |
| 3249 | __ cvtsi2ss(temp, output); |
| 3250 | // if input >= temp goto done |
| 3251 | __ comiss(input, temp); |
| 3252 | __ j(kAboveEqual, &done); |
| 3253 | // if input == NaN goto nan |
| 3254 | __ j(kUnordered, &nan); |
| 3255 | // output = float-to-int-truncate(input) |
| 3256 | __ cvttss2si(output, input); |
| 3257 | __ jmp(&done); |
| 3258 | __ Bind(&nan); |
| 3259 | // output = 0 |
| 3260 | __ xorl(output, output); |
| 3261 | __ Bind(&done); |
| 3262 | break; |
| 3263 | } |
| 3264 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3265 | case DataType::Type::kFloat64: { |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3266 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 3267 | Register output = out.AsRegister<Register>(); |
| 3268 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3269 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3270 | |
| 3271 | __ movl(output, Immediate(kPrimIntMax)); |
| 3272 | // temp = int-to-double(output) |
| 3273 | __ cvtsi2sd(temp, output); |
| 3274 | // if input >= temp goto done |
| 3275 | __ comisd(input, temp); |
| 3276 | __ j(kAboveEqual, &done); |
| 3277 | // if input == NaN goto nan |
| 3278 | __ j(kUnordered, &nan); |
| 3279 | // output = double-to-int-truncate(input) |
| 3280 | __ cvttsd2si(output, input); |
| 3281 | __ jmp(&done); |
| 3282 | __ Bind(&nan); |
| 3283 | // output = 0 |
| 3284 | __ xorl(output, output); |
| 3285 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3286 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3287 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3288 | |
| 3289 | default: |
| 3290 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3291 | << " to " << result_type; |
| 3292 | } |
| 3293 | break; |
| 3294 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3295 | case DataType::Type::kInt64: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3296 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3297 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3298 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3299 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3300 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3301 | case DataType::Type::kInt16: |
| 3302 | case DataType::Type::kInt32: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3303 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 3304 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3305 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3306 | __ cdq(); |
| 3307 | break; |
| 3308 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3309 | case DataType::Type::kFloat32: |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3310 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3311 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3312 | break; |
| 3313 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3314 | case DataType::Type::kFloat64: |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3315 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3316 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3317 | break; |
| 3318 | |
| 3319 | default: |
| 3320 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3321 | << " to " << result_type; |
| 3322 | } |
| 3323 | break; |
| 3324 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3325 | case DataType::Type::kFloat32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3326 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3327 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3328 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3329 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3330 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3331 | case DataType::Type::kInt16: |
| 3332 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3333 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3334 | break; |
| 3335 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3336 | case DataType::Type::kInt64: { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3337 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3338 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3339 | // Create stack space for the call to |
| 3340 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 3341 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3342 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3343 | adjustment = DataType::Size(DataType::Type::kInt64); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 3344 | codegen_->IncreaseFrame(adjustment); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3345 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3346 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3347 | // Load the value to the FP stack, using temporaries if needed. |
| 3348 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 3349 | |
| 3350 | if (out.IsStackSlot()) { |
| 3351 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 3352 | } else { |
| 3353 | __ fstps(Address(ESP, 0)); |
| 3354 | Location stack_temp = Location::StackSlot(0); |
| 3355 | codegen_->Move32(out, stack_temp); |
| 3356 | } |
| 3357 | |
| 3358 | // Remove the temporary stack space we allocated. |
| 3359 | if (adjustment != 0) { |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 3360 | codegen_->DecreaseFrame(adjustment); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3361 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3362 | break; |
| 3363 | } |
| 3364 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3365 | case DataType::Type::kFloat64: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3366 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3367 | break; |
| 3368 | |
| 3369 | default: |
| 3370 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3371 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3372 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3373 | break; |
| 3374 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3375 | case DataType::Type::kFloat64: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3376 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3377 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3378 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3379 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3380 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3381 | case DataType::Type::kInt16: |
| 3382 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3383 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3384 | break; |
| 3385 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3386 | case DataType::Type::kInt64: { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3387 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3388 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3389 | // Create stack space for the call to |
| 3390 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 3391 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3392 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3393 | adjustment = DataType::Size(DataType::Type::kInt64); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 3394 | codegen_->IncreaseFrame(adjustment); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3395 | } |
| 3396 | |
| 3397 | // Load the value to the FP stack, using temporaries if needed. |
| 3398 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 3399 | |
| 3400 | if (out.IsDoubleStackSlot()) { |
| 3401 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 3402 | } else { |
| 3403 | __ fstpl(Address(ESP, 0)); |
| 3404 | Location stack_temp = Location::DoubleStackSlot(0); |
| 3405 | codegen_->Move64(out, stack_temp); |
| 3406 | } |
| 3407 | |
| 3408 | // Remove the temporary stack space we allocated. |
| 3409 | if (adjustment != 0) { |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 3410 | codegen_->DecreaseFrame(adjustment); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3411 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3412 | break; |
| 3413 | } |
| 3414 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3415 | case DataType::Type::kFloat32: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3416 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3417 | break; |
| 3418 | |
| 3419 | default: |
| 3420 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3421 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3422 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3423 | break; |
| 3424 | |
| 3425 | default: |
| 3426 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3427 | << " to " << result_type; |
| 3428 | } |
| 3429 | } |
| 3430 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3431 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3432 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3433 | new (GetGraph()->GetAllocator()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3434 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3435 | case DataType::Type::kInt32: { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3436 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3437 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 3438 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3439 | break; |
| 3440 | } |
| 3441 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3442 | case DataType::Type::kInt64: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3443 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3444 | locations->SetInAt(1, Location::Any()); |
| 3445 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3446 | break; |
| 3447 | } |
| 3448 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3449 | case DataType::Type::kFloat32: |
| 3450 | case DataType::Type::kFloat64: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3451 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3452 | if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3453 | DCHECK(add->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3454 | } else if (add->InputAt(1)->IsConstant()) { |
| 3455 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3456 | } else { |
| 3457 | locations->SetInAt(1, Location::Any()); |
| 3458 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3459 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3460 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3461 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3462 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3463 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3464 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 3465 | UNREACHABLE(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3466 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3467 | } |
| 3468 | |
| 3469 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 3470 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3471 | Location first = locations->InAt(0); |
| 3472 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3473 | Location out = locations->Out(); |
| 3474 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3475 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3476 | case DataType::Type::kInt32: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3477 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3478 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3479 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 3480 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 3481 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3482 | } else { |
| 3483 | __ leal(out.AsRegister<Register>(), Address( |
| 3484 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 3485 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3486 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3487 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3488 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3489 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 3490 | } else { |
| 3491 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 3492 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3493 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3494 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3495 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3496 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3497 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3498 | } |
| 3499 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3500 | case DataType::Type::kInt64: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3501 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3502 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3503 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3504 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3505 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 3506 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3507 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3508 | } else { |
| 3509 | DCHECK(second.IsConstant()) << second; |
| 3510 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3511 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 3512 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3513 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3514 | break; |
| 3515 | } |
| 3516 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3517 | case DataType::Type::kFloat32: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3518 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3519 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3520 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3521 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3522 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3523 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 3524 | codegen_->LiteralFloatAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3525 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3526 | const_area->GetBaseMethodAddress(), |
| 3527 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3528 | } else { |
| 3529 | DCHECK(second.IsStackSlot()); |
| 3530 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3531 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3532 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3533 | } |
| 3534 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3535 | case DataType::Type::kFloat64: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3536 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3537 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3538 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3539 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3540 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3541 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 3542 | codegen_->LiteralDoubleAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3543 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3544 | const_area->GetBaseMethodAddress(), |
| 3545 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3546 | } else { |
| 3547 | DCHECK(second.IsDoubleStackSlot()); |
| 3548 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3549 | } |
| 3550 | break; |
| 3551 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3552 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3553 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3554 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3555 | } |
| 3556 | } |
| 3557 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3558 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3559 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3560 | new (GetGraph()->GetAllocator()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3561 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3562 | case DataType::Type::kInt32: |
| 3563 | case DataType::Type::kInt64: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3564 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3565 | locations->SetInAt(1, Location::Any()); |
| 3566 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3567 | break; |
| 3568 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3569 | case DataType::Type::kFloat32: |
| 3570 | case DataType::Type::kFloat64: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3571 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3572 | if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3573 | DCHECK(sub->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3574 | } else if (sub->InputAt(1)->IsConstant()) { |
| 3575 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3576 | } else { |
| 3577 | locations->SetInAt(1, Location::Any()); |
| 3578 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3579 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3580 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3581 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3582 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3583 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3584 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3585 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3586 | } |
| 3587 | |
| 3588 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 3589 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3590 | Location first = locations->InAt(0); |
| 3591 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3592 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3593 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3594 | case DataType::Type::kInt32: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3595 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3596 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3597 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3598 | __ subl(first.AsRegister<Register>(), |
| 3599 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3600 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3601 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3602 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3603 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3604 | } |
| 3605 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3606 | case DataType::Type::kInt64: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3607 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3608 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3609 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3610 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3611 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3612 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 3613 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3614 | } else { |
| 3615 | DCHECK(second.IsConstant()) << second; |
| 3616 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3617 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 3618 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3619 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3620 | break; |
| 3621 | } |
| 3622 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3623 | case DataType::Type::kFloat32: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3624 | if (second.IsFpuRegister()) { |
| 3625 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3626 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3627 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3628 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3629 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3630 | codegen_->LiteralFloatAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3631 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3632 | const_area->GetBaseMethodAddress(), |
| 3633 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3634 | } else { |
| 3635 | DCHECK(second.IsStackSlot()); |
| 3636 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3637 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3638 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3639 | } |
| 3640 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3641 | case DataType::Type::kFloat64: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3642 | if (second.IsFpuRegister()) { |
| 3643 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3644 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3645 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3646 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3647 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3648 | codegen_->LiteralDoubleAddress( |
| 3649 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3650 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3651 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3652 | } else { |
| 3653 | DCHECK(second.IsDoubleStackSlot()); |
| 3654 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3655 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3656 | break; |
| 3657 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3658 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3659 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3660 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3661 | } |
| 3662 | } |
| 3663 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3664 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 3665 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3666 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3667 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3668 | case DataType::Type::kInt32: |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3669 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3670 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3671 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3672 | // Can use 3 operand multiply. |
| 3673 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3674 | } else { |
| 3675 | locations->SetOut(Location::SameAsFirstInput()); |
| 3676 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3677 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3678 | case DataType::Type::kInt64: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3679 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3680 | locations->SetInAt(1, Location::Any()); |
| 3681 | locations->SetOut(Location::SameAsFirstInput()); |
| 3682 | // Needed for imul on 32bits with 64bits output. |
| 3683 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 3684 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 3685 | break; |
| 3686 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3687 | case DataType::Type::kFloat32: |
| 3688 | case DataType::Type::kFloat64: { |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3689 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3690 | if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3691 | DCHECK(mul->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3692 | } else if (mul->InputAt(1)->IsConstant()) { |
| 3693 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3694 | } else { |
| 3695 | locations->SetInAt(1, Location::Any()); |
| 3696 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3697 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3698 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3699 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3700 | |
| 3701 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3702 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3703 | } |
| 3704 | } |
| 3705 | |
| 3706 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 3707 | LocationSummary* locations = mul->GetLocations(); |
| 3708 | Location first = locations->InAt(0); |
| 3709 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3710 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3711 | |
| 3712 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3713 | case DataType::Type::kInt32: |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3714 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3715 | // problems where the output may not be the same as the first operand. |
| 3716 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3717 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3718 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 3719 | } else if (second.IsRegister()) { |
| 3720 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3721 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3722 | } else { |
| 3723 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3724 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3725 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3726 | } |
| 3727 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3728 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3729 | case DataType::Type::kInt64: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3730 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 3731 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3732 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 3733 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3734 | |
| 3735 | DCHECK_EQ(EAX, eax); |
| 3736 | DCHECK_EQ(EDX, edx); |
| 3737 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3738 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3739 | // output: in1 |
| 3740 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3741 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3742 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3743 | if (second.IsConstant()) { |
| 3744 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3745 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3746 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3747 | int32_t low_value = Low32Bits(value); |
| 3748 | int32_t high_value = High32Bits(value); |
| 3749 | Immediate low(low_value); |
| 3750 | Immediate high(high_value); |
| 3751 | |
| 3752 | __ movl(eax, high); |
| 3753 | // eax <- in1.lo * in2.hi |
| 3754 | __ imull(eax, in1_lo); |
| 3755 | // in1.hi <- in1.hi * in2.lo |
| 3756 | __ imull(in1_hi, low); |
| 3757 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3758 | __ addl(in1_hi, eax); |
| 3759 | // move in2_lo to eax to prepare for double precision |
| 3760 | __ movl(eax, low); |
| 3761 | // edx:eax <- in1.lo * in2.lo |
| 3762 | __ mull(in1_lo); |
| 3763 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3764 | __ addl(in1_hi, edx); |
| 3765 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3766 | __ movl(in1_lo, eax); |
| 3767 | } else if (second.IsRegisterPair()) { |
| 3768 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3769 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3770 | |
| 3771 | __ movl(eax, in2_hi); |
| 3772 | // eax <- in1.lo * in2.hi |
| 3773 | __ imull(eax, in1_lo); |
| 3774 | // in1.hi <- in1.hi * in2.lo |
| 3775 | __ imull(in1_hi, in2_lo); |
| 3776 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3777 | __ addl(in1_hi, eax); |
| 3778 | // move in1_lo to eax to prepare for double precision |
| 3779 | __ movl(eax, in1_lo); |
| 3780 | // edx:eax <- in1.lo * in2.lo |
| 3781 | __ mull(in2_lo); |
| 3782 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3783 | __ addl(in1_hi, edx); |
| 3784 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3785 | __ movl(in1_lo, eax); |
| 3786 | } else { |
| 3787 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 3788 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 3789 | Address in2_lo(ESP, second.GetStackIndex()); |
| 3790 | |
| 3791 | __ movl(eax, in2_hi); |
| 3792 | // eax <- in1.lo * in2.hi |
| 3793 | __ imull(eax, in1_lo); |
| 3794 | // in1.hi <- in1.hi * in2.lo |
| 3795 | __ imull(in1_hi, in2_lo); |
| 3796 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3797 | __ addl(in1_hi, eax); |
| 3798 | // move in1_lo to eax to prepare for double precision |
| 3799 | __ movl(eax, in1_lo); |
| 3800 | // edx:eax <- in1.lo * in2.lo |
| 3801 | __ mull(in2_lo); |
| 3802 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3803 | __ addl(in1_hi, edx); |
| 3804 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3805 | __ movl(in1_lo, eax); |
| 3806 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3807 | |
| 3808 | break; |
| 3809 | } |
| 3810 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3811 | case DataType::Type::kFloat32: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3812 | DCHECK(first.Equals(locations->Out())); |
| 3813 | if (second.IsFpuRegister()) { |
| 3814 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3815 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3816 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3817 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3818 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3819 | codegen_->LiteralFloatAddress( |
| 3820 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3821 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3822 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3823 | } else { |
| 3824 | DCHECK(second.IsStackSlot()); |
| 3825 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3826 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3827 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3828 | } |
| 3829 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3830 | case DataType::Type::kFloat64: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3831 | DCHECK(first.Equals(locations->Out())); |
| 3832 | if (second.IsFpuRegister()) { |
| 3833 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3834 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3835 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3836 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3837 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3838 | codegen_->LiteralDoubleAddress( |
| 3839 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3840 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3841 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3842 | } else { |
| 3843 | DCHECK(second.IsDoubleStackSlot()); |
| 3844 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3845 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3846 | break; |
| 3847 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3848 | |
| 3849 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3850 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3851 | } |
| 3852 | } |
| 3853 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3854 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 3855 | uint32_t temp_offset, |
| 3856 | uint32_t stack_adjustment, |
| 3857 | bool is_fp, |
| 3858 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3859 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3860 | DCHECK(!is_wide); |
| 3861 | if (is_fp) { |
| 3862 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3863 | } else { |
| 3864 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3865 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3866 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3867 | DCHECK(is_wide); |
| 3868 | if (is_fp) { |
| 3869 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3870 | } else { |
| 3871 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3872 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3873 | } else { |
| 3874 | // 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] | 3875 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3876 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3877 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3878 | if (is_fp) { |
| 3879 | __ flds(Address(ESP, temp_offset)); |
| 3880 | } else { |
| 3881 | __ filds(Address(ESP, temp_offset)); |
| 3882 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3883 | } else { |
| 3884 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3885 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3886 | if (is_fp) { |
| 3887 | __ fldl(Address(ESP, temp_offset)); |
| 3888 | } else { |
| 3889 | __ fildl(Address(ESP, temp_offset)); |
| 3890 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3891 | } |
| 3892 | } |
| 3893 | } |
| 3894 | |
| 3895 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3896 | DataType::Type type = rem->GetResultType(); |
| 3897 | bool is_float = type == DataType::Type::kFloat32; |
| 3898 | size_t elem_size = DataType::Size(type); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3899 | LocationSummary* locations = rem->GetLocations(); |
| 3900 | Location first = locations->InAt(0); |
| 3901 | Location second = locations->InAt(1); |
| 3902 | Location out = locations->Out(); |
| 3903 | |
| 3904 | // Create stack space for 2 elements. |
| 3905 | // TODO: enhance register allocator to ask for stack temporaries. |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 3906 | codegen_->IncreaseFrame(2 * elem_size); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3907 | |
| 3908 | // 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] | 3909 | const bool is_wide = !is_float; |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3910 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp= */ true, is_wide); |
| 3911 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp= */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3912 | |
| 3913 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3914 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3915 | __ Bind(&retry); |
| 3916 | __ fprem(); |
| 3917 | |
| 3918 | // Move FP status to AX. |
| 3919 | __ fstsw(); |
| 3920 | |
| 3921 | // And see if the argument reduction is complete. This is signaled by the |
| 3922 | // C2 FPU flag bit set to 0. |
| 3923 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 3924 | __ j(kNotEqual, &retry); |
| 3925 | |
| 3926 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3927 | // Store FP top of stack to real stack. |
| 3928 | if (is_float) { |
| 3929 | __ fsts(Address(ESP, 0)); |
| 3930 | } else { |
| 3931 | __ fstl(Address(ESP, 0)); |
| 3932 | } |
| 3933 | |
| 3934 | // Pop the 2 items from the FP stack. |
| 3935 | __ fucompp(); |
| 3936 | |
| 3937 | // Load the value from the stack into an XMM register. |
| 3938 | DCHECK(out.IsFpuRegister()) << out; |
| 3939 | if (is_float) { |
| 3940 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3941 | } else { |
| 3942 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3943 | } |
| 3944 | |
| 3945 | // And remove the temporary stack space we allocated. |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 3946 | codegen_->DecreaseFrame(2 * elem_size); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3947 | } |
| 3948 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3949 | |
| 3950 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3951 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3952 | |
| 3953 | LocationSummary* locations = instruction->GetLocations(); |
| 3954 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3955 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3956 | |
| 3957 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3958 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3959 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3960 | |
| 3961 | DCHECK(imm == 1 || imm == -1); |
| 3962 | |
| 3963 | if (instruction->IsRem()) { |
| 3964 | __ xorl(out_register, out_register); |
| 3965 | } else { |
| 3966 | __ movl(out_register, input_register); |
| 3967 | if (imm == -1) { |
| 3968 | __ negl(out_register); |
| 3969 | } |
| 3970 | } |
| 3971 | } |
| 3972 | |
Shalini Salomi Bodapati | a66784b | 2018-11-06 13:05:44 +0530 | [diff] [blame] | 3973 | void InstructionCodeGeneratorX86::RemByPowerOfTwo(HRem* instruction) { |
| 3974 | LocationSummary* locations = instruction->GetLocations(); |
| 3975 | Location second = locations->InAt(1); |
| 3976 | |
| 3977 | Register out = locations->Out().AsRegister<Register>(); |
| 3978 | Register numerator = locations->InAt(0).AsRegister<Register>(); |
| 3979 | |
| 3980 | int32_t imm = Int64FromConstant(second.GetConstant()); |
| 3981 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3982 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
| 3983 | |
| 3984 | Register tmp = locations->GetTemp(0).AsRegister<Register>(); |
| 3985 | NearLabel done; |
| 3986 | __ movl(out, numerator); |
| 3987 | __ andl(out, Immediate(abs_imm-1)); |
| 3988 | __ j(Condition::kZero, &done); |
| 3989 | __ leal(tmp, Address(out, static_cast<int32_t>(~(abs_imm-1)))); |
| 3990 | __ testl(numerator, numerator); |
| 3991 | __ cmovl(Condition::kLess, out, tmp); |
| 3992 | __ Bind(&done); |
| 3993 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3994 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3995 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3996 | LocationSummary* locations = instruction->GetLocations(); |
| 3997 | |
| 3998 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3999 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 4000 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4001 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 4002 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4003 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4004 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 4005 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4006 | __ leal(num, Address(input_register, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4007 | __ testl(input_register, input_register); |
| 4008 | __ cmovl(kGreaterEqual, num, input_register); |
| 4009 | int shift = CTZ(imm); |
| 4010 | __ sarl(num, Immediate(shift)); |
| 4011 | |
| 4012 | if (imm < 0) { |
| 4013 | __ negl(num); |
| 4014 | } |
| 4015 | |
| 4016 | __ movl(out_register, num); |
| 4017 | } |
| 4018 | |
| 4019 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 4020 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 4021 | |
| 4022 | LocationSummary* locations = instruction->GetLocations(); |
| 4023 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 4024 | |
| 4025 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 4026 | Register out = locations->Out().AsRegister<Register>(); |
| 4027 | Register num; |
| 4028 | Register edx; |
| 4029 | |
| 4030 | if (instruction->IsDiv()) { |
| 4031 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 4032 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 4033 | } else { |
| 4034 | edx = locations->Out().AsRegister<Register>(); |
| 4035 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 4036 | } |
| 4037 | |
| 4038 | DCHECK_EQ(EAX, eax); |
| 4039 | DCHECK_EQ(EDX, edx); |
| 4040 | if (instruction->IsDiv()) { |
| 4041 | DCHECK_EQ(EAX, out); |
| 4042 | } else { |
| 4043 | DCHECK_EQ(EDX, out); |
| 4044 | } |
| 4045 | |
| 4046 | int64_t magic; |
| 4047 | int shift; |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4048 | CalculateMagicAndShiftForDivRem(imm, /* is_long= */ false, &magic, &shift); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4049 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4050 | // Save the numerator. |
| 4051 | __ movl(num, eax); |
| 4052 | |
| 4053 | // EAX = magic |
| 4054 | __ movl(eax, Immediate(magic)); |
| 4055 | |
| 4056 | // EDX:EAX = magic * numerator |
| 4057 | __ imull(num); |
| 4058 | |
| 4059 | if (imm > 0 && magic < 0) { |
| 4060 | // EDX += num |
| 4061 | __ addl(edx, num); |
| 4062 | } else if (imm < 0 && magic > 0) { |
| 4063 | __ subl(edx, num); |
| 4064 | } |
| 4065 | |
| 4066 | // Shift if needed. |
| 4067 | if (shift != 0) { |
| 4068 | __ sarl(edx, Immediate(shift)); |
| 4069 | } |
| 4070 | |
| 4071 | // EDX += 1 if EDX < 0 |
| 4072 | __ movl(eax, edx); |
| 4073 | __ shrl(edx, Immediate(31)); |
| 4074 | __ addl(edx, eax); |
| 4075 | |
| 4076 | if (instruction->IsRem()) { |
| 4077 | __ movl(eax, num); |
| 4078 | __ imull(edx, Immediate(imm)); |
| 4079 | __ subl(eax, edx); |
| 4080 | __ movl(edx, eax); |
| 4081 | } else { |
| 4082 | __ movl(eax, edx); |
| 4083 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4084 | } |
| 4085 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4086 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 4087 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 4088 | |
| 4089 | LocationSummary* locations = instruction->GetLocations(); |
| 4090 | Location out = locations->Out(); |
| 4091 | Location first = locations->InAt(0); |
| 4092 | Location second = locations->InAt(1); |
| 4093 | bool is_div = instruction->IsDiv(); |
| 4094 | |
| 4095 | switch (instruction->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4096 | case DataType::Type::kInt32: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4097 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 4098 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4099 | |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 4100 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 4101 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4102 | |
| 4103 | if (imm == 0) { |
| 4104 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 4105 | } else if (imm == 1 || imm == -1) { |
| 4106 | DivRemOneOrMinusOne(instruction); |
Shalini Salomi Bodapati | a66784b | 2018-11-06 13:05:44 +0530 | [diff] [blame] | 4107 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 4108 | if (is_div) { |
| 4109 | DivByPowerOfTwo(instruction->AsDiv()); |
| 4110 | } else { |
| 4111 | RemByPowerOfTwo(instruction->AsRem()); |
| 4112 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4113 | } else { |
| 4114 | DCHECK(imm <= -2 || imm >= 2); |
| 4115 | GenerateDivRemWithAnyConstant(instruction); |
| 4116 | } |
| 4117 | } else { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4118 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) DivRemMinusOneSlowPathX86( |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 4119 | instruction, out.AsRegister<Register>(), is_div); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4120 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4121 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4122 | Register second_reg = second.AsRegister<Register>(); |
| 4123 | // 0x80000000/-1 triggers an arithmetic exception! |
| 4124 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 4125 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4126 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4127 | __ cmpl(second_reg, Immediate(-1)); |
| 4128 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4129 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4130 | // edx:eax <- sign-extended of eax |
| 4131 | __ cdq(); |
| 4132 | // eax = quotient, edx = remainder |
| 4133 | __ idivl(second_reg); |
| 4134 | __ Bind(slow_path->GetExitLabel()); |
| 4135 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4136 | break; |
| 4137 | } |
| 4138 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4139 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4140 | InvokeRuntimeCallingConvention calling_convention; |
| 4141 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 4142 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 4143 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 4144 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 4145 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 4146 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 4147 | |
| 4148 | if (is_div) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 4149 | codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4150 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4151 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 4152 | codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4153 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4154 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4155 | break; |
| 4156 | } |
| 4157 | |
| 4158 | default: |
| 4159 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 4160 | } |
| 4161 | } |
| 4162 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4163 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4164 | LocationSummary::CallKind call_kind = (div->GetResultType() == DataType::Type::kInt64) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4165 | ? LocationSummary::kCallOnMainOnly |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4166 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4167 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(div, call_kind); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4168 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4169 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4170 | case DataType::Type::kInt32: { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4171 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4172 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4173 | locations->SetOut(Location::SameAsFirstInput()); |
| 4174 | // Intel uses edx:eax as the dividend. |
| 4175 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4176 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 4177 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 4178 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 4179 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4180 | locations->AddTemp(Location::RequiresRegister()); |
| 4181 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4182 | break; |
| 4183 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4184 | case DataType::Type::kInt64: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4185 | InvokeRuntimeCallingConvention calling_convention; |
| 4186 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 4187 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4188 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 4189 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4190 | // Runtime helper puts the result in EAX, EDX. |
| 4191 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4192 | break; |
| 4193 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4194 | case DataType::Type::kFloat32: |
| 4195 | case DataType::Type::kFloat64: { |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4196 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 4197 | if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4198 | DCHECK(div->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 4199 | } else if (div->InputAt(1)->IsConstant()) { |
| 4200 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 4201 | } else { |
| 4202 | locations->SetInAt(1, Location::Any()); |
| 4203 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4204 | locations->SetOut(Location::SameAsFirstInput()); |
| 4205 | break; |
| 4206 | } |
| 4207 | |
| 4208 | default: |
| 4209 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4210 | } |
| 4211 | } |
| 4212 | |
| 4213 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 4214 | LocationSummary* locations = div->GetLocations(); |
| 4215 | Location first = locations->InAt(0); |
| 4216 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4217 | |
| 4218 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4219 | case DataType::Type::kInt32: |
| 4220 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4221 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4222 | break; |
| 4223 | } |
| 4224 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4225 | case DataType::Type::kFloat32: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 4226 | if (second.IsFpuRegister()) { |
| 4227 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 4228 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4229 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 4230 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 4231 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 4232 | codegen_->LiteralFloatAddress( |
| 4233 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4234 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 4235 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 4236 | } else { |
| 4237 | DCHECK(second.IsStackSlot()); |
| 4238 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 4239 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4240 | break; |
| 4241 | } |
| 4242 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4243 | case DataType::Type::kFloat64: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 4244 | if (second.IsFpuRegister()) { |
| 4245 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 4246 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4247 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 4248 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 4249 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 4250 | codegen_->LiteralDoubleAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4251 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 4252 | const_area->GetBaseMethodAddress(), |
| 4253 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 4254 | } else { |
| 4255 | DCHECK(second.IsDoubleStackSlot()); |
| 4256 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 4257 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4258 | break; |
| 4259 | } |
| 4260 | |
| 4261 | default: |
| 4262 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4263 | } |
| 4264 | } |
| 4265 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4266 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4267 | DataType::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4268 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4269 | LocationSummary::CallKind call_kind = (rem->GetResultType() == DataType::Type::kInt64) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4270 | ? LocationSummary::kCallOnMainOnly |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4271 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4272 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4273 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4274 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4275 | case DataType::Type::kInt32: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4276 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4277 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4278 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4279 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 4280 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 4281 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 4282 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4283 | locations->AddTemp(Location::RequiresRegister()); |
| 4284 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4285 | break; |
| 4286 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4287 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4288 | InvokeRuntimeCallingConvention calling_convention; |
| 4289 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 4290 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4291 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 4292 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4293 | // Runtime helper puts the result in EAX, EDX. |
| 4294 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 4295 | break; |
| 4296 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4297 | case DataType::Type::kFloat64: |
| 4298 | case DataType::Type::kFloat32: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 4299 | locations->SetInAt(0, Location::Any()); |
| 4300 | locations->SetInAt(1, Location::Any()); |
| 4301 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4302 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4303 | break; |
| 4304 | } |
| 4305 | |
| 4306 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4307 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4308 | } |
| 4309 | } |
| 4310 | |
| 4311 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4312 | DataType::Type type = rem->GetResultType(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4313 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4314 | case DataType::Type::kInt32: |
| 4315 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4316 | GenerateDivRemIntegral(rem); |
| 4317 | break; |
| 4318 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4319 | case DataType::Type::kFloat32: |
| 4320 | case DataType::Type::kFloat64: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 4321 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4322 | break; |
| 4323 | } |
| 4324 | default: |
| 4325 | LOG(FATAL) << "Unexpected rem type " << type; |
| 4326 | } |
| 4327 | } |
| 4328 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4329 | static void CreateMinMaxLocations(ArenaAllocator* allocator, HBinaryOperation* minmax) { |
| 4330 | LocationSummary* locations = new (allocator) LocationSummary(minmax); |
| 4331 | switch (minmax->GetResultType()) { |
| 4332 | case DataType::Type::kInt32: |
| 4333 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4334 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4335 | locations->SetOut(Location::SameAsFirstInput()); |
| 4336 | break; |
| 4337 | case DataType::Type::kInt64: |
| 4338 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4339 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4340 | locations->SetOut(Location::SameAsFirstInput()); |
| 4341 | // Register to use to perform a long subtract to set cc. |
| 4342 | locations->AddTemp(Location::RequiresRegister()); |
| 4343 | break; |
| 4344 | case DataType::Type::kFloat32: |
| 4345 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4346 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4347 | locations->SetOut(Location::SameAsFirstInput()); |
| 4348 | locations->AddTemp(Location::RequiresRegister()); |
| 4349 | break; |
| 4350 | case DataType::Type::kFloat64: |
| 4351 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4352 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4353 | locations->SetOut(Location::SameAsFirstInput()); |
| 4354 | break; |
| 4355 | default: |
| 4356 | LOG(FATAL) << "Unexpected type for HMinMax " << minmax->GetResultType(); |
| 4357 | } |
| 4358 | } |
| 4359 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4360 | void InstructionCodeGeneratorX86::GenerateMinMaxInt(LocationSummary* locations, |
| 4361 | bool is_min, |
| 4362 | DataType::Type type) { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4363 | Location op1_loc = locations->InAt(0); |
| 4364 | Location op2_loc = locations->InAt(1); |
| 4365 | |
| 4366 | // Shortcut for same input locations. |
| 4367 | if (op1_loc.Equals(op2_loc)) { |
| 4368 | // Can return immediately, as op1_loc == out_loc. |
| 4369 | // Note: if we ever support separate registers, e.g., output into memory, we need to check for |
| 4370 | // a copy here. |
| 4371 | DCHECK(locations->Out().Equals(op1_loc)); |
| 4372 | return; |
| 4373 | } |
| 4374 | |
| 4375 | if (type == DataType::Type::kInt64) { |
| 4376 | // Need to perform a subtract to get the sign right. |
| 4377 | // op1 is already in the same location as the output. |
| 4378 | Location output = locations->Out(); |
| 4379 | Register output_lo = output.AsRegisterPairLow<Register>(); |
| 4380 | Register output_hi = output.AsRegisterPairHigh<Register>(); |
| 4381 | |
| 4382 | Register op2_lo = op2_loc.AsRegisterPairLow<Register>(); |
| 4383 | Register op2_hi = op2_loc.AsRegisterPairHigh<Register>(); |
| 4384 | |
| 4385 | // The comparison is performed by subtracting the second operand from |
| 4386 | // the first operand and then setting the status flags in the same |
| 4387 | // manner as the SUB instruction." |
| 4388 | __ cmpl(output_lo, op2_lo); |
| 4389 | |
| 4390 | // Now use a temp and the borrow to finish the subtraction of op2_hi. |
| 4391 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4392 | __ movl(temp, output_hi); |
| 4393 | __ sbbl(temp, op2_hi); |
| 4394 | |
| 4395 | // Now the condition code is correct. |
| 4396 | Condition cond = is_min ? Condition::kGreaterEqual : Condition::kLess; |
| 4397 | __ cmovl(cond, output_lo, op2_lo); |
| 4398 | __ cmovl(cond, output_hi, op2_hi); |
| 4399 | } else { |
| 4400 | DCHECK_EQ(type, DataType::Type::kInt32); |
| 4401 | Register out = locations->Out().AsRegister<Register>(); |
| 4402 | Register op2 = op2_loc.AsRegister<Register>(); |
| 4403 | |
| 4404 | // (out := op1) |
| 4405 | // out <=? op2 |
| 4406 | // if out is min jmp done |
| 4407 | // out := op2 |
| 4408 | // done: |
| 4409 | |
| 4410 | __ cmpl(out, op2); |
| 4411 | Condition cond = is_min ? Condition::kGreater : Condition::kLess; |
| 4412 | __ cmovl(cond, out, op2); |
| 4413 | } |
| 4414 | } |
| 4415 | |
| 4416 | void InstructionCodeGeneratorX86::GenerateMinMaxFP(LocationSummary* locations, |
| 4417 | bool is_min, |
| 4418 | DataType::Type type) { |
| 4419 | Location op1_loc = locations->InAt(0); |
| 4420 | Location op2_loc = locations->InAt(1); |
| 4421 | Location out_loc = locations->Out(); |
| 4422 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
| 4423 | |
| 4424 | // Shortcut for same input locations. |
| 4425 | if (op1_loc.Equals(op2_loc)) { |
| 4426 | DCHECK(out_loc.Equals(op1_loc)); |
| 4427 | return; |
| 4428 | } |
| 4429 | |
| 4430 | // (out := op1) |
| 4431 | // out <=? op2 |
| 4432 | // if Nan jmp Nan_label |
| 4433 | // if out is min jmp done |
| 4434 | // if op2 is min jmp op2_label |
| 4435 | // handle -0/+0 |
| 4436 | // jmp done |
| 4437 | // Nan_label: |
| 4438 | // out := NaN |
| 4439 | // op2_label: |
| 4440 | // out := op2 |
| 4441 | // done: |
| 4442 | // |
| 4443 | // This removes one jmp, but needs to copy one input (op1) to out. |
| 4444 | // |
| 4445 | // TODO: This is straight from Quick (except literal pool). Make NaN an out-of-line slowpath? |
| 4446 | |
| 4447 | XmmRegister op2 = op2_loc.AsFpuRegister<XmmRegister>(); |
| 4448 | |
| 4449 | NearLabel nan, done, op2_label; |
| 4450 | if (type == DataType::Type::kFloat64) { |
| 4451 | __ ucomisd(out, op2); |
| 4452 | } else { |
| 4453 | DCHECK_EQ(type, DataType::Type::kFloat32); |
| 4454 | __ ucomiss(out, op2); |
| 4455 | } |
| 4456 | |
| 4457 | __ j(Condition::kParityEven, &nan); |
| 4458 | |
| 4459 | __ j(is_min ? Condition::kAbove : Condition::kBelow, &op2_label); |
| 4460 | __ j(is_min ? Condition::kBelow : Condition::kAbove, &done); |
| 4461 | |
| 4462 | // Handle 0.0/-0.0. |
| 4463 | if (is_min) { |
| 4464 | if (type == DataType::Type::kFloat64) { |
| 4465 | __ orpd(out, op2); |
| 4466 | } else { |
| 4467 | __ orps(out, op2); |
| 4468 | } |
| 4469 | } else { |
| 4470 | if (type == DataType::Type::kFloat64) { |
| 4471 | __ andpd(out, op2); |
| 4472 | } else { |
| 4473 | __ andps(out, op2); |
| 4474 | } |
| 4475 | } |
| 4476 | __ jmp(&done); |
| 4477 | |
| 4478 | // NaN handling. |
| 4479 | __ Bind(&nan); |
| 4480 | if (type == DataType::Type::kFloat64) { |
| 4481 | // TODO: Use a constant from the constant table (requires extra input). |
| 4482 | __ LoadLongConstant(out, kDoubleNaN); |
| 4483 | } else { |
| 4484 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 4485 | __ movl(constant, Immediate(kFloatNaN)); |
| 4486 | __ movd(out, constant); |
| 4487 | } |
| 4488 | __ jmp(&done); |
| 4489 | |
| 4490 | // out := op2; |
| 4491 | __ Bind(&op2_label); |
| 4492 | if (type == DataType::Type::kFloat64) { |
| 4493 | __ movsd(out, op2); |
| 4494 | } else { |
| 4495 | __ movss(out, op2); |
| 4496 | } |
| 4497 | |
| 4498 | // Done. |
| 4499 | __ Bind(&done); |
| 4500 | } |
| 4501 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4502 | void InstructionCodeGeneratorX86::GenerateMinMax(HBinaryOperation* minmax, bool is_min) { |
| 4503 | DataType::Type type = minmax->GetResultType(); |
| 4504 | switch (type) { |
| 4505 | case DataType::Type::kInt32: |
| 4506 | case DataType::Type::kInt64: |
| 4507 | GenerateMinMaxInt(minmax->GetLocations(), is_min, type); |
| 4508 | break; |
| 4509 | case DataType::Type::kFloat32: |
| 4510 | case DataType::Type::kFloat64: |
| 4511 | GenerateMinMaxFP(minmax->GetLocations(), is_min, type); |
| 4512 | break; |
| 4513 | default: |
| 4514 | LOG(FATAL) << "Unexpected type for HMinMax " << type; |
| 4515 | } |
| 4516 | } |
| 4517 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4518 | void LocationsBuilderX86::VisitMin(HMin* min) { |
| 4519 | CreateMinMaxLocations(GetGraph()->GetAllocator(), min); |
| 4520 | } |
| 4521 | |
| 4522 | void InstructionCodeGeneratorX86::VisitMin(HMin* min) { |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4523 | GenerateMinMax(min, /*is_min*/ true); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4524 | } |
| 4525 | |
| 4526 | void LocationsBuilderX86::VisitMax(HMax* max) { |
| 4527 | CreateMinMaxLocations(GetGraph()->GetAllocator(), max); |
| 4528 | } |
| 4529 | |
| 4530 | void InstructionCodeGeneratorX86::VisitMax(HMax* max) { |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4531 | GenerateMinMax(max, /*is_min*/ false); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4532 | } |
| 4533 | |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 4534 | void LocationsBuilderX86::VisitAbs(HAbs* abs) { |
| 4535 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 4536 | switch (abs->GetResultType()) { |
| 4537 | case DataType::Type::kInt32: |
| 4538 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 4539 | locations->SetOut(Location::SameAsFirstInput()); |
| 4540 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 4541 | break; |
| 4542 | case DataType::Type::kInt64: |
| 4543 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4544 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4545 | locations->AddTemp(Location::RequiresRegister()); |
| 4546 | break; |
| 4547 | case DataType::Type::kFloat32: |
| 4548 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4549 | locations->SetOut(Location::SameAsFirstInput()); |
| 4550 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4551 | locations->AddTemp(Location::RequiresRegister()); |
| 4552 | break; |
| 4553 | case DataType::Type::kFloat64: |
| 4554 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4555 | locations->SetOut(Location::SameAsFirstInput()); |
| 4556 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4557 | break; |
| 4558 | default: |
| 4559 | LOG(FATAL) << "Unexpected type for HAbs " << abs->GetResultType(); |
| 4560 | } |
| 4561 | } |
| 4562 | |
| 4563 | void InstructionCodeGeneratorX86::VisitAbs(HAbs* abs) { |
| 4564 | LocationSummary* locations = abs->GetLocations(); |
| 4565 | switch (abs->GetResultType()) { |
| 4566 | case DataType::Type::kInt32: { |
| 4567 | Register out = locations->Out().AsRegister<Register>(); |
| 4568 | DCHECK_EQ(out, EAX); |
| 4569 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4570 | DCHECK_EQ(temp, EDX); |
| 4571 | // Sign extend EAX into EDX. |
| 4572 | __ cdq(); |
| 4573 | // XOR EAX with sign. |
| 4574 | __ xorl(EAX, EDX); |
| 4575 | // Subtract out sign to correct. |
| 4576 | __ subl(EAX, EDX); |
| 4577 | // The result is in EAX. |
| 4578 | break; |
| 4579 | } |
| 4580 | case DataType::Type::kInt64: { |
| 4581 | Location input = locations->InAt(0); |
| 4582 | Register input_lo = input.AsRegisterPairLow<Register>(); |
| 4583 | Register input_hi = input.AsRegisterPairHigh<Register>(); |
| 4584 | Location output = locations->Out(); |
| 4585 | Register output_lo = output.AsRegisterPairLow<Register>(); |
| 4586 | Register output_hi = output.AsRegisterPairHigh<Register>(); |
| 4587 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4588 | // Compute the sign into the temporary. |
| 4589 | __ movl(temp, input_hi); |
| 4590 | __ sarl(temp, Immediate(31)); |
| 4591 | // Store the sign into the output. |
| 4592 | __ movl(output_lo, temp); |
| 4593 | __ movl(output_hi, temp); |
| 4594 | // XOR the input to the output. |
| 4595 | __ xorl(output_lo, input_lo); |
| 4596 | __ xorl(output_hi, input_hi); |
| 4597 | // Subtract the sign. |
| 4598 | __ subl(output_lo, temp); |
| 4599 | __ sbbl(output_hi, temp); |
| 4600 | break; |
| 4601 | } |
| 4602 | case DataType::Type::kFloat32: { |
| 4603 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4604 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4605 | Register constant = locations->GetTemp(1).AsRegister<Register>(); |
| 4606 | __ movl(constant, Immediate(INT32_C(0x7FFFFFFF))); |
| 4607 | __ movd(temp, constant); |
| 4608 | __ andps(out, temp); |
| 4609 | break; |
| 4610 | } |
| 4611 | case DataType::Type::kFloat64: { |
| 4612 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4613 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4614 | // TODO: Use a constant from the constant table (requires extra input). |
| 4615 | __ LoadLongConstant(temp, INT64_C(0x7FFFFFFFFFFFFFFF)); |
| 4616 | __ andpd(out, temp); |
| 4617 | break; |
| 4618 | } |
| 4619 | default: |
| 4620 | LOG(FATAL) << "Unexpected type for HAbs " << abs->GetResultType(); |
| 4621 | } |
| 4622 | } |
| 4623 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4624 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4625 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4626 | switch (instruction->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4627 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4628 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4629 | case DataType::Type::kInt8: |
| 4630 | case DataType::Type::kUint16: |
| 4631 | case DataType::Type::kInt16: |
| 4632 | case DataType::Type::kInt32: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4633 | locations->SetInAt(0, Location::Any()); |
| 4634 | break; |
| 4635 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4636 | case DataType::Type::kInt64: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4637 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 4638 | if (!instruction->IsConstant()) { |
| 4639 | locations->AddTemp(Location::RequiresRegister()); |
| 4640 | } |
| 4641 | break; |
| 4642 | } |
| 4643 | default: |
| 4644 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 4645 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4646 | } |
| 4647 | |
| 4648 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4649 | SlowPathCode* slow_path = |
| 4650 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathX86(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4651 | codegen_->AddSlowPath(slow_path); |
| 4652 | |
| 4653 | LocationSummary* locations = instruction->GetLocations(); |
| 4654 | Location value = locations->InAt(0); |
| 4655 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4656 | switch (instruction->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4657 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4658 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4659 | case DataType::Type::kInt8: |
| 4660 | case DataType::Type::kUint16: |
| 4661 | case DataType::Type::kInt16: |
| 4662 | case DataType::Type::kInt32: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4663 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4664 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4665 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4666 | } else if (value.IsStackSlot()) { |
| 4667 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 4668 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4669 | } else { |
| 4670 | DCHECK(value.IsConstant()) << value; |
| 4671 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4672 | __ jmp(slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4673 | } |
| 4674 | } |
| 4675 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4676 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4677 | case DataType::Type::kInt64: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4678 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4679 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4680 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 4681 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 4682 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4683 | } else { |
| 4684 | DCHECK(value.IsConstant()) << value; |
| 4685 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 4686 | __ jmp(slow_path->GetEntryLabel()); |
| 4687 | } |
| 4688 | } |
| 4689 | break; |
| 4690 | } |
| 4691 | default: |
| 4692 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4693 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4694 | } |
| 4695 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4696 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 4697 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4698 | |
| 4699 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4700 | new (GetGraph()->GetAllocator()) LocationSummary(op, LocationSummary::kNoCall); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4701 | |
| 4702 | switch (op->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4703 | case DataType::Type::kInt32: |
| 4704 | case DataType::Type::kInt64: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4705 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4706 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4707 | // The shift count needs to be in CL or a constant. |
| 4708 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4709 | locations->SetOut(Location::SameAsFirstInput()); |
| 4710 | break; |
| 4711 | } |
| 4712 | default: |
| 4713 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 4714 | } |
| 4715 | } |
| 4716 | |
| 4717 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 4718 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4719 | |
| 4720 | LocationSummary* locations = op->GetLocations(); |
| 4721 | Location first = locations->InAt(0); |
| 4722 | Location second = locations->InAt(1); |
| 4723 | DCHECK(first.Equals(locations->Out())); |
| 4724 | |
| 4725 | switch (op->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4726 | case DataType::Type::kInt32: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4727 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4728 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4729 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4730 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4731 | DCHECK_EQ(ECX, second_reg); |
| 4732 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4733 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4734 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4735 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4736 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4737 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4738 | } |
| 4739 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4740 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4741 | if (shift == 0) { |
| 4742 | return; |
| 4743 | } |
| 4744 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4745 | if (op->IsShl()) { |
| 4746 | __ shll(first_reg, imm); |
| 4747 | } else if (op->IsShr()) { |
| 4748 | __ sarl(first_reg, imm); |
| 4749 | } else { |
| 4750 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4751 | } |
| 4752 | } |
| 4753 | break; |
| 4754 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4755 | case DataType::Type::kInt64: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4756 | if (second.IsRegister()) { |
| 4757 | Register second_reg = second.AsRegister<Register>(); |
| 4758 | DCHECK_EQ(ECX, second_reg); |
| 4759 | if (op->IsShl()) { |
| 4760 | GenerateShlLong(first, second_reg); |
| 4761 | } else if (op->IsShr()) { |
| 4762 | GenerateShrLong(first, second_reg); |
| 4763 | } else { |
| 4764 | GenerateUShrLong(first, second_reg); |
| 4765 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4766 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4767 | // Shift by a constant. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4768 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4769 | // Nothing to do if the shift is 0, as the input is already the output. |
| 4770 | if (shift != 0) { |
| 4771 | if (op->IsShl()) { |
| 4772 | GenerateShlLong(first, shift); |
| 4773 | } else if (op->IsShr()) { |
| 4774 | GenerateShrLong(first, shift); |
| 4775 | } else { |
| 4776 | GenerateUShrLong(first, shift); |
| 4777 | } |
| 4778 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4779 | } |
| 4780 | break; |
| 4781 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4782 | default: |
| 4783 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 4784 | } |
| 4785 | } |
| 4786 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4787 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 4788 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4789 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 4790 | if (shift == 1) { |
| 4791 | // This is just an addition. |
| 4792 | __ addl(low, low); |
| 4793 | __ adcl(high, high); |
| 4794 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4795 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 4796 | codegen_->EmitParallelMoves( |
| 4797 | loc.ToLow(), |
| 4798 | loc.ToHigh(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4799 | DataType::Type::kInt32, |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4800 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 4801 | loc.ToLow(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4802 | DataType::Type::kInt32); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4803 | } else if (shift > 32) { |
| 4804 | // Low part becomes 0. High part is low part << (shift-32). |
| 4805 | __ movl(high, low); |
| 4806 | __ shll(high, Immediate(shift - 32)); |
| 4807 | __ xorl(low, low); |
| 4808 | } else { |
| 4809 | // Between 1 and 31. |
| 4810 | __ shld(high, low, Immediate(shift)); |
| 4811 | __ shll(low, Immediate(shift)); |
| 4812 | } |
| 4813 | } |
| 4814 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4815 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4816 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4817 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 4818 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 4819 | __ testl(shifter, Immediate(32)); |
| 4820 | __ j(kEqual, &done); |
| 4821 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 4822 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 4823 | __ Bind(&done); |
| 4824 | } |
| 4825 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4826 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 4827 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4828 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 4829 | if (shift == 32) { |
| 4830 | // Need to copy the sign. |
| 4831 | DCHECK_NE(low, high); |
| 4832 | __ movl(low, high); |
| 4833 | __ sarl(high, Immediate(31)); |
| 4834 | } else if (shift > 32) { |
| 4835 | DCHECK_NE(low, high); |
| 4836 | // High part becomes sign. Low part is shifted by shift - 32. |
| 4837 | __ movl(low, high); |
| 4838 | __ sarl(high, Immediate(31)); |
| 4839 | __ sarl(low, Immediate(shift - 32)); |
| 4840 | } else { |
| 4841 | // Between 1 and 31. |
| 4842 | __ shrd(low, high, Immediate(shift)); |
| 4843 | __ sarl(high, Immediate(shift)); |
| 4844 | } |
| 4845 | } |
| 4846 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4847 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4848 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4849 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4850 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4851 | __ testl(shifter, Immediate(32)); |
| 4852 | __ j(kEqual, &done); |
| 4853 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4854 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 4855 | __ Bind(&done); |
| 4856 | } |
| 4857 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4858 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 4859 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4860 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 4861 | if (shift == 32) { |
| 4862 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 4863 | codegen_->EmitParallelMoves( |
| 4864 | loc.ToHigh(), |
| 4865 | loc.ToLow(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4866 | DataType::Type::kInt32, |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4867 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 4868 | loc.ToHigh(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4869 | DataType::Type::kInt32); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4870 | } else if (shift > 32) { |
| 4871 | // Low part is high >> (shift - 32). High part becomes 0. |
| 4872 | __ movl(low, high); |
| 4873 | __ shrl(low, Immediate(shift - 32)); |
| 4874 | __ xorl(high, high); |
| 4875 | } else { |
| 4876 | // Between 1 and 31. |
| 4877 | __ shrd(low, high, Immediate(shift)); |
| 4878 | __ shrl(high, Immediate(shift)); |
| 4879 | } |
| 4880 | } |
| 4881 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4882 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4883 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4884 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4885 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4886 | __ testl(shifter, Immediate(32)); |
| 4887 | __ j(kEqual, &done); |
| 4888 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4889 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 4890 | __ Bind(&done); |
| 4891 | } |
| 4892 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4893 | void LocationsBuilderX86::VisitRor(HRor* ror) { |
| 4894 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4895 | new (GetGraph()->GetAllocator()) LocationSummary(ror, LocationSummary::kNoCall); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4896 | |
| 4897 | switch (ror->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4898 | case DataType::Type::kInt64: |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4899 | // Add the temporary needed. |
| 4900 | locations->AddTemp(Location::RequiresRegister()); |
| 4901 | FALLTHROUGH_INTENDED; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4902 | case DataType::Type::kInt32: |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4903 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4904 | // The shift count needs to be in CL (unless it is a constant). |
| 4905 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); |
| 4906 | locations->SetOut(Location::SameAsFirstInput()); |
| 4907 | break; |
| 4908 | default: |
| 4909 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4910 | UNREACHABLE(); |
| 4911 | } |
| 4912 | } |
| 4913 | |
| 4914 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { |
| 4915 | LocationSummary* locations = ror->GetLocations(); |
| 4916 | Location first = locations->InAt(0); |
| 4917 | Location second = locations->InAt(1); |
| 4918 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4919 | if (ror->GetResultType() == DataType::Type::kInt32) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4920 | Register first_reg = first.AsRegister<Register>(); |
| 4921 | if (second.IsRegister()) { |
| 4922 | Register second_reg = second.AsRegister<Register>(); |
| 4923 | __ rorl(first_reg, second_reg); |
| 4924 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4925 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4926 | __ rorl(first_reg, imm); |
| 4927 | } |
| 4928 | return; |
| 4929 | } |
| 4930 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4931 | DCHECK_EQ(ror->GetResultType(), DataType::Type::kInt64); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4932 | Register first_reg_lo = first.AsRegisterPairLow<Register>(); |
| 4933 | Register first_reg_hi = first.AsRegisterPairHigh<Register>(); |
| 4934 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 4935 | if (second.IsRegister()) { |
| 4936 | Register second_reg = second.AsRegister<Register>(); |
| 4937 | DCHECK_EQ(second_reg, ECX); |
| 4938 | __ movl(temp_reg, first_reg_hi); |
| 4939 | __ shrd(first_reg_hi, first_reg_lo, second_reg); |
| 4940 | __ shrd(first_reg_lo, temp_reg, second_reg); |
| 4941 | __ movl(temp_reg, first_reg_hi); |
| 4942 | __ testl(second_reg, Immediate(32)); |
| 4943 | __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); |
| 4944 | __ cmovl(kNotEqual, first_reg_lo, temp_reg); |
| 4945 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4946 | int32_t shift_amt = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4947 | if (shift_amt == 0) { |
| 4948 | // Already fine. |
| 4949 | return; |
| 4950 | } |
| 4951 | if (shift_amt == 32) { |
| 4952 | // Just swap. |
| 4953 | __ movl(temp_reg, first_reg_lo); |
| 4954 | __ movl(first_reg_lo, first_reg_hi); |
| 4955 | __ movl(first_reg_hi, temp_reg); |
| 4956 | return; |
| 4957 | } |
| 4958 | |
| 4959 | Immediate imm(shift_amt); |
| 4960 | // Save the constents of the low value. |
| 4961 | __ movl(temp_reg, first_reg_lo); |
| 4962 | |
| 4963 | // Shift right into low, feeding bits from high. |
| 4964 | __ shrd(first_reg_lo, first_reg_hi, imm); |
| 4965 | |
| 4966 | // Shift right into high, feeding bits from the original low. |
| 4967 | __ shrd(first_reg_hi, temp_reg, imm); |
| 4968 | |
| 4969 | // Swap if needed. |
| 4970 | if (shift_amt > 32) { |
| 4971 | __ movl(temp_reg, first_reg_lo); |
| 4972 | __ movl(first_reg_lo, first_reg_hi); |
| 4973 | __ movl(first_reg_hi, temp_reg); |
| 4974 | } |
| 4975 | } |
| 4976 | } |
| 4977 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4978 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 4979 | HandleShift(shl); |
| 4980 | } |
| 4981 | |
| 4982 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 4983 | HandleShift(shl); |
| 4984 | } |
| 4985 | |
| 4986 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 4987 | HandleShift(shr); |
| 4988 | } |
| 4989 | |
| 4990 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 4991 | HandleShift(shr); |
| 4992 | } |
| 4993 | |
| 4994 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 4995 | HandleShift(ushr); |
| 4996 | } |
| 4997 | |
| 4998 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 4999 | HandleShift(ushr); |
| 5000 | } |
| 5001 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 5002 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5003 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5004 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5005 | locations->SetOut(Location::RegisterLocation(EAX)); |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 5006 | InvokeRuntimeCallingConvention calling_convention; |
| 5007 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 5008 | } |
| 5009 | |
| 5010 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 5011 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
| 5012 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| 5013 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 5014 | } |
| 5015 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 5016 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5017 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5018 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 5019 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 5020 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5021 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5022 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 5023 | } |
| 5024 | |
| 5025 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 5026 | // Note: if heap poisoning is enabled, the entry point takes care of poisoning the reference. |
| 5027 | QuickEntrypointEnum entrypoint = CodeGenerator::GetArrayAllocationEntrypoint(instruction); |
Nicolas Geoffray | d095844 | 2017-01-30 14:57:16 +0000 | [diff] [blame] | 5028 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5029 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 5030 | DCHECK(!codegen_->IsLeafMethod()); |
| 5031 | } |
| 5032 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5033 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5034 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5035 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 5036 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 5037 | if (location.IsStackSlot()) { |
| 5038 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5039 | } else if (location.IsDoubleStackSlot()) { |
| 5040 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5041 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 5042 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5043 | } |
| 5044 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5045 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 5046 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 5047 | } |
| 5048 | |
| 5049 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 5050 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5051 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5052 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 5053 | } |
| 5054 | |
| 5055 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5056 | } |
| 5057 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5058 | void LocationsBuilderX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 5059 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5060 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5061 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5062 | locations->SetOut(Location::RequiresRegister()); |
| 5063 | } |
| 5064 | |
| 5065 | void InstructionCodeGeneratorX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 5066 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5067 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 5068 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5069 | instruction->GetIndex(), kX86PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 5070 | __ movl(locations->Out().AsRegister<Register>(), |
| 5071 | Address(locations->InAt(0).AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5072 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 5073 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 5074 | instruction->GetIndex(), kX86PointerSize)); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 5075 | __ movl(locations->Out().AsRegister<Register>(), |
| 5076 | Address(locations->InAt(0).AsRegister<Register>(), |
| 5077 | mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
| 5078 | // temp = temp->GetImtEntryAt(method_offset); |
| 5079 | __ movl(locations->Out().AsRegister<Register>(), |
| 5080 | Address(locations->Out().AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5081 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 5082 | } |
| 5083 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 5084 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5085 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5086 | new (GetGraph()->GetAllocator()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 5087 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5088 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5089 | } |
| 5090 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 5091 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 5092 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 5093 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 5094 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 5095 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 5096 | switch (not_->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5097 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5098 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 5099 | break; |
| 5100 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5101 | case DataType::Type::kInt64: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 5102 | __ notl(out.AsRegisterPairLow<Register>()); |
| 5103 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 5104 | break; |
| 5105 | |
| 5106 | default: |
| 5107 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 5108 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5109 | } |
| 5110 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5111 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 5112 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5113 | new (GetGraph()->GetAllocator()) LocationSummary(bool_not, LocationSummary::kNoCall); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5114 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5115 | locations->SetOut(Location::SameAsFirstInput()); |
| 5116 | } |
| 5117 | |
| 5118 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5119 | LocationSummary* locations = bool_not->GetLocations(); |
| 5120 | Location in = locations->InAt(0); |
| 5121 | Location out = locations->Out(); |
| 5122 | DCHECK(in.Equals(out)); |
| 5123 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 5124 | } |
| 5125 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5126 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5127 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5128 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5129 | switch (compare->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5130 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5131 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5132 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5133 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5134 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5135 | case DataType::Type::kInt32: |
| 5136 | case DataType::Type::kInt64: { |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5137 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5138 | locations->SetInAt(1, Location::Any()); |
| 5139 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5140 | break; |
| 5141 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5142 | case DataType::Type::kFloat32: |
| 5143 | case DataType::Type::kFloat64: { |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5144 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 5145 | if (compare->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 5146 | DCHECK(compare->InputAt(1)->IsEmittedAtUseSite()); |
| 5147 | } else if (compare->InputAt(1)->IsConstant()) { |
| 5148 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 5149 | } else { |
| 5150 | locations->SetInAt(1, Location::Any()); |
| 5151 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5152 | locations->SetOut(Location::RequiresRegister()); |
| 5153 | break; |
| 5154 | } |
| 5155 | default: |
| 5156 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 5157 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5158 | } |
| 5159 | |
| 5160 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5161 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5162 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5163 | Location left = locations->InAt(0); |
| 5164 | Location right = locations->InAt(1); |
| 5165 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 5166 | NearLabel less, greater, done; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5167 | Condition less_cond = kLess; |
| 5168 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5169 | switch (compare->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5170 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5171 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5172 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5173 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5174 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5175 | case DataType::Type::kInt32: { |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 5176 | codegen_->GenerateIntCompare(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5177 | break; |
| 5178 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5179 | case DataType::Type::kInt64: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5180 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 5181 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 5182 | int32_t val_low = 0; |
| 5183 | int32_t val_high = 0; |
| 5184 | bool right_is_const = false; |
| 5185 | |
| 5186 | if (right.IsConstant()) { |
| 5187 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 5188 | right_is_const = true; |
| 5189 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 5190 | val_low = Low32Bits(val); |
| 5191 | val_high = High32Bits(val); |
| 5192 | } |
| 5193 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5194 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5195 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5196 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5197 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5198 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5199 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5200 | codegen_->Compare32BitValue(left_high, val_high); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5201 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5202 | __ j(kLess, &less); // Signed compare. |
| 5203 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5204 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5205 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5206 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5207 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5208 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5209 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5210 | codegen_->Compare32BitValue(left_low, val_low); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5211 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5212 | less_cond = kBelow; // for CF (unsigned). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5213 | break; |
| 5214 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5215 | case DataType::Type::kFloat32: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 5216 | GenerateFPCompare(left, right, compare, false); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5217 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5218 | less_cond = kBelow; // for CF (floats). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5219 | break; |
| 5220 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5221 | case DataType::Type::kFloat64: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 5222 | GenerateFPCompare(left, right, compare, true); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5223 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5224 | less_cond = kBelow; // for CF (floats). |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5225 | break; |
| 5226 | } |
| 5227 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5228 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5229 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5230 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5231 | __ movl(out, Immediate(0)); |
| 5232 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5233 | __ j(less_cond, &less); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5234 | |
| 5235 | __ Bind(&greater); |
| 5236 | __ movl(out, Immediate(1)); |
| 5237 | __ jmp(&done); |
| 5238 | |
| 5239 | __ Bind(&less); |
| 5240 | __ movl(out, Immediate(-1)); |
| 5241 | |
| 5242 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5243 | } |
| 5244 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 5245 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5246 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5247 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5248 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 5249 | locations->SetInAt(i, Location::Any()); |
| 5250 | } |
| 5251 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 5252 | } |
| 5253 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5254 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5255 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 5256 | } |
| 5257 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5258 | void CodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5259 | /* |
| 5260 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 5261 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 5262 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 5263 | */ |
| 5264 | switch (kind) { |
| 5265 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 5266 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5267 | break; |
| 5268 | } |
| 5269 | case MemBarrierKind::kAnyStore: |
| 5270 | case MemBarrierKind::kLoadAny: |
| 5271 | case MemBarrierKind::kStoreStore: { |
| 5272 | // nop |
| 5273 | break; |
| 5274 | } |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 5275 | case MemBarrierKind::kNTStoreStore: |
| 5276 | // Non-Temporal Store/Store needs an explicit fence. |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5277 | MemoryFence(/* non-temporal= */ true); |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 5278 | break; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 5279 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5280 | } |
| 5281 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5282 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( |
| 5283 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | bdb2ecc | 2018-09-18 14:33:55 +0100 | [diff] [blame] | 5284 | ArtMethod* method ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 5285 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5286 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5287 | |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5288 | Register CodeGeneratorX86::GetInvokeExtraParameter(HInvoke* invoke, Register temp) { |
| 5289 | if (invoke->IsInvokeStaticOrDirect()) { |
| 5290 | return GetInvokeStaticOrDirectExtraParameter(invoke->AsInvokeStaticOrDirect(), temp); |
| 5291 | } |
| 5292 | DCHECK(invoke->IsInvokeInterface()); |
| 5293 | Location location = |
| 5294 | invoke->GetLocations()->InAt(invoke->AsInvokeInterface()->GetSpecialInputIndex()); |
| 5295 | return location.AsRegister<Register>(); |
| 5296 | } |
| 5297 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 5298 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 5299 | Register temp) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 5300 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 5301 | if (!invoke->GetLocations()->Intrinsified()) { |
| 5302 | return location.AsRegister<Register>(); |
| 5303 | } |
| 5304 | // For intrinsics we allow any location, so it may be on the stack. |
| 5305 | if (!location.IsRegister()) { |
| 5306 | __ movl(temp, Address(ESP, location.GetStackIndex())); |
| 5307 | return temp; |
| 5308 | } |
| 5309 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 5310 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 5311 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 5312 | // simple and more robust approach rather that trying to determine if that's the case. |
| 5313 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
Vladimir Marko | 4ee8e29 | 2017-06-02 15:39:30 +0000 | [diff] [blame] | 5314 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 5315 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 5316 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 5317 | __ movl(temp, Address(ESP, stack_offset)); |
| 5318 | return temp; |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 5319 | } |
| 5320 | return location.AsRegister<Register>(); |
| 5321 | } |
| 5322 | |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5323 | void CodeGeneratorX86::LoadMethod(MethodLoadKind load_kind, Location temp, HInvoke* invoke) { |
| 5324 | switch (load_kind) { |
| 5325 | case MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 5326 | DCHECK(GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()); |
| 5327 | Register base_reg = GetInvokeExtraParameter(invoke, temp.AsRegister<Register>()); |
| 5328 | __ leal(temp.AsRegister<Register>(), |
| 5329 | Address(base_reg, CodeGeneratorX86::kPlaceholder32BitOffset)); |
| 5330 | RecordBootImageMethodPatch(invoke); |
| 5331 | break; |
| 5332 | } |
| 5333 | case MethodLoadKind::kBootImageRelRo: { |
| 5334 | size_t index = invoke->IsInvokeInterface() |
| 5335 | ? invoke->AsInvokeInterface()->GetSpecialInputIndex() |
| 5336 | : invoke->AsInvokeStaticOrDirect()->GetSpecialInputIndex(); |
| 5337 | Register base_reg = GetInvokeExtraParameter(invoke, temp.AsRegister<Register>()); |
| 5338 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kPlaceholder32BitOffset)); |
| 5339 | RecordBootImageRelRoPatch( |
| 5340 | invoke->InputAt(index)->AsX86ComputeBaseMethodAddress(), |
| 5341 | GetBootImageOffset(invoke)); |
| 5342 | break; |
| 5343 | } |
| 5344 | case MethodLoadKind::kBssEntry: { |
| 5345 | Register base_reg = GetInvokeExtraParameter(invoke, temp.AsRegister<Register>()); |
| 5346 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kPlaceholder32BitOffset)); |
| 5347 | RecordMethodBssEntryPatch(invoke); |
| 5348 | // No need for memory fence, thanks to the x86 memory model. |
| 5349 | break; |
| 5350 | } |
| 5351 | case MethodLoadKind::kJitDirectAddress: { |
| 5352 | __ movl(temp.AsRegister<Register>(), |
| 5353 | Immediate(reinterpret_cast32<uint32_t>(invoke->GetResolvedMethod()))); |
| 5354 | break; |
| 5355 | } |
| 5356 | case MethodLoadKind::kRuntimeCall: { |
| 5357 | // Test situation, don't do anything. |
| 5358 | break; |
| 5359 | } |
| 5360 | default: { |
| 5361 | LOG(FATAL) << "Load kind should have already been handled " << load_kind; |
| 5362 | UNREACHABLE(); |
| 5363 | } |
| 5364 | } |
| 5365 | } |
| 5366 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5367 | void CodeGeneratorX86::GenerateStaticOrDirectCall( |
| 5368 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5369 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 5370 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 5371 | case MethodLoadKind::kStringInit: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5372 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5373 | uint32_t offset = |
| 5374 | GetThreadOffset<kX86PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 5375 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5376 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5377 | } |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5378 | case MethodLoadKind::kRecursive: { |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 5379 | callee_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5380 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5381 | } |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 5382 | case MethodLoadKind::kRuntimeCall: { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5383 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 5384 | return; // No code pointer retrieval; the runtime performs the call directly. |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 5385 | } |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 5386 | case MethodLoadKind::kBootImageLinkTimePcRelative: |
| 5387 | // For kCallCriticalNative we skip loading the method and do the call directly. |
| 5388 | if (invoke->GetCodePtrLocation() == CodePtrLocation::kCallCriticalNative) { |
| 5389 | break; |
| 5390 | } |
| 5391 | FALLTHROUGH_INTENDED; |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5392 | default: { |
| 5393 | LoadMethod(invoke->GetMethodLoadKind(), callee_method, invoke); |
| 5394 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5395 | } |
| 5396 | |
| 5397 | switch (invoke->GetCodePtrLocation()) { |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 5398 | case CodePtrLocation::kCallSelf: |
Nicolas Geoffray | 282795c | 2021-09-24 18:16:41 +0100 | [diff] [blame] | 5399 | DCHECK(!GetGraph()->HasShouldDeoptimizeFlag()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5400 | __ call(GetFrameEntryLabel()); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 5401 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5402 | break; |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 5403 | case CodePtrLocation::kCallCriticalNative: { |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 5404 | size_t out_frame_size = |
| 5405 | PrepareCriticalNativeCall<CriticalNativeCallingConventionVisitorX86, |
| 5406 | kNativeStackAlignment, |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 5407 | GetCriticalNativeDirectCallFrameSize>(invoke); |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 5408 | if (invoke->GetMethodLoadKind() == MethodLoadKind::kBootImageLinkTimePcRelative) { |
| 5409 | DCHECK(GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()); |
| 5410 | Register base_reg = GetInvokeExtraParameter(invoke, temp.AsRegister<Register>()); |
| 5411 | __ call(Address(base_reg, CodeGeneratorX86::kPlaceholder32BitOffset)); |
| 5412 | RecordBootImageJniEntrypointPatch(invoke); |
| 5413 | } else { |
| 5414 | // (callee_method + offset_of_jni_entry_point)() |
| 5415 | __ call(Address(callee_method.AsRegister<Register>(), |
| 5416 | ArtMethod::EntryPointFromJniOffset(kX86PointerSize).Int32Value())); |
| 5417 | } |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 5418 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 5419 | if (out_frame_size == 0u && DataType::IsFloatingPointType(invoke->GetType())) { |
| 5420 | // Create space for conversion. |
| 5421 | out_frame_size = 8u; |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 5422 | IncreaseFrame(out_frame_size); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 5423 | } |
| 5424 | // Zero-/sign-extend or move the result when needed due to native and managed ABI mismatch. |
| 5425 | switch (invoke->GetType()) { |
| 5426 | case DataType::Type::kBool: |
| 5427 | __ movzxb(EAX, AL); |
| 5428 | break; |
| 5429 | case DataType::Type::kInt8: |
| 5430 | __ movsxb(EAX, AL); |
| 5431 | break; |
| 5432 | case DataType::Type::kUint16: |
| 5433 | __ movzxw(EAX, EAX); |
| 5434 | break; |
| 5435 | case DataType::Type::kInt16: |
| 5436 | __ movsxw(EAX, EAX); |
| 5437 | break; |
| 5438 | case DataType::Type::kFloat32: |
| 5439 | __ fstps(Address(ESP, 0)); |
| 5440 | __ movss(XMM0, Address(ESP, 0)); |
| 5441 | break; |
| 5442 | case DataType::Type::kFloat64: |
| 5443 | __ fstpl(Address(ESP, 0)); |
| 5444 | __ movsd(XMM0, Address(ESP, 0)); |
| 5445 | break; |
| 5446 | case DataType::Type::kInt32: |
| 5447 | case DataType::Type::kInt64: |
| 5448 | case DataType::Type::kVoid: |
| 5449 | break; |
| 5450 | default: |
| 5451 | DCHECK(false) << invoke->GetType(); |
| 5452 | break; |
| 5453 | } |
| 5454 | if (out_frame_size != 0u) { |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 5455 | DecreaseFrame(out_frame_size); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 5456 | } |
| 5457 | break; |
| 5458 | } |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 5459 | case CodePtrLocation::kCallArtMethod: |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5460 | // (callee_method + offset_of_quick_compiled_code)() |
| 5461 | __ call(Address(callee_method.AsRegister<Register>(), |
| 5462 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5463 | kX86PointerSize).Int32Value())); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 5464 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5465 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 5466 | } |
| 5467 | |
| 5468 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 5469 | } |
| 5470 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5471 | void CodeGeneratorX86::GenerateVirtualCall( |
| 5472 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5473 | Register temp = temp_in.AsRegister<Register>(); |
| 5474 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 5475 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 5476 | |
| 5477 | // Use the calling convention instead of the location of the receiver, as |
| 5478 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 5479 | // slow path, the arguments have been moved to the right place, so here we are |
| 5480 | // guaranteed that the receiver is the first register of the calling convention. |
| 5481 | InvokeDexCallingConvention calling_convention; |
| 5482 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5483 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5484 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 5485 | __ movl(temp, Address(receiver, class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5486 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5487 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 5488 | // emit a read barrier for the previous class reference load. |
| 5489 | // However this is not required in practice, as this is an |
| 5490 | // intermediate/temporary reference and because the current |
| 5491 | // concurrent copying collector keeps the from-space memory |
| 5492 | // intact/accessible until the end of the marking phase (the |
| 5493 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5494 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 5495 | |
| 5496 | MaybeGenerateInlineCacheCheck(invoke, temp); |
| 5497 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5498 | // temp = temp->GetMethodAt(method_offset); |
| 5499 | __ movl(temp, Address(temp, method_offset)); |
| 5500 | // call temp->GetEntryPoint(); |
| 5501 | __ call(Address( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5502 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5503 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5504 | } |
| 5505 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5506 | void CodeGeneratorX86::RecordBootImageIntrinsicPatch(HX86ComputeBaseMethodAddress* method_address, |
| 5507 | uint32_t intrinsic_data) { |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5508 | boot_image_other_patches_.emplace_back( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5509 | method_address, /* target_dex_file= */ nullptr, intrinsic_data); |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5510 | __ Bind(&boot_image_other_patches_.back().label); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5511 | } |
| 5512 | |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 5513 | void CodeGeneratorX86::RecordBootImageRelRoPatch(HX86ComputeBaseMethodAddress* method_address, |
| 5514 | uint32_t boot_image_offset) { |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5515 | boot_image_other_patches_.emplace_back( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5516 | method_address, /* target_dex_file= */ nullptr, boot_image_offset); |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5517 | __ Bind(&boot_image_other_patches_.back().label); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 5518 | } |
| 5519 | |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5520 | void CodeGeneratorX86::RecordBootImageMethodPatch(HInvoke* invoke) { |
| 5521 | size_t index = invoke->IsInvokeInterface() |
| 5522 | ? invoke->AsInvokeInterface()->GetSpecialInputIndex() |
| 5523 | : invoke->AsInvokeStaticOrDirect()->GetSpecialInputIndex(); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5524 | HX86ComputeBaseMethodAddress* method_address = |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5525 | invoke->InputAt(index)->AsX86ComputeBaseMethodAddress(); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5526 | boot_image_method_patches_.emplace_back( |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 5527 | method_address, |
| 5528 | invoke->GetResolvedMethodReference().dex_file, |
| 5529 | invoke->GetResolvedMethodReference().index); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5530 | __ Bind(&boot_image_method_patches_.back().label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5531 | } |
| 5532 | |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5533 | void CodeGeneratorX86::RecordMethodBssEntryPatch(HInvoke* invoke) { |
| 5534 | size_t index = invoke->IsInvokeInterface() |
| 5535 | ? invoke->AsInvokeInterface()->GetSpecialInputIndex() |
| 5536 | : invoke->AsInvokeStaticOrDirect()->GetSpecialInputIndex(); |
Santiago Aboy Solanes | a0232ad | 2021-11-08 17:00:06 +0000 | [diff] [blame] | 5537 | DCHECK(IsSameDexFile(GetGraph()->GetDexFile(), *invoke->GetMethodReference().dex_file) || |
Santiago Aboy Solanes | 69a87e3 | 2022-03-08 16:43:54 +0000 | [diff] [blame] | 5538 | GetCompilerOptions().WithinOatFile(invoke->GetMethodReference().dex_file) || |
| 5539 | ContainsElement(Runtime::Current()->GetClassLinker()->GetBootClassPath(), |
| 5540 | invoke->GetMethodReference().dex_file)); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5541 | HX86ComputeBaseMethodAddress* method_address = |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 5542 | invoke->InputAt(index)->AsX86ComputeBaseMethodAddress(); |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5543 | // 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] | 5544 | method_bss_entry_patches_.emplace_back( |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 5545 | method_address, |
| 5546 | invoke->GetMethodReference().dex_file, |
| 5547 | invoke->GetMethodReference().index); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5548 | __ Bind(&method_bss_entry_patches_.back().label); |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5549 | } |
| 5550 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5551 | void CodeGeneratorX86::RecordBootImageTypePatch(HLoadClass* load_class) { |
| 5552 | HX86ComputeBaseMethodAddress* method_address = |
| 5553 | load_class->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 5554 | boot_image_type_patches_.emplace_back( |
| 5555 | method_address, &load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5556 | __ Bind(&boot_image_type_patches_.back().label); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5557 | } |
| 5558 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5559 | Label* CodeGeneratorX86::NewTypeBssEntryPatch(HLoadClass* load_class) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5560 | HX86ComputeBaseMethodAddress* method_address = |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 5561 | load_class->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5562 | ArenaDeque<X86PcRelativePatchInfo>* patches = nullptr; |
| 5563 | switch (load_class->GetLoadKind()) { |
| 5564 | case HLoadClass::LoadKind::kBssEntry: |
| 5565 | patches = &type_bss_entry_patches_; |
| 5566 | break; |
| 5567 | case HLoadClass::LoadKind::kBssEntryPublic: |
| 5568 | patches = &public_type_bss_entry_patches_; |
| 5569 | break; |
| 5570 | case HLoadClass::LoadKind::kBssEntryPackage: |
| 5571 | patches = &package_type_bss_entry_patches_; |
| 5572 | break; |
| 5573 | default: |
| 5574 | LOG(FATAL) << "Unexpected load kind: " << load_class->GetLoadKind(); |
| 5575 | UNREACHABLE(); |
| 5576 | } |
| 5577 | patches->emplace_back( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5578 | method_address, &load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5579 | return &patches->back().label; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5580 | } |
| 5581 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5582 | void CodeGeneratorX86::RecordBootImageStringPatch(HLoadString* load_string) { |
| 5583 | HX86ComputeBaseMethodAddress* method_address = |
| 5584 | load_string->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 5585 | boot_image_string_patches_.emplace_back( |
| 5586 | method_address, &load_string->GetDexFile(), load_string->GetStringIndex().index_); |
| 5587 | __ Bind(&boot_image_string_patches_.back().label); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5588 | } |
| 5589 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5590 | Label* CodeGeneratorX86::NewStringBssEntryPatch(HLoadString* load_string) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5591 | HX86ComputeBaseMethodAddress* method_address = |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 5592 | load_string->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5593 | string_bss_entry_patches_.emplace_back( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5594 | method_address, &load_string->GetDexFile(), load_string->GetStringIndex().index_); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5595 | return &string_bss_entry_patches_.back().label; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5596 | } |
| 5597 | |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 5598 | void CodeGeneratorX86::RecordBootImageJniEntrypointPatch(HInvokeStaticOrDirect* invoke) { |
| 5599 | HX86ComputeBaseMethodAddress* method_address = |
| 5600 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
| 5601 | boot_image_jni_entrypoint_patches_.emplace_back( |
| 5602 | method_address, |
| 5603 | invoke->GetResolvedMethodReference().dex_file, |
| 5604 | invoke->GetResolvedMethodReference().index); |
| 5605 | __ Bind(&boot_image_jni_entrypoint_patches_.back().label); |
| 5606 | } |
| 5607 | |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5608 | void CodeGeneratorX86::LoadBootImageAddress(Register reg, |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5609 | uint32_t boot_image_reference, |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5610 | HInvokeStaticOrDirect* invoke) { |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5611 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5612 | HX86ComputeBaseMethodAddress* method_address = |
| 5613 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
| 5614 | DCHECK(method_address != nullptr); |
| 5615 | Register method_address_reg = |
| 5616 | invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()).AsRegister<Register>(); |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 5617 | __ leal(reg, Address(method_address_reg, CodeGeneratorX86::kPlaceholder32BitOffset)); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5618 | RecordBootImageIntrinsicPatch(method_address, boot_image_reference); |
Vladimir Marko | a2da9b9 | 2018-10-10 14:21:55 +0100 | [diff] [blame] | 5619 | } else if (GetCompilerOptions().GetCompilePic()) { |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5620 | HX86ComputeBaseMethodAddress* method_address = |
| 5621 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
| 5622 | DCHECK(method_address != nullptr); |
| 5623 | Register method_address_reg = |
| 5624 | invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()).AsRegister<Register>(); |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 5625 | __ movl(reg, Address(method_address_reg, CodeGeneratorX86::kPlaceholder32BitOffset)); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5626 | RecordBootImageRelRoPatch(method_address, boot_image_reference); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5627 | } else { |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 5628 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5629 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 5630 | DCHECK(!heap->GetBootImageSpaces().empty()); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5631 | const uint8_t* address = heap->GetBootImageSpaces()[0]->Begin() + boot_image_reference; |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5632 | __ movl(reg, Immediate(dchecked_integral_cast<uint32_t>(reinterpret_cast<uintptr_t>(address)))); |
| 5633 | } |
| 5634 | } |
| 5635 | |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 5636 | void CodeGeneratorX86::LoadIntrinsicDeclaringClass(Register reg, HInvokeStaticOrDirect* invoke) { |
| 5637 | DCHECK_NE(invoke->GetIntrinsic(), Intrinsics::kNone); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5638 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5639 | // Load the class the same way as for HLoadClass::LoadKind::kBootImageLinkTimePcRelative. |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5640 | HX86ComputeBaseMethodAddress* method_address = |
| 5641 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
| 5642 | DCHECK(method_address != nullptr); |
| 5643 | Register method_address_reg = |
| 5644 | invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()).AsRegister<Register>(); |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 5645 | __ leal(reg, Address(method_address_reg, CodeGeneratorX86::kPlaceholder32BitOffset)); |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 5646 | MethodReference target_method = invoke->GetResolvedMethodReference(); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5647 | dex::TypeIndex type_idx = target_method.dex_file->GetMethodId(target_method.index).class_idx_; |
| 5648 | boot_image_type_patches_.emplace_back(method_address, target_method.dex_file, type_idx.index_); |
| 5649 | __ Bind(&boot_image_type_patches_.back().label); |
| 5650 | } else { |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 5651 | uint32_t boot_image_offset = GetBootImageOffsetOfIntrinsicDeclaringClass(invoke); |
| 5652 | LoadBootImageAddress(reg, boot_image_offset, invoke); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5653 | } |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5654 | } |
| 5655 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5656 | // The label points to the end of the "movl" or another instruction but the literal offset |
| 5657 | // for method patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 5658 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
| 5659 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5660 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5661 | inline void CodeGeneratorX86::EmitPcRelativeLinkerPatches( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 5662 | const ArenaDeque<X86PcRelativePatchInfo>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5663 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 5664 | for (const X86PcRelativePatchInfo& info : infos) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5665 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5666 | linker_patches->push_back(Factory(literal_offset, |
| 5667 | info.target_dex_file, |
| 5668 | GetMethodAddressOffset(info.method_address), |
| 5669 | info.offset_or_index)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5670 | } |
| 5671 | } |
| 5672 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5673 | template <linker::LinkerPatch (*Factory)(size_t, uint32_t, uint32_t)> |
| 5674 | linker::LinkerPatch NoDexFileAdapter(size_t literal_offset, |
| 5675 | const DexFile* target_dex_file, |
| 5676 | uint32_t pc_insn_offset, |
| 5677 | uint32_t boot_image_offset) { |
| 5678 | DCHECK(target_dex_file == nullptr); // Unused for these patches, should be null. |
| 5679 | return Factory(literal_offset, pc_insn_offset, boot_image_offset); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 5680 | } |
| 5681 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5682 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5683 | DCHECK(linker_patches->empty()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 5684 | size_t size = |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5685 | boot_image_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5686 | method_bss_entry_patches_.size() + |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5687 | boot_image_type_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5688 | type_bss_entry_patches_.size() + |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5689 | public_type_bss_entry_patches_.size() + |
| 5690 | package_type_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5691 | boot_image_string_patches_.size() + |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5692 | string_bss_entry_patches_.size() + |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 5693 | boot_image_jni_entrypoint_patches_.size() + |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5694 | boot_image_other_patches_.size(); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 5695 | linker_patches->reserve(size); |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 5696 | if (GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5697 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
| 5698 | boot_image_method_patches_, linker_patches); |
| 5699 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
| 5700 | boot_image_type_patches_, linker_patches); |
| 5701 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5702 | boot_image_string_patches_, linker_patches); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5703 | } else { |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5704 | DCHECK(boot_image_method_patches_.empty()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5705 | DCHECK(boot_image_type_patches_.empty()); |
| 5706 | DCHECK(boot_image_string_patches_.empty()); |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5707 | } |
| 5708 | if (GetCompilerOptions().IsBootImage()) { |
| 5709 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::IntrinsicReferencePatch>>( |
| 5710 | boot_image_other_patches_, linker_patches); |
| 5711 | } else { |
| 5712 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::DataBimgRelRoPatch>>( |
| 5713 | boot_image_other_patches_, linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5714 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5715 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 5716 | method_bss_entry_patches_, linker_patches); |
| 5717 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 5718 | type_bss_entry_patches_, linker_patches); |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5719 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::PublicTypeBssEntryPatch>( |
| 5720 | public_type_bss_entry_patches_, linker_patches); |
| 5721 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::PackageTypeBssEntryPatch>( |
| 5722 | package_type_bss_entry_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5723 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 5724 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 5725 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeJniEntrypointPatch>( |
| 5726 | boot_image_jni_entrypoint_patches_, linker_patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5727 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5728 | } |
| 5729 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5730 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 5731 | Register card, |
| 5732 | Register object, |
| 5733 | Register value, |
| 5734 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 5735 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5736 | if (value_can_be_null) { |
| 5737 | __ testl(value, value); |
| 5738 | __ j(kEqual, &is_null); |
| 5739 | } |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5740 | // Load the address of the card table into `card`. |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5741 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86PointerSize>().Int32Value())); |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5742 | // Calculate the offset (in the card table) of the card corresponding to |
| 5743 | // `object`. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5744 | __ movl(temp, object); |
| 5745 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5746 | // Write the `art::gc::accounting::CardTable::kCardDirty` value into the |
| 5747 | // `object`'s card. |
| 5748 | // |
| 5749 | // Register `card` contains the address of the card table. Note that the card |
| 5750 | // table's base is biased during its creation so that it always starts at an |
| 5751 | // address whose least-significant byte is equal to `kCardDirty` (see |
| 5752 | // art::gc::accounting::CardTable::Create). Therefore the MOVB instruction |
| 5753 | // below writes the `kCardDirty` (byte) value into the `object`'s card |
| 5754 | // (located at `card + object >> kCardShift`). |
| 5755 | // |
| 5756 | // This dual use of the value in register `card` (1. to calculate the location |
| 5757 | // of the card to mark; and 2. to load the `kCardDirty` value) saves a load |
| 5758 | // (no need to explicitly load `kCardDirty` as an immediate value). |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 5759 | __ movb(Address(temp, card, TIMES_1, 0), |
| 5760 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5761 | if (value_can_be_null) { |
| 5762 | __ Bind(&is_null); |
| 5763 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5764 | } |
| 5765 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5766 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 5767 | DCHECK(instruction->IsInstanceFieldGet() || |
| 5768 | instruction->IsStaticFieldGet() || |
| 5769 | instruction->IsPredicatedInstanceFieldGet()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5770 | |
| 5771 | bool object_field_get_with_read_barrier = |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 5772 | gUseReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 5773 | bool is_predicated = instruction->IsPredicatedInstanceFieldGet(); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5774 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5775 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 5776 | gUseReadBarrier |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5777 | ? LocationSummary::kCallOnSlowPath |
| 5778 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5779 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5780 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5781 | } |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 5782 | // receiver_input |
| 5783 | locations->SetInAt(is_predicated ? 1 : 0, Location::RequiresRegister()); |
| 5784 | if (is_predicated) { |
| 5785 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
| 5786 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5787 | } else { |
| 5788 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5789 | } |
| 5790 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5791 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 5792 | locations->SetOut(is_predicated ? Location::SameAsFirstInput() |
| 5793 | : Location::RequiresFpuRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5794 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5795 | // The output overlaps in case of long: we don't want the low move |
| 5796 | // to overwrite the object's location. Likewise, in the case of |
| 5797 | // an object field get with read barriers enabled, we do not want |
| 5798 | // the move to overwrite the object's location, as we need it to emit |
| 5799 | // the read barrier. |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 5800 | locations->SetOut(is_predicated ? Location::SameAsFirstInput() : Location::RequiresRegister(), |
| 5801 | (object_field_get_with_read_barrier || |
| 5802 | instruction->GetType() == DataType::Type::kInt64 || |
| 5803 | is_predicated) |
| 5804 | ? Location::kOutputOverlap |
| 5805 | : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5806 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5807 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5808 | if (field_info.IsVolatile() && (field_info.GetFieldType() == DataType::Type::kInt64)) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5809 | // Long values can be loaded atomically into an XMM using movsd. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5810 | // So we use an XMM register as a temp to achieve atomicity (first |
| 5811 | // load the temp into the XMM and then copy the XMM into the |
| 5812 | // output, 32 bits at a time). |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5813 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 5814 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5815 | } |
| 5816 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5817 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 5818 | const FieldInfo& field_info) { |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 5819 | DCHECK(instruction->IsInstanceFieldGet() || |
| 5820 | instruction->IsStaticFieldGet() || |
| 5821 | instruction->IsPredicatedInstanceFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5822 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5823 | LocationSummary* locations = instruction->GetLocations(); |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 5824 | Location base_loc = locations->InAt(instruction->IsPredicatedInstanceFieldGet() ? 1 : 0); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5825 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5826 | Location out = locations->Out(); |
| 5827 | bool is_volatile = field_info.IsVolatile(); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5828 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 5829 | DataType::Type load_type = instruction->GetType(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5830 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5831 | |
Ulya Trafimovich | 322eced | 2021-06-02 15:39:36 +0100 | [diff] [blame] | 5832 | if (load_type == DataType::Type::kReference) { |
| 5833 | // /* HeapReference<Object> */ out = *(base + offset) |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 5834 | if (gUseReadBarrier && kUseBakerReadBarrier) { |
Ulya Trafimovich | 322eced | 2021-06-02 15:39:36 +0100 | [diff] [blame] | 5835 | // Note that a potential implicit null check is handled in this |
| 5836 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 5837 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 5838 | instruction, out, base, offset, /* needs_null_check= */ true); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5839 | if (is_volatile) { |
Ulya Trafimovich | 322eced | 2021-06-02 15:39:36 +0100 | [diff] [blame] | 5840 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5841 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5842 | } else { |
Ulya Trafimovich | 322eced | 2021-06-02 15:39:36 +0100 | [diff] [blame] | 5843 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| 5844 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5845 | if (is_volatile) { |
| 5846 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5847 | } |
| 5848 | // If read barriers are enabled, emit read barriers other than |
| 5849 | // Baker's using a slow path (and also unpoison the loaded |
| 5850 | // reference, if heap poisoning is enabled). |
| 5851 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 5852 | } |
| 5853 | } else { |
| 5854 | Address src(base, offset); |
| 5855 | XmmRegister temp = (load_type == DataType::Type::kInt64 && is_volatile) |
| 5856 | ? locations->GetTemp(0).AsFpuRegister<XmmRegister>() |
| 5857 | : kNoXmmRegister; |
| 5858 | codegen_->LoadFromMemoryNoBarrier(load_type, out, src, instruction, temp, is_volatile); |
| 5859 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5860 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5861 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5862 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5863 | } |
| 5864 | |
| 5865 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 5866 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5867 | |
| 5868 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5869 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5870 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5871 | bool is_volatile = field_info.IsVolatile(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5872 | DataType::Type field_type = field_info.GetFieldType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5873 | bool is_byte_type = DataType::Size(field_type) == 1u; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5874 | |
| 5875 | // The register allocator does not support multiple |
| 5876 | // inputs that die at entry with one in a specific register. |
| 5877 | if (is_byte_type) { |
| 5878 | // Ensure the value is in a byte register. |
| 5879 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5880 | } else if (DataType::IsFloatingPointType(field_type)) { |
| 5881 | if (is_volatile && field_type == DataType::Type::kFloat64) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5882 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 5883 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 5884 | } else { |
| 5885 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 5886 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5887 | } else if (is_volatile && field_type == DataType::Type::kInt64) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5888 | // 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] | 5889 | locations->SetInAt(1, Location::RequiresRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5890 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5891 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 5892 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 5893 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 5894 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 5895 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 5896 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 5897 | locations->AddTemp(Location::RequiresFpuRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5898 | } else { |
| 5899 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5900 | |
| 5901 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 5902 | // Temporary registers for the write barrier. |
| 5903 | locations->AddTemp(Location::RequiresRegister()); // May be used for reference poisoning too. |
| 5904 | // Ensure the card is in a byte register. |
| 5905 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 5906 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5907 | } |
| 5908 | } |
| 5909 | |
| 5910 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5911 | uint32_t value_index, |
| 5912 | DataType::Type field_type, |
| 5913 | Address field_addr, |
| 5914 | Register base, |
| 5915 | bool is_volatile, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5916 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5917 | LocationSummary* locations = instruction->GetLocations(); |
Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5918 | Location value = locations->InAt(value_index); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5919 | bool needs_write_barrier = |
Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5920 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(value_index)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5921 | |
| 5922 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5923 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5924 | } |
| 5925 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5926 | bool maybe_record_implicit_null_check_done = false; |
| 5927 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5928 | switch (field_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5929 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5930 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5931 | case DataType::Type::kInt8: { |
Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5932 | if (value.IsConstant()) { |
| 5933 | __ movb(field_addr, Immediate(CodeGenerator::GetInt8ValueOf(value.GetConstant()))); |
| 5934 | } else { |
| 5935 | __ movb(field_addr, value.AsRegister<ByteRegister>()); |
| 5936 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5937 | break; |
| 5938 | } |
| 5939 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5940 | case DataType::Type::kUint16: |
| 5941 | case DataType::Type::kInt16: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5942 | if (value.IsConstant()) { |
Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5943 | __ movw(field_addr, Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5944 | } else { |
Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5945 | __ movw(field_addr, value.AsRegister<Register>()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5946 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5947 | break; |
| 5948 | } |
| 5949 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5950 | case DataType::Type::kInt32: |
| 5951 | case DataType::Type::kReference: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5952 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 5953 | // Note that in the case where `value` is a null reference, |
| 5954 | // we do not enter this block, as the reference does not |
| 5955 | // need poisoning. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5956 | DCHECK_EQ(field_type, DataType::Type::kReference); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5957 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5958 | __ movl(temp, value.AsRegister<Register>()); |
| 5959 | __ PoisonHeapReference(temp); |
Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5960 | __ movl(field_addr, temp); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5961 | } else if (value.IsConstant()) { |
| 5962 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5963 | __ movl(field_addr, Immediate(v)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5964 | } else { |
Nicolas Geoffray | 0397163 | 2016-03-17 10:44:24 +0000 | [diff] [blame] | 5965 | DCHECK(value.IsRegister()) << value; |
Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5966 | __ movl(field_addr, value.AsRegister<Register>()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5967 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5968 | break; |
| 5969 | } |
| 5970 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5971 | case DataType::Type::kInt64: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5972 | if (is_volatile) { |
| 5973 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 5974 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 5975 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 5976 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 5977 | __ punpckldq(temp1, temp2); |
Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5978 | __ movsd(field_addr, temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5979 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5980 | } else if (value.IsConstant()) { |
| 5981 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5982 | __ movl(field_addr, Immediate(Low32Bits(v))); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5983 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Ulya Trafimovich | 893e2ed | 2021-06-10 16:18:12 +0100 | [diff] [blame] | 5984 | __ movl(Address::displace(field_addr, kX86WordSize), Immediate(High32Bits(v))); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5985 | } else { |
Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5986 | __ movl(field_addr, value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5987 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Ulya Trafimovich | 893e2ed | 2021-06-10 16:18:12 +0100 | [diff] [blame] | 5988 | __ movl(Address::displace(field_addr, kX86WordSize), value.AsRegisterPairHigh<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5989 | } |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5990 | maybe_record_implicit_null_check_done = true; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5991 | break; |
| 5992 | } |
| 5993 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5994 | case DataType::Type::kFloat32: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5995 | if (value.IsConstant()) { |
| 5996 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5997 | __ movl(field_addr, Immediate(v)); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5998 | } else { |
Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 5999 | __ movss(field_addr, value.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6000 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6001 | break; |
| 6002 | } |
| 6003 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6004 | case DataType::Type::kFloat64: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6005 | if (value.IsConstant()) { |
Andra Danciu | c992e42 | 2020-09-16 08:12:02 +0000 | [diff] [blame] | 6006 | DCHECK(!is_volatile); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6007 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 6008 | __ movl(field_addr, Immediate(Low32Bits(v))); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6009 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Ulya Trafimovich | 893e2ed | 2021-06-10 16:18:12 +0100 | [diff] [blame] | 6010 | __ movl(Address::displace(field_addr, kX86WordSize), Immediate(High32Bits(v))); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6011 | maybe_record_implicit_null_check_done = true; |
| 6012 | } else { |
Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 6013 | __ movsd(field_addr, value.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6014 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6015 | break; |
| 6016 | } |
| 6017 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 6018 | case DataType::Type::kUint32: |
| 6019 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6020 | case DataType::Type::kVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6021 | LOG(FATAL) << "Unreachable type " << field_type; |
| 6022 | UNREACHABLE(); |
| 6023 | } |
| 6024 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6025 | if (!maybe_record_implicit_null_check_done) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6026 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6027 | } |
| 6028 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 6029 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6030 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 6031 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 6032 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6033 | } |
| 6034 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6035 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6036 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6037 | } |
| 6038 | } |
| 6039 | |
Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 6040 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
| 6041 | const FieldInfo& field_info, |
| 6042 | bool value_can_be_null) { |
| 6043 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 6044 | |
| 6045 | LocationSummary* locations = instruction->GetLocations(); |
| 6046 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 6047 | bool is_volatile = field_info.IsVolatile(); |
| 6048 | DataType::Type field_type = field_info.GetFieldType(); |
| 6049 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 6050 | bool is_predicated = |
| 6051 | instruction->IsInstanceFieldSet() && instruction->AsInstanceFieldSet()->GetIsPredicatedSet(); |
Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 6052 | |
| 6053 | Address field_addr(base, offset); |
| 6054 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 6055 | NearLabel pred_is_null; |
| 6056 | if (is_predicated) { |
| 6057 | __ testl(base, base); |
| 6058 | __ j(kEqual, &pred_is_null); |
| 6059 | } |
| 6060 | |
Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 6061 | HandleFieldSet(instruction, |
| 6062 | /* value_index= */ 1, |
| 6063 | field_type, |
| 6064 | field_addr, |
| 6065 | base, |
| 6066 | is_volatile, |
| 6067 | value_can_be_null); |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 6068 | |
| 6069 | if (is_predicated) { |
| 6070 | __ Bind(&pred_is_null); |
| 6071 | } |
Andra Danciu | cde9819 | 2020-09-13 12:32:09 +0000 | [diff] [blame] | 6072 | } |
| 6073 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6074 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 6075 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6076 | } |
| 6077 | |
| 6078 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 6079 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6080 | } |
| 6081 | |
| 6082 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 6083 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 6084 | } |
| 6085 | |
| 6086 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 6087 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6088 | } |
| 6089 | |
| 6090 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 6091 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 6092 | } |
| 6093 | |
| 6094 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 6095 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6096 | } |
| 6097 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 6098 | void LocationsBuilderX86::VisitPredicatedInstanceFieldGet( |
| 6099 | HPredicatedInstanceFieldGet* instruction) { |
| 6100 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6101 | } |
| 6102 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6103 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 6104 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6105 | } |
| 6106 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 6107 | void InstructionCodeGeneratorX86::VisitPredicatedInstanceFieldGet( |
| 6108 | HPredicatedInstanceFieldGet* instruction) { |
| 6109 | NearLabel finish; |
| 6110 | LocationSummary* locations = instruction->GetLocations(); |
| 6111 | Register recv = locations->InAt(1).AsRegister<Register>(); |
| 6112 | __ testl(recv, recv); |
| 6113 | __ j(kZero, &finish); |
| 6114 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6115 | __ Bind(&finish); |
| 6116 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6117 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 6118 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6119 | } |
| 6120 | |
Vladimir Marko | 552a134 | 2017-10-31 10:56:47 +0000 | [diff] [blame] | 6121 | void LocationsBuilderX86::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 6122 | codegen_->CreateStringBuilderAppendLocations(instruction, Location::RegisterLocation(EAX)); |
| 6123 | } |
| 6124 | |
| 6125 | void InstructionCodeGeneratorX86::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 6126 | __ movl(EAX, Immediate(instruction->GetFormat()->GetValue())); |
| 6127 | codegen_->InvokeRuntime(kQuickStringBuilderAppend, instruction, instruction->GetDexPc()); |
| 6128 | } |
| 6129 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6130 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 6131 | HUnresolvedInstanceFieldGet* instruction) { |
| 6132 | FieldAccessCallingConventionX86 calling_convention; |
| 6133 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6134 | instruction, instruction->GetFieldType(), calling_convention); |
| 6135 | } |
| 6136 | |
| 6137 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 6138 | HUnresolvedInstanceFieldGet* instruction) { |
| 6139 | FieldAccessCallingConventionX86 calling_convention; |
| 6140 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6141 | instruction->GetFieldType(), |
| 6142 | instruction->GetFieldIndex(), |
| 6143 | instruction->GetDexPc(), |
| 6144 | calling_convention); |
| 6145 | } |
| 6146 | |
| 6147 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 6148 | HUnresolvedInstanceFieldSet* instruction) { |
| 6149 | FieldAccessCallingConventionX86 calling_convention; |
| 6150 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6151 | instruction, instruction->GetFieldType(), calling_convention); |
| 6152 | } |
| 6153 | |
| 6154 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 6155 | HUnresolvedInstanceFieldSet* instruction) { |
| 6156 | FieldAccessCallingConventionX86 calling_convention; |
| 6157 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6158 | instruction->GetFieldType(), |
| 6159 | instruction->GetFieldIndex(), |
| 6160 | instruction->GetDexPc(), |
| 6161 | calling_convention); |
| 6162 | } |
| 6163 | |
| 6164 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 6165 | HUnresolvedStaticFieldGet* instruction) { |
| 6166 | FieldAccessCallingConventionX86 calling_convention; |
| 6167 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6168 | instruction, instruction->GetFieldType(), calling_convention); |
| 6169 | } |
| 6170 | |
| 6171 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 6172 | HUnresolvedStaticFieldGet* instruction) { |
| 6173 | FieldAccessCallingConventionX86 calling_convention; |
| 6174 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6175 | instruction->GetFieldType(), |
| 6176 | instruction->GetFieldIndex(), |
| 6177 | instruction->GetDexPc(), |
| 6178 | calling_convention); |
| 6179 | } |
| 6180 | |
| 6181 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 6182 | HUnresolvedStaticFieldSet* instruction) { |
| 6183 | FieldAccessCallingConventionX86 calling_convention; |
| 6184 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6185 | instruction, instruction->GetFieldType(), calling_convention); |
| 6186 | } |
| 6187 | |
| 6188 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 6189 | HUnresolvedStaticFieldSet* instruction) { |
| 6190 | FieldAccessCallingConventionX86 calling_convention; |
| 6191 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6192 | instruction->GetFieldType(), |
| 6193 | instruction->GetFieldIndex(), |
| 6194 | instruction->GetDexPc(), |
| 6195 | calling_convention); |
| 6196 | } |
| 6197 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6198 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6199 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 6200 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 6201 | ? Location::RequiresRegister() |
| 6202 | : Location::Any(); |
| 6203 | locations->SetInAt(0, loc); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6204 | } |
| 6205 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6206 | void CodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 6207 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6208 | return; |
| 6209 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 6210 | LocationSummary* locations = instruction->GetLocations(); |
| 6211 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6212 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 6213 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6214 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 6215 | } |
| 6216 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6217 | void CodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6218 | SlowPathCode* slow_path = new (GetScopedAllocator()) NullCheckSlowPathX86(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6219 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6220 | |
| 6221 | LocationSummary* locations = instruction->GetLocations(); |
| 6222 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6223 | |
| 6224 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 6225 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 6226 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6227 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 6228 | } else { |
| 6229 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 6230 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 6231 | __ jmp(slow_path->GetEntryLabel()); |
| 6232 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6233 | } |
| 6234 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6235 | } |
| 6236 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 6237 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6238 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 6239 | } |
| 6240 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6241 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6242 | bool object_array_get_with_read_barrier = |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 6243 | gUseReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 6244 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6245 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 6246 | object_array_get_with_read_barrier |
| 6247 | ? LocationSummary::kCallOnSlowPath |
| 6248 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6249 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6250 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6251 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 6252 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6253 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6254 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 6255 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6256 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6257 | // The output overlaps in case of long: we don't want the low move |
| 6258 | // to overwrite the array's location. Likewise, in the case of an |
| 6259 | // object array get with read barriers enabled, we do not want the |
| 6260 | // move to overwrite the array's location, as we need it to emit |
| 6261 | // the read barrier. |
| 6262 | locations->SetOut( |
| 6263 | Location::RequiresRegister(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6264 | (instruction->GetType() == DataType::Type::kInt64 || object_array_get_with_read_barrier) |
| 6265 | ? Location::kOutputOverlap |
| 6266 | : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 6267 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6268 | } |
| 6269 | |
| 6270 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 6271 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6272 | Location obj_loc = locations->InAt(0); |
| 6273 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6274 | Location index = locations->InAt(1); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6275 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6276 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6277 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6278 | DataType::Type type = instruction->GetType(); |
Ulya Trafimovich | 322eced | 2021-06-02 15:39:36 +0100 | [diff] [blame] | 6279 | if (type == DataType::Type::kReference) { |
| 6280 | static_assert( |
| 6281 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6282 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 6283 | // /* HeapReference<Object> */ out = |
| 6284 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 6285 | if (gUseReadBarrier && kUseBakerReadBarrier) { |
Ulya Trafimovich | 322eced | 2021-06-02 15:39:36 +0100 | [diff] [blame] | 6286 | // Note that a potential implicit null check is handled in this |
| 6287 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 6288 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 6289 | instruction, out_loc, obj, data_offset, index, /* needs_null_check= */ true); |
| 6290 | } else { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6291 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6292 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6293 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Ulya Trafimovich | 322eced | 2021-06-02 15:39:36 +0100 | [diff] [blame] | 6294 | // If read barriers are enabled, emit read barriers other than |
| 6295 | // Baker's using a slow path (and also unpoison the loaded |
| 6296 | // reference, if heap poisoning is enabled). |
| 6297 | if (index.IsConstant()) { |
| 6298 | uint32_t offset = |
| 6299 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 6300 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 6301 | } else { |
| 6302 | codegen_->MaybeGenerateReadBarrierSlow( |
| 6303 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 6304 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6305 | } |
Ulya Trafimovich | 322eced | 2021-06-02 15:39:36 +0100 | [diff] [blame] | 6306 | } else if (type == DataType::Type::kUint16 |
| 6307 | && mirror::kUseStringCompression |
| 6308 | && instruction->IsStringCharAt()) { |
| 6309 | // Branch cases into compressed and uncompressed for each index's type. |
| 6310 | Register out = out_loc.AsRegister<Register>(); |
| 6311 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 6312 | NearLabel done, not_compressed; |
| 6313 | __ testb(Address(obj, count_offset), Immediate(1)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6314 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Ulya Trafimovich | 322eced | 2021-06-02 15:39:36 +0100 | [diff] [blame] | 6315 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 6316 | "Expecting 0=compressed, 1=uncompressed"); |
| 6317 | __ j(kNotZero, ¬_compressed); |
| 6318 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| 6319 | __ jmp(&done); |
| 6320 | __ Bind(¬_compressed); |
| 6321 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 6322 | __ Bind(&done); |
| 6323 | } else { |
Ulya Trafimovich | c8451cb | 2021-06-02 17:35:16 +0100 | [diff] [blame] | 6324 | ScaleFactor scale = CodeGenerator::ScaleFactorForType(type); |
| 6325 | Address src = CodeGeneratorX86::ArrayAddress(obj, index, scale, data_offset); |
Ulya Trafimovich | 322eced | 2021-06-02 15:39:36 +0100 | [diff] [blame] | 6326 | codegen_->LoadFromMemoryNoBarrier(type, out_loc, src, instruction); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6327 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6328 | } |
| 6329 | |
| 6330 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6331 | DataType::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6332 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6333 | bool needs_write_barrier = |
| 6334 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6335 | bool needs_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6336 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6337 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 6338 | instruction, |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6339 | needs_type_check ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 6340 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6341 | bool is_byte_type = DataType::Size(value_type) == 1u; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6342 | // We need the inputs to be different than the output in case of long operation. |
| 6343 | // In case of a byte operation, the register allocator does not support multiple |
| 6344 | // inputs that die at entry with one in a specific register. |
| 6345 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6346 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 6347 | if (is_byte_type) { |
| 6348 | // Ensure the value is in a byte register. |
| 6349 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6350 | } else if (DataType::IsFloatingPointType(value_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6351 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6352 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6353 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 6354 | } |
| 6355 | if (needs_write_barrier) { |
| 6356 | // Temporary registers for the write barrier. |
| 6357 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 6358 | // Ensure the card is in a byte register. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 6359 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6360 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6361 | } |
| 6362 | |
| 6363 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 6364 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6365 | Location array_loc = locations->InAt(0); |
| 6366 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6367 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 6368 | Location value = locations->InAt(2); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6369 | DataType::Type value_type = instruction->GetComponentType(); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6370 | bool needs_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6371 | bool needs_write_barrier = |
| 6372 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6373 | |
| 6374 | switch (value_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6375 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6376 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6377 | case DataType::Type::kInt8: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6378 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6379 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_1, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6380 | if (value.IsRegister()) { |
| 6381 | __ movb(address, value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6382 | } else { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 6383 | __ movb(address, Immediate(CodeGenerator::GetInt8ValueOf(value.GetConstant()))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6384 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6385 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6386 | break; |
| 6387 | } |
| 6388 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6389 | case DataType::Type::kUint16: |
| 6390 | case DataType::Type::kInt16: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6391 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6392 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_2, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6393 | if (value.IsRegister()) { |
| 6394 | __ movw(address, value.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6395 | } else { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 6396 | __ movw(address, Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6397 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6398 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6399 | break; |
| 6400 | } |
| 6401 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6402 | case DataType::Type::kReference: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6403 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6404 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6405 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6406 | if (!value.IsRegister()) { |
| 6407 | // Just setting null. |
| 6408 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 6409 | DCHECK(value.IsConstant()) << value; |
| 6410 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6411 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6412 | DCHECK(!needs_write_barrier); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6413 | DCHECK(!needs_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6414 | break; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6415 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6416 | |
| 6417 | DCHECK(needs_write_barrier); |
| 6418 | Register register_value = value.AsRegister<Register>(); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6419 | Location temp_loc = locations->GetTemp(0); |
| 6420 | Register temp = temp_loc.AsRegister<Register>(); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6421 | |
| 6422 | bool can_value_be_null = instruction->GetValueCanBeNull(); |
| 6423 | NearLabel do_store; |
| 6424 | if (can_value_be_null) { |
| 6425 | __ testl(register_value, register_value); |
| 6426 | __ j(kEqual, &do_store); |
| 6427 | } |
| 6428 | |
| 6429 | SlowPathCode* slow_path = nullptr; |
| 6430 | if (needs_type_check) { |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6431 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathX86(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6432 | codegen_->AddSlowPath(slow_path); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6433 | |
| 6434 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6435 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6436 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6437 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6438 | // Note that when Baker read barriers are enabled, the type |
| 6439 | // checks are performed without read barriers. This is fine, |
| 6440 | // even in the case where a class object is in the from-space |
| 6441 | // after the flip, as a comparison involving such a type would |
| 6442 | // not produce a false positive; it may of course produce a |
| 6443 | // false negative, in which case we would take the ArraySet |
| 6444 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6445 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6446 | // /* HeapReference<Class> */ temp = array->klass_ |
| 6447 | __ movl(temp, Address(array, class_offset)); |
| 6448 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6449 | __ MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6450 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6451 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 6452 | __ movl(temp, Address(temp, component_offset)); |
| 6453 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 6454 | // nor the object reference in `register_value->klass`, as |
| 6455 | // we are comparing two poisoned references. |
| 6456 | __ cmpl(temp, Address(register_value, class_offset)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6457 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6458 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6459 | NearLabel do_put; |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6460 | __ j(kEqual, &do_put); |
| 6461 | // If heap poisoning is enabled, the `temp` reference has |
| 6462 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6463 | __ MaybeUnpoisonHeapReference(temp); |
| 6464 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6465 | // If heap poisoning is enabled, no need to unpoison the |
| 6466 | // heap reference loaded below, as it is only used for a |
| 6467 | // comparison with null. |
| 6468 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 6469 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6470 | __ Bind(&do_put); |
| 6471 | } else { |
| 6472 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6473 | } |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6474 | } |
| 6475 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6476 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 6477 | codegen_->MarkGCCard( |
| 6478 | temp, card, array, value.AsRegister<Register>(), /* value_can_be_null= */ false); |
| 6479 | |
| 6480 | if (can_value_be_null) { |
| 6481 | DCHECK(do_store.IsLinked()); |
| 6482 | __ Bind(&do_store); |
| 6483 | } |
| 6484 | |
| 6485 | Register source = register_value; |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6486 | if (kPoisonHeapReferences) { |
| 6487 | __ movl(temp, register_value); |
| 6488 | __ PoisonHeapReference(temp); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6489 | source = temp; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6490 | } |
| 6491 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6492 | __ movl(address, source); |
| 6493 | |
| 6494 | if (can_value_be_null || !needs_type_check) { |
| 6495 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6496 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6497 | |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6498 | if (slow_path != nullptr) { |
| 6499 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6500 | } |
| 6501 | |
| 6502 | break; |
| 6503 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6504 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6505 | case DataType::Type::kInt32: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6506 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6507 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6508 | if (value.IsRegister()) { |
| 6509 | __ movl(address, value.AsRegister<Register>()); |
| 6510 | } else { |
| 6511 | DCHECK(value.IsConstant()) << value; |
| 6512 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 6513 | __ movl(address, Immediate(v)); |
| 6514 | } |
| 6515 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6516 | break; |
| 6517 | } |
| 6518 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6519 | case DataType::Type::kInt64: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6520 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6521 | if (value.IsRegisterPair()) { |
| 6522 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 6523 | value.AsRegisterPairLow<Register>()); |
| 6524 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6525 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 6526 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6527 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6528 | DCHECK(value.IsConstant()); |
| 6529 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
| 6530 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 6531 | Immediate(Low32Bits(val))); |
| 6532 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6533 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 6534 | Immediate(High32Bits(val))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6535 | } |
| 6536 | break; |
| 6537 | } |
| 6538 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6539 | case DataType::Type::kFloat32: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6540 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6541 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6542 | if (value.IsFpuRegister()) { |
| 6543 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 6544 | } else { |
| 6545 | DCHECK(value.IsConstant()); |
| 6546 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 6547 | __ movl(address, Immediate(v)); |
| 6548 | } |
| 6549 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6550 | break; |
| 6551 | } |
| 6552 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6553 | case DataType::Type::kFloat64: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6554 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6555 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6556 | if (value.IsFpuRegister()) { |
| 6557 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 6558 | } else { |
| 6559 | DCHECK(value.IsConstant()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6560 | Address address_hi = |
| 6561 | CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset + kX86WordSize); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6562 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 6563 | __ movl(address, Immediate(Low32Bits(v))); |
| 6564 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6565 | __ movl(address_hi, Immediate(High32Bits(v))); |
| 6566 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6567 | break; |
| 6568 | } |
| 6569 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 6570 | case DataType::Type::kUint32: |
| 6571 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6572 | case DataType::Type::kVoid: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6573 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 6574 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6575 | } |
| 6576 | } |
| 6577 | |
| 6578 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6579 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 6580 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6581 | if (!instruction->IsEmittedAtUseSite()) { |
| 6582 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6583 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6584 | } |
| 6585 | |
| 6586 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6587 | if (instruction->IsEmittedAtUseSite()) { |
| 6588 | return; |
| 6589 | } |
| 6590 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6591 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 6592 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6593 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 6594 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6595 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6596 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6597 | // Mask out most significant bit in case the array is String's array of char. |
| 6598 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6599 | __ shrl(out, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6600 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6601 | } |
| 6602 | |
| 6603 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6604 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6605 | InvokeRuntimeCallingConvention calling_convention; |
| 6606 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6607 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 6608 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 6609 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6610 | HInstruction* length = instruction->InputAt(1); |
| 6611 | if (!length->IsEmittedAtUseSite()) { |
| 6612 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 6613 | } |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6614 | // Need register to see array's length. |
| 6615 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 6616 | locations->AddTemp(Location::RequiresRegister()); |
| 6617 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6618 | } |
| 6619 | |
| 6620 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6621 | const bool is_string_compressed_char_at = |
| 6622 | mirror::kUseStringCompression && instruction->IsStringCharAt(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6623 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 6624 | Location index_loc = locations->InAt(0); |
| 6625 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6626 | SlowPathCode* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6627 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathX86(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6628 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 6629 | if (length_loc.IsConstant()) { |
| 6630 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 6631 | if (index_loc.IsConstant()) { |
| 6632 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 6633 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 6634 | if (index < 0 || index >= length) { |
| 6635 | codegen_->AddSlowPath(slow_path); |
| 6636 | __ jmp(slow_path->GetEntryLabel()); |
| 6637 | } else { |
| 6638 | // Some optimization after BCE may have generated this, and we should not |
| 6639 | // generate a bounds check if it is a valid range. |
| 6640 | } |
| 6641 | return; |
| 6642 | } |
| 6643 | |
| 6644 | // We have to reverse the jump condition because the length is the constant. |
| 6645 | Register index_reg = index_loc.AsRegister<Register>(); |
| 6646 | __ cmpl(index_reg, Immediate(length)); |
| 6647 | codegen_->AddSlowPath(slow_path); |
| 6648 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 6649 | } else { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6650 | HInstruction* array_length = instruction->InputAt(1); |
| 6651 | if (array_length->IsEmittedAtUseSite()) { |
| 6652 | // Address the length field in the array. |
| 6653 | DCHECK(array_length->IsArrayLength()); |
| 6654 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 6655 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 6656 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6657 | if (is_string_compressed_char_at) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6658 | // TODO: if index_loc.IsConstant(), compare twice the index (to compensate for |
| 6659 | // the string compression flag) with the in-memory length and avoid the temporary. |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6660 | Register length_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 6661 | __ movl(length_reg, array_len); |
| 6662 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6663 | __ shrl(length_reg, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6664 | codegen_->GenerateIntCompare(length_reg, index_loc); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6665 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6666 | // Checking bounds for general case: |
| 6667 | // Array of char or string's array with feature compression off. |
| 6668 | if (index_loc.IsConstant()) { |
| 6669 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 6670 | __ cmpl(array_len, Immediate(value)); |
| 6671 | } else { |
| 6672 | __ cmpl(array_len, index_loc.AsRegister<Register>()); |
| 6673 | } |
| 6674 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6675 | } |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 6676 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6677 | codegen_->GenerateIntCompare(length_loc, index_loc); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 6678 | } |
| 6679 | codegen_->AddSlowPath(slow_path); |
| 6680 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 6681 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6682 | } |
| 6683 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6684 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6685 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6686 | } |
| 6687 | |
| 6688 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 6689 | if (instruction->GetNext()->IsSuspendCheck() && |
| 6690 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 6691 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 6692 | // The back edge will generate the suspend check. |
| 6693 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 6694 | } |
| 6695 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6696 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 6697 | } |
| 6698 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6699 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6700 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6701 | instruction, LocationSummary::kCallOnSlowPath); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 6702 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 6703 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 6704 | // registers in full width (since the runtime only saves/restores lower part). |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6705 | locations->SetCustomSlowPathCallerSaves( |
| 6706 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6707 | } |
| 6708 | |
| 6709 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6710 | HBasicBlock* block = instruction->GetBlock(); |
| 6711 | if (block->GetLoopInformation() != nullptr) { |
| 6712 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 6713 | // The back edge will generate the suspend check. |
| 6714 | return; |
| 6715 | } |
| 6716 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 6717 | // The goto will generate the suspend check. |
| 6718 | return; |
| 6719 | } |
| 6720 | GenerateSuspendCheck(instruction, nullptr); |
| 6721 | } |
| 6722 | |
| 6723 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 6724 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6725 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6726 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 6727 | if (slow_path == nullptr) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6728 | slow_path = |
| 6729 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathX86(instruction, successor); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6730 | instruction->SetSlowPath(slow_path); |
| 6731 | codegen_->AddSlowPath(slow_path); |
| 6732 | if (successor != nullptr) { |
| 6733 | DCHECK(successor->IsLoopHeader()); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6734 | } |
| 6735 | } else { |
| 6736 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 6737 | } |
| 6738 | |
Vladimir Marko | 254a858 | 2021-11-29 14:08:37 +0000 | [diff] [blame] | 6739 | __ fs()->testl(Address::Absolute(Thread::ThreadFlagsOffset<kX86PointerSize>().Int32Value()), |
| 6740 | Immediate(Thread::SuspendOrCheckpointRequestFlags())); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6741 | if (successor == nullptr) { |
Vladimir Marko | 254a858 | 2021-11-29 14:08:37 +0000 | [diff] [blame] | 6742 | __ j(kNotZero, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6743 | __ Bind(slow_path->GetReturnLabel()); |
| 6744 | } else { |
Vladimir Marko | 254a858 | 2021-11-29 14:08:37 +0000 | [diff] [blame] | 6745 | __ j(kZero, codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6746 | __ jmp(slow_path->GetEntryLabel()); |
| 6747 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6748 | } |
| 6749 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6750 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 6751 | return codegen_->GetAssembler(); |
| 6752 | } |
| 6753 | |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6754 | void ParallelMoveResolverX86::MoveMemoryToMemory(int dst, int src, int number_of_words) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6755 | ScratchRegisterScope ensure_scratch( |
| 6756 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 6757 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 6758 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6759 | |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6760 | // Now that temp register is available (possibly spilled), move blocks of memory. |
| 6761 | for (int i = 0; i < number_of_words; i++) { |
| 6762 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 6763 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 6764 | stack_offset += kX86WordSize; |
| 6765 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6766 | } |
| 6767 | |
| 6768 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6769 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6770 | Location source = move->GetSource(); |
| 6771 | Location destination = move->GetDestination(); |
| 6772 | |
| 6773 | if (source.IsRegister()) { |
| 6774 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6775 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6776 | } else if (destination.IsFpuRegister()) { |
| 6777 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6778 | } else { |
| 6779 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6780 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6781 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6782 | } else if (source.IsRegisterPair()) { |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 6783 | if (destination.IsRegisterPair()) { |
| 6784 | __ movl(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 6785 | DCHECK_NE(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>()); |
| 6786 | __ movl(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
| 6787 | } else if (destination.IsFpuRegister()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6788 | size_t elem_size = DataType::Size(DataType::Type::kInt32); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 6789 | // Push the 2 source registers to the stack. |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 6790 | __ pushl(source.AsRegisterPairHigh<Register>()); |
| 6791 | __ cfi().AdjustCFAOffset(elem_size); |
| 6792 | __ pushl(source.AsRegisterPairLow<Register>()); |
| 6793 | __ cfi().AdjustCFAOffset(elem_size); |
| 6794 | // Load the destination register. |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6795 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 6796 | // And remove the temporary stack space we allocated. |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 6797 | codegen_->DecreaseFrame(2 * elem_size); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 6798 | } else { |
| 6799 | DCHECK(destination.IsDoubleStackSlot()); |
| 6800 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
| 6801 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
| 6802 | source.AsRegisterPairHigh<Register>()); |
| 6803 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6804 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6805 | if (destination.IsRegister()) { |
| 6806 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
| 6807 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6808 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6809 | } else if (destination.IsRegisterPair()) { |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 6810 | size_t elem_size = DataType::Size(DataType::Type::kInt32); |
| 6811 | // Create stack space for 2 elements. |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 6812 | codegen_->IncreaseFrame(2 * elem_size); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 6813 | // Store the source register. |
| 6814 | __ movsd(Address(ESP, 0), source.AsFpuRegister<XmmRegister>()); |
| 6815 | // And pop the values into destination registers. |
| 6816 | __ popl(destination.AsRegisterPairLow<Register>()); |
| 6817 | __ cfi().AdjustCFAOffset(-elem_size); |
| 6818 | __ popl(destination.AsRegisterPairHigh<Register>()); |
| 6819 | __ cfi().AdjustCFAOffset(-elem_size); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6820 | } else if (destination.IsStackSlot()) { |
| 6821 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6822 | } else if (destination.IsDoubleStackSlot()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6823 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6824 | } else { |
| 6825 | DCHECK(destination.IsSIMDStackSlot()); |
| 6826 | __ movups(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6827 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6828 | } else if (source.IsStackSlot()) { |
| 6829 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6830 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6831 | } else if (destination.IsFpuRegister()) { |
| 6832 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6833 | } else { |
| 6834 | DCHECK(destination.IsStackSlot()); |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6835 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 1); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6836 | } |
| 6837 | } else if (source.IsDoubleStackSlot()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6838 | if (destination.IsRegisterPair()) { |
| 6839 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 6840 | __ movl(destination.AsRegisterPairHigh<Register>(), |
| 6841 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 6842 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6843 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 6844 | } else { |
| 6845 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6846 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 2); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6847 | } |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6848 | } else if (source.IsSIMDStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6849 | if (destination.IsFpuRegister()) { |
| 6850 | __ movups(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 6851 | } else { |
| 6852 | DCHECK(destination.IsSIMDStackSlot()); |
| 6853 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 4); |
| 6854 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 6855 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6856 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 6857 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 6858 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6859 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 6860 | if (value == 0) { |
| 6861 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 6862 | } else { |
| 6863 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 6864 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6865 | } else { |
| 6866 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 6867 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6868 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6869 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6870 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 6871 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6872 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6873 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6874 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 6875 | if (value == 0) { |
| 6876 | // Easy handling of 0.0. |
| 6877 | __ xorps(dest, dest); |
| 6878 | } else { |
| 6879 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6880 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 6881 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 6882 | __ movl(temp, Immediate(value)); |
| 6883 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6884 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6885 | } else { |
| 6886 | DCHECK(destination.IsStackSlot()) << destination; |
| 6887 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 6888 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6889 | } else if (constant->IsLongConstant()) { |
| 6890 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 6891 | int32_t low_value = Low32Bits(value); |
| 6892 | int32_t high_value = High32Bits(value); |
| 6893 | Immediate low(low_value); |
| 6894 | Immediate high(high_value); |
| 6895 | if (destination.IsDoubleStackSlot()) { |
| 6896 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 6897 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 6898 | } else { |
| 6899 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 6900 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 6901 | } |
| 6902 | } else { |
| 6903 | DCHECK(constant->IsDoubleConstant()); |
| 6904 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 6905 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6906 | int32_t low_value = Low32Bits(value); |
| 6907 | int32_t high_value = High32Bits(value); |
| 6908 | Immediate low(low_value); |
| 6909 | Immediate high(high_value); |
| 6910 | if (destination.IsFpuRegister()) { |
| 6911 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 6912 | if (value == 0) { |
| 6913 | // Easy handling of 0.0. |
| 6914 | __ xorpd(dest, dest); |
| 6915 | } else { |
| 6916 | __ pushl(high); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 6917 | __ cfi().AdjustCFAOffset(4); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6918 | __ pushl(low); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 6919 | __ cfi().AdjustCFAOffset(4); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6920 | __ movsd(dest, Address(ESP, 0)); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 6921 | codegen_->DecreaseFrame(8); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6922 | } |
| 6923 | } else { |
| 6924 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6925 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 6926 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 6927 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 6928 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6929 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 6930 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6931 | } |
| 6932 | } |
| 6933 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 6934 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6935 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 6936 | ScratchRegisterScope ensure_scratch( |
| 6937 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 6938 | |
| 6939 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 6940 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 6941 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 6942 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6943 | } |
| 6944 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6945 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6946 | ScratchRegisterScope ensure_scratch( |
| 6947 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 6948 | |
| 6949 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 6950 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 6951 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 6952 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 6953 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6954 | } |
| 6955 | |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6956 | void ParallelMoveResolverX86::Exchange128(XmmRegister reg, int mem) { |
| 6957 | size_t extra_slot = 4 * kX86WordSize; |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 6958 | codegen_->IncreaseFrame(extra_slot); |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6959 | __ movups(Address(ESP, 0), XmmRegister(reg)); |
| 6960 | ExchangeMemory(0, mem + extra_slot, 4); |
| 6961 | __ movups(XmmRegister(reg), Address(ESP, 0)); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 6962 | codegen_->DecreaseFrame(extra_slot); |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6963 | } |
| 6964 | |
| 6965 | void ParallelMoveResolverX86::ExchangeMemory(int mem1, int mem2, int number_of_words) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6966 | ScratchRegisterScope ensure_scratch1( |
| 6967 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6968 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6969 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 6970 | ScratchRegisterScope ensure_scratch2( |
| 6971 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6972 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6973 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 6974 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6975 | |
| 6976 | // Now that temp registers are available (possibly spilled), exchange blocks of memory. |
| 6977 | for (int i = 0; i < number_of_words; i++) { |
| 6978 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 6979 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 6980 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 6981 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
| 6982 | stack_offset += kX86WordSize; |
| 6983 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6984 | } |
| 6985 | |
| 6986 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6987 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6988 | Location source = move->GetSource(); |
| 6989 | Location destination = move->GetDestination(); |
| 6990 | |
| 6991 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 6992 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 6993 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 6994 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 6995 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 6996 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6997 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6998 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6999 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7000 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 7001 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 7002 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 1); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 7003 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 7004 | // Use XOR Swap algorithm to avoid a temporary. |
| 7005 | DCHECK_NE(source.reg(), destination.reg()); |
| 7006 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 7007 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 7008 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 7009 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 7010 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 7011 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 7012 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7013 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 7014 | // Take advantage of the 16 bytes in the XMM register. |
| 7015 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 7016 | Address stack(ESP, destination.GetStackIndex()); |
| 7017 | // Load the double into the high doubleword. |
| 7018 | __ movhpd(reg, stack); |
| 7019 | |
| 7020 | // Store the low double into the destination. |
| 7021 | __ movsd(stack, reg); |
| 7022 | |
| 7023 | // Move the high double to the low double. |
| 7024 | __ psrldq(reg, Immediate(8)); |
| 7025 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 7026 | // Take advantage of the 16 bytes in the XMM register. |
| 7027 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 7028 | Address stack(ESP, source.GetStackIndex()); |
| 7029 | // Load the double into the high doubleword. |
| 7030 | __ movhpd(reg, stack); |
| 7031 | |
| 7032 | // Store the low double into the destination. |
| 7033 | __ movsd(stack, reg); |
| 7034 | |
| 7035 | // Move the high double to the low double. |
| 7036 | __ psrldq(reg, Immediate(8)); |
| 7037 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 7038 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 2); |
| 7039 | } else if (source.IsSIMDStackSlot() && destination.IsSIMDStackSlot()) { |
| 7040 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 4); |
| 7041 | } else if (source.IsFpuRegister() && destination.IsSIMDStackSlot()) { |
| 7042 | Exchange128(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 7043 | } else if (destination.IsFpuRegister() && source.IsSIMDStackSlot()) { |
| 7044 | Exchange128(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 7045 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 7046 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 7047 | } |
| 7048 | } |
| 7049 | |
| 7050 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 7051 | __ pushl(static_cast<Register>(reg)); |
| 7052 | } |
| 7053 | |
| 7054 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 7055 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7056 | } |
| 7057 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7058 | HLoadClass::LoadKind CodeGeneratorX86::GetSupportedLoadClassKind( |
| 7059 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7060 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7061 | case HLoadClass::LoadKind::kInvalid: |
| 7062 | LOG(FATAL) << "UNREACHABLE"; |
| 7063 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7064 | case HLoadClass::LoadKind::kReferrersClass: |
| 7065 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7066 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7067 | case HLoadClass::LoadKind::kBootImageRelRo: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7068 | case HLoadClass::LoadKind::kBssEntry: |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 7069 | case HLoadClass::LoadKind::kBssEntryPublic: |
| 7070 | case HLoadClass::LoadKind::kBssEntryPackage: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 7071 | DCHECK(!GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7072 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7073 | case HLoadClass::LoadKind::kJitBootImageAddress: |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7074 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 7075 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7076 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7077 | case HLoadClass::LoadKind::kRuntimeCall: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7078 | break; |
| 7079 | } |
| 7080 | return desired_class_load_kind; |
| 7081 | } |
| 7082 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7083 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7084 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7085 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7086 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7087 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7088 | cls, |
| 7089 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7090 | Location::RegisterLocation(EAX)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7091 | DCHECK_EQ(calling_convention.GetRegisterAt(0), EAX); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7092 | return; |
| 7093 | } |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 7094 | DCHECK_EQ(cls->NeedsAccessCheck(), |
| 7095 | load_kind == HLoadClass::LoadKind::kBssEntryPublic || |
| 7096 | load_kind == HLoadClass::LoadKind::kBssEntryPackage); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7097 | |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 7098 | const bool requires_read_barrier = gUseReadBarrier && !cls->IsInBootImage(); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7099 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7100 | ? LocationSummary::kCallOnSlowPath |
| 7101 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7102 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7103 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 7104 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7105 | } |
| 7106 | |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 7107 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || cls->HasPcRelativeLoadKind()) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7108 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7109 | } |
| 7110 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 7111 | if (call_kind == LocationSummary::kCallOnSlowPath && cls->HasPcRelativeLoadKind()) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 7112 | if (!gUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7113 | // Rely on the type resolution and/or initialization to save everything. |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 7114 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7115 | } else { |
| 7116 | // For non-Baker read barrier we have a temp-clobbering call. |
| 7117 | } |
| 7118 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7119 | } |
| 7120 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7121 | Label* CodeGeneratorX86::NewJitRootClassPatch(const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7122 | dex::TypeIndex type_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7123 | Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7124 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7125 | // Add a patch entry and return the label. |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7126 | jit_class_patches_.emplace_back(&dex_file, type_index.index_); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7127 | PatchInfo<Label>* info = &jit_class_patches_.back(); |
| 7128 | return &info->label; |
| 7129 | } |
| 7130 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7131 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 7132 | // move. |
| 7133 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7134 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7135 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7136 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 7137 | return; |
| 7138 | } |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 7139 | DCHECK_EQ(cls->NeedsAccessCheck(), |
| 7140 | load_kind == HLoadClass::LoadKind::kBssEntryPublic || |
| 7141 | load_kind == HLoadClass::LoadKind::kBssEntryPackage); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 7142 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7143 | LocationSummary* locations = cls->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7144 | Location out_loc = locations->Out(); |
| 7145 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7146 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7147 | bool generate_null_check = false; |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7148 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 7149 | ? kWithoutReadBarrier |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 7150 | : gCompilerReadBarrierOption; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7151 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7152 | case HLoadClass::LoadKind::kReferrersClass: { |
| 7153 | DCHECK(!cls->CanCallRuntime()); |
| 7154 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 7155 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 7156 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 7157 | GenerateGcRootFieldLoad( |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7158 | cls, |
| 7159 | out_loc, |
| 7160 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7161 | /* fixup_label= */ nullptr, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7162 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7163 | break; |
| 7164 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7165 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 7166 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 7167 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7168 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7169 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 7170 | __ leal(out, Address(method_address, CodeGeneratorX86::kPlaceholder32BitOffset)); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7171 | codegen_->RecordBootImageTypePatch(cls); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7172 | break; |
| 7173 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7174 | case HLoadClass::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 7175 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 7176 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 7177 | __ movl(out, Address(method_address, CodeGeneratorX86::kPlaceholder32BitOffset)); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7178 | codegen_->RecordBootImageRelRoPatch(cls->InputAt(0)->AsX86ComputeBaseMethodAddress(), |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 7179 | CodeGenerator::GetBootImageOffset(cls)); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 7180 | break; |
| 7181 | } |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 7182 | case HLoadClass::LoadKind::kBssEntry: |
| 7183 | case HLoadClass::LoadKind::kBssEntryPublic: |
| 7184 | case HLoadClass::LoadKind::kBssEntryPackage: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7185 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 7186 | Address address(method_address, CodeGeneratorX86::kPlaceholder32BitOffset); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7187 | Label* fixup_label = codegen_->NewTypeBssEntryPatch(cls); |
| 7188 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 7189 | // No need for memory fence, thanks to the x86 memory model. |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7190 | generate_null_check = true; |
| 7191 | break; |
| 7192 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7193 | case HLoadClass::LoadKind::kJitBootImageAddress: { |
| 7194 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 7195 | uint32_t address = reinterpret_cast32<uint32_t>(cls->GetClass().Get()); |
| 7196 | DCHECK_NE(address, 0u); |
| 7197 | __ movl(out, Immediate(address)); |
| 7198 | break; |
| 7199 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7200 | case HLoadClass::LoadKind::kJitTableAddress: { |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 7201 | Address address = Address::Absolute(CodeGeneratorX86::kPlaceholder32BitOffset); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7202 | Label* fixup_label = codegen_->NewJitRootClassPatch( |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7203 | cls->GetDexFile(), cls->GetTypeIndex(), cls->GetClass()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7204 | // /* GcRoot<mirror::Class> */ out = *address |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7205 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7206 | break; |
| 7207 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7208 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7209 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7210 | LOG(FATAL) << "UNREACHABLE"; |
| 7211 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7212 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 7213 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7214 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 7215 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 7216 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86(cls, cls); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7217 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 7218 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7219 | if (generate_null_check) { |
| 7220 | __ testl(out, out); |
| 7221 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 7222 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 7223 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7224 | if (cls->MustGenerateClinitCheck()) { |
| 7225 | GenerateClassInitializationCheck(slow_path, out); |
| 7226 | } else { |
| 7227 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 7228 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7229 | } |
| 7230 | } |
| 7231 | |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 7232 | void LocationsBuilderX86::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 7233 | InvokeRuntimeCallingConvention calling_convention; |
| 7234 | Location location = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 7235 | CodeGenerator::CreateLoadMethodHandleRuntimeCallLocationSummary(load, location, location); |
| 7236 | } |
| 7237 | |
| 7238 | void InstructionCodeGeneratorX86::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 7239 | codegen_->GenerateLoadMethodHandleRuntimeCall(load); |
| 7240 | } |
| 7241 | |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 7242 | void LocationsBuilderX86::VisitLoadMethodType(HLoadMethodType* load) { |
| 7243 | InvokeRuntimeCallingConvention calling_convention; |
| 7244 | Location location = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 7245 | CodeGenerator::CreateLoadMethodTypeRuntimeCallLocationSummary(load, location, location); |
| 7246 | } |
| 7247 | |
| 7248 | void InstructionCodeGeneratorX86::VisitLoadMethodType(HLoadMethodType* load) { |
| 7249 | codegen_->GenerateLoadMethodTypeRuntimeCall(load); |
| 7250 | } |
| 7251 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7252 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 7253 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7254 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7255 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7256 | if (check->HasUses()) { |
| 7257 | locations->SetOut(Location::SameAsFirstInput()); |
| 7258 | } |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 7259 | // Rely on the type initialization to save everything we need. |
| 7260 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7261 | } |
| 7262 | |
| 7263 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 7264 | // We assume the class to not be null. |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 7265 | SlowPathCode* slow_path = |
| 7266 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86(check->GetLoadClass(), check); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7267 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 7268 | GenerateClassInitializationCheck(slow_path, |
| 7269 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 7270 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7271 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 7272 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7273 | SlowPathCode* slow_path, Register class_reg) { |
Vladimir Marko | bf12191 | 2019-06-04 13:49:05 +0100 | [diff] [blame] | 7274 | __ cmpb(Address(class_reg, status_byte_offset), Immediate(shifted_visibly_initialized_value)); |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 7275 | __ j(kBelow, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7276 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7277 | } |
| 7278 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7279 | void InstructionCodeGeneratorX86::GenerateBitstringTypeCheckCompare(HTypeCheckInstruction* check, |
| 7280 | Register temp) { |
| 7281 | uint32_t path_to_root = check->GetBitstringPathToRoot(); |
| 7282 | uint32_t mask = check->GetBitstringMask(); |
| 7283 | DCHECK(IsPowerOfTwo(mask + 1)); |
| 7284 | size_t mask_bits = WhichPowerOf2(mask + 1); |
| 7285 | |
| 7286 | if (mask_bits == 16u) { |
| 7287 | // Compare the bitstring in memory. |
| 7288 | __ cmpw(Address(temp, mirror::Class::StatusOffset()), Immediate(path_to_root)); |
| 7289 | } else { |
| 7290 | // /* uint32_t */ temp = temp->status_ |
| 7291 | __ movl(temp, Address(temp, mirror::Class::StatusOffset())); |
| 7292 | // Compare the bitstring bits using SUB. |
| 7293 | __ subl(temp, Immediate(path_to_root)); |
| 7294 | // Shift out bits that do not contribute to the comparison. |
| 7295 | __ shll(temp, Immediate(32u - mask_bits)); |
| 7296 | } |
| 7297 | } |
| 7298 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7299 | HLoadString::LoadKind CodeGeneratorX86::GetSupportedLoadStringKind( |
| 7300 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7301 | switch (desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7302 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7303 | case HLoadString::LoadKind::kBootImageRelRo: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7304 | case HLoadString::LoadKind::kBssEntry: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 7305 | DCHECK(!GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7306 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7307 | case HLoadString::LoadKind::kJitBootImageAddress: |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7308 | case HLoadString::LoadKind::kJitTableAddress: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 7309 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7310 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7311 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7312 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7313 | } |
| 7314 | return desired_string_load_kind; |
| 7315 | } |
| 7316 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 7317 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7318 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7319 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7320 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 7321 | if (load_kind == HLoadString::LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7322 | load_kind == HLoadString::LoadKind::kBootImageRelRo || |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7323 | load_kind == HLoadString::LoadKind::kBssEntry) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7324 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7325 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7326 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 7327 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 7328 | } else { |
| 7329 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 7330 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 7331 | if (!gUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7332 | // Rely on the pResolveString to save everything. |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 7333 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 7334 | } else { |
| 7335 | // For non-Baker read barrier we have a temp-clobbering call. |
| 7336 | } |
| 7337 | } |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 7338 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 7339 | } |
| 7340 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7341 | Label* CodeGeneratorX86::NewJitRootStringPatch(const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7342 | dex::StringIndex string_index, |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7343 | Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7344 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7345 | // Add a patch entry and return the label. |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7346 | jit_string_patches_.emplace_back(&dex_file, string_index.index_); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7347 | PatchInfo<Label>* info = &jit_string_patches_.back(); |
| 7348 | return &info->label; |
| 7349 | } |
| 7350 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7351 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 7352 | // move. |
| 7353 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 7354 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7355 | Location out_loc = locations->Out(); |
| 7356 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7357 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7358 | switch (load->GetLoadKind()) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7359 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 7360 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 7361 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7362 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 7363 | __ leal(out, Address(method_address, CodeGeneratorX86::kPlaceholder32BitOffset)); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7364 | codegen_->RecordBootImageStringPatch(load); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7365 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7366 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7367 | case HLoadString::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7368 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 7369 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 7370 | __ movl(out, Address(method_address, CodeGeneratorX86::kPlaceholder32BitOffset)); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7371 | codegen_->RecordBootImageRelRoPatch(load->InputAt(0)->AsX86ComputeBaseMethodAddress(), |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 7372 | CodeGenerator::GetBootImageOffset(load)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7373 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7374 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7375 | case HLoadString::LoadKind::kBssEntry: { |
| 7376 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 7377 | Address address = Address(method_address, CodeGeneratorX86::kPlaceholder32BitOffset); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7378 | Label* fixup_label = codegen_->NewStringBssEntryPatch(load); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7379 | // /* GcRoot<mirror::String> */ out = *address /* PC-relative */ |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 7380 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, gCompilerReadBarrierOption); |
Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 7381 | // No need for memory fence, thanks to the x86 memory model. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7382 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadStringSlowPathX86(load); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7383 | codegen_->AddSlowPath(slow_path); |
| 7384 | __ testl(out, out); |
| 7385 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 7386 | __ Bind(slow_path->GetExitLabel()); |
| 7387 | return; |
| 7388 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7389 | case HLoadString::LoadKind::kJitBootImageAddress: { |
| 7390 | uint32_t address = reinterpret_cast32<uint32_t>(load->GetString().Get()); |
| 7391 | DCHECK_NE(address, 0u); |
| 7392 | __ movl(out, Immediate(address)); |
| 7393 | return; |
| 7394 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7395 | case HLoadString::LoadKind::kJitTableAddress: { |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 7396 | Address address = Address::Absolute(CodeGeneratorX86::kPlaceholder32BitOffset); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7397 | Label* fixup_label = codegen_->NewJitRootStringPatch( |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7398 | load->GetDexFile(), load->GetStringIndex(), load->GetString()); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7399 | // /* GcRoot<mirror::String> */ out = *address |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 7400 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, gCompilerReadBarrierOption); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7401 | return; |
| 7402 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7403 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 7404 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7405 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7406 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 7407 | // 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] | 7408 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 7409 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7410 | __ movl(calling_convention.GetRegisterAt(0), Immediate(load->GetStringIndex().index_)); |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 7411 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 7412 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 7413 | } |
| 7414 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7415 | static Address GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7416 | return Address::Absolute(Thread::ExceptionOffset<kX86PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7417 | } |
| 7418 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7419 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 7420 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7421 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7422 | locations->SetOut(Location::RequiresRegister()); |
| 7423 | } |
| 7424 | |
| 7425 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7426 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 7427 | } |
| 7428 | |
| 7429 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7430 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7431 | } |
| 7432 | |
| 7433 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 7434 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7435 | } |
| 7436 | |
| 7437 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7438 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 7439 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7440 | InvokeRuntimeCallingConvention calling_convention; |
| 7441 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 7442 | } |
| 7443 | |
| 7444 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 7445 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7446 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7447 | } |
| 7448 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7449 | // Temp is used for read barrier. |
| 7450 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 7451 | if (gUseReadBarrier && |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7452 | !kUseBakerReadBarrier && |
| 7453 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7454 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7455 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 7456 | return 1; |
| 7457 | } |
| 7458 | return 0; |
| 7459 | } |
| 7460 | |
Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 7461 | // Interface case has 2 temps, one for holding the number of interfaces, one for the current |
| 7462 | // interface pointer, the current interface is compared in memory. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7463 | // The other checks have one temp for loading the object's class. |
| 7464 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 7465 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7466 | return 2; |
| 7467 | } |
| 7468 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7469 | } |
| 7470 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7471 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7472 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7473 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7474 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7475 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7476 | case TypeCheckKind::kExactCheck: |
| 7477 | case TypeCheckKind::kAbstractClassCheck: |
| 7478 | case TypeCheckKind::kClassHierarchyCheck: |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7479 | case TypeCheckKind::kArrayObjectCheck: { |
| 7480 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 7481 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 7482 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7483 | break; |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7484 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7485 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7486 | case TypeCheckKind::kUnresolvedCheck: |
| 7487 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7488 | call_kind = LocationSummary::kCallOnSlowPath; |
| 7489 | break; |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7490 | case TypeCheckKind::kBitstringCheck: |
| 7491 | break; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7492 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7493 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7494 | LocationSummary* locations = |
| 7495 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7496 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 7497 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7498 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7499 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7500 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 7501 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 7502 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 7503 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 7504 | } else { |
| 7505 | locations->SetInAt(1, Location::Any()); |
| 7506 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7507 | // Note that TypeCheckSlowPathX86 uses this "out" register too. |
| 7508 | locations->SetOut(Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7509 | // When read barriers are enabled, we need a temporary register for some cases. |
| 7510 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7511 | } |
| 7512 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7513 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7514 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7515 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7516 | Location obj_loc = locations->InAt(0); |
| 7517 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7518 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7519 | Location out_loc = locations->Out(); |
| 7520 | Register out = out_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7521 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 7522 | DCHECK_LE(num_temps, 1u); |
| 7523 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7524 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7525 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7526 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7527 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7528 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7529 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7530 | |
| 7531 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7532 | // Avoid null check if we know obj is not null. |
| 7533 | if (instruction->MustDoNullCheck()) { |
| 7534 | __ testl(obj, obj); |
| 7535 | __ j(kEqual, &zero); |
| 7536 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7537 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7538 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7539 | case TypeCheckKind::kExactCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7540 | ReadBarrierOption read_barrier_option = |
| 7541 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7542 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7543 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7544 | out_loc, |
| 7545 | obj_loc, |
| 7546 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7547 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7548 | if (cls.IsRegister()) { |
| 7549 | __ cmpl(out, cls.AsRegister<Register>()); |
| 7550 | } else { |
| 7551 | DCHECK(cls.IsStackSlot()) << cls; |
| 7552 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 7553 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7554 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7555 | // Classes must be equal for the instanceof to succeed. |
| 7556 | __ j(kNotEqual, &zero); |
| 7557 | __ movl(out, Immediate(1)); |
| 7558 | __ jmp(&done); |
| 7559 | break; |
| 7560 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7561 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7562 | case TypeCheckKind::kAbstractClassCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7563 | ReadBarrierOption read_barrier_option = |
| 7564 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7565 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7566 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7567 | out_loc, |
| 7568 | obj_loc, |
| 7569 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7570 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7571 | // If the class is abstract, we eagerly fetch the super class of the |
| 7572 | // object to avoid doing a comparison we know will fail. |
| 7573 | NearLabel loop; |
| 7574 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7575 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7576 | GenerateReferenceLoadOneRegister(instruction, |
| 7577 | out_loc, |
| 7578 | super_offset, |
| 7579 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7580 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7581 | __ testl(out, out); |
| 7582 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7583 | __ j(kEqual, &done); |
| 7584 | if (cls.IsRegister()) { |
| 7585 | __ cmpl(out, cls.AsRegister<Register>()); |
| 7586 | } else { |
| 7587 | DCHECK(cls.IsStackSlot()) << cls; |
| 7588 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 7589 | } |
| 7590 | __ j(kNotEqual, &loop); |
| 7591 | __ movl(out, Immediate(1)); |
| 7592 | if (zero.IsLinked()) { |
| 7593 | __ jmp(&done); |
| 7594 | } |
| 7595 | break; |
| 7596 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7597 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7598 | case TypeCheckKind::kClassHierarchyCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7599 | ReadBarrierOption read_barrier_option = |
| 7600 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7601 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7602 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7603 | out_loc, |
| 7604 | obj_loc, |
| 7605 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7606 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7607 | // Walk over the class hierarchy to find a match. |
| 7608 | NearLabel loop, success; |
| 7609 | __ Bind(&loop); |
| 7610 | if (cls.IsRegister()) { |
| 7611 | __ cmpl(out, cls.AsRegister<Register>()); |
| 7612 | } else { |
| 7613 | DCHECK(cls.IsStackSlot()) << cls; |
| 7614 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 7615 | } |
| 7616 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7617 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7618 | GenerateReferenceLoadOneRegister(instruction, |
| 7619 | out_loc, |
| 7620 | super_offset, |
| 7621 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7622 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7623 | __ testl(out, out); |
| 7624 | __ j(kNotEqual, &loop); |
| 7625 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7626 | __ jmp(&done); |
| 7627 | __ Bind(&success); |
| 7628 | __ movl(out, Immediate(1)); |
| 7629 | if (zero.IsLinked()) { |
| 7630 | __ jmp(&done); |
| 7631 | } |
| 7632 | break; |
| 7633 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7634 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7635 | case TypeCheckKind::kArrayObjectCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7636 | ReadBarrierOption read_barrier_option = |
| 7637 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7638 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7639 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7640 | out_loc, |
| 7641 | obj_loc, |
| 7642 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7643 | read_barrier_option); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7644 | // Do an exact check. |
| 7645 | NearLabel exact_check; |
| 7646 | if (cls.IsRegister()) { |
| 7647 | __ cmpl(out, cls.AsRegister<Register>()); |
| 7648 | } else { |
| 7649 | DCHECK(cls.IsStackSlot()) << cls; |
| 7650 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 7651 | } |
| 7652 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7653 | // 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] | 7654 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7655 | GenerateReferenceLoadOneRegister(instruction, |
| 7656 | out_loc, |
| 7657 | component_offset, |
| 7658 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7659 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7660 | __ testl(out, out); |
| 7661 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7662 | __ j(kEqual, &done); |
| 7663 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 7664 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7665 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7666 | __ movl(out, Immediate(1)); |
| 7667 | __ jmp(&done); |
| 7668 | break; |
| 7669 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7670 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7671 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7672 | // No read barrier since the slow path will retry upon failure. |
| 7673 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7674 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7675 | out_loc, |
| 7676 | obj_loc, |
| 7677 | class_offset, |
| 7678 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7679 | if (cls.IsRegister()) { |
| 7680 | __ cmpl(out, cls.AsRegister<Register>()); |
| 7681 | } else { |
| 7682 | DCHECK(cls.IsStackSlot()) << cls; |
| 7683 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 7684 | } |
| 7685 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7686 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7687 | instruction, /* is_fatal= */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7688 | codegen_->AddSlowPath(slow_path); |
| 7689 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 7690 | __ movl(out, Immediate(1)); |
| 7691 | if (zero.IsLinked()) { |
| 7692 | __ jmp(&done); |
| 7693 | } |
| 7694 | break; |
| 7695 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7696 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 7697 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7698 | case TypeCheckKind::kInterfaceCheck: { |
| 7699 | // 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] | 7700 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7701 | // cases. |
| 7702 | // |
| 7703 | // We cannot directly call the InstanceofNonTrivial runtime |
| 7704 | // entry point without resorting to a type checking slow path |
| 7705 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 7706 | // require to assign fixed registers for the inputs of this |
| 7707 | // HInstanceOf instruction (following the runtime calling |
| 7708 | // convention), which might be cluttered by the potential first |
| 7709 | // read barrier emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7710 | // |
| 7711 | // TODO: Introduce a new runtime entry point taking the object |
| 7712 | // to test (instead of its class) as argument, and let it deal |
| 7713 | // with the read barrier issues. This will let us refactor this |
| 7714 | // case of the `switch` code as it was previously (with a direct |
| 7715 | // call to the runtime not using a type checking slow path). |
| 7716 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7717 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7718 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7719 | instruction, /* is_fatal= */ false); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7720 | codegen_->AddSlowPath(slow_path); |
| 7721 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7722 | if (zero.IsLinked()) { |
| 7723 | __ jmp(&done); |
| 7724 | } |
| 7725 | break; |
| 7726 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7727 | |
| 7728 | case TypeCheckKind::kBitstringCheck: { |
| 7729 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7730 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7731 | out_loc, |
| 7732 | obj_loc, |
| 7733 | class_offset, |
| 7734 | kWithoutReadBarrier); |
| 7735 | |
| 7736 | GenerateBitstringTypeCheckCompare(instruction, out); |
| 7737 | __ j(kNotEqual, &zero); |
| 7738 | __ movl(out, Immediate(1)); |
| 7739 | __ jmp(&done); |
| 7740 | break; |
| 7741 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7742 | } |
| 7743 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7744 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7745 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7746 | __ xorl(out, out); |
| 7747 | } |
| 7748 | |
| 7749 | if (done.IsLinked()) { |
| 7750 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7751 | } |
| 7752 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7753 | if (slow_path != nullptr) { |
| 7754 | __ Bind(slow_path->GetExitLabel()); |
| 7755 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7756 | } |
| 7757 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7758 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7759 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7760 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7761 | LocationSummary* locations = |
| 7762 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7763 | locations->SetInAt(0, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7764 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 7765 | // Require a register for the interface check since there is a loop that compares the class to |
| 7766 | // a memory address. |
| 7767 | locations->SetInAt(1, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7768 | } else if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 7769 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 7770 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 7771 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7772 | } else { |
| 7773 | locations->SetInAt(1, Location::Any()); |
| 7774 | } |
Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 7775 | // 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] | 7776 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
| 7777 | } |
| 7778 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7779 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7780 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7781 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7782 | Location obj_loc = locations->InAt(0); |
| 7783 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7784 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7785 | Location temp_loc = locations->GetTemp(0); |
| 7786 | Register temp = temp_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7787 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 7788 | DCHECK_GE(num_temps, 1u); |
| 7789 | DCHECK_LE(num_temps, 2u); |
| 7790 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 7791 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7792 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7793 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7794 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 7795 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 7796 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 7797 | const uint32_t object_array_data_offset = |
| 7798 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7799 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7800 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7801 | SlowPathCode* type_check_slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7802 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
| 7803 | instruction, is_type_check_slow_path_fatal); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7804 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7805 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7806 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7807 | // Avoid null check if we know obj is not null. |
| 7808 | if (instruction->MustDoNullCheck()) { |
| 7809 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7810 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7811 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7812 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7813 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7814 | case TypeCheckKind::kExactCheck: |
| 7815 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7816 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7817 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7818 | temp_loc, |
| 7819 | obj_loc, |
| 7820 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7821 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7822 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7823 | if (cls.IsRegister()) { |
| 7824 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 7825 | } else { |
| 7826 | DCHECK(cls.IsStackSlot()) << cls; |
| 7827 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 7828 | } |
| 7829 | // Jump to slow path for throwing the exception or doing a |
| 7830 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7831 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7832 | break; |
| 7833 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7834 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7835 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7836 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7837 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7838 | temp_loc, |
| 7839 | obj_loc, |
| 7840 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7841 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7842 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7843 | // If the class is abstract, we eagerly fetch the super class of the |
| 7844 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7845 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7846 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7847 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7848 | GenerateReferenceLoadOneRegister(instruction, |
| 7849 | temp_loc, |
| 7850 | super_offset, |
| 7851 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7852 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7853 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7854 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 7855 | // exception. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7856 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7857 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7858 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7859 | // Otherwise, compare the classes |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7860 | if (cls.IsRegister()) { |
| 7861 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 7862 | } else { |
| 7863 | DCHECK(cls.IsStackSlot()) << cls; |
| 7864 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 7865 | } |
| 7866 | __ j(kNotEqual, &loop); |
| 7867 | break; |
| 7868 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7869 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7870 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7871 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7872 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7873 | temp_loc, |
| 7874 | obj_loc, |
| 7875 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7876 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7877 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7878 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7879 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7880 | __ Bind(&loop); |
| 7881 | if (cls.IsRegister()) { |
| 7882 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 7883 | } else { |
| 7884 | DCHECK(cls.IsStackSlot()) << cls; |
| 7885 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 7886 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7887 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7888 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7889 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7890 | GenerateReferenceLoadOneRegister(instruction, |
| 7891 | temp_loc, |
| 7892 | super_offset, |
| 7893 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7894 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7895 | |
| 7896 | // If the class reference currently in `temp` is not null, jump |
| 7897 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7898 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7899 | __ j(kNotZero, &loop); |
| 7900 | // Otherwise, jump to the slow path to throw the exception.; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7901 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7902 | break; |
| 7903 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7904 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7905 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7906 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7907 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7908 | temp_loc, |
| 7909 | obj_loc, |
| 7910 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7911 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7912 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7913 | // Do an exact check. |
| 7914 | if (cls.IsRegister()) { |
| 7915 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 7916 | } else { |
| 7917 | DCHECK(cls.IsStackSlot()) << cls; |
| 7918 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 7919 | } |
| 7920 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7921 | |
| 7922 | // 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] | 7923 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7924 | GenerateReferenceLoadOneRegister(instruction, |
| 7925 | temp_loc, |
| 7926 | component_offset, |
| 7927 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7928 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7929 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7930 | // If the component type is null (i.e. the object not an array), jump to the slow path to |
| 7931 | // throw the exception. Otherwise proceed with the check. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7932 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7933 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7934 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7935 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7936 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7937 | break; |
| 7938 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7939 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 7940 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7941 | // 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] | 7942 | // We cannot directly call the CheckCast runtime entry point |
| 7943 | // without resorting to a type checking slow path here (i.e. by |
| 7944 | // calling InvokeRuntime directly), as it would require to |
| 7945 | // assign fixed registers for the inputs of this HInstanceOf |
| 7946 | // instruction (following the runtime calling convention), which |
| 7947 | // might be cluttered by the potential first read barrier |
| 7948 | // emission at the beginning of this method. |
| 7949 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7950 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7951 | |
| 7952 | case TypeCheckKind::kInterfaceCheck: { |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 7953 | // Fast path for the interface check. Try to avoid read barriers to improve the fast path. |
| 7954 | // We can not get false positives by doing this. |
| 7955 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7956 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7957 | temp_loc, |
| 7958 | obj_loc, |
| 7959 | class_offset, |
| 7960 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7961 | |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 7962 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 7963 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7964 | temp_loc, |
| 7965 | temp_loc, |
| 7966 | iftable_offset, |
| 7967 | kWithoutReadBarrier); |
| 7968 | // Iftable is never null. |
| 7969 | __ movl(maybe_temp2_loc.AsRegister<Register>(), Address(temp, array_length_offset)); |
| 7970 | // Maybe poison the `cls` for direct comparison with memory. |
| 7971 | __ MaybePoisonHeapReference(cls.AsRegister<Register>()); |
| 7972 | // Loop through the iftable and check if any class matches. |
| 7973 | NearLabel start_loop; |
| 7974 | __ Bind(&start_loop); |
| 7975 | // Need to subtract first to handle the empty array case. |
| 7976 | __ subl(maybe_temp2_loc.AsRegister<Register>(), Immediate(2)); |
| 7977 | __ j(kNegative, type_check_slow_path->GetEntryLabel()); |
| 7978 | // Go to next interface if the classes do not match. |
| 7979 | __ cmpl(cls.AsRegister<Register>(), |
| 7980 | CodeGeneratorX86::ArrayAddress(temp, |
| 7981 | maybe_temp2_loc, |
| 7982 | TIMES_4, |
| 7983 | object_array_data_offset)); |
| 7984 | __ j(kNotEqual, &start_loop); |
| 7985 | // If `cls` was poisoned above, unpoison it. |
| 7986 | __ MaybeUnpoisonHeapReference(cls.AsRegister<Register>()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7987 | break; |
| 7988 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7989 | |
| 7990 | case TypeCheckKind::kBitstringCheck: { |
| 7991 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7992 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7993 | temp_loc, |
| 7994 | obj_loc, |
| 7995 | class_offset, |
| 7996 | kWithoutReadBarrier); |
| 7997 | |
| 7998 | GenerateBitstringTypeCheckCompare(instruction, temp); |
| 7999 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
| 8000 | break; |
| 8001 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 8002 | } |
| 8003 | __ Bind(&done); |
| 8004 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8005 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 8006 | } |
| 8007 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 8008 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8009 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 8010 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 8011 | InvokeRuntimeCallingConvention calling_convention; |
| 8012 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 8013 | } |
| 8014 | |
| 8015 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 8016 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject |
| 8017 | : kQuickUnlockObject, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 8018 | instruction, |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 8019 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 8020 | if (instruction->IsEnter()) { |
| 8021 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 8022 | } else { |
| 8023 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 8024 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 8025 | } |
| 8026 | |
Shalini Salomi Bodapati | dd121f6 | 2018-10-26 15:03:53 +0530 | [diff] [blame] | 8027 | void LocationsBuilderX86::VisitX86AndNot(HX86AndNot* instruction) { |
| 8028 | DCHECK(codegen_->GetInstructionSetFeatures().HasAVX2()); |
| 8029 | DCHECK(DataType::IsIntOrLongType(instruction->GetType())) << instruction->GetType(); |
| 8030 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| 8031 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8032 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8033 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8034 | } |
| 8035 | |
| 8036 | void InstructionCodeGeneratorX86::VisitX86AndNot(HX86AndNot* instruction) { |
| 8037 | LocationSummary* locations = instruction->GetLocations(); |
| 8038 | Location first = locations->InAt(0); |
| 8039 | Location second = locations->InAt(1); |
| 8040 | Location dest = locations->Out(); |
| 8041 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
| 8042 | __ andn(dest.AsRegister<Register>(), |
| 8043 | first.AsRegister<Register>(), |
| 8044 | second.AsRegister<Register>()); |
| 8045 | } else { |
| 8046 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
| 8047 | __ andn(dest.AsRegisterPairLow<Register>(), |
| 8048 | first.AsRegisterPairLow<Register>(), |
| 8049 | second.AsRegisterPairLow<Register>()); |
| 8050 | __ andn(dest.AsRegisterPairHigh<Register>(), |
| 8051 | first.AsRegisterPairHigh<Register>(), |
| 8052 | second.AsRegisterPairHigh<Register>()); |
| 8053 | } |
| 8054 | } |
| 8055 | |
| 8056 | void LocationsBuilderX86::VisitX86MaskOrResetLeastSetBit(HX86MaskOrResetLeastSetBit* instruction) { |
| 8057 | DCHECK(codegen_->GetInstructionSetFeatures().HasAVX2()); |
| 8058 | DCHECK(instruction->GetType() == DataType::Type::kInt32) << instruction->GetType(); |
| 8059 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| 8060 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8061 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8062 | } |
| 8063 | |
| 8064 | void InstructionCodeGeneratorX86::VisitX86MaskOrResetLeastSetBit( |
| 8065 | HX86MaskOrResetLeastSetBit* instruction) { |
| 8066 | LocationSummary* locations = instruction->GetLocations(); |
| 8067 | Location src = locations->InAt(0); |
| 8068 | Location dest = locations->Out(); |
| 8069 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
| 8070 | switch (instruction->GetOpKind()) { |
| 8071 | case HInstruction::kAnd: |
| 8072 | __ blsr(dest.AsRegister<Register>(), src.AsRegister<Register>()); |
| 8073 | break; |
| 8074 | case HInstruction::kXor: |
| 8075 | __ blsmsk(dest.AsRegister<Register>(), src.AsRegister<Register>()); |
| 8076 | break; |
| 8077 | default: |
| 8078 | LOG(FATAL) << "Unreachable"; |
| 8079 | } |
| 8080 | } |
| 8081 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8082 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 8083 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 8084 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 8085 | |
| 8086 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 8087 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8088 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8089 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 |
| 8090 | || instruction->GetResultType() == DataType::Type::kInt64); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8091 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8092 | locations->SetInAt(1, Location::Any()); |
| 8093 | locations->SetOut(Location::SameAsFirstInput()); |
| 8094 | } |
| 8095 | |
| 8096 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 8097 | HandleBitwiseOperation(instruction); |
| 8098 | } |
| 8099 | |
| 8100 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 8101 | HandleBitwiseOperation(instruction); |
| 8102 | } |
| 8103 | |
| 8104 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 8105 | HandleBitwiseOperation(instruction); |
| 8106 | } |
| 8107 | |
| 8108 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 8109 | LocationSummary* locations = instruction->GetLocations(); |
| 8110 | Location first = locations->InAt(0); |
| 8111 | Location second = locations->InAt(1); |
| 8112 | DCHECK(first.Equals(locations->Out())); |
| 8113 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8114 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8115 | if (second.IsRegister()) { |
| 8116 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 8117 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8118 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 8119 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8120 | } else { |
| 8121 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 8122 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8123 | } |
| 8124 | } else if (second.IsConstant()) { |
| 8125 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 8126 | __ andl(first.AsRegister<Register>(), |
| 8127 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8128 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 8129 | __ orl(first.AsRegister<Register>(), |
| 8130 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8131 | } else { |
| 8132 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 8133 | __ xorl(first.AsRegister<Register>(), |
| 8134 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8135 | } |
| 8136 | } else { |
| 8137 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 8138 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8139 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 8140 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8141 | } else { |
| 8142 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 8143 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8144 | } |
| 8145 | } |
| 8146 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8147 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8148 | if (second.IsRegisterPair()) { |
| 8149 | if (instruction->IsAnd()) { |
| 8150 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 8151 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 8152 | } else if (instruction->IsOr()) { |
| 8153 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 8154 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 8155 | } else { |
| 8156 | DCHECK(instruction->IsXor()); |
| 8157 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 8158 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 8159 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 8160 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8161 | if (instruction->IsAnd()) { |
| 8162 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 8163 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 8164 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 8165 | } else if (instruction->IsOr()) { |
| 8166 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 8167 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 8168 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 8169 | } else { |
| 8170 | DCHECK(instruction->IsXor()); |
| 8171 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 8172 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 8173 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 8174 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 8175 | } else { |
| 8176 | DCHECK(second.IsConstant()) << second; |
| 8177 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 8178 | int32_t low_value = Low32Bits(value); |
| 8179 | int32_t high_value = High32Bits(value); |
| 8180 | Immediate low(low_value); |
| 8181 | Immediate high(high_value); |
| 8182 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 8183 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 8184 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 8185 | if (low_value == 0) { |
| 8186 | __ xorl(first_low, first_low); |
| 8187 | } else if (low_value != -1) { |
| 8188 | __ andl(first_low, low); |
| 8189 | } |
| 8190 | if (high_value == 0) { |
| 8191 | __ xorl(first_high, first_high); |
| 8192 | } else if (high_value != -1) { |
| 8193 | __ andl(first_high, high); |
| 8194 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 8195 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 8196 | if (low_value != 0) { |
| 8197 | __ orl(first_low, low); |
| 8198 | } |
| 8199 | if (high_value != 0) { |
| 8200 | __ orl(first_high, high); |
| 8201 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 8202 | } else { |
| 8203 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 8204 | if (low_value != 0) { |
| 8205 | __ xorl(first_low, low); |
| 8206 | } |
| 8207 | if (high_value != 0) { |
| 8208 | __ xorl(first_high, high); |
| 8209 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 8210 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8211 | } |
| 8212 | } |
| 8213 | } |
| 8214 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 8215 | void InstructionCodeGeneratorX86::GenerateReferenceLoadOneRegister( |
| 8216 | HInstruction* instruction, |
| 8217 | Location out, |
| 8218 | uint32_t offset, |
| 8219 | Location maybe_temp, |
| 8220 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8221 | Register out_reg = out.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 8222 | if (read_barrier_option == kWithReadBarrier) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 8223 | CHECK(gUseReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8224 | if (kUseBakerReadBarrier) { |
| 8225 | // Load with fast path based Baker's read barrier. |
| 8226 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8227 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8228 | instruction, out, out_reg, offset, /* needs_null_check= */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8229 | } else { |
| 8230 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 8231 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8232 | // in the following move operation, as we will need it for the |
| 8233 | // read barrier below. |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 8234 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 8235 | __ movl(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8236 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8237 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 8238 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8239 | } |
| 8240 | } else { |
| 8241 | // Plain load with no read barrier. |
| 8242 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8243 | __ movl(out_reg, Address(out_reg, offset)); |
| 8244 | __ MaybeUnpoisonHeapReference(out_reg); |
| 8245 | } |
| 8246 | } |
| 8247 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 8248 | void InstructionCodeGeneratorX86::GenerateReferenceLoadTwoRegisters( |
| 8249 | HInstruction* instruction, |
| 8250 | Location out, |
| 8251 | Location obj, |
| 8252 | uint32_t offset, |
| 8253 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8254 | Register out_reg = out.AsRegister<Register>(); |
| 8255 | Register obj_reg = obj.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 8256 | if (read_barrier_option == kWithReadBarrier) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 8257 | CHECK(gUseReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8258 | if (kUseBakerReadBarrier) { |
| 8259 | // Load with fast path based Baker's read barrier. |
| 8260 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8261 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8262 | instruction, out, obj_reg, offset, /* needs_null_check= */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8263 | } else { |
| 8264 | // Load with slow path based read barrier. |
| 8265 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8266 | __ movl(out_reg, Address(obj_reg, offset)); |
| 8267 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 8268 | } |
| 8269 | } else { |
| 8270 | // Plain load with no read barrier. |
| 8271 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8272 | __ movl(out_reg, Address(obj_reg, offset)); |
| 8273 | __ MaybeUnpoisonHeapReference(out_reg); |
| 8274 | } |
| 8275 | } |
| 8276 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 8277 | void InstructionCodeGeneratorX86::GenerateGcRootFieldLoad( |
| 8278 | HInstruction* instruction, |
| 8279 | Location root, |
| 8280 | const Address& address, |
| 8281 | Label* fixup_label, |
| 8282 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8283 | Register root_reg = root.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 8284 | if (read_barrier_option == kWithReadBarrier) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 8285 | DCHECK(gUseReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8286 | if (kUseBakerReadBarrier) { |
| 8287 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 8288 | // Baker's read barrier are used: |
| 8289 | // |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 8290 | // root = obj.field; |
| 8291 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 8292 | // if (temp != null) { |
| 8293 | // root = temp(root) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8294 | // } |
| 8295 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8296 | // /* GcRoot<mirror::Object> */ root = *address |
| 8297 | __ movl(root_reg, address); |
| 8298 | if (fixup_label != nullptr) { |
| 8299 | __ Bind(fixup_label); |
| 8300 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8301 | static_assert( |
| 8302 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 8303 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 8304 | "have different sizes."); |
| 8305 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 8306 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 8307 | "have different sizes."); |
| 8308 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 8309 | // Slow path marking the GC root `root`. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8310 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathX86( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8311 | instruction, root, /* unpoison_ref_before_marking= */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8312 | codegen_->AddSlowPath(slow_path); |
| 8313 | |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 8314 | // Test the entrypoint (`Thread::Current()->pReadBarrierMarkReg ## root.reg()`). |
| 8315 | const int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 8316 | Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(root.reg()); |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 8317 | __ fs()->cmpl(Address::Absolute(entry_point_offset), Immediate(0)); |
| 8318 | // The entrypoint is null when the GC is not marking. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8319 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 8320 | __ Bind(slow_path->GetExitLabel()); |
| 8321 | } else { |
| 8322 | // GC root loaded through a slow path for read barriers other |
| 8323 | // than Baker's. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8324 | // /* GcRoot<mirror::Object>* */ root = address |
| 8325 | __ leal(root_reg, address); |
| 8326 | if (fixup_label != nullptr) { |
| 8327 | __ Bind(fixup_label); |
| 8328 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8329 | // /* mirror::Object* */ root = root->Read() |
| 8330 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 8331 | } |
| 8332 | } else { |
| 8333 | // Plain GC root load with no read barrier. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8334 | // /* GcRoot<mirror::Object> */ root = *address |
| 8335 | __ movl(root_reg, address); |
| 8336 | if (fixup_label != nullptr) { |
| 8337 | __ Bind(fixup_label); |
| 8338 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 8339 | // Note that GC roots are not affected by heap poisoning, thus we |
| 8340 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8341 | } |
| 8342 | } |
| 8343 | |
| 8344 | void CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8345 | Location ref, |
| 8346 | Register obj, |
| 8347 | uint32_t offset, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8348 | bool needs_null_check) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 8349 | DCHECK(gUseReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8350 | DCHECK(kUseBakerReadBarrier); |
| 8351 | |
| 8352 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 8353 | Address src(obj, offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 8354 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8355 | } |
| 8356 | |
| 8357 | void CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8358 | Location ref, |
| 8359 | Register obj, |
| 8360 | uint32_t data_offset, |
| 8361 | Location index, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8362 | bool needs_null_check) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 8363 | DCHECK(gUseReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8364 | DCHECK(kUseBakerReadBarrier); |
| 8365 | |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 8366 | static_assert( |
| 8367 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 8368 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8369 | // /* HeapReference<Object> */ ref = |
| 8370 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8371 | Address src = CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 8372 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8373 | } |
| 8374 | |
| 8375 | void CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8376 | Location ref, |
| 8377 | Register obj, |
| 8378 | const Address& src, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 8379 | bool needs_null_check, |
| 8380 | bool always_update_field, |
| 8381 | Register* temp) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 8382 | DCHECK(gUseReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8383 | DCHECK(kUseBakerReadBarrier); |
| 8384 | |
| 8385 | // In slow path based read barriers, the read barrier call is |
| 8386 | // inserted after the original load. However, in fast path based |
| 8387 | // Baker's read barriers, we need to perform the load of |
| 8388 | // mirror::Object::monitor_ *before* the original reference load. |
| 8389 | // This load-load ordering is required by the read barrier. |
| 8390 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 8391 | // |
| 8392 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 8393 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 8394 | // HeapReference<Object> ref = *src; // Original reference load. |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 8395 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8396 | // if (is_gray) { |
| 8397 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 8398 | // } |
| 8399 | // |
| 8400 | // Note: the original implementation in ReadBarrier::Barrier is |
| 8401 | // slightly more complex as: |
| 8402 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 8403 | // the high-bits of rb_state, which are expected to be all zeroes |
| 8404 | // (we use CodeGeneratorX86::GenerateMemoryBarrier instead here, |
| 8405 | // which is a no-op thanks to the x86 memory model); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8406 | // - it performs additional checks that we do not do here for |
| 8407 | // performance reasons. |
| 8408 | |
| 8409 | Register ref_reg = ref.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8410 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 8411 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 8412 | // 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] | 8413 | static_assert(ReadBarrier::NonGrayState() == 0, "Expecting non-gray to have value 0"); |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 8414 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 8415 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 8416 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 8417 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 8418 | |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 8419 | // if (rb_state == ReadBarrier::GrayState()) |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 8420 | // ref = ReadBarrier::Mark(ref); |
| 8421 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 8422 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8423 | if (needs_null_check) { |
| 8424 | MaybeRecordImplicitNullCheck(instruction); |
| 8425 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8426 | |
| 8427 | // Load fence to prevent load-load reordering. |
| 8428 | // Note that this is a no-op, thanks to the x86 memory model. |
| 8429 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 8430 | |
| 8431 | // The actual reference load. |
| 8432 | // /* HeapReference<Object> */ ref = *src |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 8433 | __ movl(ref_reg, src); // Flags are unaffected. |
| 8434 | |
| 8435 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 8436 | // Slow path marking the object `ref` when it is gray. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 8437 | SlowPathCode* slow_path; |
| 8438 | if (always_update_field) { |
| 8439 | DCHECK(temp != nullptr); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8440 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkAndUpdateFieldSlowPathX86( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8441 | instruction, ref, obj, src, /* unpoison_ref_before_marking= */ true, *temp); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 8442 | } else { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8443 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkSlowPathX86( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8444 | instruction, ref, /* unpoison_ref_before_marking= */ true); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 8445 | } |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 8446 | AddSlowPath(slow_path); |
| 8447 | |
| 8448 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 8449 | __ j(kNotZero, slow_path->GetEntryLabel()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8450 | |
| 8451 | // Object* ref = ref_addr->AsMirrorPtr() |
| 8452 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 8453 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8454 | __ Bind(slow_path->GetExitLabel()); |
| 8455 | } |
| 8456 | |
| 8457 | void CodeGeneratorX86::GenerateReadBarrierSlow(HInstruction* instruction, |
| 8458 | Location out, |
| 8459 | Location ref, |
| 8460 | Location obj, |
| 8461 | uint32_t offset, |
| 8462 | Location index) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 8463 | DCHECK(gUseReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8464 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8465 | // Insert a slow path based read barrier *after* the reference load. |
| 8466 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8467 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 8468 | // reference will be carried out by the runtime within the slow |
| 8469 | // path. |
| 8470 | // |
| 8471 | // Note that `ref` currently does not get unpoisoned (when heap |
| 8472 | // poisoning is enabled), which is alright as the `ref` argument is |
| 8473 | // not used by the artReadBarrierSlow entry point. |
| 8474 | // |
| 8475 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8476 | SlowPathCode* slow_path = new (GetScopedAllocator()) |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8477 | ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); |
| 8478 | AddSlowPath(slow_path); |
| 8479 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8480 | __ jmp(slow_path->GetEntryLabel()); |
| 8481 | __ Bind(slow_path->GetExitLabel()); |
| 8482 | } |
| 8483 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8484 | void CodeGeneratorX86::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 8485 | Location out, |
| 8486 | Location ref, |
| 8487 | Location obj, |
| 8488 | uint32_t offset, |
| 8489 | Location index) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 8490 | if (gUseReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8491 | // Baker's read barriers shall be handled by the fast path |
| 8492 | // (CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier). |
| 8493 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8494 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 8495 | // by the runtime within the slow path. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8496 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8497 | } else if (kPoisonHeapReferences) { |
| 8498 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 8499 | } |
| 8500 | } |
| 8501 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8502 | void CodeGeneratorX86::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 8503 | Location out, |
| 8504 | Location root) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 8505 | DCHECK(gUseReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8506 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8507 | // Insert a slow path based read barrier *after* the GC root load. |
| 8508 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8509 | // Note that GC roots are not affected by heap poisoning, so we do |
| 8510 | // not need to do anything special for this here. |
| 8511 | SlowPathCode* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8512 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathX86(instruction, out, root); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8513 | AddSlowPath(slow_path); |
| 8514 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8515 | __ jmp(slow_path->GetEntryLabel()); |
| 8516 | __ Bind(slow_path->GetExitLabel()); |
| 8517 | } |
| 8518 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 8519 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8520 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8521 | LOG(FATAL) << "Unreachable"; |
| 8522 | } |
| 8523 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 8524 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8525 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8526 | LOG(FATAL) << "Unreachable"; |
| 8527 | } |
| 8528 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8529 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 8530 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 8531 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8532 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8533 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8534 | } |
| 8535 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8536 | void InstructionCodeGeneratorX86::GenPackedSwitchWithCompares(Register value_reg, |
| 8537 | int32_t lower_bound, |
| 8538 | uint32_t num_entries, |
| 8539 | HBasicBlock* switch_block, |
| 8540 | HBasicBlock* default_block) { |
| 8541 | // Figure out the correct compare values and jump conditions. |
| 8542 | // Handle the first compare/branch as a special case because it might |
| 8543 | // jump to the default case. |
| 8544 | DCHECK_GT(num_entries, 2u); |
| 8545 | Condition first_condition; |
| 8546 | uint32_t index; |
| 8547 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 8548 | if (lower_bound != 0) { |
| 8549 | first_condition = kLess; |
| 8550 | __ cmpl(value_reg, Immediate(lower_bound)); |
| 8551 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 8552 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8553 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8554 | index = 1; |
| 8555 | } else { |
| 8556 | // Handle all the compare/jumps below. |
| 8557 | first_condition = kBelow; |
| 8558 | index = 0; |
| 8559 | } |
| 8560 | |
| 8561 | // Handle the rest of the compare/jumps. |
| 8562 | for (; index + 1 < num_entries; index += 2) { |
| 8563 | int32_t compare_to_value = lower_bound + index + 1; |
| 8564 | __ cmpl(value_reg, Immediate(compare_to_value)); |
| 8565 | // Jump to successors[index] if value < case_value[index]. |
| 8566 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 8567 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 8568 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 8569 | } |
| 8570 | |
| 8571 | if (index != num_entries) { |
| 8572 | // There are an odd number of entries. Handle the last one. |
| 8573 | DCHECK_EQ(index + 1, num_entries); |
| 8574 | __ cmpl(value_reg, Immediate(lower_bound + index)); |
| 8575 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8576 | } |
| 8577 | |
| 8578 | // And the default for any other value. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8579 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
| 8580 | __ jmp(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8581 | } |
| 8582 | } |
| 8583 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8584 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 8585 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 8586 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 8587 | LocationSummary* locations = switch_instr->GetLocations(); |
| 8588 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 8589 | |
| 8590 | GenPackedSwitchWithCompares(value_reg, |
| 8591 | lower_bound, |
| 8592 | num_entries, |
| 8593 | switch_instr->GetBlock(), |
| 8594 | switch_instr->GetDefaultBlock()); |
| 8595 | } |
| 8596 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8597 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 8598 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8599 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8600 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8601 | |
| 8602 | // Constant area pointer. |
| 8603 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8604 | |
| 8605 | // And the temporary we need. |
| 8606 | locations->AddTemp(Location::RequiresRegister()); |
| 8607 | } |
| 8608 | |
| 8609 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 8610 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8611 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8612 | LocationSummary* locations = switch_instr->GetLocations(); |
| 8613 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 8614 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 8615 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8616 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 8617 | GenPackedSwitchWithCompares(value_reg, |
| 8618 | lower_bound, |
| 8619 | num_entries, |
| 8620 | switch_instr->GetBlock(), |
| 8621 | default_block); |
| 8622 | return; |
| 8623 | } |
| 8624 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8625 | // Optimizing has a jump area. |
| 8626 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 8627 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 8628 | |
| 8629 | // Remove the bias, if needed. |
| 8630 | if (lower_bound != 0) { |
| 8631 | __ leal(temp_reg, Address(value_reg, -lower_bound)); |
| 8632 | value_reg = temp_reg; |
| 8633 | } |
| 8634 | |
| 8635 | // Is the value in range? |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8636 | DCHECK_GE(num_entries, 1u); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8637 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 8638 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| 8639 | |
| 8640 | // We are in the range of the table. |
| 8641 | // Load (target-constant_area) from the jump table, indexing by the value. |
| 8642 | __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); |
| 8643 | |
| 8644 | // Compute the actual target address by adding in constant_area. |
| 8645 | __ addl(temp_reg, constant_area); |
| 8646 | |
| 8647 | // And jump. |
| 8648 | __ jmp(temp_reg); |
| 8649 | } |
| 8650 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8651 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 8652 | HX86ComputeBaseMethodAddress* insn) { |
| 8653 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8654 | new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8655 | locations->SetOut(Location::RequiresRegister()); |
| 8656 | } |
| 8657 | |
| 8658 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 8659 | HX86ComputeBaseMethodAddress* insn) { |
| 8660 | LocationSummary* locations = insn->GetLocations(); |
| 8661 | Register reg = locations->Out().AsRegister<Register>(); |
| 8662 | |
| 8663 | // Generate call to next instruction. |
| 8664 | Label next_instruction; |
| 8665 | __ call(&next_instruction); |
| 8666 | __ Bind(&next_instruction); |
| 8667 | |
| 8668 | // Remember this offset for later use with constant area. |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8669 | codegen_->AddMethodAddressOffset(insn, GetAssembler()->CodeSize()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8670 | |
| 8671 | // Grab the return address off the stack. |
| 8672 | __ popl(reg); |
| 8673 | } |
| 8674 | |
| 8675 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 8676 | HX86LoadFromConstantTable* insn) { |
| 8677 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8678 | new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8679 | |
| 8680 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8681 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 8682 | |
| 8683 | // 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] | 8684 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8685 | return; |
| 8686 | } |
| 8687 | |
| 8688 | switch (insn->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8689 | case DataType::Type::kFloat32: |
| 8690 | case DataType::Type::kFloat64: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8691 | locations->SetOut(Location::RequiresFpuRegister()); |
| 8692 | break; |
| 8693 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8694 | case DataType::Type::kInt32: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8695 | locations->SetOut(Location::RequiresRegister()); |
| 8696 | break; |
| 8697 | |
| 8698 | default: |
| 8699 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 8700 | } |
| 8701 | } |
| 8702 | |
| 8703 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 8704 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8705 | return; |
| 8706 | } |
| 8707 | |
| 8708 | LocationSummary* locations = insn->GetLocations(); |
| 8709 | Location out = locations->Out(); |
| 8710 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 8711 | HConstant *value = insn->GetConstant(); |
| 8712 | |
| 8713 | switch (insn->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8714 | case DataType::Type::kFloat32: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8715 | __ movss(out.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8716 | codegen_->LiteralFloatAddress( |
| 8717 | value->AsFloatConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8718 | break; |
| 8719 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8720 | case DataType::Type::kFloat64: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8721 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8722 | codegen_->LiteralDoubleAddress( |
| 8723 | value->AsDoubleConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8724 | break; |
| 8725 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8726 | case DataType::Type::kInt32: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8727 | __ movl(out.AsRegister<Register>(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8728 | codegen_->LiteralInt32Address( |
| 8729 | value->AsIntConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8730 | break; |
| 8731 | |
| 8732 | default: |
| 8733 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 8734 | } |
| 8735 | } |
| 8736 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8737 | /** |
| 8738 | * Class to handle late fixup of offsets into constant area. |
| 8739 | */ |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 8740 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8741 | public: |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8742 | RIPFixup(CodeGeneratorX86& codegen, |
| 8743 | HX86ComputeBaseMethodAddress* base_method_address, |
| 8744 | size_t offset) |
| 8745 | : codegen_(&codegen), |
| 8746 | base_method_address_(base_method_address), |
| 8747 | offset_into_constant_area_(offset) {} |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8748 | |
| 8749 | protected: |
| 8750 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 8751 | |
| 8752 | CodeGeneratorX86* codegen_; |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8753 | HX86ComputeBaseMethodAddress* base_method_address_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8754 | |
| 8755 | private: |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8756 | void Process(const MemoryRegion& region, int pos) override { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8757 | // Patch the correct offset for the instruction. The place to patch is the |
| 8758 | // last 4 bytes of the instruction. |
| 8759 | // The value to patch is the distance from the offset in the constant area |
| 8760 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8761 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8762 | int32_t relative_position = |
| 8763 | constant_offset - codegen_->GetMethodAddressOffset(base_method_address_); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8764 | |
| 8765 | // Patch in the right value. |
| 8766 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 8767 | } |
| 8768 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8769 | // Location in constant area that the fixup refers to. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8770 | int32_t offset_into_constant_area_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8771 | }; |
| 8772 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8773 | /** |
| 8774 | * Class to handle late fixup of offsets to a jump table that will be created in the |
| 8775 | * constant area. |
| 8776 | */ |
| 8777 | class JumpTableRIPFixup : public RIPFixup { |
| 8778 | public: |
| 8779 | JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8780 | : RIPFixup(codegen, switch_instr->GetBaseMethodAddress(), static_cast<size_t>(-1)), |
| 8781 | switch_instr_(switch_instr) {} |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8782 | |
| 8783 | void CreateJumpTable() { |
| 8784 | X86Assembler* assembler = codegen_->GetAssembler(); |
| 8785 | |
| 8786 | // Ensure that the reference to the jump table has the correct offset. |
| 8787 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 8788 | SetOffset(offset_in_constant_table); |
| 8789 | |
| 8790 | // The label values in the jump table are computed relative to the |
| 8791 | // instruction addressing the constant area. |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8792 | const int32_t relative_offset = codegen_->GetMethodAddressOffset(base_method_address_); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8793 | |
| 8794 | // Populate the jump table with the correct values for the jump table. |
| 8795 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 8796 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 8797 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 8798 | // The value that we want is the target offset - the position of the table. |
| 8799 | for (int32_t i = 0; i < num_entries; i++) { |
| 8800 | HBasicBlock* b = successors[i]; |
| 8801 | Label* l = codegen_->GetLabelOf(b); |
| 8802 | DCHECK(l->IsBound()); |
| 8803 | int32_t offset_to_block = l->Position() - relative_offset; |
| 8804 | assembler->AppendInt32(offset_to_block); |
| 8805 | } |
| 8806 | } |
| 8807 | |
| 8808 | private: |
| 8809 | const HX86PackedSwitch* switch_instr_; |
| 8810 | }; |
| 8811 | |
| 8812 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 8813 | // Generate the constant area if needed. |
| 8814 | X86Assembler* assembler = GetAssembler(); |
jaishank | 20d1c94 | 2019-03-08 15:08:17 +0530 | [diff] [blame] | 8815 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8816 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 8817 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 8818 | // byte values. |
| 8819 | assembler->Align(4, 0); |
| 8820 | constant_area_start_ = assembler->CodeSize(); |
| 8821 | |
| 8822 | // Populate any jump tables. |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 8823 | for (JumpTableRIPFixup* jump_table : fixups_to_jump_tables_) { |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8824 | jump_table->CreateJumpTable(); |
| 8825 | } |
| 8826 | |
| 8827 | // And now add the constant area to the generated code. |
| 8828 | assembler->AddConstantArea(); |
| 8829 | } |
| 8830 | |
| 8831 | // And finish up. |
| 8832 | CodeGenerator::Finalize(allocator); |
| 8833 | } |
| 8834 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8835 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, |
| 8836 | HX86ComputeBaseMethodAddress* method_base, |
| 8837 | Register reg) { |
| 8838 | AssemblerFixup* fixup = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8839 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddDouble(v)); |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 8840 | return Address(reg, kPlaceholder32BitOffset, fixup); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8841 | } |
| 8842 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8843 | Address CodeGeneratorX86::LiteralFloatAddress(float v, |
| 8844 | HX86ComputeBaseMethodAddress* method_base, |
| 8845 | Register reg) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8846 | AssemblerFixup* fixup = |
| 8847 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddFloat(v)); |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 8848 | return Address(reg, kPlaceholder32BitOffset, fixup); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8849 | } |
| 8850 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8851 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, |
| 8852 | HX86ComputeBaseMethodAddress* method_base, |
| 8853 | Register reg) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8854 | AssemblerFixup* fixup = |
| 8855 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddInt32(v)); |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 8856 | return Address(reg, kPlaceholder32BitOffset, fixup); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8857 | } |
| 8858 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8859 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, |
| 8860 | HX86ComputeBaseMethodAddress* method_base, |
| 8861 | Register reg) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8862 | AssemblerFixup* fixup = |
| 8863 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddInt64(v)); |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 8864 | return Address(reg, kPlaceholder32BitOffset, fixup); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8865 | } |
| 8866 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 8867 | void CodeGeneratorX86::Load32BitValue(Register dest, int32_t value) { |
| 8868 | if (value == 0) { |
| 8869 | __ xorl(dest, dest); |
| 8870 | } else { |
| 8871 | __ movl(dest, Immediate(value)); |
| 8872 | } |
| 8873 | } |
| 8874 | |
| 8875 | void CodeGeneratorX86::Compare32BitValue(Register dest, int32_t value) { |
| 8876 | if (value == 0) { |
| 8877 | __ testl(dest, dest); |
| 8878 | } else { |
| 8879 | __ cmpl(dest, Immediate(value)); |
| 8880 | } |
| 8881 | } |
| 8882 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8883 | void CodeGeneratorX86::GenerateIntCompare(Location lhs, Location rhs) { |
| 8884 | Register lhs_reg = lhs.AsRegister<Register>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8885 | GenerateIntCompare(lhs_reg, rhs); |
| 8886 | } |
| 8887 | |
| 8888 | void CodeGeneratorX86::GenerateIntCompare(Register lhs, Location rhs) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8889 | if (rhs.IsConstant()) { |
| 8890 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8891 | Compare32BitValue(lhs, value); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8892 | } else if (rhs.IsStackSlot()) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8893 | __ cmpl(lhs, Address(ESP, rhs.GetStackIndex())); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8894 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8895 | __ cmpl(lhs, rhs.AsRegister<Register>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8896 | } |
| 8897 | } |
| 8898 | |
| 8899 | Address CodeGeneratorX86::ArrayAddress(Register obj, |
| 8900 | Location index, |
| 8901 | ScaleFactor scale, |
| 8902 | uint32_t data_offset) { |
| 8903 | return index.IsConstant() ? |
| 8904 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) : |
| 8905 | Address(obj, index.AsRegister<Register>(), scale, data_offset); |
| 8906 | } |
| 8907 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8908 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, |
| 8909 | Register reg, |
| 8910 | Register value) { |
| 8911 | // Create a fixup to be used to create and address the jump table. |
| 8912 | JumpTableRIPFixup* table_fixup = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8913 | new (GetGraph()->GetAllocator()) JumpTableRIPFixup(*this, switch_instr); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8914 | |
| 8915 | // We have to populate the jump tables. |
| 8916 | fixups_to_jump_tables_.push_back(table_fixup); |
| 8917 | |
| 8918 | // 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] | 8919 | return Address(reg, value, TIMES_4, kPlaceholder32BitOffset, table_fixup); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8920 | } |
| 8921 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8922 | // TODO: target as memory. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8923 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, DataType::Type type) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8924 | if (!target.IsValid()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8925 | DCHECK_EQ(type, DataType::Type::kVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8926 | return; |
| 8927 | } |
| 8928 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8929 | DCHECK_NE(type, DataType::Type::kVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8930 | |
| 8931 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 8932 | if (target.Equals(return_loc)) { |
| 8933 | return; |
| 8934 | } |
| 8935 | |
| 8936 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 8937 | // with the else branch. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8938 | if (type == DataType::Type::kInt64) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8939 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8940 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), DataType::Type::kInt32, nullptr); |
| 8941 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), DataType::Type::kInt32, nullptr); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8942 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 8943 | } else { |
| 8944 | // Let the parallel move resolver take care of all of this. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8945 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8946 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 8947 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 8948 | } |
| 8949 | } |
| 8950 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8951 | void CodeGeneratorX86::PatchJitRootUse(uint8_t* code, |
| 8952 | const uint8_t* roots_data, |
| 8953 | const PatchInfo<Label>& info, |
| 8954 | uint64_t index_in_table) const { |
| 8955 | uint32_t code_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 8956 | uintptr_t address = |
| 8957 | 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] | 8958 | using unaligned_uint32_t __attribute__((__aligned__(1))) = uint32_t; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8959 | reinterpret_cast<unaligned_uint32_t*>(code + code_offset)[0] = |
| 8960 | dchecked_integral_cast<uint32_t>(address); |
| 8961 | } |
| 8962 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 8963 | void CodeGeneratorX86::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 8964 | for (const PatchInfo<Label>& info : jit_string_patches_) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8965 | 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] | 8966 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 8967 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8968 | } |
| 8969 | |
| 8970 | for (const PatchInfo<Label>& info : jit_class_patches_) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8971 | 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] | 8972 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 8973 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 8974 | } |
| 8975 | } |
| 8976 | |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 8977 | void LocationsBuilderX86::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 8978 | ATTRIBUTE_UNUSED) { |
| 8979 | LOG(FATAL) << "Unreachable"; |
| 8980 | } |
| 8981 | |
| 8982 | void InstructionCodeGeneratorX86::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 8983 | ATTRIBUTE_UNUSED) { |
| 8984 | LOG(FATAL) << "Unreachable"; |
| 8985 | } |
| 8986 | |
Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 8987 | bool LocationsBuilderX86::CpuHasAvxFeatureFlag() { |
| 8988 | return codegen_->GetInstructionSetFeatures().HasAVX(); |
| 8989 | } |
| 8990 | bool LocationsBuilderX86::CpuHasAvx2FeatureFlag() { |
| 8991 | return codegen_->GetInstructionSetFeatures().HasAVX2(); |
| 8992 | } |
| 8993 | bool InstructionCodeGeneratorX86::CpuHasAvxFeatureFlag() { |
| 8994 | return codegen_->GetInstructionSetFeatures().HasAVX(); |
| 8995 | } |
| 8996 | bool InstructionCodeGeneratorX86::CpuHasAvx2FeatureFlag() { |
| 8997 | return codegen_->GetInstructionSetFeatures().HasAVX2(); |
| 8998 | } |
| 8999 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 9000 | #undef __ |
| 9001 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 9002 | } // namespace x86 |
| 9003 | } // namespace art |