| 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 | |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 19 | #include "art_method-inl.h" |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 20 | #include "class_table.h" |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 21 | #include "code_generator_utils.h" |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 22 | #include "compiled_method.h" |
| Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 23 | #include "entrypoints/quick/quick_entrypoints.h" |
| Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 24 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
| Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 25 | #include "gc/accounting/card_table.h" |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 26 | #include "gc/space/image_space.h" |
| Andreas Gampe | 09659c2 | 2017-09-18 18:23:32 -0700 | [diff] [blame] | 27 | #include "heap_poisoning.h" |
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 28 | #include "intrinsics.h" |
| 29 | #include "intrinsics_x86.h" |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 30 | #include "jit/profiling_info.h" |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 31 | #include "linker/linker_patch.h" |
| Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 32 | #include "lock_word.h" |
| Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 33 | #include "mirror/array-inl.h" |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 34 | #include "mirror/class-inl.h" |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 35 | #include "scoped_thread_state_change-inl.h" |
| Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 36 | #include "thread.h" |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 37 | #include "utils/assembler.h" |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 38 | #include "utils/stack_checks.h" |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 39 | #include "utils/x86/assembler_x86.h" |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 40 | #include "utils/x86/managed_register_x86.h" |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 41 | |
| Vladimir Marko | 0a51605 | 2019-10-14 13:00:44 +0000 | [diff] [blame] | 42 | namespace art { |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 43 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 44 | template<class MirrorType> |
| 45 | class GcRoot; |
| 46 | |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 47 | namespace x86 { |
| 48 | |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 49 | static constexpr int kCurrentMethodStackOffset = 0; |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 50 | static constexpr Register kMethodRegisterArgument = EAX; |
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 51 | static constexpr Register kCoreCalleeSaves[] = { EBP, ESI, EDI }; |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 52 | |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 53 | static constexpr int kC2ConditionMask = 0x400; |
| 54 | |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 55 | static constexpr int kFakeReturnRegister = Register(8); |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 56 | |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 57 | static constexpr int64_t kDoubleNaN = INT64_C(0x7FF8000000000000); |
| 58 | static constexpr int32_t kFloatNaN = INT32_C(0x7FC00000); |
| 59 | |
| Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 60 | static RegisterSet OneRegInReferenceOutSaveEverythingCallerSaves() { |
| 61 | InvokeRuntimeCallingConvention calling_convention; |
| 62 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 63 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 64 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 65 | // that the the kPrimNot result register is the same as the first argument register. |
| 66 | return caller_saves; |
| 67 | } |
| 68 | |
| Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 69 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 70 | #define __ down_cast<X86Assembler*>(codegen->GetAssembler())-> // NOLINT |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 71 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86PointerSize, x).Int32Value() |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 72 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 73 | class NullCheckSlowPathX86 : public SlowPathCode { |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 74 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 75 | explicit NullCheckSlowPathX86(HNullCheck* instruction) : SlowPathCode(instruction) {} |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 76 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 77 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 78 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 79 | __ Bind(GetEntryLabel()); |
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 80 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 81 | // Live registers will be restored in the catch block if caught. |
| 82 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 83 | } |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 84 | x86_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 85 | instruction_, |
| 86 | instruction_->GetDexPc(), |
| 87 | this); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 88 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 89 | } |
| 90 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 91 | bool IsFatal() const override { return true; } |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 92 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 93 | const char* GetDescription() const override { return "NullCheckSlowPathX86"; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 94 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 95 | private: |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 96 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86); |
| 97 | }; |
| 98 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 99 | class DivZeroCheckSlowPathX86 : public SlowPathCode { |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 100 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 101 | explicit DivZeroCheckSlowPathX86(HDivZeroCheck* instruction) : SlowPathCode(instruction) {} |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 102 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 103 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 104 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 105 | __ Bind(GetEntryLabel()); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 106 | x86_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 107 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 108 | } |
| 109 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 110 | bool IsFatal() const override { return true; } |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 111 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 112 | const char* GetDescription() const override { return "DivZeroCheckSlowPathX86"; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 113 | |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 114 | private: |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 115 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86); |
| 116 | }; |
| 117 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 118 | class DivRemMinusOneSlowPathX86 : public SlowPathCode { |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 119 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 120 | DivRemMinusOneSlowPathX86(HInstruction* instruction, Register reg, bool is_div) |
| 121 | : SlowPathCode(instruction), reg_(reg), is_div_(is_div) {} |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 122 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 123 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 124 | __ Bind(GetEntryLabel()); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 125 | if (is_div_) { |
| 126 | __ negl(reg_); |
| 127 | } else { |
| 128 | __ movl(reg_, Immediate(0)); |
| 129 | } |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 130 | __ jmp(GetExitLabel()); |
| 131 | } |
| 132 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 133 | const char* GetDescription() const override { return "DivRemMinusOneSlowPathX86"; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 134 | |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 135 | private: |
| 136 | Register reg_; |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 137 | bool is_div_; |
| 138 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 139 | }; |
| 140 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 141 | class BoundsCheckSlowPathX86 : public SlowPathCode { |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 142 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 143 | explicit BoundsCheckSlowPathX86(HBoundsCheck* instruction) : SlowPathCode(instruction) {} |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 144 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 145 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 146 | LocationSummary* locations = instruction_->GetLocations(); |
| Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 147 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 148 | __ Bind(GetEntryLabel()); |
| Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 149 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 150 | // move resolver. |
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 151 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 152 | // Live registers will be restored in the catch block if caught. |
| 153 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 154 | } |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 155 | |
| 156 | // Are we using an array length from memory? |
| 157 | HInstruction* array_length = instruction_->InputAt(1); |
| 158 | Location length_loc = locations->InAt(1); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 159 | InvokeRuntimeCallingConvention calling_convention; |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 160 | if (array_length->IsArrayLength() && array_length->IsEmittedAtUseSite()) { |
| 161 | // Load the array length into our temporary. |
| Nicolas Geoffray | 0aff3a8 | 2017-10-13 13:12:36 +0100 | [diff] [blame] | 162 | HArrayLength* length = array_length->AsArrayLength(); |
| 163 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(length); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 164 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 165 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
| 166 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(1)); |
| 167 | // Check for conflicts with index. |
| 168 | if (length_loc.Equals(locations->InAt(0))) { |
| 169 | // We know we aren't using parameter 2. |
| 170 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(2)); |
| 171 | } |
| 172 | __ movl(length_loc.AsRegister<Register>(), array_len); |
| Nicolas Geoffray | 0aff3a8 | 2017-10-13 13:12:36 +0100 | [diff] [blame] | 173 | if (mirror::kUseStringCompression && length->IsStringLength()) { |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 174 | __ shrl(length_loc.AsRegister<Register>(), Immediate(1)); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 175 | } |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 176 | } |
| Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 177 | x86_codegen->EmitParallelMoves( |
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 178 | locations->InAt(0), |
| Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 179 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 180 | DataType::Type::kInt32, |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 181 | length_loc, |
| Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 182 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 183 | DataType::Type::kInt32); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 184 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 185 | ? kQuickThrowStringBounds |
| 186 | : kQuickThrowArrayBounds; |
| 187 | x86_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 188 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 189 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 190 | } |
| 191 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 192 | bool IsFatal() const override { return true; } |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 193 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 194 | const char* GetDescription() const override { return "BoundsCheckSlowPathX86"; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 195 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 196 | private: |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 197 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86); |
| 198 | }; |
| 199 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 200 | class SuspendCheckSlowPathX86 : public SlowPathCode { |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 201 | public: |
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 202 | SuspendCheckSlowPathX86(HSuspendCheck* instruction, HBasicBlock* successor) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 203 | : SlowPathCode(instruction), successor_(successor) {} |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 204 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 205 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 206 | LocationSummary* locations = instruction_->GetLocations(); |
| Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 207 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 208 | __ Bind(GetEntryLabel()); |
| Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 209 | SaveLiveRegisters(codegen, locations); // Only saves full width XMM for SIMD. |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 210 | x86_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 211 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
| Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 212 | RestoreLiveRegisters(codegen, locations); // Only restores full width XMM for SIMD. |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 213 | if (successor_ == nullptr) { |
| 214 | __ jmp(GetReturnLabel()); |
| 215 | } else { |
| Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 216 | __ jmp(x86_codegen->GetLabelOf(successor_)); |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 217 | } |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 218 | } |
| 219 | |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 220 | Label* GetReturnLabel() { |
| 221 | DCHECK(successor_ == nullptr); |
| 222 | return &return_label_; |
| 223 | } |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 224 | |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 225 | HBasicBlock* GetSuccessor() const { |
| 226 | return successor_; |
| 227 | } |
| 228 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 229 | const char* GetDescription() const override { return "SuspendCheckSlowPathX86"; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 230 | |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 231 | private: |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 232 | HBasicBlock* const successor_; |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 233 | Label return_label_; |
| 234 | |
| 235 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86); |
| 236 | }; |
| 237 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 238 | class LoadStringSlowPathX86 : public SlowPathCode { |
| 239 | public: |
| 240 | explicit LoadStringSlowPathX86(HLoadString* instruction): SlowPathCode(instruction) {} |
| 241 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 242 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 243 | LocationSummary* locations = instruction_->GetLocations(); |
| 244 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 245 | |
| 246 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 247 | __ Bind(GetEntryLabel()); |
| 248 | SaveLiveRegisters(codegen, locations); |
| 249 | |
| 250 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 251 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 252 | __ movl(calling_convention.GetRegisterAt(0), Immediate(string_index.index_)); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 253 | x86_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 254 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 255 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 256 | RestoreLiveRegisters(codegen, locations); |
| 257 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 258 | __ jmp(GetExitLabel()); |
| 259 | } |
| 260 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 261 | const char* GetDescription() const override { return "LoadStringSlowPathX86"; } |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 262 | |
| 263 | private: |
| 264 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86); |
| 265 | }; |
| 266 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 267 | class LoadClassSlowPathX86 : public SlowPathCode { |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 268 | public: |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 269 | LoadClassSlowPathX86(HLoadClass* cls, HInstruction* at) |
| 270 | : SlowPathCode(at), cls_(cls) { |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 271 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 272 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 273 | } |
| 274 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 275 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 276 | LocationSummary* locations = instruction_->GetLocations(); |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 277 | Location out = locations->Out(); |
| 278 | const uint32_t dex_pc = instruction_->GetDexPc(); |
| 279 | bool must_resolve_type = instruction_->IsLoadClass() && cls_->MustResolveTypeOnSlowPath(); |
| 280 | bool must_do_clinit = instruction_->IsClinitCheck() || cls_->MustGenerateClinitCheck(); |
| 281 | |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 282 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 283 | __ Bind(GetEntryLabel()); |
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 284 | SaveLiveRegisters(codegen, locations); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 285 | |
| 286 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 287 | if (must_resolve_type) { |
| 288 | DCHECK(IsSameDexFile(cls_->GetDexFile(), x86_codegen->GetGraph()->GetDexFile())); |
| 289 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 290 | __ movl(calling_convention.GetRegisterAt(0), Immediate(type_index.index_)); |
| Vladimir Marko | 9d47925 | 2018-07-24 11:35:20 +0100 | [diff] [blame] | 291 | x86_codegen->InvokeRuntime(kQuickResolveType, instruction_, dex_pc, this); |
| 292 | CheckEntrypointTypes<kQuickResolveType, void*, uint32_t>(); |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 293 | // If we also must_do_clinit, the resolved type is now in the correct register. |
| 294 | } else { |
| 295 | DCHECK(must_do_clinit); |
| 296 | Location source = instruction_->IsLoadClass() ? out : locations->InAt(0); |
| 297 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), source); |
| 298 | } |
| 299 | if (must_do_clinit) { |
| 300 | x86_codegen->InvokeRuntime(kQuickInitializeStaticStorage, instruction_, dex_pc, this); |
| 301 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, mirror::Class*>(); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 302 | } |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 303 | |
| 304 | // Move the class to the desired location. |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 305 | if (out.IsValid()) { |
| 306 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 307 | x86_codegen->Move32(out, Location::RegisterLocation(EAX)); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 308 | } |
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 309 | RestoreLiveRegisters(codegen, locations); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 310 | __ jmp(GetExitLabel()); |
| 311 | } |
| 312 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 313 | const char* GetDescription() const override { return "LoadClassSlowPathX86"; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 314 | |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 315 | private: |
| 316 | // The class this slow path will load. |
| 317 | HLoadClass* const cls_; |
| 318 | |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 319 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86); |
| 320 | }; |
| 321 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 322 | class TypeCheckSlowPathX86 : public SlowPathCode { |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 323 | public: |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 324 | TypeCheckSlowPathX86(HInstruction* instruction, bool is_fatal) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 325 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 326 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 327 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 328 | LocationSummary* locations = instruction_->GetLocations(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 329 | DCHECK(instruction_->IsCheckCast() |
| 330 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 331 | |
| 332 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 333 | __ Bind(GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 334 | |
| Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 335 | if (kPoisonHeapReferences && |
| 336 | instruction_->IsCheckCast() && |
| 337 | instruction_->AsCheckCast()->GetTypeCheckKind() == TypeCheckKind::kInterfaceCheck) { |
| 338 | // First, unpoison the `cls` reference that was poisoned for direct memory comparison. |
| 339 | __ UnpoisonHeapReference(locations->InAt(1).AsRegister<Register>()); |
| 340 | } |
| 341 | |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 342 | if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 343 | SaveLiveRegisters(codegen, locations); |
| 344 | } |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 345 | |
| 346 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 347 | // move resolver. |
| 348 | InvokeRuntimeCallingConvention calling_convention; |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 349 | x86_codegen->EmitParallelMoves(locations->InAt(0), |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 350 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 351 | DataType::Type::kReference, |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 352 | locations->InAt(1), |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 353 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 354 | DataType::Type::kReference); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 355 | if (instruction_->IsInstanceOf()) { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 356 | x86_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 357 | instruction_, |
| 358 | instruction_->GetDexPc(), |
| 359 | this); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 360 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 361 | } else { |
| 362 | DCHECK(instruction_->IsCheckCast()); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 363 | x86_codegen->InvokeRuntime(kQuickCheckInstanceOf, |
| 364 | instruction_, |
| 365 | instruction_->GetDexPc(), |
| 366 | this); |
| 367 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 368 | } |
| 369 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 370 | if (!is_fatal_) { |
| 371 | if (instruction_->IsInstanceOf()) { |
| 372 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 373 | } |
| 374 | RestoreLiveRegisters(codegen, locations); |
| Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 375 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 376 | __ jmp(GetExitLabel()); |
| 377 | } |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 378 | } |
| 379 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 380 | const char* GetDescription() const override { return "TypeCheckSlowPathX86"; } |
| 381 | bool IsFatal() const override { return is_fatal_; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 382 | |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 383 | private: |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 384 | const bool is_fatal_; |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 385 | |
| 386 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86); |
| 387 | }; |
| 388 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 389 | class DeoptimizationSlowPathX86 : public SlowPathCode { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 390 | public: |
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 391 | explicit DeoptimizationSlowPathX86(HDeoptimize* instruction) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 392 | : SlowPathCode(instruction) {} |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 393 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 394 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 395 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 396 | __ Bind(GetEntryLabel()); |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 397 | LocationSummary* locations = instruction_->GetLocations(); |
| 398 | SaveLiveRegisters(codegen, locations); |
| 399 | InvokeRuntimeCallingConvention calling_convention; |
| 400 | x86_codegen->Load32BitValue( |
| 401 | calling_convention.GetRegisterAt(0), |
| 402 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 403 | x86_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 404 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 405 | } |
| 406 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 407 | const char* GetDescription() const override { return "DeoptimizationSlowPathX86"; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 408 | |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 409 | private: |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 410 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86); |
| 411 | }; |
| 412 | |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 413 | class ArraySetSlowPathX86 : public SlowPathCode { |
| 414 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 415 | explicit ArraySetSlowPathX86(HInstruction* instruction) : SlowPathCode(instruction) {} |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 416 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 417 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 418 | LocationSummary* locations = instruction_->GetLocations(); |
| 419 | __ Bind(GetEntryLabel()); |
| 420 | SaveLiveRegisters(codegen, locations); |
| 421 | |
| 422 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 423 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 424 | parallel_move.AddMove( |
| 425 | locations->InAt(0), |
| 426 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 427 | DataType::Type::kReference, |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 428 | nullptr); |
| 429 | parallel_move.AddMove( |
| 430 | locations->InAt(1), |
| 431 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 432 | DataType::Type::kInt32, |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 433 | nullptr); |
| 434 | parallel_move.AddMove( |
| 435 | locations->InAt(2), |
| 436 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 437 | DataType::Type::kReference, |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 438 | nullptr); |
| 439 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 440 | |
| 441 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 442 | x86_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 443 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 444 | RestoreLiveRegisters(codegen, locations); |
| 445 | __ jmp(GetExitLabel()); |
| 446 | } |
| 447 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 448 | const char* GetDescription() const override { return "ArraySetSlowPathX86"; } |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 449 | |
| 450 | private: |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 451 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86); |
| 452 | }; |
| 453 | |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 454 | // Slow path marking an object reference `ref` during a read |
| 455 | // barrier. The field `obj.field` in the object `obj` holding this |
| 456 | // reference does not get updated by this slow path after marking (see |
| 457 | // ReadBarrierMarkAndUpdateFieldSlowPathX86 below for that). |
| 458 | // |
| 459 | // This means that after the execution of this slow path, `ref` will |
| 460 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 461 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 462 | // probably still be a from-space reference (unless it gets updated by |
| 463 | // another thread, or if another thread installed another object |
| 464 | // reference (different from `ref`) in `obj.field`). |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 465 | class ReadBarrierMarkSlowPathX86 : public SlowPathCode { |
| 466 | public: |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 467 | ReadBarrierMarkSlowPathX86(HInstruction* instruction, |
| 468 | Location ref, |
| 469 | bool unpoison_ref_before_marking) |
| 470 | : SlowPathCode(instruction), |
| 471 | ref_(ref), |
| 472 | unpoison_ref_before_marking_(unpoison_ref_before_marking) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 473 | DCHECK(kEmitCompilerReadBarrier); |
| 474 | } |
| 475 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 476 | const char* GetDescription() const override { return "ReadBarrierMarkSlowPathX86"; } |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 477 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 478 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 479 | LocationSummary* locations = instruction_->GetLocations(); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 480 | Register ref_reg = ref_.AsRegister<Register>(); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 481 | DCHECK(locations->CanCall()); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 482 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 483 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 484 | instruction_->IsStaticFieldGet() || |
| 485 | instruction_->IsArrayGet() || |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 486 | instruction_->IsArraySet() || |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 487 | instruction_->IsLoadClass() || |
| 488 | instruction_->IsLoadString() || |
| 489 | instruction_->IsInstanceOf() || |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 490 | instruction_->IsCheckCast() || |
| Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 491 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 492 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 493 | << "Unexpected instruction in read barrier marking slow path: " |
| 494 | << instruction_->DebugName(); |
| 495 | |
| 496 | __ Bind(GetEntryLabel()); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 497 | if (unpoison_ref_before_marking_) { |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 498 | // Object* ref = ref_addr->AsMirrorPtr() |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 499 | __ MaybeUnpoisonHeapReference(ref_reg); |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 500 | } |
| Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 501 | // No need to save live registers; it's taken care of by the |
| 502 | // entrypoint. Also, there is no need to update the stack mask, |
| 503 | // as this runtime call will not trigger a garbage collection. |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 504 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 505 | DCHECK_NE(ref_reg, ESP); |
| 506 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 507 | // "Compact" slow path, saving two moves. |
| 508 | // |
| 509 | // Instead of using the standard runtime calling convention (input |
| 510 | // and output in EAX): |
| 511 | // |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 512 | // EAX <- ref |
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 513 | // EAX <- ReadBarrierMark(EAX) |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 514 | // ref <- EAX |
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 515 | // |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 516 | // we just use rX (the register containing `ref`) as input and output |
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 517 | // of a dedicated entrypoint: |
| 518 | // |
| 519 | // rX <- ReadBarrierMarkRegX(rX) |
| 520 | // |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 521 | int32_t entry_point_offset = Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(ref_reg); |
| Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 522 | // This runtime call does not require a stack map. |
| 523 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 524 | __ jmp(GetExitLabel()); |
| 525 | } |
| 526 | |
| 527 | private: |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 528 | // The location (register) of the marked object reference. |
| 529 | const Location ref_; |
| 530 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 531 | const bool unpoison_ref_before_marking_; |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 532 | |
| 533 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86); |
| 534 | }; |
| 535 | |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 536 | // Slow path marking an object reference `ref` during a read barrier, |
| 537 | // and if needed, atomically updating the field `obj.field` in the |
| 538 | // object `obj` holding this reference after marking (contrary to |
| 539 | // ReadBarrierMarkSlowPathX86 above, which never tries to update |
| 540 | // `obj.field`). |
| 541 | // |
| 542 | // This means that after the execution of this slow path, both `ref` |
| 543 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 544 | // hold the same to-space reference (unless another thread installed |
| 545 | // another object reference (different from `ref`) in `obj.field`). |
| 546 | class ReadBarrierMarkAndUpdateFieldSlowPathX86 : public SlowPathCode { |
| 547 | public: |
| 548 | ReadBarrierMarkAndUpdateFieldSlowPathX86(HInstruction* instruction, |
| 549 | Location ref, |
| 550 | Register obj, |
| 551 | const Address& field_addr, |
| 552 | bool unpoison_ref_before_marking, |
| 553 | Register temp) |
| 554 | : SlowPathCode(instruction), |
| 555 | ref_(ref), |
| 556 | obj_(obj), |
| 557 | field_addr_(field_addr), |
| 558 | unpoison_ref_before_marking_(unpoison_ref_before_marking), |
| 559 | temp_(temp) { |
| 560 | DCHECK(kEmitCompilerReadBarrier); |
| 561 | } |
| 562 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 563 | const char* GetDescription() const override { return "ReadBarrierMarkAndUpdateFieldSlowPathX86"; } |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 564 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 565 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 566 | LocationSummary* locations = instruction_->GetLocations(); |
| 567 | Register ref_reg = ref_.AsRegister<Register>(); |
| 568 | DCHECK(locations->CanCall()); |
| 569 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 570 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 571 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 572 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 573 | << instruction_->DebugName(); |
| 574 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 575 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 576 | |
| 577 | __ Bind(GetEntryLabel()); |
| 578 | if (unpoison_ref_before_marking_) { |
| 579 | // Object* ref = ref_addr->AsMirrorPtr() |
| 580 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 581 | } |
| 582 | |
| 583 | // Save the old (unpoisoned) reference. |
| 584 | __ movl(temp_, ref_reg); |
| 585 | |
| 586 | // No need to save live registers; it's taken care of by the |
| 587 | // entrypoint. Also, there is no need to update the stack mask, |
| 588 | // as this runtime call will not trigger a garbage collection. |
| 589 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 590 | DCHECK_NE(ref_reg, ESP); |
| 591 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
| 592 | // "Compact" slow path, saving two moves. |
| 593 | // |
| 594 | // Instead of using the standard runtime calling convention (input |
| 595 | // and output in EAX): |
| 596 | // |
| 597 | // EAX <- ref |
| 598 | // EAX <- ReadBarrierMark(EAX) |
| 599 | // ref <- EAX |
| 600 | // |
| 601 | // we just use rX (the register containing `ref`) as input and output |
| 602 | // of a dedicated entrypoint: |
| 603 | // |
| 604 | // rX <- ReadBarrierMarkRegX(rX) |
| 605 | // |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 606 | int32_t entry_point_offset = Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(ref_reg); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 607 | // This runtime call does not require a stack map. |
| 608 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 609 | |
| 610 | // If the new reference is different from the old reference, |
| 611 | // update the field in the holder (`*field_addr`). |
| 612 | // |
| 613 | // Note that this field could also hold a different object, if |
| 614 | // another thread had concurrently changed it. In that case, the |
| 615 | // LOCK CMPXCHGL instruction in the compare-and-set (CAS) |
| 616 | // operation below would abort the CAS, leaving the field as-is. |
| 617 | NearLabel done; |
| 618 | __ cmpl(temp_, ref_reg); |
| 619 | __ j(kEqual, &done); |
| 620 | |
| 621 | // Update the the holder's field atomically. This may fail if |
| 622 | // mutator updates before us, but it's OK. This is achieved |
| 623 | // using a strong compare-and-set (CAS) operation with relaxed |
| 624 | // memory synchronization ordering, where the expected value is |
| 625 | // the old reference and the desired value is the new reference. |
| 626 | // This operation is implemented with a 32-bit LOCK CMPXLCHG |
| 627 | // instruction, which requires the expected value (the old |
| 628 | // reference) to be in EAX. Save EAX beforehand, and move the |
| 629 | // expected value (stored in `temp_`) into EAX. |
| 630 | __ pushl(EAX); |
| 631 | __ movl(EAX, temp_); |
| 632 | |
| 633 | // Convenience aliases. |
| 634 | Register base = obj_; |
| 635 | Register expected = EAX; |
| 636 | Register value = ref_reg; |
| 637 | |
| 638 | bool base_equals_value = (base == value); |
| 639 | if (kPoisonHeapReferences) { |
| 640 | if (base_equals_value) { |
| 641 | // If `base` and `value` are the same register location, move |
| 642 | // `value` to a temporary register. This way, poisoning |
| 643 | // `value` won't invalidate `base`. |
| 644 | value = temp_; |
| 645 | __ movl(value, base); |
| 646 | } |
| 647 | |
| 648 | // Check that the register allocator did not assign the location |
| 649 | // of `expected` (EAX) to `value` nor to `base`, so that heap |
| 650 | // poisoning (when enabled) works as intended below. |
| 651 | // - If `value` were equal to `expected`, both references would |
| 652 | // be poisoned twice, meaning they would not be poisoned at |
| 653 | // all, as heap poisoning uses address negation. |
| 654 | // - If `base` were equal to `expected`, poisoning `expected` |
| 655 | // would invalidate `base`. |
| 656 | DCHECK_NE(value, expected); |
| 657 | DCHECK_NE(base, expected); |
| 658 | |
| 659 | __ PoisonHeapReference(expected); |
| 660 | __ PoisonHeapReference(value); |
| 661 | } |
| 662 | |
| 663 | __ LockCmpxchgl(field_addr_, value); |
| 664 | |
| 665 | // If heap poisoning is enabled, we need to unpoison the values |
| 666 | // that were poisoned earlier. |
| 667 | if (kPoisonHeapReferences) { |
| 668 | if (base_equals_value) { |
| 669 | // `value` has been moved to a temporary register, no need |
| 670 | // to unpoison it. |
| 671 | } else { |
| 672 | __ UnpoisonHeapReference(value); |
| 673 | } |
| 674 | // No need to unpoison `expected` (EAX), as it is be overwritten below. |
| 675 | } |
| 676 | |
| 677 | // Restore EAX. |
| 678 | __ popl(EAX); |
| 679 | |
| 680 | __ Bind(&done); |
| 681 | __ jmp(GetExitLabel()); |
| 682 | } |
| 683 | |
| 684 | private: |
| 685 | // The location (register) of the marked object reference. |
| 686 | const Location ref_; |
| 687 | // The register containing the object holding the marked object reference field. |
| 688 | const Register obj_; |
| 689 | // The address of the marked reference field. The base of this address must be `obj_`. |
| 690 | const Address field_addr_; |
| 691 | |
| 692 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 693 | const bool unpoison_ref_before_marking_; |
| 694 | |
| 695 | const Register temp_; |
| 696 | |
| 697 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathX86); |
| 698 | }; |
| 699 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 700 | // Slow path generating a read barrier for a heap reference. |
| 701 | class ReadBarrierForHeapReferenceSlowPathX86 : public SlowPathCode { |
| 702 | public: |
| 703 | ReadBarrierForHeapReferenceSlowPathX86(HInstruction* instruction, |
| 704 | Location out, |
| 705 | Location ref, |
| 706 | Location obj, |
| 707 | uint32_t offset, |
| 708 | Location index) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 709 | : SlowPathCode(instruction), |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 710 | out_(out), |
| 711 | ref_(ref), |
| 712 | obj_(obj), |
| 713 | offset_(offset), |
| 714 | index_(index) { |
| 715 | DCHECK(kEmitCompilerReadBarrier); |
| 716 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 717 | // has been overwritten by (or after) the heap object reference load |
| 718 | // to be instrumented, e.g.: |
| 719 | // |
| 720 | // __ movl(out, Address(out, offset)); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 721 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 722 | // |
| 723 | // In that case, we have lost the information about the original |
| 724 | // object, and the emitted read barrier cannot work properly. |
| 725 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 726 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 727 | } |
| 728 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 729 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 730 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 731 | LocationSummary* locations = instruction_->GetLocations(); |
| 732 | Register reg_out = out_.AsRegister<Register>(); |
| 733 | DCHECK(locations->CanCall()); |
| 734 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 735 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 736 | instruction_->IsStaticFieldGet() || |
| 737 | instruction_->IsArrayGet() || |
| 738 | instruction_->IsInstanceOf() || |
| 739 | instruction_->IsCheckCast() || |
| Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 740 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 741 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 742 | << instruction_->DebugName(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 743 | |
| 744 | __ Bind(GetEntryLabel()); |
| 745 | SaveLiveRegisters(codegen, locations); |
| 746 | |
| 747 | // We may have to change the index's value, but as `index_` is a |
| 748 | // constant member (like other "inputs" of this slow path), |
| 749 | // introduce a copy of it, `index`. |
| 750 | Location index = index_; |
| 751 | if (index_.IsValid()) { |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 752 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 753 | if (instruction_->IsArrayGet()) { |
| 754 | // Compute the actual memory offset and store it in `index`. |
| 755 | Register index_reg = index_.AsRegister<Register>(); |
| 756 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 757 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 758 | // We are about to change the value of `index_reg` (see the |
| 759 | // calls to art::x86::X86Assembler::shll and |
| 760 | // art::x86::X86Assembler::AddImmediate below), but it has |
| 761 | // not been saved by the previous call to |
| 762 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 763 | // callee-save register -- |
| 764 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 765 | // callee-save registers, as it has been designed with the |
| 766 | // assumption that callee-save registers are supposed to be |
| 767 | // handled by the called function. So, as a callee-save |
| 768 | // register, `index_reg` _would_ eventually be saved onto |
| 769 | // the stack, but it would be too late: we would have |
| 770 | // changed its value earlier. Therefore, we manually save |
| 771 | // it here into another freely available register, |
| 772 | // `free_reg`, chosen of course among the caller-save |
| 773 | // registers (as a callee-save `free_reg` register would |
| 774 | // exhibit the same problem). |
| 775 | // |
| 776 | // Note we could have requested a temporary register from |
| 777 | // the register allocator instead; but we prefer not to, as |
| 778 | // this is a slow path, and we know we can find a |
| 779 | // caller-save register that is available. |
| 780 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 781 | __ movl(free_reg, index_reg); |
| 782 | index_reg = free_reg; |
| 783 | index = Location::RegisterLocation(index_reg); |
| 784 | } else { |
| 785 | // The initial register stored in `index_` has already been |
| 786 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 787 | // (as it is not a callee-save register), so we can freely |
| 788 | // use it. |
| 789 | } |
| 790 | // Shifting the index value contained in `index_reg` by the scale |
| 791 | // factor (2) cannot overflow in practice, as the runtime is |
| 792 | // unable to allocate object arrays with a size larger than |
| 793 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 794 | __ shll(index_reg, Immediate(TIMES_4)); |
| 795 | static_assert( |
| 796 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 797 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 798 | __ AddImmediate(index_reg, Immediate(offset_)); |
| 799 | } else { |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 800 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 801 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 802 | // (as in the case of ArrayGet), as it is actually an offset |
| 803 | // to an object field within an object. |
| 804 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 805 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 806 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 807 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 808 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 809 | DCHECK_EQ(offset_, 0U); |
| 810 | DCHECK(index_.IsRegisterPair()); |
| 811 | // UnsafeGet's offset location is a register pair, the low |
| 812 | // part contains the correct offset. |
| 813 | index = index_.ToLow(); |
| 814 | } |
| 815 | } |
| 816 | |
| 817 | // We're moving two or three locations to locations that could |
| 818 | // overlap, so we need a parallel move resolver. |
| 819 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 820 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 821 | parallel_move.AddMove(ref_, |
| 822 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 823 | DataType::Type::kReference, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 824 | nullptr); |
| 825 | parallel_move.AddMove(obj_, |
| 826 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 827 | DataType::Type::kReference, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 828 | nullptr); |
| 829 | if (index.IsValid()) { |
| 830 | parallel_move.AddMove(index, |
| 831 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 832 | DataType::Type::kInt32, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 833 | nullptr); |
| 834 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 835 | } else { |
| 836 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 837 | __ movl(calling_convention.GetRegisterAt(2), Immediate(offset_)); |
| 838 | } |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 839 | x86_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 840 | CheckEntrypointTypes< |
| 841 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 842 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 843 | |
| 844 | RestoreLiveRegisters(codegen, locations); |
| 845 | __ jmp(GetExitLabel()); |
| 846 | } |
| 847 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 848 | const char* GetDescription() const override { return "ReadBarrierForHeapReferenceSlowPathX86"; } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 849 | |
| 850 | private: |
| 851 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 852 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 853 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 854 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 855 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 856 | return static_cast<Register>(i); |
| 857 | } |
| 858 | } |
| 859 | // We shall never fail to find a free caller-save register, as |
| 860 | // there are more than two core caller-save registers on x86 |
| 861 | // (meaning it is possible to find one which is different from |
| 862 | // `ref` and `obj`). |
| 863 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 864 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 865 | UNREACHABLE(); |
| 866 | } |
| 867 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 868 | const Location out_; |
| 869 | const Location ref_; |
| 870 | const Location obj_; |
| 871 | const uint32_t offset_; |
| 872 | // An additional location containing an index to an array. |
| 873 | // Only used for HArrayGet and the UnsafeGetObject & |
| 874 | // UnsafeGetObjectVolatile intrinsics. |
| 875 | const Location index_; |
| 876 | |
| 877 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86); |
| 878 | }; |
| 879 | |
| 880 | // Slow path generating a read barrier for a GC root. |
| 881 | class ReadBarrierForRootSlowPathX86 : public SlowPathCode { |
| 882 | public: |
| 883 | ReadBarrierForRootSlowPathX86(HInstruction* instruction, Location out, Location root) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 884 | : SlowPathCode(instruction), out_(out), root_(root) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 885 | DCHECK(kEmitCompilerReadBarrier); |
| 886 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 887 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 888 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 889 | LocationSummary* locations = instruction_->GetLocations(); |
| 890 | Register reg_out = out_.AsRegister<Register>(); |
| 891 | DCHECK(locations->CanCall()); |
| 892 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 893 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 894 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 895 | << instruction_->DebugName(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 896 | |
| 897 | __ Bind(GetEntryLabel()); |
| 898 | SaveLiveRegisters(codegen, locations); |
| 899 | |
| 900 | InvokeRuntimeCallingConvention calling_convention; |
| 901 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 902 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 903 | x86_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 904 | instruction_, |
| 905 | instruction_->GetDexPc(), |
| 906 | this); |
| 907 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 908 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 909 | |
| 910 | RestoreLiveRegisters(codegen, locations); |
| 911 | __ jmp(GetExitLabel()); |
| 912 | } |
| 913 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 914 | const char* GetDescription() const override { return "ReadBarrierForRootSlowPathX86"; } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 915 | |
| 916 | private: |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 917 | const Location out_; |
| 918 | const Location root_; |
| 919 | |
| 920 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86); |
| 921 | }; |
| 922 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 923 | #undef __ |
| Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 924 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 925 | #define __ down_cast<X86Assembler*>(GetAssembler())-> // NOLINT |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 926 | |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 927 | inline Condition X86Condition(IfCondition cond) { |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 928 | switch (cond) { |
| 929 | case kCondEQ: return kEqual; |
| 930 | case kCondNE: return kNotEqual; |
| 931 | case kCondLT: return kLess; |
| 932 | case kCondLE: return kLessEqual; |
| 933 | case kCondGT: return kGreater; |
| 934 | case kCondGE: return kGreaterEqual; |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 935 | case kCondB: return kBelow; |
| 936 | case kCondBE: return kBelowEqual; |
| 937 | case kCondA: return kAbove; |
| 938 | case kCondAE: return kAboveEqual; |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 939 | } |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 940 | LOG(FATAL) << "Unreachable"; |
| 941 | UNREACHABLE(); |
| 942 | } |
| 943 | |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 944 | // Maps signed condition to unsigned condition and FP condition to x86 name. |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 945 | inline Condition X86UnsignedOrFPCondition(IfCondition cond) { |
| 946 | switch (cond) { |
| 947 | case kCondEQ: return kEqual; |
| 948 | case kCondNE: return kNotEqual; |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 949 | // Signed to unsigned, and FP to x86 name. |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 950 | case kCondLT: return kBelow; |
| 951 | case kCondLE: return kBelowEqual; |
| 952 | case kCondGT: return kAbove; |
| 953 | case kCondGE: return kAboveEqual; |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 954 | // Unsigned remain unchanged. |
| 955 | case kCondB: return kBelow; |
| 956 | case kCondBE: return kBelowEqual; |
| 957 | case kCondA: return kAbove; |
| 958 | case kCondAE: return kAboveEqual; |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 959 | } |
| 960 | LOG(FATAL) << "Unreachable"; |
| 961 | UNREACHABLE(); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 962 | } |
| 963 | |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 964 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 965 | stream << Register(reg); |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 969 | stream << XmmRegister(reg); |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 970 | } |
| 971 | |
| Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 972 | const X86InstructionSetFeatures& CodeGeneratorX86::GetInstructionSetFeatures() const { |
| 973 | return *GetCompilerOptions().GetInstructionSetFeatures()->AsX86InstructionSetFeatures(); |
| 974 | } |
| 975 | |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 976 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 977 | __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); |
| 978 | return kX86WordSize; |
| Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 979 | } |
| 980 | |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 981 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 982 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); |
| 983 | return kX86WordSize; |
| Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 984 | } |
| 985 | |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 986 | size_t CodeGeneratorX86::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 987 | if (GetGraph()->HasSIMD()) { |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 988 | __ movups(Address(ESP, stack_index), XmmRegister(reg_id)); |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 989 | } else { |
| 990 | __ movsd(Address(ESP, stack_index), XmmRegister(reg_id)); |
| 991 | } |
| Artem Serov | 6a0b657 | 2019-07-26 20:38:37 +0100 | [diff] [blame] | 992 | return GetSlowPathFPWidth(); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | size_t CodeGeneratorX86::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 996 | if (GetGraph()->HasSIMD()) { |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 997 | __ movups(XmmRegister(reg_id), Address(ESP, stack_index)); |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 998 | } else { |
| 999 | __ movsd(XmmRegister(reg_id), Address(ESP, stack_index)); |
| 1000 | } |
| Artem Serov | 6a0b657 | 2019-07-26 20:38:37 +0100 | [diff] [blame] | 1001 | return GetSlowPathFPWidth(); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1002 | } |
| 1003 | |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1004 | void CodeGeneratorX86::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1005 | HInstruction* instruction, |
| 1006 | uint32_t dex_pc, |
| 1007 | SlowPathCode* slow_path) { |
| Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1008 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1009 | GenerateInvokeRuntime(GetThreadOffset<kX86PointerSize>(entrypoint).Int32Value()); |
| 1010 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1011 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1012 | } |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 1013 | } |
| 1014 | |
| Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1015 | void CodeGeneratorX86::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1016 | HInstruction* instruction, |
| 1017 | SlowPathCode* slow_path) { |
| 1018 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1019 | GenerateInvokeRuntime(entry_point_offset); |
| 1020 | } |
| 1021 | |
| 1022 | void CodeGeneratorX86::GenerateInvokeRuntime(int32_t entry_point_offset) { |
| Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1023 | __ fs()->call(Address::Absolute(entry_point_offset)); |
| 1024 | } |
| 1025 | |
| Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1026 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1027 | const CompilerOptions& compiler_options, |
| 1028 | OptimizingCompilerStats* stats) |
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1029 | : CodeGenerator(graph, |
| 1030 | kNumberOfCpuRegisters, |
| 1031 | kNumberOfXmmRegisters, |
| 1032 | kNumberOfRegisterPairs, |
| 1033 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1034 | arraysize(kCoreCalleeSaves)) |
| 1035 | | (1 << kFakeReturnRegister), |
| Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1036 | 0, |
| 1037 | compiler_options, |
| 1038 | stats), |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1039 | block_labels_(nullptr), |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1040 | location_builder_(graph, this), |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1041 | instruction_visitor_(graph, this), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1042 | move_resolver_(graph->GetAllocator(), this), |
| 1043 | assembler_(graph->GetAllocator()), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1044 | boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1045 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1046 | boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1047 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1048 | boot_image_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1049 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 1050 | boot_image_other_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1051 | jit_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1052 | jit_class_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1053 | constant_area_start_(-1), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1054 | fixups_to_jump_tables_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1055 | method_address_offset_(std::less<uint32_t>(), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1056 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1057 | // Use a fake return address register to mimic Quick. |
| 1058 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1059 | } |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1060 | |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1061 | void CodeGeneratorX86::SetupBlockedRegisters() const { |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1062 | // Stack register is always reserved. |
| Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1063 | blocked_core_registers_[ESP] = true; |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1064 | } |
| 1065 | |
| Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1066 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1067 | : InstructionCodeGenerator(graph, codegen), |
| Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1068 | assembler_(codegen->GetAssembler()), |
| 1069 | codegen_(codegen) {} |
| 1070 | |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1071 | static dwarf::Reg DWARFReg(Register reg) { |
| David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1072 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1073 | } |
| 1074 | |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1075 | void CodeGeneratorX86::MaybeIncrementHotness(bool is_frame_entry) { |
| 1076 | if (GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 1077 | Register reg = EAX; |
| 1078 | if (is_frame_entry) { |
| 1079 | reg = kMethodRegisterArgument; |
| 1080 | } else { |
| 1081 | __ pushl(EAX); |
| 1082 | __ movl(EAX, Address(ESP, kX86WordSize)); |
| 1083 | } |
| 1084 | NearLabel overflow; |
| 1085 | __ cmpw(Address(reg, ArtMethod::HotnessCountOffset().Int32Value()), |
| 1086 | Immediate(ArtMethod::MaxCounter())); |
| 1087 | __ j(kEqual, &overflow); |
| 1088 | __ addw(Address(reg, ArtMethod::HotnessCountOffset().Int32Value()), |
| 1089 | Immediate(1)); |
| 1090 | __ Bind(&overflow); |
| 1091 | if (!is_frame_entry) { |
| 1092 | __ popl(EAX); |
| 1093 | } |
| 1094 | } |
| 1095 | |
| 1096 | if (GetGraph()->IsCompilingBaseline() && !Runtime::Current()->IsAotCompiler()) { |
| 1097 | ScopedObjectAccess soa(Thread::Current()); |
| 1098 | ProfilingInfo* info = GetGraph()->GetArtMethod()->GetProfilingInfo(kRuntimePointerSize); |
| 1099 | uint32_t address = reinterpret_cast32<uint32_t>(info); |
| 1100 | NearLabel done; |
| 1101 | if (HasEmptyFrame()) { |
| 1102 | CHECK(is_frame_entry); |
| 1103 | // Alignment |
| 1104 | __ subl(ESP, Immediate(8)); |
| 1105 | __ cfi().AdjustCFAOffset(8); |
| 1106 | // We need a temporary. The stub also expects the method at bottom of stack. |
| 1107 | __ pushl(EAX); |
| 1108 | __ cfi().AdjustCFAOffset(4); |
| 1109 | __ movl(EAX, Immediate(address)); |
| 1110 | __ addw(Address(EAX, ProfilingInfo::BaselineHotnessCountOffset().Int32Value()), Immediate(1)); |
| 1111 | __ j(kCarryClear, &done); |
| 1112 | GenerateInvokeRuntime( |
| 1113 | GetThreadOffset<kX86PointerSize>(kQuickCompileOptimized).Int32Value()); |
| 1114 | __ Bind(&done); |
| 1115 | // We don't strictly require to restore EAX, but this makes the generated |
| 1116 | // code easier to reason about. |
| 1117 | __ popl(EAX); |
| 1118 | __ cfi().AdjustCFAOffset(-4); |
| 1119 | __ addl(ESP, Immediate(8)); |
| 1120 | __ cfi().AdjustCFAOffset(-8); |
| 1121 | } else { |
| 1122 | if (!RequiresCurrentMethod()) { |
| 1123 | CHECK(is_frame_entry); |
| 1124 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
| 1125 | } |
| 1126 | // We need a temporary. |
| 1127 | __ pushl(EAX); |
| 1128 | __ cfi().AdjustCFAOffset(4); |
| 1129 | __ movl(EAX, Immediate(address)); |
| 1130 | __ addw(Address(EAX, ProfilingInfo::BaselineHotnessCountOffset().Int32Value()), Immediate(1)); |
| 1131 | __ popl(EAX); // Put stack as expected before exiting or calling stub. |
| 1132 | __ cfi().AdjustCFAOffset(-4); |
| 1133 | __ j(kCarryClear, &done); |
| 1134 | GenerateInvokeRuntime( |
| 1135 | GetThreadOffset<kX86PointerSize>(kQuickCompileOptimized).Int32Value()); |
| 1136 | __ Bind(&done); |
| 1137 | } |
| 1138 | } |
| 1139 | } |
| 1140 | |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1141 | void CodeGeneratorX86::GenerateFrameEntry() { |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1142 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
| Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1143 | __ Bind(&frame_entry_label_); |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1144 | bool skip_overflow_check = |
| 1145 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1146 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
| Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 1147 | |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1148 | if (!skip_overflow_check) { |
| Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1149 | size_t reserved_bytes = GetStackOverflowReservedBytes(InstructionSet::kX86); |
| 1150 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(reserved_bytes))); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1151 | RecordPcInfo(nullptr, 0); |
| Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 1152 | } |
| 1153 | |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1154 | if (!HasEmptyFrame()) { |
| 1155 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 1156 | Register reg = kCoreCalleeSaves[i]; |
| 1157 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1158 | __ pushl(reg); |
| 1159 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 1160 | __ cfi().RelOffset(DWARFReg(reg), 0); |
| 1161 | } |
| 1162 | } |
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1163 | |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1164 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1165 | __ subl(ESP, Immediate(adjust)); |
| 1166 | __ cfi().AdjustCFAOffset(adjust); |
| 1167 | // Save the current method if we need it. Note that we do not |
| 1168 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1169 | // in the SSA graph. |
| 1170 | if (RequiresCurrentMethod()) { |
| 1171 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
| 1172 | } |
| 1173 | |
| 1174 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1175 | // Initialize should_deoptimize flag to 0. |
| 1176 | __ movl(Address(ESP, GetStackOffsetOfShouldDeoptimizeFlag()), Immediate(0)); |
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1177 | } |
| 1178 | } |
| 1179 | |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1180 | MaybeIncrementHotness(/* is_frame_entry= */ true); |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1181 | } |
| 1182 | |
| 1183 | void CodeGeneratorX86::GenerateFrameExit() { |
| David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1184 | __ cfi().RememberState(); |
| 1185 | if (!HasEmptyFrame()) { |
| 1186 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1187 | __ addl(ESP, Immediate(adjust)); |
| 1188 | __ cfi().AdjustCFAOffset(-adjust); |
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1189 | |
| David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1190 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1191 | Register reg = kCoreCalleeSaves[i]; |
| 1192 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1193 | __ popl(reg); |
| 1194 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 1195 | __ cfi().Restore(DWARFReg(reg)); |
| 1196 | } |
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1197 | } |
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1198 | } |
| David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1199 | __ ret(); |
| 1200 | __ cfi().RestoreState(); |
| 1201 | __ cfi().DefCFAOffset(GetFrameSize()); |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1202 | } |
| 1203 | |
| Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1204 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 1205 | __ Bind(GetLabelOf(block)); |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1206 | } |
| 1207 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1208 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(DataType::Type type) const { |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1209 | switch (type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1210 | case DataType::Type::kReference: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1211 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1212 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1213 | case DataType::Type::kInt8: |
| 1214 | case DataType::Type::kUint16: |
| 1215 | case DataType::Type::kInt16: |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1216 | case DataType::Type::kUint32: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1217 | case DataType::Type::kInt32: |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1218 | return Location::RegisterLocation(EAX); |
| 1219 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1220 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1221 | case DataType::Type::kInt64: |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1222 | return Location::RegisterPairLocation(EAX, EDX); |
| 1223 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1224 | case DataType::Type::kVoid: |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1225 | return Location::NoLocation(); |
| 1226 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1227 | case DataType::Type::kFloat64: |
| 1228 | case DataType::Type::kFloat32: |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1229 | return Location::FpuRegisterLocation(XMM0); |
| 1230 | } |
| Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1231 | |
| 1232 | UNREACHABLE(); |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1233 | } |
| 1234 | |
| 1235 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 1236 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1237 | } |
| 1238 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1239 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(DataType::Type type) { |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1240 | switch (type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1241 | case DataType::Type::kReference: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1242 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1243 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1244 | case DataType::Type::kInt8: |
| 1245 | case DataType::Type::kUint16: |
| 1246 | case DataType::Type::kInt16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1247 | case DataType::Type::kInt32: { |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1248 | uint32_t index = gp_index_++; |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1249 | stack_index_++; |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1250 | if (index < calling_convention.GetNumberOfRegisters()) { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1251 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1252 | } else { |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1253 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1254 | } |
| Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1255 | } |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1256 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1257 | case DataType::Type::kInt64: { |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1258 | uint32_t index = gp_index_; |
| 1259 | gp_index_ += 2; |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1260 | stack_index_ += 2; |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1261 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1262 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 1263 | calling_convention.GetRegisterPairAt(index)); |
| 1264 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1265 | } else { |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1266 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1267 | } |
| 1268 | } |
| 1269 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1270 | case DataType::Type::kFloat32: { |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1271 | uint32_t index = float_index_++; |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1272 | stack_index_++; |
| 1273 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1274 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1275 | } else { |
| 1276 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1277 | } |
| 1278 | } |
| 1279 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1280 | case DataType::Type::kFloat64: { |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1281 | uint32_t index = float_index_++; |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1282 | stack_index_ += 2; |
| 1283 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1284 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1285 | } else { |
| 1286 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1287 | } |
| 1288 | } |
| 1289 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1290 | case DataType::Type::kUint32: |
| 1291 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1292 | case DataType::Type::kVoid: |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1293 | LOG(FATAL) << "Unexpected parameter type " << type; |
| Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 1294 | UNREACHABLE(); |
| Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1295 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1296 | return Location::NoLocation(); |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1297 | } |
| Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1298 | |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1299 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 1300 | if (source.Equals(destination)) { |
| 1301 | return; |
| 1302 | } |
| 1303 | if (destination.IsRegister()) { |
| 1304 | if (source.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1305 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1306 | } else if (source.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1307 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1308 | } else { |
| 1309 | DCHECK(source.IsStackSlot()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1310 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1311 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1312 | } else if (destination.IsFpuRegister()) { |
| 1313 | if (source.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1314 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1315 | } else if (source.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1316 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1317 | } else { |
| 1318 | DCHECK(source.IsStackSlot()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1319 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1320 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1321 | } else { |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1322 | DCHECK(destination.IsStackSlot()) << destination; |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1323 | if (source.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1324 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1325 | } else if (source.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1326 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1327 | } else if (source.IsConstant()) { |
| 1328 | HConstant* constant = source.GetConstant(); |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1329 | int32_t value = GetInt32ValueOf(constant); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1330 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1331 | } else { |
| 1332 | DCHECK(source.IsStackSlot()); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1333 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 1334 | __ popl(Address(ESP, destination.GetStackIndex())); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1335 | } |
| 1336 | } |
| 1337 | } |
| 1338 | |
| 1339 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 1340 | if (source.Equals(destination)) { |
| 1341 | return; |
| 1342 | } |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1343 | if (destination.IsRegisterPair()) { |
| 1344 | if (source.IsRegisterPair()) { |
| Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1345 | EmitParallelMoves( |
| 1346 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1347 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1348 | DataType::Type::kInt32, |
| Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1349 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
| Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1350 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1351 | DataType::Type::kInt32); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1352 | } else if (source.IsFpuRegister()) { |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1353 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 1354 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 1355 | __ psrlq(src_reg, Immediate(32)); |
| 1356 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1357 | } else { |
| Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1358 | // No conflict possible, so just do the moves. |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1359 | DCHECK(source.IsDoubleStackSlot()); |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1360 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 1361 | __ movl(destination.AsRegisterPairHigh<Register>(), |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1362 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 1363 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1364 | } else if (destination.IsFpuRegister()) { |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1365 | if (source.IsFpuRegister()) { |
| 1366 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 1367 | } else if (source.IsDoubleStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1368 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1369 | } else if (source.IsRegisterPair()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1370 | size_t elem_size = DataType::Size(DataType::Type::kInt32); |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1371 | // Create stack space for 2 elements. |
| 1372 | __ subl(ESP, Immediate(2 * elem_size)); |
| 1373 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 1374 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 1375 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 1376 | // And remove the temporary stack space we allocated. |
| 1377 | __ addl(ESP, Immediate(2 * elem_size)); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1378 | } else { |
| 1379 | LOG(FATAL) << "Unimplemented"; |
| 1380 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1381 | } else { |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1382 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1383 | if (source.IsRegisterPair()) { |
| Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1384 | // No conflict possible, so just do the moves. |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1385 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1386 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1387 | source.AsRegisterPairHigh<Register>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1388 | } else if (source.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1389 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1390 | } else if (source.IsConstant()) { |
| 1391 | HConstant* constant = source.GetConstant(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1392 | DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant()); |
| 1393 | int64_t value = GetInt64ValueOf(constant); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1394 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1395 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
| 1396 | Immediate(High32Bits(value))); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1397 | } else { |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1398 | DCHECK(source.IsDoubleStackSlot()) << source; |
| Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1399 | EmitParallelMoves( |
| 1400 | Location::StackSlot(source.GetStackIndex()), |
| 1401 | Location::StackSlot(destination.GetStackIndex()), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1402 | DataType::Type::kInt32, |
| Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1403 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
| Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1404 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1405 | DataType::Type::kInt32); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1406 | } |
| 1407 | } |
| 1408 | } |
| 1409 | |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1410 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { |
| 1411 | DCHECK(location.IsRegister()); |
| 1412 | __ movl(location.AsRegister<Register>(), Immediate(value)); |
| 1413 | } |
| 1414 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1415 | void CodeGeneratorX86::MoveLocation(Location dst, Location src, DataType::Type dst_type) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1416 | HParallelMove move(GetGraph()->GetAllocator()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1417 | if (dst_type == DataType::Type::kInt64 && !src.IsConstant() && !src.IsFpuRegister()) { |
| 1418 | move.AddMove(src.ToLow(), dst.ToLow(), DataType::Type::kInt32, nullptr); |
| 1419 | move.AddMove(src.ToHigh(), dst.ToHigh(), DataType::Type::kInt32, nullptr); |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1420 | } else { |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1421 | move.AddMove(src, dst, dst_type, nullptr); |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1422 | } |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1423 | GetMoveResolver()->EmitNativeCode(&move); |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1424 | } |
| 1425 | |
| 1426 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1427 | if (location.IsRegister()) { |
| 1428 | locations->AddTemp(location); |
| 1429 | } else if (location.IsRegisterPair()) { |
| 1430 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1431 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1432 | } else { |
| 1433 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1434 | } |
| 1435 | } |
| 1436 | |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1437 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
| Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 1438 | if (successor->IsExitBlock()) { |
| 1439 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 1440 | return; // no code needed |
| 1441 | } |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1442 | |
| 1443 | HBasicBlock* block = got->GetBlock(); |
| 1444 | HInstruction* previous = got->GetPrevious(); |
| 1445 | |
| 1446 | HLoopInformation* info = block->GetLoopInformation(); |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1447 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1448 | codegen_->MaybeIncrementHotness(/* is_frame_entry= */ false); |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1449 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1450 | return; |
| 1451 | } |
| 1452 | |
| 1453 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1454 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1455 | } |
| 1456 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1457 | __ jmp(codegen_->GetLabelOf(successor)); |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1458 | } |
| 1459 | } |
| 1460 | |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1461 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 1462 | got->SetLocations(nullptr); |
| 1463 | } |
| 1464 | |
| 1465 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 1466 | HandleGoto(got, got->GetSuccessor()); |
| 1467 | } |
| 1468 | |
| 1469 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1470 | try_boundary->SetLocations(nullptr); |
| 1471 | } |
| 1472 | |
| 1473 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1474 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1475 | if (!successor->IsExitBlock()) { |
| 1476 | HandleGoto(try_boundary, successor); |
| 1477 | } |
| 1478 | } |
| 1479 | |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1480 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1481 | exit->SetLocations(nullptr); |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1482 | } |
| 1483 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1484 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1485 | } |
| 1486 | |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1487 | template<class LabelType> |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1488 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1489 | LabelType* true_label, |
| 1490 | LabelType* false_label) { |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1491 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1492 | __ j(kUnordered, true_label); |
| 1493 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1494 | __ j(kUnordered, false_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1495 | } |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1496 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1497 | } |
| 1498 | |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1499 | template<class LabelType> |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1500 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1501 | LabelType* true_label, |
| 1502 | LabelType* false_label) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1503 | LocationSummary* locations = cond->GetLocations(); |
| 1504 | Location left = locations->InAt(0); |
| 1505 | Location right = locations->InAt(1); |
| 1506 | IfCondition if_cond = cond->GetCondition(); |
| 1507 | |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1508 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1509 | Register left_low = left.AsRegisterPairLow<Register>(); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1510 | IfCondition true_high_cond = if_cond; |
| 1511 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1512 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); // unsigned on lower part |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1513 | |
| 1514 | // Set the conditions for the test, remembering that == needs to be |
| 1515 | // decided using the low words. |
| 1516 | switch (if_cond) { |
| 1517 | case kCondEQ: |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1518 | case kCondNE: |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1519 | // Nothing to do. |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1520 | break; |
| 1521 | case kCondLT: |
| 1522 | false_high_cond = kCondGT; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1523 | break; |
| 1524 | case kCondLE: |
| 1525 | true_high_cond = kCondLT; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1526 | break; |
| 1527 | case kCondGT: |
| 1528 | false_high_cond = kCondLT; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1529 | break; |
| 1530 | case kCondGE: |
| 1531 | true_high_cond = kCondGT; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1532 | break; |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1533 | case kCondB: |
| 1534 | false_high_cond = kCondA; |
| 1535 | break; |
| 1536 | case kCondBE: |
| 1537 | true_high_cond = kCondB; |
| 1538 | break; |
| 1539 | case kCondA: |
| 1540 | false_high_cond = kCondB; |
| 1541 | break; |
| 1542 | case kCondAE: |
| 1543 | true_high_cond = kCondA; |
| 1544 | break; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1545 | } |
| 1546 | |
| 1547 | if (right.IsConstant()) { |
| 1548 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1549 | int32_t val_high = High32Bits(value); |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1550 | int32_t val_low = Low32Bits(value); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1551 | |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1552 | codegen_->Compare32BitValue(left_high, val_high); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1553 | if (if_cond == kCondNE) { |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1554 | __ j(X86Condition(true_high_cond), true_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1555 | } else if (if_cond == kCondEQ) { |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1556 | __ j(X86Condition(false_high_cond), false_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1557 | } else { |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1558 | __ j(X86Condition(true_high_cond), true_label); |
| 1559 | __ j(X86Condition(false_high_cond), false_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1560 | } |
| 1561 | // Must be equal high, so compare the lows. |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1562 | codegen_->Compare32BitValue(left_low, val_low); |
| Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1563 | } else if (right.IsRegisterPair()) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1564 | Register right_high = right.AsRegisterPairHigh<Register>(); |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1565 | Register right_low = right.AsRegisterPairLow<Register>(); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1566 | |
| 1567 | __ cmpl(left_high, right_high); |
| 1568 | if (if_cond == kCondNE) { |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1569 | __ j(X86Condition(true_high_cond), true_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1570 | } else if (if_cond == kCondEQ) { |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1571 | __ j(X86Condition(false_high_cond), false_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1572 | } else { |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1573 | __ j(X86Condition(true_high_cond), true_label); |
| 1574 | __ j(X86Condition(false_high_cond), false_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1575 | } |
| 1576 | // Must be equal high, so compare the lows. |
| 1577 | __ cmpl(left_low, right_low); |
| Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1578 | } else { |
| 1579 | DCHECK(right.IsDoubleStackSlot()); |
| 1580 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
| 1581 | if (if_cond == kCondNE) { |
| 1582 | __ j(X86Condition(true_high_cond), true_label); |
| 1583 | } else if (if_cond == kCondEQ) { |
| 1584 | __ j(X86Condition(false_high_cond), false_label); |
| 1585 | } else { |
| 1586 | __ j(X86Condition(true_high_cond), true_label); |
| 1587 | __ j(X86Condition(false_high_cond), false_label); |
| 1588 | } |
| 1589 | // Must be equal high, so compare the lows. |
| 1590 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1591 | } |
| 1592 | // The last comparison might be unsigned. |
| 1593 | __ j(final_condition, true_label); |
| 1594 | } |
| 1595 | |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1596 | void InstructionCodeGeneratorX86::GenerateFPCompare(Location lhs, |
| 1597 | Location rhs, |
| 1598 | HInstruction* insn, |
| 1599 | bool is_double) { |
| 1600 | HX86LoadFromConstantTable* const_area = insn->InputAt(1)->AsX86LoadFromConstantTable(); |
| 1601 | if (is_double) { |
| 1602 | if (rhs.IsFpuRegister()) { |
| 1603 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1604 | } else if (const_area != nullptr) { |
| 1605 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1606 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), |
| 1607 | codegen_->LiteralDoubleAddress( |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1608 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 1609 | const_area->GetBaseMethodAddress(), |
| 1610 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1611 | } else { |
| 1612 | DCHECK(rhs.IsDoubleStackSlot()); |
| 1613 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1614 | } |
| 1615 | } else { |
| 1616 | if (rhs.IsFpuRegister()) { |
| 1617 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1618 | } else if (const_area != nullptr) { |
| 1619 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1620 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), |
| 1621 | codegen_->LiteralFloatAddress( |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1622 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 1623 | const_area->GetBaseMethodAddress(), |
| 1624 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1625 | } else { |
| 1626 | DCHECK(rhs.IsStackSlot()); |
| 1627 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1628 | } |
| 1629 | } |
| 1630 | } |
| 1631 | |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1632 | template<class LabelType> |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1633 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1634 | LabelType* true_target_in, |
| 1635 | LabelType* false_target_in) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1636 | // Generated branching requires both targets to be explicit. If either of the |
| 1637 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1638 | LabelType fallthrough_target; |
| 1639 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1640 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1641 | |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1642 | LocationSummary* locations = condition->GetLocations(); |
| 1643 | Location left = locations->InAt(0); |
| 1644 | Location right = locations->InAt(1); |
| 1645 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1646 | DataType::Type type = condition->InputAt(0)->GetType(); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1647 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1648 | case DataType::Type::kInt64: |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1649 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1650 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1651 | case DataType::Type::kFloat32: |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1652 | GenerateFPCompare(left, right, condition, false); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1653 | GenerateFPJumps(condition, true_target, false_target); |
| 1654 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1655 | case DataType::Type::kFloat64: |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1656 | GenerateFPCompare(left, right, condition, true); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1657 | GenerateFPJumps(condition, true_target, false_target); |
| 1658 | break; |
| 1659 | default: |
| 1660 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1661 | } |
| 1662 | |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1663 | if (false_target != &fallthrough_target) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1664 | __ jmp(false_target); |
| 1665 | } |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1666 | |
| 1667 | if (fallthrough_target.IsLinked()) { |
| 1668 | __ Bind(&fallthrough_target); |
| 1669 | } |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1670 | } |
| 1671 | |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1672 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1673 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1674 | // are set only strictly before `branch`. We can't use the eflags on long/FP |
| 1675 | // conditions if they are materialized due to the complex branching. |
| 1676 | return cond->IsCondition() && |
| 1677 | cond->GetNext() == branch && |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1678 | cond->InputAt(0)->GetType() != DataType::Type::kInt64 && |
| 1679 | !DataType::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1680 | } |
| 1681 | |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1682 | template<class LabelType> |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1683 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1684 | size_t condition_input_index, |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1685 | LabelType* true_target, |
| 1686 | LabelType* false_target) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1687 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1688 | |
| 1689 | if (true_target == nullptr && false_target == nullptr) { |
| 1690 | // Nothing to do. The code always falls through. |
| 1691 | return; |
| 1692 | } else if (cond->IsIntConstant()) { |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1693 | // Constant condition, statically compared against "true" (integer value 1). |
| 1694 | if (cond->AsIntConstant()->IsTrue()) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1695 | if (true_target != nullptr) { |
| 1696 | __ jmp(true_target); |
| Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1697 | } |
| Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1698 | } else { |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1699 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1700 | if (false_target != nullptr) { |
| 1701 | __ jmp(false_target); |
| 1702 | } |
| 1703 | } |
| 1704 | return; |
| 1705 | } |
| 1706 | |
| 1707 | // The following code generates these patterns: |
| 1708 | // (1) true_target == nullptr && false_target != nullptr |
| 1709 | // - opposite condition true => branch to false_target |
| 1710 | // (2) true_target != nullptr && false_target == nullptr |
| 1711 | // - condition true => branch to true_target |
| 1712 | // (3) true_target != nullptr && false_target != nullptr |
| 1713 | // - condition true => branch to true_target |
| 1714 | // - branch to false_target |
| 1715 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1716 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1717 | if (true_target == nullptr) { |
| 1718 | __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1719 | } else { |
| 1720 | __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); |
| 1721 | } |
| 1722 | } else { |
| 1723 | // Materialized condition, compare against 0. |
| 1724 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1725 | if (lhs.IsRegister()) { |
| 1726 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1727 | } else { |
| 1728 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1729 | } |
| 1730 | if (true_target == nullptr) { |
| 1731 | __ j(kEqual, false_target); |
| 1732 | } else { |
| 1733 | __ j(kNotEqual, true_target); |
| 1734 | } |
| Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1735 | } |
| 1736 | } else { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1737 | // Condition has not been materialized, use its inputs as the comparison and |
| 1738 | // its condition as the branch condition. |
| Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1739 | HCondition* condition = cond->AsCondition(); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1740 | |
| 1741 | // If this is a long or FP comparison that has been folded into |
| 1742 | // the HCondition, generate the comparison directly. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1743 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 1744 | if (type == DataType::Type::kInt64 || DataType::IsFloatingPointType(type)) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1745 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1746 | return; |
| 1747 | } |
| 1748 | |
| 1749 | Location lhs = condition->GetLocations()->InAt(0); |
| 1750 | Location rhs = condition->GetLocations()->InAt(1); |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1751 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition). |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1752 | codegen_->GenerateIntCompare(lhs, rhs); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1753 | if (true_target == nullptr) { |
| 1754 | __ j(X86Condition(condition->GetOppositeCondition()), false_target); |
| 1755 | } else { |
| Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1756 | __ j(X86Condition(condition->GetCondition()), true_target); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1757 | } |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1758 | } |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1759 | |
| 1760 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1761 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1762 | if (true_target != nullptr && false_target != nullptr) { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1763 | __ jmp(false_target); |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1764 | } |
| 1765 | } |
| 1766 | |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1767 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1768 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1769 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1770 | locations->SetInAt(0, Location::Any()); |
| 1771 | } |
| 1772 | } |
| 1773 | |
| 1774 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1775 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1776 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1777 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1778 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1779 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1780 | nullptr : codegen_->GetLabelOf(false_successor); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1781 | GenerateTestAndBranch(if_instr, /* condition_input_index= */ 0, true_target, false_target); |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1782 | } |
| 1783 | |
| 1784 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1785 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1786 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 1787 | InvokeRuntimeCallingConvention calling_convention; |
| 1788 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 1789 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1790 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1791 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1792 | locations->SetInAt(0, Location::Any()); |
| 1793 | } |
| 1794 | } |
| 1795 | |
| 1796 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1797 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86>(deoptimize); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1798 | GenerateTestAndBranch<Label>(deoptimize, |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1799 | /* condition_input_index= */ 0, |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1800 | slow_path->GetEntryLabel(), |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1801 | /* false_target= */ nullptr); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1802 | } |
| 1803 | |
| Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1804 | void LocationsBuilderX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1805 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
| Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1806 | LocationSummary(flag, LocationSummary::kNoCall); |
| 1807 | locations->SetOut(Location::RequiresRegister()); |
| 1808 | } |
| 1809 | |
| 1810 | void InstructionCodeGeneratorX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1811 | __ movl(flag->GetLocations()->Out().AsRegister<Register>(), |
| 1812 | Address(ESP, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1813 | } |
| 1814 | |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1815 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1816 | // There are no conditional move instructions for XMMs. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1817 | if (DataType::IsFloatingPointType(select->GetType())) { |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1818 | return false; |
| 1819 | } |
| 1820 | |
| 1821 | // A FP condition doesn't generate the single CC that we need. |
| 1822 | // In 32 bit mode, a long condition doesn't generate a single CC either. |
| 1823 | HInstruction* condition = select->GetCondition(); |
| 1824 | if (condition->IsCondition()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1825 | DataType::Type compare_type = condition->InputAt(0)->GetType(); |
| 1826 | if (compare_type == DataType::Type::kInt64 || |
| 1827 | DataType::IsFloatingPointType(compare_type)) { |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1828 | return false; |
| 1829 | } |
| 1830 | } |
| 1831 | |
| 1832 | // We can generate a CMOV for this Select. |
| 1833 | return true; |
| 1834 | } |
| 1835 | |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1836 | void LocationsBuilderX86::VisitSelect(HSelect* select) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1837 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1838 | if (DataType::IsFloatingPointType(select->GetType())) { |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1839 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1840 | locations->SetInAt(1, Location::Any()); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1841 | } else { |
| 1842 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1843 | if (SelectCanUseCMOV(select)) { |
| 1844 | if (select->InputAt(1)->IsConstant()) { |
| 1845 | // Cmov can't handle a constant value. |
| 1846 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1847 | } else { |
| 1848 | locations->SetInAt(1, Location::Any()); |
| 1849 | } |
| 1850 | } else { |
| 1851 | locations->SetInAt(1, Location::Any()); |
| 1852 | } |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1853 | } |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1854 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1855 | locations->SetInAt(2, Location::RequiresRegister()); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1856 | } |
| 1857 | locations->SetOut(Location::SameAsFirstInput()); |
| 1858 | } |
| 1859 | |
| 1860 | void InstructionCodeGeneratorX86::VisitSelect(HSelect* select) { |
| 1861 | LocationSummary* locations = select->GetLocations(); |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1862 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1863 | if (SelectCanUseCMOV(select)) { |
| 1864 | // If both the condition and the source types are integer, we can generate |
| 1865 | // a CMOV to implement Select. |
| 1866 | |
| 1867 | HInstruction* select_condition = select->GetCondition(); |
| 1868 | Condition cond = kNotEqual; |
| 1869 | |
| 1870 | // Figure out how to test the 'condition'. |
| 1871 | if (select_condition->IsCondition()) { |
| 1872 | HCondition* condition = select_condition->AsCondition(); |
| 1873 | if (!condition->IsEmittedAtUseSite()) { |
| 1874 | // This was a previously materialized condition. |
| 1875 | // Can we use the existing condition code? |
| 1876 | if (AreEflagsSetFrom(condition, select)) { |
| 1877 | // Materialization was the previous instruction. Condition codes are right. |
| 1878 | cond = X86Condition(condition->GetCondition()); |
| 1879 | } else { |
| 1880 | // No, we have to recreate the condition code. |
| 1881 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1882 | __ testl(cond_reg, cond_reg); |
| 1883 | } |
| 1884 | } else { |
| 1885 | // We can't handle FP or long here. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1886 | DCHECK_NE(condition->InputAt(0)->GetType(), DataType::Type::kInt64); |
| 1887 | DCHECK(!DataType::IsFloatingPointType(condition->InputAt(0)->GetType())); |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1888 | LocationSummary* cond_locations = condition->GetLocations(); |
| Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1889 | codegen_->GenerateIntCompare(cond_locations->InAt(0), cond_locations->InAt(1)); |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1890 | cond = X86Condition(condition->GetCondition()); |
| 1891 | } |
| 1892 | } else { |
| Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 1893 | // Must be a Boolean condition, which needs to be compared to 0. |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1894 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1895 | __ testl(cond_reg, cond_reg); |
| 1896 | } |
| 1897 | |
| 1898 | // If the condition is true, overwrite the output, which already contains false. |
| 1899 | Location false_loc = locations->InAt(0); |
| 1900 | Location true_loc = locations->InAt(1); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1901 | if (select->GetType() == DataType::Type::kInt64) { |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1902 | // 64 bit conditional move. |
| 1903 | Register false_high = false_loc.AsRegisterPairHigh<Register>(); |
| 1904 | Register false_low = false_loc.AsRegisterPairLow<Register>(); |
| 1905 | if (true_loc.IsRegisterPair()) { |
| 1906 | __ cmovl(cond, false_high, true_loc.AsRegisterPairHigh<Register>()); |
| 1907 | __ cmovl(cond, false_low, true_loc.AsRegisterPairLow<Register>()); |
| 1908 | } else { |
| 1909 | __ cmovl(cond, false_high, Address(ESP, true_loc.GetHighStackIndex(kX86WordSize))); |
| 1910 | __ cmovl(cond, false_low, Address(ESP, true_loc.GetStackIndex())); |
| 1911 | } |
| 1912 | } else { |
| 1913 | // 32 bit conditional move. |
| 1914 | Register false_reg = false_loc.AsRegister<Register>(); |
| 1915 | if (true_loc.IsRegister()) { |
| 1916 | __ cmovl(cond, false_reg, true_loc.AsRegister<Register>()); |
| 1917 | } else { |
| 1918 | __ cmovl(cond, false_reg, Address(ESP, true_loc.GetStackIndex())); |
| 1919 | } |
| 1920 | } |
| 1921 | } else { |
| 1922 | NearLabel false_target; |
| 1923 | GenerateTestAndBranch<NearLabel>( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1924 | select, /* condition_input_index= */ 2, /* true_target= */ nullptr, &false_target); |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1925 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1926 | __ Bind(&false_target); |
| 1927 | } |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1928 | } |
| 1929 | |
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1930 | void LocationsBuilderX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1931 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1932 | } |
| 1933 | |
| David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1934 | void InstructionCodeGeneratorX86::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1935 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
| David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1936 | } |
| 1937 | |
| 1938 | void CodeGeneratorX86::GenerateNop() { |
| 1939 | __ nop(); |
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1940 | } |
| 1941 | |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1942 | void LocationsBuilderX86::HandleCondition(HCondition* cond) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1943 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1944 | new (GetGraph()->GetAllocator()) LocationSummary(cond, LocationSummary::kNoCall); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1945 | // Handle the long/FP comparisons made in instruction simplification. |
| 1946 | switch (cond->InputAt(0)->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1947 | case DataType::Type::kInt64: { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1948 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1949 | locations->SetInAt(1, Location::Any()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1950 | if (!cond->IsEmittedAtUseSite()) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1951 | locations->SetOut(Location::RequiresRegister()); |
| 1952 | } |
| 1953 | break; |
| 1954 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1955 | case DataType::Type::kFloat32: |
| 1956 | case DataType::Type::kFloat64: { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1957 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1958 | if (cond->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 1959 | DCHECK(cond->InputAt(1)->IsEmittedAtUseSite()); |
| 1960 | } else if (cond->InputAt(1)->IsConstant()) { |
| 1961 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1962 | } else { |
| 1963 | locations->SetInAt(1, Location::Any()); |
| 1964 | } |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1965 | if (!cond->IsEmittedAtUseSite()) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1966 | locations->SetOut(Location::RequiresRegister()); |
| 1967 | } |
| 1968 | break; |
| 1969 | } |
| 1970 | default: |
| 1971 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1972 | locations->SetInAt(1, Location::Any()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1973 | if (!cond->IsEmittedAtUseSite()) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1974 | // We need a byte register. |
| 1975 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1976 | } |
| 1977 | break; |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1978 | } |
| Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1979 | } |
| 1980 | |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1981 | void InstructionCodeGeneratorX86::HandleCondition(HCondition* cond) { |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1982 | if (cond->IsEmittedAtUseSite()) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1983 | return; |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1984 | } |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1985 | |
| 1986 | LocationSummary* locations = cond->GetLocations(); |
| 1987 | Location lhs = locations->InAt(0); |
| 1988 | Location rhs = locations->InAt(1); |
| 1989 | Register reg = locations->Out().AsRegister<Register>(); |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1990 | NearLabel true_label, false_label; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1991 | |
| 1992 | switch (cond->InputAt(0)->GetType()) { |
| 1993 | default: { |
| 1994 | // Integer case. |
| 1995 | |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 1996 | // Clear output register: setb only sets the low byte. |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1997 | __ xorl(reg, reg); |
| Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1998 | codegen_->GenerateIntCompare(lhs, rhs); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1999 | __ setb(X86Condition(cond->GetCondition()), reg); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2000 | return; |
| 2001 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2002 | case DataType::Type::kInt64: |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2003 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 2004 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2005 | case DataType::Type::kFloat32: |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2006 | GenerateFPCompare(lhs, rhs, cond, false); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2007 | GenerateFPJumps(cond, &true_label, &false_label); |
| 2008 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2009 | case DataType::Type::kFloat64: |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2010 | GenerateFPCompare(lhs, rhs, cond, true); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2011 | GenerateFPJumps(cond, &true_label, &false_label); |
| 2012 | break; |
| 2013 | } |
| 2014 | |
| 2015 | // Convert the jumps into the result. |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2016 | NearLabel done_label; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2017 | |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2018 | // False case: result = 0. |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2019 | __ Bind(&false_label); |
| 2020 | __ xorl(reg, reg); |
| 2021 | __ jmp(&done_label); |
| 2022 | |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2023 | // True case: result = 1. |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2024 | __ Bind(&true_label); |
| 2025 | __ movl(reg, Immediate(1)); |
| 2026 | __ Bind(&done_label); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2027 | } |
| 2028 | |
| 2029 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2030 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2031 | } |
| 2032 | |
| 2033 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2034 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2035 | } |
| 2036 | |
| 2037 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2038 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2039 | } |
| 2040 | |
| 2041 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2042 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2043 | } |
| 2044 | |
| 2045 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2046 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2047 | } |
| 2048 | |
| 2049 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2050 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2051 | } |
| 2052 | |
| 2053 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2054 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2055 | } |
| 2056 | |
| 2057 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2058 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2059 | } |
| 2060 | |
| 2061 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2062 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2063 | } |
| 2064 | |
| 2065 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2066 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2067 | } |
| 2068 | |
| 2069 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2070 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2071 | } |
| 2072 | |
| 2073 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2074 | HandleCondition(comp); |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2075 | } |
| 2076 | |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2077 | void LocationsBuilderX86::VisitBelow(HBelow* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2078 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2079 | } |
| 2080 | |
| 2081 | void InstructionCodeGeneratorX86::VisitBelow(HBelow* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2082 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2083 | } |
| 2084 | |
| 2085 | void LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2086 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2087 | } |
| 2088 | |
| 2089 | void InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2090 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2091 | } |
| 2092 | |
| 2093 | void LocationsBuilderX86::VisitAbove(HAbove* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2094 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2095 | } |
| 2096 | |
| 2097 | void InstructionCodeGeneratorX86::VisitAbove(HAbove* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2098 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2099 | } |
| 2100 | |
| 2101 | void LocationsBuilderX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2102 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2103 | } |
| 2104 | |
| 2105 | void InstructionCodeGeneratorX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2106 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2107 | } |
| 2108 | |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2109 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2110 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2111 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2112 | locations->SetOut(Location::ConstantLocation(constant)); |
| Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2113 | } |
| 2114 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2115 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2116 | // Will be generated at use site. |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2117 | } |
| 2118 | |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2119 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 2120 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2121 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2122 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2123 | } |
| 2124 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2125 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2126 | // Will be generated at use site. |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2127 | } |
| 2128 | |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2129 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2130 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2131 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2132 | locations->SetOut(Location::ConstantLocation(constant)); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2133 | } |
| 2134 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2135 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2136 | // Will be generated at use site. |
| 2137 | } |
| 2138 | |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2139 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 2140 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2141 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2142 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2143 | } |
| 2144 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2145 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2146 | // Will be generated at use site. |
| 2147 | } |
| 2148 | |
| 2149 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2150 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2151 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2152 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2153 | } |
| 2154 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2155 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2156 | // Will be generated at use site. |
| 2157 | } |
| 2158 | |
| Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2159 | void LocationsBuilderX86::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 2160 | constructor_fence->SetLocations(nullptr); |
| 2161 | } |
| 2162 | |
| 2163 | void InstructionCodeGeneratorX86::VisitConstructorFence( |
| 2164 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 2165 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 2166 | } |
| 2167 | |
| Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2168 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2169 | memory_barrier->SetLocations(nullptr); |
| 2170 | } |
| 2171 | |
| 2172 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 2173 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2174 | } |
| 2175 | |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2176 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2177 | ret->SetLocations(nullptr); |
| Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2178 | } |
| 2179 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2180 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2181 | codegen_->GenerateFrameExit(); |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2182 | } |
| 2183 | |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2184 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2185 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2186 | new (GetGraph()->GetAllocator()) LocationSummary(ret, LocationSummary::kNoCall); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2187 | switch (ret->InputAt(0)->GetType()) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2188 | case DataType::Type::kReference: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2189 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2190 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2191 | case DataType::Type::kInt8: |
| 2192 | case DataType::Type::kUint16: |
| 2193 | case DataType::Type::kInt16: |
| 2194 | case DataType::Type::kInt32: |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2195 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2196 | break; |
| 2197 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2198 | case DataType::Type::kInt64: |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2199 | locations->SetInAt( |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2200 | 0, Location::RegisterPairLocation(EAX, EDX)); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2201 | break; |
| 2202 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2203 | case DataType::Type::kFloat32: |
| 2204 | case DataType::Type::kFloat64: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2205 | locations->SetInAt( |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2206 | 0, Location::FpuRegisterLocation(XMM0)); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2207 | break; |
| 2208 | |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2209 | default: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2210 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2211 | } |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2212 | } |
| 2213 | |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2214 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2215 | if (kIsDebugBuild) { |
| 2216 | switch (ret->InputAt(0)->GetType()) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2217 | case DataType::Type::kReference: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2218 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2219 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2220 | case DataType::Type::kInt8: |
| 2221 | case DataType::Type::kUint16: |
| 2222 | case DataType::Type::kInt16: |
| 2223 | case DataType::Type::kInt32: |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2224 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2225 | break; |
| 2226 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2227 | case DataType::Type::kInt64: |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2228 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 2229 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2230 | break; |
| 2231 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2232 | case DataType::Type::kFloat32: |
| 2233 | case DataType::Type::kFloat64: |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2234 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2235 | break; |
| 2236 | |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2237 | default: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2238 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2239 | } |
| 2240 | } |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2241 | codegen_->GenerateFrameExit(); |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2242 | } |
| 2243 | |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2244 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2245 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2246 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2247 | // the method_idx. |
| 2248 | HandleInvoke(invoke); |
| 2249 | } |
| 2250 | |
| 2251 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2252 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2253 | } |
| 2254 | |
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2255 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2256 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2257 | // art::PrepareForRegisterAllocation. |
| 2258 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2259 | |
| Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2260 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2261 | if (intrinsic.TryDispatch(invoke)) { |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 2262 | if (invoke->GetLocations()->CanCall() && |
| 2263 | invoke->HasPcRelativeMethodLoadKind() && |
| 2264 | invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()).IsInvalid()) { |
| Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 2265 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2266 | } |
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2267 | return; |
| 2268 | } |
| 2269 | |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2270 | HandleInvoke(invoke); |
| Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2271 | |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2272 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 2273 | if (invoke->HasPcRelativeMethodLoadKind()) { |
| Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2274 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2275 | } |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2276 | } |
| 2277 | |
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2278 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 2279 | if (invoke->GetLocations()->Intrinsified()) { |
| 2280 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 2281 | intrinsic.Dispatch(invoke); |
| 2282 | return true; |
| 2283 | } |
| 2284 | return false; |
| 2285 | } |
| 2286 | |
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2287 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2288 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2289 | // art::PrepareForRegisterAllocation. |
| 2290 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2291 | |
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2292 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2293 | return; |
| Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2294 | } |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2295 | |
| Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2296 | LocationSummary* locations = invoke->GetLocations(); |
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2297 | codegen_->GenerateStaticOrDirectCall( |
| Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2298 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2299 | } |
| 2300 | |
| 2301 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 2302 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 2303 | if (intrinsic.TryDispatch(invoke)) { |
| 2304 | return; |
| 2305 | } |
| 2306 | |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2307 | HandleInvoke(invoke); |
| Nicolas Geoffray | 9b5271e | 2019-12-04 14:39:46 +0000 | [diff] [blame^] | 2308 | |
| 2309 | if (GetGraph()->IsCompilingBaseline() && !Runtime::Current()->IsAotCompiler()) { |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2310 | // Add one temporary for inline cache update. |
| 2311 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(EBP)); |
| 2312 | } |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2313 | } |
| 2314 | |
| 2315 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2316 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2317 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2318 | } |
| 2319 | |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2320 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2321 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2322 | return; |
| 2323 | } |
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2324 | |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2325 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2326 | DCHECK(!codegen_->IsLeafMethod()); |
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2327 | } |
| 2328 | |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2329 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2330 | // This call to HandleInvoke allocates a temporary (core) register |
| 2331 | // which is also used to transfer the hidden argument from FP to |
| 2332 | // core register. |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2333 | HandleInvoke(invoke); |
| 2334 | // Add the hidden argument. |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2335 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2336 | |
| Nicolas Geoffray | 9b5271e | 2019-12-04 14:39:46 +0000 | [diff] [blame^] | 2337 | if (GetGraph()->IsCompilingBaseline() && !Runtime::Current()->IsAotCompiler()) { |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2338 | // Add one temporary for inline cache update. |
| 2339 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(EBP)); |
| 2340 | } |
| 2341 | } |
| 2342 | |
| 2343 | void CodeGeneratorX86::MaybeGenerateInlineCacheCheck(HInstruction* instruction, Register klass) { |
| 2344 | DCHECK_EQ(EAX, klass); |
| Nicolas Geoffray | 17a39ba | 2019-11-27 20:57:48 +0000 | [diff] [blame] | 2345 | // We know the destination of an intrinsic, so no need to record inline |
| 2346 | // caches (also the intrinsic location builder doesn't request an additional |
| 2347 | // temporary). |
| 2348 | if (!instruction->GetLocations()->Intrinsified() && |
| Nicolas Geoffray | 9b5271e | 2019-12-04 14:39:46 +0000 | [diff] [blame^] | 2349 | GetGraph()->IsCompilingBaseline() && |
| Nicolas Geoffray | 17a39ba | 2019-11-27 20:57:48 +0000 | [diff] [blame] | 2350 | !Runtime::Current()->IsAotCompiler()) { |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2351 | DCHECK(!instruction->GetEnvironment()->IsFromInlinedInvoke()); |
| 2352 | ScopedObjectAccess soa(Thread::Current()); |
| 2353 | ProfilingInfo* info = GetGraph()->GetArtMethod()->GetProfilingInfo(kRuntimePointerSize); |
| 2354 | InlineCache* cache = info->GetInlineCache(instruction->GetDexPc()); |
| 2355 | uint32_t address = reinterpret_cast32<uint32_t>(cache); |
| 2356 | if (kIsDebugBuild) { |
| 2357 | uint32_t temp_index = instruction->GetLocations()->GetTempCount() - 1u; |
| 2358 | CHECK_EQ(EBP, instruction->GetLocations()->GetTemp(temp_index).AsRegister<Register>()); |
| 2359 | } |
| 2360 | Register temp = EBP; |
| 2361 | NearLabel done; |
| 2362 | __ movl(temp, Immediate(address)); |
| 2363 | // Fast path for a monomorphic cache. |
| 2364 | __ cmpl(klass, Address(temp, InlineCache::ClassesOffset().Int32Value())); |
| 2365 | __ j(kEqual, &done); |
| 2366 | GenerateInvokeRuntime(GetThreadOffset<kX86PointerSize>(kQuickUpdateInlineCache).Int32Value()); |
| 2367 | __ Bind(&done); |
| 2368 | } |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2369 | } |
| 2370 | |
| 2371 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2372 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2373 | LocationSummary* locations = invoke->GetLocations(); |
| 2374 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2375 | XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2376 | Location receiver = locations->InAt(0); |
| 2377 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2378 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2379 | // Set the hidden argument. This is safe to do this here, as XMM7 |
| 2380 | // won't be modified thereafter, before the `call` instruction. |
| 2381 | DCHECK_EQ(XMM7, hidden_reg); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2382 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2383 | __ movd(hidden_reg, temp); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2384 | |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2385 | if (receiver.IsStackSlot()) { |
| 2386 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2387 | // /* HeapReference<Class> */ temp = temp->klass_ |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2388 | __ movl(temp, Address(temp, class_offset)); |
| 2389 | } else { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2390 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2391 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2392 | } |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2393 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2394 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2395 | // emit a read barrier for the previous class reference load. |
| 2396 | // However this is not required in practice, as this is an |
| 2397 | // intermediate/temporary reference and because the current |
| 2398 | // concurrent copying collector keeps the from-space memory |
| 2399 | // intact/accessible until the end of the marking phase (the |
| 2400 | // concurrent copying collector may not in the future). |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2401 | __ MaybeUnpoisonHeapReference(temp); |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2402 | |
| 2403 | codegen_->MaybeGenerateInlineCacheCheck(invoke, temp); |
| 2404 | |
| Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2405 | // temp = temp->GetAddressOfIMT() |
| 2406 | __ movl(temp, |
| 2407 | Address(temp, mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2408 | // temp = temp->GetImtEntryAt(method_offset); |
| Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2409 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2410 | invoke->GetImtIndex(), kX86PointerSize)); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2411 | __ movl(temp, Address(temp, method_offset)); |
| 2412 | // call temp->GetEntryPoint(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2413 | __ call(Address(temp, |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2414 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2415 | |
| 2416 | DCHECK(!codegen_->IsLeafMethod()); |
| 2417 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2418 | } |
| 2419 | |
| Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2420 | void LocationsBuilderX86::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2421 | HandleInvoke(invoke); |
| 2422 | } |
| 2423 | |
| 2424 | void InstructionCodeGeneratorX86::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2425 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 2426 | } |
| 2427 | |
| Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 2428 | void LocationsBuilderX86::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 2429 | HandleInvoke(invoke); |
| 2430 | } |
| 2431 | |
| 2432 | void InstructionCodeGeneratorX86::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 2433 | codegen_->GenerateInvokeCustomCall(invoke); |
| 2434 | } |
| 2435 | |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2436 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 2437 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2438 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2439 | switch (neg->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2440 | case DataType::Type::kInt32: |
| 2441 | case DataType::Type::kInt64: |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2442 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2443 | locations->SetOut(Location::SameAsFirstInput()); |
| 2444 | break; |
| 2445 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2446 | case DataType::Type::kFloat32: |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2447 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2448 | locations->SetOut(Location::SameAsFirstInput()); |
| 2449 | locations->AddTemp(Location::RequiresRegister()); |
| 2450 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2451 | break; |
| 2452 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2453 | case DataType::Type::kFloat64: |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2454 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2455 | locations->SetOut(Location::SameAsFirstInput()); |
| 2456 | locations->AddTemp(Location::RequiresFpuRegister()); |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2457 | break; |
| 2458 | |
| 2459 | default: |
| 2460 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2461 | } |
| 2462 | } |
| 2463 | |
| 2464 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 2465 | LocationSummary* locations = neg->GetLocations(); |
| 2466 | Location out = locations->Out(); |
| 2467 | Location in = locations->InAt(0); |
| 2468 | switch (neg->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2469 | case DataType::Type::kInt32: |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2470 | DCHECK(in.IsRegister()); |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2471 | DCHECK(in.Equals(out)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2472 | __ negl(out.AsRegister<Register>()); |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2473 | break; |
| 2474 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2475 | case DataType::Type::kInt64: |
| Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2476 | DCHECK(in.IsRegisterPair()); |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2477 | DCHECK(in.Equals(out)); |
| Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2478 | __ negl(out.AsRegisterPairLow<Register>()); |
| 2479 | // Negation is similar to subtraction from zero. The least |
| 2480 | // significant byte triggers a borrow when it is different from |
| 2481 | // zero; to take it into account, add 1 to the most significant |
| 2482 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 2483 | // operation. |
| 2484 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2485 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 2486 | break; |
| 2487 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2488 | case DataType::Type::kFloat32: { |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2489 | DCHECK(in.Equals(out)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2490 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 2491 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2492 | // Implement float negation with an exclusive or with value |
| 2493 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2494 | // single-precision floating-point number). |
| 2495 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 2496 | __ movd(mask, constant); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2497 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2498 | break; |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2499 | } |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2500 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2501 | case DataType::Type::kFloat64: { |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2502 | DCHECK(in.Equals(out)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2503 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2504 | // Implement double negation with an exclusive or with value |
| 2505 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 2506 | // a double-precision floating-point number). |
| 2507 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2508 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2509 | break; |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2510 | } |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2511 | |
| 2512 | default: |
| 2513 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2514 | } |
| 2515 | } |
| 2516 | |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2517 | void LocationsBuilderX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2518 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2519 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2520 | DCHECK(DataType::IsFloatingPointType(neg->GetType())); |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2521 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2522 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2523 | locations->SetOut(Location::SameAsFirstInput()); |
| 2524 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2525 | } |
| 2526 | |
| 2527 | void InstructionCodeGeneratorX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2528 | LocationSummary* locations = neg->GetLocations(); |
| 2529 | Location out = locations->Out(); |
| 2530 | DCHECK(locations->InAt(0).Equals(out)); |
| 2531 | |
| 2532 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 2533 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2534 | if (neg->GetType() == DataType::Type::kFloat32) { |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 2535 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x80000000), |
| 2536 | neg->GetBaseMethodAddress(), |
| 2537 | constant_area)); |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2538 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| 2539 | } else { |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 2540 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000), |
| 2541 | neg->GetBaseMethodAddress(), |
| 2542 | constant_area)); |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2543 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| 2544 | } |
| 2545 | } |
| 2546 | |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2547 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2548 | DataType::Type result_type = conversion->GetResultType(); |
| 2549 | DataType::Type input_type = conversion->GetInputType(); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2550 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 2551 | << input_type << " -> " << result_type; |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2552 | |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2553 | // The float-to-long and double-to-long type conversions rely on a |
| 2554 | // call to the runtime. |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2555 | LocationSummary::CallKind call_kind = |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2556 | ((input_type == DataType::Type::kFloat32 || input_type == DataType::Type::kFloat64) |
| 2557 | && result_type == DataType::Type::kInt64) |
| Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2558 | ? LocationSummary::kCallOnMainOnly |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2559 | : LocationSummary::kNoCall; |
| 2560 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2561 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, call_kind); |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2562 | |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2563 | switch (result_type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2564 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2565 | case DataType::Type::kInt8: |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2566 | switch (input_type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2567 | case DataType::Type::kUint8: |
| 2568 | case DataType::Type::kInt8: |
| 2569 | case DataType::Type::kUint16: |
| 2570 | case DataType::Type::kInt16: |
| 2571 | case DataType::Type::kInt32: |
| 2572 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 2573 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2574 | // the validation of the linear scan implementation |
| 2575 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2576 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2577 | case DataType::Type::kInt64: { |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2578 | HInstruction* input = conversion->InputAt(0); |
| 2579 | Location input_location = input->IsConstant() |
| 2580 | ? Location::ConstantLocation(input->AsConstant()) |
| 2581 | : Location::RegisterPairLocation(EAX, EDX); |
| 2582 | locations->SetInAt(0, input_location); |
| 2583 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2584 | // the validation of the linear scan implementation |
| 2585 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2586 | break; |
| 2587 | } |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2588 | |
| 2589 | default: |
| 2590 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2591 | << " to " << result_type; |
| 2592 | } |
| 2593 | break; |
| 2594 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2595 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2596 | case DataType::Type::kInt16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2597 | DCHECK(DataType::IsIntegralType(input_type)) << input_type; |
| 2598 | locations->SetInAt(0, Location::Any()); |
| 2599 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2600 | break; |
| 2601 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2602 | case DataType::Type::kInt32: |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2603 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2604 | case DataType::Type::kInt64: |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2605 | locations->SetInAt(0, Location::Any()); |
| 2606 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2607 | break; |
| 2608 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2609 | case DataType::Type::kFloat32: |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2610 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2611 | locations->SetOut(Location::RequiresRegister()); |
| 2612 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2613 | break; |
| 2614 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2615 | case DataType::Type::kFloat64: |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2616 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2617 | locations->SetOut(Location::RequiresRegister()); |
| 2618 | locations->AddTemp(Location::RequiresFpuRegister()); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2619 | break; |
| 2620 | |
| 2621 | default: |
| 2622 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2623 | << " to " << result_type; |
| 2624 | } |
| 2625 | break; |
| 2626 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2627 | case DataType::Type::kInt64: |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2628 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2629 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2630 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2631 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2632 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2633 | case DataType::Type::kInt16: |
| 2634 | case DataType::Type::kInt32: |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2635 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 2636 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2637 | break; |
| 2638 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2639 | case DataType::Type::kFloat32: |
| 2640 | case DataType::Type::kFloat64: { |
| Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2641 | InvokeRuntimeCallingConvention calling_convention; |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2642 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 2643 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 2644 | |
| Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2645 | // The runtime helper puts the result in EAX, EDX. |
| 2646 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2647 | } |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2648 | break; |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2649 | |
| 2650 | default: |
| 2651 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2652 | << " to " << result_type; |
| 2653 | } |
| 2654 | break; |
| 2655 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2656 | case DataType::Type::kFloat32: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2657 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2658 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2659 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2660 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2661 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2662 | case DataType::Type::kInt16: |
| 2663 | case DataType::Type::kInt32: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2664 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2665 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2666 | break; |
| 2667 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2668 | case DataType::Type::kInt64: |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2669 | locations->SetInAt(0, Location::Any()); |
| 2670 | locations->SetOut(Location::Any()); |
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2671 | break; |
| 2672 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2673 | case DataType::Type::kFloat64: |
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2674 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2675 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2676 | break; |
| 2677 | |
| 2678 | default: |
| 2679 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2680 | << " to " << result_type; |
| Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 2681 | } |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2682 | break; |
| 2683 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2684 | case DataType::Type::kFloat64: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2685 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2686 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2687 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2688 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2689 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2690 | case DataType::Type::kInt16: |
| 2691 | case DataType::Type::kInt32: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2692 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2693 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2694 | break; |
| 2695 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2696 | case DataType::Type::kInt64: |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2697 | locations->SetInAt(0, Location::Any()); |
| 2698 | locations->SetOut(Location::Any()); |
| Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2699 | break; |
| 2700 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2701 | case DataType::Type::kFloat32: |
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2702 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2703 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2704 | break; |
| 2705 | |
| 2706 | default: |
| 2707 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2708 | << " to " << result_type; |
| 2709 | } |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2710 | break; |
| 2711 | |
| 2712 | default: |
| 2713 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2714 | << " to " << result_type; |
| 2715 | } |
| 2716 | } |
| 2717 | |
| 2718 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 2719 | LocationSummary* locations = conversion->GetLocations(); |
| 2720 | Location out = locations->Out(); |
| 2721 | Location in = locations->InAt(0); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2722 | DataType::Type result_type = conversion->GetResultType(); |
| 2723 | DataType::Type input_type = conversion->GetInputType(); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2724 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 2725 | << input_type << " -> " << result_type; |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2726 | switch (result_type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2727 | case DataType::Type::kUint8: |
| 2728 | switch (input_type) { |
| 2729 | case DataType::Type::kInt8: |
| 2730 | case DataType::Type::kUint16: |
| 2731 | case DataType::Type::kInt16: |
| 2732 | case DataType::Type::kInt32: |
| 2733 | if (in.IsRegister()) { |
| 2734 | __ movzxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
| 2735 | } else { |
| 2736 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2737 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2738 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint8_t>(value))); |
| 2739 | } |
| 2740 | break; |
| 2741 | case DataType::Type::kInt64: |
| 2742 | if (in.IsRegisterPair()) { |
| 2743 | __ movzxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 2744 | } else { |
| 2745 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2746 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2747 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint8_t>(value))); |
| 2748 | } |
| 2749 | break; |
| 2750 | |
| 2751 | default: |
| 2752 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2753 | << " to " << result_type; |
| 2754 | } |
| 2755 | break; |
| 2756 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2757 | case DataType::Type::kInt8: |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2758 | switch (input_type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2759 | case DataType::Type::kUint8: |
| 2760 | case DataType::Type::kUint16: |
| 2761 | case DataType::Type::kInt16: |
| 2762 | case DataType::Type::kInt32: |
| 2763 | if (in.IsRegister()) { |
| 2764 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
| 2765 | } else { |
| 2766 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2767 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2768 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2769 | } |
| 2770 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2771 | case DataType::Type::kInt64: |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2772 | if (in.IsRegisterPair()) { |
| 2773 | __ movsxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 2774 | } else { |
| 2775 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2776 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2777 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2778 | } |
| 2779 | break; |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2780 | |
| 2781 | default: |
| 2782 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2783 | << " to " << result_type; |
| 2784 | } |
| 2785 | break; |
| 2786 | |
| 2787 | case DataType::Type::kUint16: |
| 2788 | switch (input_type) { |
| 2789 | case DataType::Type::kInt8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2790 | case DataType::Type::kInt16: |
| 2791 | case DataType::Type::kInt32: |
| Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2792 | if (in.IsRegister()) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2793 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
| 2794 | } else if (in.IsStackSlot()) { |
| 2795 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2796 | } else { |
| 2797 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2798 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2799 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
| 2800 | } |
| 2801 | break; |
| 2802 | case DataType::Type::kInt64: |
| 2803 | if (in.IsRegisterPair()) { |
| 2804 | __ movzxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2805 | } else if (in.IsDoubleStackSlot()) { |
| 2806 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2807 | } else { |
| 2808 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2809 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2810 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
| Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2811 | } |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2812 | break; |
| 2813 | |
| 2814 | default: |
| 2815 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2816 | << " to " << result_type; |
| 2817 | } |
| 2818 | break; |
| 2819 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2820 | case DataType::Type::kInt16: |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2821 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2822 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2823 | case DataType::Type::kInt32: |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2824 | if (in.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2825 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2826 | } else if (in.IsStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2827 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2828 | } else { |
| 2829 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2830 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2831 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2832 | } |
| 2833 | break; |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2834 | case DataType::Type::kInt64: |
| 2835 | if (in.IsRegisterPair()) { |
| 2836 | __ movsxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2837 | } else if (in.IsDoubleStackSlot()) { |
| 2838 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2839 | } else { |
| 2840 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2841 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2842 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
| 2843 | } |
| 2844 | break; |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2845 | |
| 2846 | default: |
| 2847 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2848 | << " to " << result_type; |
| 2849 | } |
| 2850 | break; |
| 2851 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2852 | case DataType::Type::kInt32: |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2853 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2854 | case DataType::Type::kInt64: |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2855 | if (in.IsRegisterPair()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2856 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2857 | } else if (in.IsDoubleStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2858 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2859 | } else { |
| 2860 | DCHECK(in.IsConstant()); |
| 2861 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2862 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2863 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2864 | } |
| 2865 | break; |
| 2866 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2867 | case DataType::Type::kFloat32: { |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2868 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2869 | Register output = out.AsRegister<Register>(); |
| 2870 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2871 | NearLabel done, nan; |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2872 | |
| 2873 | __ movl(output, Immediate(kPrimIntMax)); |
| 2874 | // temp = int-to-float(output) |
| 2875 | __ cvtsi2ss(temp, output); |
| 2876 | // if input >= temp goto done |
| 2877 | __ comiss(input, temp); |
| 2878 | __ j(kAboveEqual, &done); |
| 2879 | // if input == NaN goto nan |
| 2880 | __ j(kUnordered, &nan); |
| 2881 | // output = float-to-int-truncate(input) |
| 2882 | __ cvttss2si(output, input); |
| 2883 | __ jmp(&done); |
| 2884 | __ Bind(&nan); |
| 2885 | // output = 0 |
| 2886 | __ xorl(output, output); |
| 2887 | __ Bind(&done); |
| 2888 | break; |
| 2889 | } |
| 2890 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2891 | case DataType::Type::kFloat64: { |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2892 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2893 | Register output = out.AsRegister<Register>(); |
| 2894 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2895 | NearLabel done, nan; |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2896 | |
| 2897 | __ movl(output, Immediate(kPrimIntMax)); |
| 2898 | // temp = int-to-double(output) |
| 2899 | __ cvtsi2sd(temp, output); |
| 2900 | // if input >= temp goto done |
| 2901 | __ comisd(input, temp); |
| 2902 | __ j(kAboveEqual, &done); |
| 2903 | // if input == NaN goto nan |
| 2904 | __ j(kUnordered, &nan); |
| 2905 | // output = double-to-int-truncate(input) |
| 2906 | __ cvttsd2si(output, input); |
| 2907 | __ jmp(&done); |
| 2908 | __ Bind(&nan); |
| 2909 | // output = 0 |
| 2910 | __ xorl(output, output); |
| 2911 | __ Bind(&done); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2912 | break; |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2913 | } |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2914 | |
| 2915 | default: |
| 2916 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2917 | << " to " << result_type; |
| 2918 | } |
| 2919 | break; |
| 2920 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2921 | case DataType::Type::kInt64: |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2922 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2923 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2924 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2925 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2926 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2927 | case DataType::Type::kInt16: |
| 2928 | case DataType::Type::kInt32: |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2929 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2930 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2931 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2932 | __ cdq(); |
| 2933 | break; |
| 2934 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2935 | case DataType::Type::kFloat32: |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2936 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2937 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2938 | break; |
| 2939 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2940 | case DataType::Type::kFloat64: |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2941 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2942 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2943 | break; |
| 2944 | |
| 2945 | default: |
| 2946 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2947 | << " to " << result_type; |
| 2948 | } |
| 2949 | break; |
| 2950 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2951 | case DataType::Type::kFloat32: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2952 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2953 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2954 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2955 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2956 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2957 | case DataType::Type::kInt16: |
| 2958 | case DataType::Type::kInt32: |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2959 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2960 | break; |
| 2961 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2962 | case DataType::Type::kInt64: { |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2963 | size_t adjustment = 0; |
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2964 | |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2965 | // Create stack space for the call to |
| 2966 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2967 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2968 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2969 | adjustment = DataType::Size(DataType::Type::kInt64); |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2970 | __ subl(ESP, Immediate(adjustment)); |
| 2971 | } |
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2972 | |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2973 | // Load the value to the FP stack, using temporaries if needed. |
| 2974 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2975 | |
| 2976 | if (out.IsStackSlot()) { |
| 2977 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2978 | } else { |
| 2979 | __ fstps(Address(ESP, 0)); |
| 2980 | Location stack_temp = Location::StackSlot(0); |
| 2981 | codegen_->Move32(out, stack_temp); |
| 2982 | } |
| 2983 | |
| 2984 | // Remove the temporary stack space we allocated. |
| 2985 | if (adjustment != 0) { |
| 2986 | __ addl(ESP, Immediate(adjustment)); |
| 2987 | } |
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2988 | break; |
| 2989 | } |
| 2990 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2991 | case DataType::Type::kFloat64: |
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2992 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2993 | break; |
| 2994 | |
| 2995 | default: |
| 2996 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2997 | << " to " << result_type; |
| Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 2998 | } |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2999 | break; |
| 3000 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3001 | case DataType::Type::kFloat64: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +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 | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3009 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3010 | break; |
| 3011 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3012 | case DataType::Type::kInt64: { |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3013 | size_t adjustment = 0; |
| Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3014 | |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3015 | // Create stack space for the call to |
| 3016 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 3017 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3018 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3019 | adjustment = DataType::Size(DataType::Type::kInt64); |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3020 | __ subl(ESP, Immediate(adjustment)); |
| 3021 | } |
| 3022 | |
| 3023 | // Load the value to the FP stack, using temporaries if needed. |
| 3024 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 3025 | |
| 3026 | if (out.IsDoubleStackSlot()) { |
| 3027 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 3028 | } else { |
| 3029 | __ fstpl(Address(ESP, 0)); |
| 3030 | Location stack_temp = Location::DoubleStackSlot(0); |
| 3031 | codegen_->Move64(out, stack_temp); |
| 3032 | } |
| 3033 | |
| 3034 | // Remove the temporary stack space we allocated. |
| 3035 | if (adjustment != 0) { |
| 3036 | __ addl(ESP, Immediate(adjustment)); |
| 3037 | } |
| Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3038 | break; |
| 3039 | } |
| 3040 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3041 | case DataType::Type::kFloat32: |
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3042 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3043 | break; |
| 3044 | |
| 3045 | default: |
| 3046 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3047 | << " to " << result_type; |
| Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3048 | } |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3049 | break; |
| 3050 | |
| 3051 | default: |
| 3052 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3053 | << " to " << result_type; |
| 3054 | } |
| 3055 | } |
| 3056 | |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3057 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3058 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3059 | new (GetGraph()->GetAllocator()) LocationSummary(add, LocationSummary::kNoCall); |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3060 | switch (add->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3061 | case DataType::Type::kInt32: { |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3062 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3063 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 3064 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3065 | break; |
| 3066 | } |
| 3067 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3068 | case DataType::Type::kInt64: { |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3069 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3070 | locations->SetInAt(1, Location::Any()); |
| 3071 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3072 | break; |
| 3073 | } |
| 3074 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3075 | case DataType::Type::kFloat32: |
| 3076 | case DataType::Type::kFloat64: { |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3077 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3078 | if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3079 | DCHECK(add->InputAt(1)->IsEmittedAtUseSite()); |
| Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3080 | } else if (add->InputAt(1)->IsConstant()) { |
| 3081 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3082 | } else { |
| 3083 | locations->SetInAt(1, Location::Any()); |
| 3084 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3085 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3086 | break; |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3087 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3088 | |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3089 | default: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3090 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 3091 | UNREACHABLE(); |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3092 | } |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3093 | } |
| 3094 | |
| 3095 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 3096 | LocationSummary* locations = add->GetLocations(); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3097 | Location first = locations->InAt(0); |
| 3098 | Location second = locations->InAt(1); |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3099 | Location out = locations->Out(); |
| 3100 | |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3101 | switch (add->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3102 | case DataType::Type::kInt32: { |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3103 | if (second.IsRegister()) { |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3104 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3105 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
| Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 3106 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 3107 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3108 | } else { |
| 3109 | __ leal(out.AsRegister<Register>(), Address( |
| 3110 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 3111 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3112 | } else if (second.IsConstant()) { |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3113 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3114 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3115 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 3116 | } else { |
| 3117 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 3118 | } |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3119 | } else { |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3120 | DCHECK(first.Equals(locations->Out())); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3121 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3122 | } |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3123 | break; |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3124 | } |
| 3125 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3126 | case DataType::Type::kInt64: { |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3127 | if (second.IsRegisterPair()) { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3128 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3129 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3130 | } else if (second.IsDoubleStackSlot()) { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3131 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 3132 | __ adcl(first.AsRegisterPairHigh<Register>(), |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3133 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3134 | } else { |
| 3135 | DCHECK(second.IsConstant()) << second; |
| 3136 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3137 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 3138 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3139 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3140 | break; |
| 3141 | } |
| 3142 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3143 | case DataType::Type::kFloat32: { |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3144 | if (second.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3145 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3146 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3147 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3148 | DCHECK(const_area->IsEmittedAtUseSite()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3149 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 3150 | codegen_->LiteralFloatAddress( |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3151 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3152 | const_area->GetBaseMethodAddress(), |
| 3153 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3154 | } else { |
| 3155 | DCHECK(second.IsStackSlot()); |
| 3156 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3157 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3158 | break; |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3159 | } |
| 3160 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3161 | case DataType::Type::kFloat64: { |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3162 | if (second.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3163 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3164 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3165 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3166 | DCHECK(const_area->IsEmittedAtUseSite()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3167 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 3168 | codegen_->LiteralDoubleAddress( |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3169 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3170 | const_area->GetBaseMethodAddress(), |
| 3171 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3172 | } else { |
| 3173 | DCHECK(second.IsDoubleStackSlot()); |
| 3174 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3175 | } |
| 3176 | break; |
| 3177 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3178 | |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3179 | default: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3180 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3181 | } |
| 3182 | } |
| 3183 | |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3184 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3185 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3186 | new (GetGraph()->GetAllocator()) LocationSummary(sub, LocationSummary::kNoCall); |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3187 | switch (sub->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3188 | case DataType::Type::kInt32: |
| 3189 | case DataType::Type::kInt64: { |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3190 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3191 | locations->SetInAt(1, Location::Any()); |
| 3192 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3193 | break; |
| 3194 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3195 | case DataType::Type::kFloat32: |
| 3196 | case DataType::Type::kFloat64: { |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3197 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3198 | if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3199 | DCHECK(sub->InputAt(1)->IsEmittedAtUseSite()); |
| Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3200 | } else if (sub->InputAt(1)->IsConstant()) { |
| 3201 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3202 | } else { |
| 3203 | locations->SetInAt(1, Location::Any()); |
| 3204 | } |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3205 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3206 | break; |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3207 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3208 | |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3209 | default: |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3210 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3211 | } |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3212 | } |
| 3213 | |
| 3214 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 3215 | LocationSummary* locations = sub->GetLocations(); |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3216 | Location first = locations->InAt(0); |
| 3217 | Location second = locations->InAt(1); |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3218 | DCHECK(first.Equals(locations->Out())); |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3219 | switch (sub->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3220 | case DataType::Type::kInt32: { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3221 | if (second.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3222 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3223 | } else if (second.IsConstant()) { |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3224 | __ subl(first.AsRegister<Register>(), |
| 3225 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3226 | } else { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3227 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3228 | } |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3229 | break; |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3230 | } |
| 3231 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3232 | case DataType::Type::kInt64: { |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3233 | if (second.IsRegisterPair()) { |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3234 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3235 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3236 | } else if (second.IsDoubleStackSlot()) { |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3237 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3238 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 3239 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3240 | } else { |
| 3241 | DCHECK(second.IsConstant()) << second; |
| 3242 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3243 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 3244 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3245 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3246 | break; |
| 3247 | } |
| 3248 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3249 | case DataType::Type::kFloat32: { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3250 | if (second.IsFpuRegister()) { |
| 3251 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3252 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3253 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3254 | DCHECK(const_area->IsEmittedAtUseSite()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3255 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3256 | codegen_->LiteralFloatAddress( |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3257 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3258 | const_area->GetBaseMethodAddress(), |
| 3259 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3260 | } else { |
| 3261 | DCHECK(second.IsStackSlot()); |
| 3262 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3263 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3264 | break; |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3265 | } |
| 3266 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3267 | case DataType::Type::kFloat64: { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3268 | if (second.IsFpuRegister()) { |
| 3269 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3270 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3271 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3272 | DCHECK(const_area->IsEmittedAtUseSite()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3273 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3274 | codegen_->LiteralDoubleAddress( |
| 3275 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3276 | const_area->GetBaseMethodAddress(), |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3277 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3278 | } else { |
| 3279 | DCHECK(second.IsDoubleStackSlot()); |
| 3280 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3281 | } |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3282 | break; |
| 3283 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3284 | |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3285 | default: |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3286 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3287 | } |
| 3288 | } |
| 3289 | |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3290 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 3291 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3292 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3293 | switch (mul->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3294 | case DataType::Type::kInt32: |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3295 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3296 | locations->SetInAt(1, Location::Any()); |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3297 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3298 | // Can use 3 operand multiply. |
| 3299 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3300 | } else { |
| 3301 | locations->SetOut(Location::SameAsFirstInput()); |
| 3302 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3303 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3304 | case DataType::Type::kInt64: { |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3305 | locations->SetInAt(0, Location::RequiresRegister()); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3306 | locations->SetInAt(1, Location::Any()); |
| 3307 | locations->SetOut(Location::SameAsFirstInput()); |
| 3308 | // Needed for imul on 32bits with 64bits output. |
| 3309 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 3310 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 3311 | break; |
| 3312 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3313 | case DataType::Type::kFloat32: |
| 3314 | case DataType::Type::kFloat64: { |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3315 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3316 | if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3317 | DCHECK(mul->InputAt(1)->IsEmittedAtUseSite()); |
| Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3318 | } else if (mul->InputAt(1)->IsConstant()) { |
| 3319 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3320 | } else { |
| 3321 | locations->SetInAt(1, Location::Any()); |
| 3322 | } |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3323 | locations->SetOut(Location::SameAsFirstInput()); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3324 | break; |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3325 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3326 | |
| 3327 | default: |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3328 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3329 | } |
| 3330 | } |
| 3331 | |
| 3332 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 3333 | LocationSummary* locations = mul->GetLocations(); |
| 3334 | Location first = locations->InAt(0); |
| 3335 | Location second = locations->InAt(1); |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3336 | Location out = locations->Out(); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3337 | |
| 3338 | switch (mul->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3339 | case DataType::Type::kInt32: |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3340 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3341 | // problems where the output may not be the same as the first operand. |
| 3342 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3343 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3344 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 3345 | } else if (second.IsRegister()) { |
| 3346 | DCHECK(first.Equals(out)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3347 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3348 | } else { |
| 3349 | DCHECK(second.IsStackSlot()); |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3350 | DCHECK(first.Equals(out)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3351 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3352 | } |
| 3353 | break; |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3354 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3355 | case DataType::Type::kInt64: { |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3356 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 3357 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3358 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 3359 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3360 | |
| 3361 | DCHECK_EQ(EAX, eax); |
| 3362 | DCHECK_EQ(EDX, edx); |
| 3363 | |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3364 | // input: in1 - 64 bits, in2 - 64 bits. |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3365 | // output: in1 |
| 3366 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3367 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3368 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3369 | if (second.IsConstant()) { |
| 3370 | DCHECK(second.GetConstant()->IsLongConstant()); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3371 | |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3372 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3373 | int32_t low_value = Low32Bits(value); |
| 3374 | int32_t high_value = High32Bits(value); |
| 3375 | Immediate low(low_value); |
| 3376 | Immediate high(high_value); |
| 3377 | |
| 3378 | __ movl(eax, high); |
| 3379 | // eax <- in1.lo * in2.hi |
| 3380 | __ imull(eax, in1_lo); |
| 3381 | // in1.hi <- in1.hi * in2.lo |
| 3382 | __ imull(in1_hi, low); |
| 3383 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3384 | __ addl(in1_hi, eax); |
| 3385 | // move in2_lo to eax to prepare for double precision |
| 3386 | __ movl(eax, low); |
| 3387 | // edx:eax <- in1.lo * in2.lo |
| 3388 | __ mull(in1_lo); |
| 3389 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3390 | __ addl(in1_hi, edx); |
| 3391 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3392 | __ movl(in1_lo, eax); |
| 3393 | } else if (second.IsRegisterPair()) { |
| 3394 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3395 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3396 | |
| 3397 | __ movl(eax, in2_hi); |
| 3398 | // eax <- in1.lo * in2.hi |
| 3399 | __ imull(eax, in1_lo); |
| 3400 | // in1.hi <- in1.hi * in2.lo |
| 3401 | __ imull(in1_hi, in2_lo); |
| 3402 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3403 | __ addl(in1_hi, eax); |
| 3404 | // move in1_lo to eax to prepare for double precision |
| 3405 | __ movl(eax, in1_lo); |
| 3406 | // edx:eax <- in1.lo * in2.lo |
| 3407 | __ mull(in2_lo); |
| 3408 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3409 | __ addl(in1_hi, edx); |
| 3410 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3411 | __ movl(in1_lo, eax); |
| 3412 | } else { |
| 3413 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 3414 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 3415 | Address in2_lo(ESP, second.GetStackIndex()); |
| 3416 | |
| 3417 | __ movl(eax, in2_hi); |
| 3418 | // eax <- in1.lo * in2.hi |
| 3419 | __ imull(eax, in1_lo); |
| 3420 | // in1.hi <- in1.hi * in2.lo |
| 3421 | __ imull(in1_hi, in2_lo); |
| 3422 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3423 | __ addl(in1_hi, eax); |
| 3424 | // move in1_lo to eax to prepare for double precision |
| 3425 | __ movl(eax, in1_lo); |
| 3426 | // edx:eax <- in1.lo * in2.lo |
| 3427 | __ mull(in2_lo); |
| 3428 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3429 | __ addl(in1_hi, edx); |
| 3430 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3431 | __ movl(in1_lo, eax); |
| 3432 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3433 | |
| 3434 | break; |
| 3435 | } |
| 3436 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3437 | case DataType::Type::kFloat32: { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3438 | DCHECK(first.Equals(locations->Out())); |
| 3439 | if (second.IsFpuRegister()) { |
| 3440 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3441 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3442 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3443 | DCHECK(const_area->IsEmittedAtUseSite()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3444 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3445 | codegen_->LiteralFloatAddress( |
| 3446 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3447 | const_area->GetBaseMethodAddress(), |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3448 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3449 | } else { |
| 3450 | DCHECK(second.IsStackSlot()); |
| 3451 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3452 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3453 | break; |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3454 | } |
| 3455 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3456 | case DataType::Type::kFloat64: { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3457 | DCHECK(first.Equals(locations->Out())); |
| 3458 | if (second.IsFpuRegister()) { |
| 3459 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3460 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3461 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3462 | DCHECK(const_area->IsEmittedAtUseSite()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3463 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3464 | codegen_->LiteralDoubleAddress( |
| 3465 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3466 | const_area->GetBaseMethodAddress(), |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3467 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3468 | } else { |
| 3469 | DCHECK(second.IsDoubleStackSlot()); |
| 3470 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3471 | } |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3472 | break; |
| 3473 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3474 | |
| 3475 | default: |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3476 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3477 | } |
| 3478 | } |
| 3479 | |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3480 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 3481 | uint32_t temp_offset, |
| 3482 | uint32_t stack_adjustment, |
| 3483 | bool is_fp, |
| 3484 | bool is_wide) { |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3485 | if (source.IsStackSlot()) { |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3486 | DCHECK(!is_wide); |
| 3487 | if (is_fp) { |
| 3488 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3489 | } else { |
| 3490 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3491 | } |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3492 | } else if (source.IsDoubleStackSlot()) { |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3493 | DCHECK(is_wide); |
| 3494 | if (is_fp) { |
| 3495 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3496 | } else { |
| 3497 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3498 | } |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3499 | } else { |
| 3500 | // 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] | 3501 | if (!is_wide) { |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3502 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3503 | codegen_->Move32(stack_temp, source); |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3504 | if (is_fp) { |
| 3505 | __ flds(Address(ESP, temp_offset)); |
| 3506 | } else { |
| 3507 | __ filds(Address(ESP, temp_offset)); |
| 3508 | } |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3509 | } else { |
| 3510 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3511 | codegen_->Move64(stack_temp, source); |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3512 | if (is_fp) { |
| 3513 | __ fldl(Address(ESP, temp_offset)); |
| 3514 | } else { |
| 3515 | __ fildl(Address(ESP, temp_offset)); |
| 3516 | } |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3517 | } |
| 3518 | } |
| 3519 | } |
| 3520 | |
| 3521 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3522 | DataType::Type type = rem->GetResultType(); |
| 3523 | bool is_float = type == DataType::Type::kFloat32; |
| 3524 | size_t elem_size = DataType::Size(type); |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3525 | LocationSummary* locations = rem->GetLocations(); |
| 3526 | Location first = locations->InAt(0); |
| 3527 | Location second = locations->InAt(1); |
| 3528 | Location out = locations->Out(); |
| 3529 | |
| 3530 | // Create stack space for 2 elements. |
| 3531 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3532 | __ subl(ESP, Immediate(2 * elem_size)); |
| 3533 | |
| 3534 | // 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] | 3535 | const bool is_wide = !is_float; |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3536 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp= */ true, is_wide); |
| 3537 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp= */ true, is_wide); |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3538 | |
| 3539 | // Loop doing FPREM until we stabilize. |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3540 | NearLabel retry; |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3541 | __ Bind(&retry); |
| 3542 | __ fprem(); |
| 3543 | |
| 3544 | // Move FP status to AX. |
| 3545 | __ fstsw(); |
| 3546 | |
| 3547 | // And see if the argument reduction is complete. This is signaled by the |
| 3548 | // C2 FPU flag bit set to 0. |
| 3549 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 3550 | __ j(kNotEqual, &retry); |
| 3551 | |
| 3552 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3553 | // Store FP top of stack to real stack. |
| 3554 | if (is_float) { |
| 3555 | __ fsts(Address(ESP, 0)); |
| 3556 | } else { |
| 3557 | __ fstl(Address(ESP, 0)); |
| 3558 | } |
| 3559 | |
| 3560 | // Pop the 2 items from the FP stack. |
| 3561 | __ fucompp(); |
| 3562 | |
| 3563 | // Load the value from the stack into an XMM register. |
| 3564 | DCHECK(out.IsFpuRegister()) << out; |
| 3565 | if (is_float) { |
| 3566 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3567 | } else { |
| 3568 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3569 | } |
| 3570 | |
| 3571 | // And remove the temporary stack space we allocated. |
| 3572 | __ addl(ESP, Immediate(2 * elem_size)); |
| 3573 | } |
| 3574 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3575 | |
| 3576 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3577 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3578 | |
| 3579 | LocationSummary* locations = instruction->GetLocations(); |
| 3580 | DCHECK(locations->InAt(1).IsConstant()); |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3581 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3582 | |
| 3583 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3584 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3585 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3586 | |
| 3587 | DCHECK(imm == 1 || imm == -1); |
| 3588 | |
| 3589 | if (instruction->IsRem()) { |
| 3590 | __ xorl(out_register, out_register); |
| 3591 | } else { |
| 3592 | __ movl(out_register, input_register); |
| 3593 | if (imm == -1) { |
| 3594 | __ negl(out_register); |
| 3595 | } |
| 3596 | } |
| 3597 | } |
| 3598 | |
| Shalini Salomi Bodapati | a66784b | 2018-11-06 13:05:44 +0530 | [diff] [blame] | 3599 | void InstructionCodeGeneratorX86::RemByPowerOfTwo(HRem* instruction) { |
| 3600 | LocationSummary* locations = instruction->GetLocations(); |
| 3601 | Location second = locations->InAt(1); |
| 3602 | |
| 3603 | Register out = locations->Out().AsRegister<Register>(); |
| 3604 | Register numerator = locations->InAt(0).AsRegister<Register>(); |
| 3605 | |
| 3606 | int32_t imm = Int64FromConstant(second.GetConstant()); |
| 3607 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3608 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
| 3609 | |
| 3610 | Register tmp = locations->GetTemp(0).AsRegister<Register>(); |
| 3611 | NearLabel done; |
| 3612 | __ movl(out, numerator); |
| 3613 | __ andl(out, Immediate(abs_imm-1)); |
| 3614 | __ j(Condition::kZero, &done); |
| 3615 | __ leal(tmp, Address(out, static_cast<int32_t>(~(abs_imm-1)))); |
| 3616 | __ testl(numerator, numerator); |
| 3617 | __ cmovl(Condition::kLess, out, tmp); |
| 3618 | __ Bind(&done); |
| 3619 | } |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3620 | |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3621 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3622 | LocationSummary* locations = instruction->GetLocations(); |
| 3623 | |
| 3624 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3625 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3626 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3627 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3628 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3629 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3630 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 3631 | |
| Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3632 | __ leal(num, Address(input_register, abs_imm - 1)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3633 | __ testl(input_register, input_register); |
| 3634 | __ cmovl(kGreaterEqual, num, input_register); |
| 3635 | int shift = CTZ(imm); |
| 3636 | __ sarl(num, Immediate(shift)); |
| 3637 | |
| 3638 | if (imm < 0) { |
| 3639 | __ negl(num); |
| 3640 | } |
| 3641 | |
| 3642 | __ movl(out_register, num); |
| 3643 | } |
| 3644 | |
| 3645 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3646 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3647 | |
| 3648 | LocationSummary* locations = instruction->GetLocations(); |
| 3649 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 3650 | |
| 3651 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 3652 | Register out = locations->Out().AsRegister<Register>(); |
| 3653 | Register num; |
| 3654 | Register edx; |
| 3655 | |
| 3656 | if (instruction->IsDiv()) { |
| 3657 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 3658 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 3659 | } else { |
| 3660 | edx = locations->Out().AsRegister<Register>(); |
| 3661 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 3662 | } |
| 3663 | |
| 3664 | DCHECK_EQ(EAX, eax); |
| 3665 | DCHECK_EQ(EDX, edx); |
| 3666 | if (instruction->IsDiv()) { |
| 3667 | DCHECK_EQ(EAX, out); |
| 3668 | } else { |
| 3669 | DCHECK_EQ(EDX, out); |
| 3670 | } |
| 3671 | |
| 3672 | int64_t magic; |
| 3673 | int shift; |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3674 | CalculateMagicAndShiftForDivRem(imm, /* is_long= */ false, &magic, &shift); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3675 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3676 | // Save the numerator. |
| 3677 | __ movl(num, eax); |
| 3678 | |
| 3679 | // EAX = magic |
| 3680 | __ movl(eax, Immediate(magic)); |
| 3681 | |
| 3682 | // EDX:EAX = magic * numerator |
| 3683 | __ imull(num); |
| 3684 | |
| 3685 | if (imm > 0 && magic < 0) { |
| 3686 | // EDX += num |
| 3687 | __ addl(edx, num); |
| 3688 | } else if (imm < 0 && magic > 0) { |
| 3689 | __ subl(edx, num); |
| 3690 | } |
| 3691 | |
| 3692 | // Shift if needed. |
| 3693 | if (shift != 0) { |
| 3694 | __ sarl(edx, Immediate(shift)); |
| 3695 | } |
| 3696 | |
| 3697 | // EDX += 1 if EDX < 0 |
| 3698 | __ movl(eax, edx); |
| 3699 | __ shrl(edx, Immediate(31)); |
| 3700 | __ addl(edx, eax); |
| 3701 | |
| 3702 | if (instruction->IsRem()) { |
| 3703 | __ movl(eax, num); |
| 3704 | __ imull(edx, Immediate(imm)); |
| 3705 | __ subl(eax, edx); |
| 3706 | __ movl(edx, eax); |
| 3707 | } else { |
| 3708 | __ movl(eax, edx); |
| 3709 | } |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3710 | } |
| 3711 | |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3712 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3713 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3714 | |
| 3715 | LocationSummary* locations = instruction->GetLocations(); |
| 3716 | Location out = locations->Out(); |
| 3717 | Location first = locations->InAt(0); |
| 3718 | Location second = locations->InAt(1); |
| 3719 | bool is_div = instruction->IsDiv(); |
| 3720 | |
| 3721 | switch (instruction->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3722 | case DataType::Type::kInt32: { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3723 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 3724 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3725 | |
| Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3726 | if (second.IsConstant()) { |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3727 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3728 | |
| 3729 | if (imm == 0) { |
| 3730 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 3731 | } else if (imm == 1 || imm == -1) { |
| 3732 | DivRemOneOrMinusOne(instruction); |
| Shalini Salomi Bodapati | a66784b | 2018-11-06 13:05:44 +0530 | [diff] [blame] | 3733 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 3734 | if (is_div) { |
| 3735 | DivByPowerOfTwo(instruction->AsDiv()); |
| 3736 | } else { |
| 3737 | RemByPowerOfTwo(instruction->AsRem()); |
| 3738 | } |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3739 | } else { |
| 3740 | DCHECK(imm <= -2 || imm >= 2); |
| 3741 | GenerateDivRemWithAnyConstant(instruction); |
| 3742 | } |
| 3743 | } else { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3744 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) DivRemMinusOneSlowPathX86( |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3745 | instruction, out.AsRegister<Register>(), is_div); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3746 | codegen_->AddSlowPath(slow_path); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3747 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3748 | Register second_reg = second.AsRegister<Register>(); |
| 3749 | // 0x80000000/-1 triggers an arithmetic exception! |
| 3750 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 3751 | // it's safe to just use negl instead of more complex comparisons. |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3752 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3753 | __ cmpl(second_reg, Immediate(-1)); |
| 3754 | __ j(kEqual, slow_path->GetEntryLabel()); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3755 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3756 | // edx:eax <- sign-extended of eax |
| 3757 | __ cdq(); |
| 3758 | // eax = quotient, edx = remainder |
| 3759 | __ idivl(second_reg); |
| 3760 | __ Bind(slow_path->GetExitLabel()); |
| 3761 | } |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3762 | break; |
| 3763 | } |
| 3764 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3765 | case DataType::Type::kInt64: { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3766 | InvokeRuntimeCallingConvention calling_convention; |
| 3767 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3768 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3769 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3770 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3771 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 3772 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 3773 | |
| 3774 | if (is_div) { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3775 | codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3776 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3777 | } else { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3778 | codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3779 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3780 | } |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3781 | break; |
| 3782 | } |
| 3783 | |
| 3784 | default: |
| 3785 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 3786 | } |
| 3787 | } |
| 3788 | |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3789 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3790 | LocationSummary::CallKind call_kind = (div->GetResultType() == DataType::Type::kInt64) |
| Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3791 | ? LocationSummary::kCallOnMainOnly |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3792 | : LocationSummary::kNoCall; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3793 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(div, call_kind); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3794 | |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3795 | switch (div->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3796 | case DataType::Type::kInt32: { |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3797 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3798 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3799 | locations->SetOut(Location::SameAsFirstInput()); |
| 3800 | // Intel uses edx:eax as the dividend. |
| 3801 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3802 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3803 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 3804 | // output and request another temp. |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3805 | if (div->InputAt(1)->IsIntConstant()) { |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3806 | locations->AddTemp(Location::RequiresRegister()); |
| 3807 | } |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3808 | break; |
| 3809 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3810 | case DataType::Type::kInt64: { |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3811 | InvokeRuntimeCallingConvention calling_convention; |
| 3812 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3813 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3814 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3815 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3816 | // Runtime helper puts the result in EAX, EDX. |
| 3817 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3818 | break; |
| 3819 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3820 | case DataType::Type::kFloat32: |
| 3821 | case DataType::Type::kFloat64: { |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3822 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3823 | if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3824 | DCHECK(div->InputAt(1)->IsEmittedAtUseSite()); |
| Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3825 | } else if (div->InputAt(1)->IsConstant()) { |
| 3826 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3827 | } else { |
| 3828 | locations->SetInAt(1, Location::Any()); |
| 3829 | } |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3830 | locations->SetOut(Location::SameAsFirstInput()); |
| 3831 | break; |
| 3832 | } |
| 3833 | |
| 3834 | default: |
| 3835 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3836 | } |
| 3837 | } |
| 3838 | |
| 3839 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 3840 | LocationSummary* locations = div->GetLocations(); |
| 3841 | Location first = locations->InAt(0); |
| 3842 | Location second = locations->InAt(1); |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3843 | |
| 3844 | switch (div->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3845 | case DataType::Type::kInt32: |
| 3846 | case DataType::Type::kInt64: { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3847 | GenerateDivRemIntegral(div); |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3848 | break; |
| 3849 | } |
| 3850 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3851 | case DataType::Type::kFloat32: { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3852 | if (second.IsFpuRegister()) { |
| 3853 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3854 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3855 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3856 | DCHECK(const_area->IsEmittedAtUseSite()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3857 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3858 | codegen_->LiteralFloatAddress( |
| 3859 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3860 | const_area->GetBaseMethodAddress(), |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3861 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3862 | } else { |
| 3863 | DCHECK(second.IsStackSlot()); |
| 3864 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3865 | } |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3866 | break; |
| 3867 | } |
| 3868 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3869 | case DataType::Type::kFloat64: { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3870 | if (second.IsFpuRegister()) { |
| 3871 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3872 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3873 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3874 | DCHECK(const_area->IsEmittedAtUseSite()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3875 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3876 | codegen_->LiteralDoubleAddress( |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3877 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3878 | const_area->GetBaseMethodAddress(), |
| 3879 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3880 | } else { |
| 3881 | DCHECK(second.IsDoubleStackSlot()); |
| 3882 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3883 | } |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3884 | break; |
| 3885 | } |
| 3886 | |
| 3887 | default: |
| 3888 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3889 | } |
| 3890 | } |
| 3891 | |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3892 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3893 | DataType::Type type = rem->GetResultType(); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3894 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3895 | LocationSummary::CallKind call_kind = (rem->GetResultType() == DataType::Type::kInt64) |
| Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3896 | ? LocationSummary::kCallOnMainOnly |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3897 | : LocationSummary::kNoCall; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3898 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3899 | |
| Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3900 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3901 | case DataType::Type::kInt32: { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3902 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3903 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3904 | locations->SetOut(Location::RegisterLocation(EDX)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3905 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3906 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 3907 | // output and request another temp. |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3908 | if (rem->InputAt(1)->IsIntConstant()) { |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3909 | locations->AddTemp(Location::RequiresRegister()); |
| 3910 | } |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3911 | break; |
| 3912 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3913 | case DataType::Type::kInt64: { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3914 | InvokeRuntimeCallingConvention calling_convention; |
| 3915 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3916 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3917 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3918 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3919 | // Runtime helper puts the result in EAX, EDX. |
| 3920 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3921 | break; |
| 3922 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3923 | case DataType::Type::kFloat64: |
| 3924 | case DataType::Type::kFloat32: { |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3925 | locations->SetInAt(0, Location::Any()); |
| 3926 | locations->SetInAt(1, Location::Any()); |
| 3927 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3928 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3929 | break; |
| 3930 | } |
| 3931 | |
| 3932 | default: |
| Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3933 | LOG(FATAL) << "Unexpected rem type " << type; |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3934 | } |
| 3935 | } |
| 3936 | |
| 3937 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3938 | DataType::Type type = rem->GetResultType(); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3939 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3940 | case DataType::Type::kInt32: |
| 3941 | case DataType::Type::kInt64: { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3942 | GenerateDivRemIntegral(rem); |
| 3943 | break; |
| 3944 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3945 | case DataType::Type::kFloat32: |
| 3946 | case DataType::Type::kFloat64: { |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3947 | GenerateRemFP(rem); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3948 | break; |
| 3949 | } |
| 3950 | default: |
| 3951 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3952 | } |
| 3953 | } |
| 3954 | |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 3955 | static void CreateMinMaxLocations(ArenaAllocator* allocator, HBinaryOperation* minmax) { |
| 3956 | LocationSummary* locations = new (allocator) LocationSummary(minmax); |
| 3957 | switch (minmax->GetResultType()) { |
| 3958 | case DataType::Type::kInt32: |
| 3959 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3960 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3961 | locations->SetOut(Location::SameAsFirstInput()); |
| 3962 | break; |
| 3963 | case DataType::Type::kInt64: |
| 3964 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3965 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3966 | locations->SetOut(Location::SameAsFirstInput()); |
| 3967 | // Register to use to perform a long subtract to set cc. |
| 3968 | locations->AddTemp(Location::RequiresRegister()); |
| 3969 | break; |
| 3970 | case DataType::Type::kFloat32: |
| 3971 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3972 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3973 | locations->SetOut(Location::SameAsFirstInput()); |
| 3974 | locations->AddTemp(Location::RequiresRegister()); |
| 3975 | break; |
| 3976 | case DataType::Type::kFloat64: |
| 3977 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3978 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3979 | locations->SetOut(Location::SameAsFirstInput()); |
| 3980 | break; |
| 3981 | default: |
| 3982 | LOG(FATAL) << "Unexpected type for HMinMax " << minmax->GetResultType(); |
| 3983 | } |
| 3984 | } |
| 3985 | |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 3986 | void InstructionCodeGeneratorX86::GenerateMinMaxInt(LocationSummary* locations, |
| 3987 | bool is_min, |
| 3988 | DataType::Type type) { |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 3989 | Location op1_loc = locations->InAt(0); |
| 3990 | Location op2_loc = locations->InAt(1); |
| 3991 | |
| 3992 | // Shortcut for same input locations. |
| 3993 | if (op1_loc.Equals(op2_loc)) { |
| 3994 | // Can return immediately, as op1_loc == out_loc. |
| 3995 | // Note: if we ever support separate registers, e.g., output into memory, we need to check for |
| 3996 | // a copy here. |
| 3997 | DCHECK(locations->Out().Equals(op1_loc)); |
| 3998 | return; |
| 3999 | } |
| 4000 | |
| 4001 | if (type == DataType::Type::kInt64) { |
| 4002 | // Need to perform a subtract to get the sign right. |
| 4003 | // op1 is already in the same location as the output. |
| 4004 | Location output = locations->Out(); |
| 4005 | Register output_lo = output.AsRegisterPairLow<Register>(); |
| 4006 | Register output_hi = output.AsRegisterPairHigh<Register>(); |
| 4007 | |
| 4008 | Register op2_lo = op2_loc.AsRegisterPairLow<Register>(); |
| 4009 | Register op2_hi = op2_loc.AsRegisterPairHigh<Register>(); |
| 4010 | |
| 4011 | // The comparison is performed by subtracting the second operand from |
| 4012 | // the first operand and then setting the status flags in the same |
| 4013 | // manner as the SUB instruction." |
| 4014 | __ cmpl(output_lo, op2_lo); |
| 4015 | |
| 4016 | // Now use a temp and the borrow to finish the subtraction of op2_hi. |
| 4017 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4018 | __ movl(temp, output_hi); |
| 4019 | __ sbbl(temp, op2_hi); |
| 4020 | |
| 4021 | // Now the condition code is correct. |
| 4022 | Condition cond = is_min ? Condition::kGreaterEqual : Condition::kLess; |
| 4023 | __ cmovl(cond, output_lo, op2_lo); |
| 4024 | __ cmovl(cond, output_hi, op2_hi); |
| 4025 | } else { |
| 4026 | DCHECK_EQ(type, DataType::Type::kInt32); |
| 4027 | Register out = locations->Out().AsRegister<Register>(); |
| 4028 | Register op2 = op2_loc.AsRegister<Register>(); |
| 4029 | |
| 4030 | // (out := op1) |
| 4031 | // out <=? op2 |
| 4032 | // if out is min jmp done |
| 4033 | // out := op2 |
| 4034 | // done: |
| 4035 | |
| 4036 | __ cmpl(out, op2); |
| 4037 | Condition cond = is_min ? Condition::kGreater : Condition::kLess; |
| 4038 | __ cmovl(cond, out, op2); |
| 4039 | } |
| 4040 | } |
| 4041 | |
| 4042 | void InstructionCodeGeneratorX86::GenerateMinMaxFP(LocationSummary* locations, |
| 4043 | bool is_min, |
| 4044 | DataType::Type type) { |
| 4045 | Location op1_loc = locations->InAt(0); |
| 4046 | Location op2_loc = locations->InAt(1); |
| 4047 | Location out_loc = locations->Out(); |
| 4048 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
| 4049 | |
| 4050 | // Shortcut for same input locations. |
| 4051 | if (op1_loc.Equals(op2_loc)) { |
| 4052 | DCHECK(out_loc.Equals(op1_loc)); |
| 4053 | return; |
| 4054 | } |
| 4055 | |
| 4056 | // (out := op1) |
| 4057 | // out <=? op2 |
| 4058 | // if Nan jmp Nan_label |
| 4059 | // if out is min jmp done |
| 4060 | // if op2 is min jmp op2_label |
| 4061 | // handle -0/+0 |
| 4062 | // jmp done |
| 4063 | // Nan_label: |
| 4064 | // out := NaN |
| 4065 | // op2_label: |
| 4066 | // out := op2 |
| 4067 | // done: |
| 4068 | // |
| 4069 | // This removes one jmp, but needs to copy one input (op1) to out. |
| 4070 | // |
| 4071 | // TODO: This is straight from Quick (except literal pool). Make NaN an out-of-line slowpath? |
| 4072 | |
| 4073 | XmmRegister op2 = op2_loc.AsFpuRegister<XmmRegister>(); |
| 4074 | |
| 4075 | NearLabel nan, done, op2_label; |
| 4076 | if (type == DataType::Type::kFloat64) { |
| 4077 | __ ucomisd(out, op2); |
| 4078 | } else { |
| 4079 | DCHECK_EQ(type, DataType::Type::kFloat32); |
| 4080 | __ ucomiss(out, op2); |
| 4081 | } |
| 4082 | |
| 4083 | __ j(Condition::kParityEven, &nan); |
| 4084 | |
| 4085 | __ j(is_min ? Condition::kAbove : Condition::kBelow, &op2_label); |
| 4086 | __ j(is_min ? Condition::kBelow : Condition::kAbove, &done); |
| 4087 | |
| 4088 | // Handle 0.0/-0.0. |
| 4089 | if (is_min) { |
| 4090 | if (type == DataType::Type::kFloat64) { |
| 4091 | __ orpd(out, op2); |
| 4092 | } else { |
| 4093 | __ orps(out, op2); |
| 4094 | } |
| 4095 | } else { |
| 4096 | if (type == DataType::Type::kFloat64) { |
| 4097 | __ andpd(out, op2); |
| 4098 | } else { |
| 4099 | __ andps(out, op2); |
| 4100 | } |
| 4101 | } |
| 4102 | __ jmp(&done); |
| 4103 | |
| 4104 | // NaN handling. |
| 4105 | __ Bind(&nan); |
| 4106 | if (type == DataType::Type::kFloat64) { |
| 4107 | // TODO: Use a constant from the constant table (requires extra input). |
| 4108 | __ LoadLongConstant(out, kDoubleNaN); |
| 4109 | } else { |
| 4110 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 4111 | __ movl(constant, Immediate(kFloatNaN)); |
| 4112 | __ movd(out, constant); |
| 4113 | } |
| 4114 | __ jmp(&done); |
| 4115 | |
| 4116 | // out := op2; |
| 4117 | __ Bind(&op2_label); |
| 4118 | if (type == DataType::Type::kFloat64) { |
| 4119 | __ movsd(out, op2); |
| 4120 | } else { |
| 4121 | __ movss(out, op2); |
| 4122 | } |
| 4123 | |
| 4124 | // Done. |
| 4125 | __ Bind(&done); |
| 4126 | } |
| 4127 | |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4128 | void InstructionCodeGeneratorX86::GenerateMinMax(HBinaryOperation* minmax, bool is_min) { |
| 4129 | DataType::Type type = minmax->GetResultType(); |
| 4130 | switch (type) { |
| 4131 | case DataType::Type::kInt32: |
| 4132 | case DataType::Type::kInt64: |
| 4133 | GenerateMinMaxInt(minmax->GetLocations(), is_min, type); |
| 4134 | break; |
| 4135 | case DataType::Type::kFloat32: |
| 4136 | case DataType::Type::kFloat64: |
| 4137 | GenerateMinMaxFP(minmax->GetLocations(), is_min, type); |
| 4138 | break; |
| 4139 | default: |
| 4140 | LOG(FATAL) << "Unexpected type for HMinMax " << type; |
| 4141 | } |
| 4142 | } |
| 4143 | |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4144 | void LocationsBuilderX86::VisitMin(HMin* min) { |
| 4145 | CreateMinMaxLocations(GetGraph()->GetAllocator(), min); |
| 4146 | } |
| 4147 | |
| 4148 | void InstructionCodeGeneratorX86::VisitMin(HMin* min) { |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4149 | GenerateMinMax(min, /*is_min*/ true); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4150 | } |
| 4151 | |
| 4152 | void LocationsBuilderX86::VisitMax(HMax* max) { |
| 4153 | CreateMinMaxLocations(GetGraph()->GetAllocator(), max); |
| 4154 | } |
| 4155 | |
| 4156 | void InstructionCodeGeneratorX86::VisitMax(HMax* max) { |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4157 | GenerateMinMax(max, /*is_min*/ false); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4158 | } |
| 4159 | |
| Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 4160 | void LocationsBuilderX86::VisitAbs(HAbs* abs) { |
| 4161 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 4162 | switch (abs->GetResultType()) { |
| 4163 | case DataType::Type::kInt32: |
| 4164 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 4165 | locations->SetOut(Location::SameAsFirstInput()); |
| 4166 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 4167 | break; |
| 4168 | case DataType::Type::kInt64: |
| 4169 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4170 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4171 | locations->AddTemp(Location::RequiresRegister()); |
| 4172 | break; |
| 4173 | case DataType::Type::kFloat32: |
| 4174 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4175 | locations->SetOut(Location::SameAsFirstInput()); |
| 4176 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4177 | locations->AddTemp(Location::RequiresRegister()); |
| 4178 | break; |
| 4179 | case DataType::Type::kFloat64: |
| 4180 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4181 | locations->SetOut(Location::SameAsFirstInput()); |
| 4182 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4183 | break; |
| 4184 | default: |
| 4185 | LOG(FATAL) << "Unexpected type for HAbs " << abs->GetResultType(); |
| 4186 | } |
| 4187 | } |
| 4188 | |
| 4189 | void InstructionCodeGeneratorX86::VisitAbs(HAbs* abs) { |
| 4190 | LocationSummary* locations = abs->GetLocations(); |
| 4191 | switch (abs->GetResultType()) { |
| 4192 | case DataType::Type::kInt32: { |
| 4193 | Register out = locations->Out().AsRegister<Register>(); |
| 4194 | DCHECK_EQ(out, EAX); |
| 4195 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4196 | DCHECK_EQ(temp, EDX); |
| 4197 | // Sign extend EAX into EDX. |
| 4198 | __ cdq(); |
| 4199 | // XOR EAX with sign. |
| 4200 | __ xorl(EAX, EDX); |
| 4201 | // Subtract out sign to correct. |
| 4202 | __ subl(EAX, EDX); |
| 4203 | // The result is in EAX. |
| 4204 | break; |
| 4205 | } |
| 4206 | case DataType::Type::kInt64: { |
| 4207 | Location input = locations->InAt(0); |
| 4208 | Register input_lo = input.AsRegisterPairLow<Register>(); |
| 4209 | Register input_hi = input.AsRegisterPairHigh<Register>(); |
| 4210 | Location output = locations->Out(); |
| 4211 | Register output_lo = output.AsRegisterPairLow<Register>(); |
| 4212 | Register output_hi = output.AsRegisterPairHigh<Register>(); |
| 4213 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4214 | // Compute the sign into the temporary. |
| 4215 | __ movl(temp, input_hi); |
| 4216 | __ sarl(temp, Immediate(31)); |
| 4217 | // Store the sign into the output. |
| 4218 | __ movl(output_lo, temp); |
| 4219 | __ movl(output_hi, temp); |
| 4220 | // XOR the input to the output. |
| 4221 | __ xorl(output_lo, input_lo); |
| 4222 | __ xorl(output_hi, input_hi); |
| 4223 | // Subtract the sign. |
| 4224 | __ subl(output_lo, temp); |
| 4225 | __ sbbl(output_hi, temp); |
| 4226 | break; |
| 4227 | } |
| 4228 | case DataType::Type::kFloat32: { |
| 4229 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4230 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4231 | Register constant = locations->GetTemp(1).AsRegister<Register>(); |
| 4232 | __ movl(constant, Immediate(INT32_C(0x7FFFFFFF))); |
| 4233 | __ movd(temp, constant); |
| 4234 | __ andps(out, temp); |
| 4235 | break; |
| 4236 | } |
| 4237 | case DataType::Type::kFloat64: { |
| 4238 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4239 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4240 | // TODO: Use a constant from the constant table (requires extra input). |
| 4241 | __ LoadLongConstant(temp, INT64_C(0x7FFFFFFFFFFFFFFF)); |
| 4242 | __ andpd(out, temp); |
| 4243 | break; |
| 4244 | } |
| 4245 | default: |
| 4246 | LOG(FATAL) << "Unexpected type for HAbs " << abs->GetResultType(); |
| 4247 | } |
| 4248 | } |
| 4249 | |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4250 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4251 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4252 | switch (instruction->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4253 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4254 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4255 | case DataType::Type::kInt8: |
| 4256 | case DataType::Type::kUint16: |
| 4257 | case DataType::Type::kInt16: |
| 4258 | case DataType::Type::kInt32: { |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4259 | locations->SetInAt(0, Location::Any()); |
| 4260 | break; |
| 4261 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4262 | case DataType::Type::kInt64: { |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4263 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 4264 | if (!instruction->IsConstant()) { |
| 4265 | locations->AddTemp(Location::RequiresRegister()); |
| 4266 | } |
| 4267 | break; |
| 4268 | } |
| 4269 | default: |
| 4270 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 4271 | } |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4272 | } |
| 4273 | |
| 4274 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4275 | SlowPathCode* slow_path = |
| 4276 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathX86(instruction); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4277 | codegen_->AddSlowPath(slow_path); |
| 4278 | |
| 4279 | LocationSummary* locations = instruction->GetLocations(); |
| 4280 | Location value = locations->InAt(0); |
| 4281 | |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4282 | switch (instruction->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4283 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4284 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4285 | case DataType::Type::kInt8: |
| 4286 | case DataType::Type::kUint16: |
| 4287 | case DataType::Type::kInt16: |
| 4288 | case DataType::Type::kInt32: { |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4289 | if (value.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4290 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4291 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4292 | } else if (value.IsStackSlot()) { |
| 4293 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 4294 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4295 | } else { |
| 4296 | DCHECK(value.IsConstant()) << value; |
| 4297 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4298 | __ jmp(slow_path->GetEntryLabel()); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4299 | } |
| 4300 | } |
| 4301 | break; |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4302 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4303 | case DataType::Type::kInt64: { |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4304 | if (value.IsRegisterPair()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4305 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4306 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 4307 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 4308 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4309 | } else { |
| 4310 | DCHECK(value.IsConstant()) << value; |
| 4311 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 4312 | __ jmp(slow_path->GetEntryLabel()); |
| 4313 | } |
| 4314 | } |
| 4315 | break; |
| 4316 | } |
| 4317 | default: |
| 4318 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4319 | } |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4320 | } |
| 4321 | |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4322 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 4323 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4324 | |
| 4325 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4326 | new (GetGraph()->GetAllocator()) LocationSummary(op, LocationSummary::kNoCall); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4327 | |
| 4328 | switch (op->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4329 | case DataType::Type::kInt32: |
| 4330 | case DataType::Type::kInt64: { |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4331 | // Can't have Location::Any() and output SameAsFirstInput() |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4332 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4333 | // The shift count needs to be in CL or a constant. |
| 4334 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4335 | locations->SetOut(Location::SameAsFirstInput()); |
| 4336 | break; |
| 4337 | } |
| 4338 | default: |
| 4339 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 4340 | } |
| 4341 | } |
| 4342 | |
| 4343 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 4344 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4345 | |
| 4346 | LocationSummary* locations = op->GetLocations(); |
| 4347 | Location first = locations->InAt(0); |
| 4348 | Location second = locations->InAt(1); |
| 4349 | DCHECK(first.Equals(locations->Out())); |
| 4350 | |
| 4351 | switch (op->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4352 | case DataType::Type::kInt32: { |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4353 | DCHECK(first.IsRegister()); |
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4354 | Register first_reg = first.AsRegister<Register>(); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4355 | if (second.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4356 | Register second_reg = second.AsRegister<Register>(); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4357 | DCHECK_EQ(ECX, second_reg); |
| 4358 | if (op->IsShl()) { |
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4359 | __ shll(first_reg, second_reg); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4360 | } else if (op->IsShr()) { |
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4361 | __ sarl(first_reg, second_reg); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4362 | } else { |
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4363 | __ shrl(first_reg, second_reg); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4364 | } |
| 4365 | } else { |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4366 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance; |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4367 | if (shift == 0) { |
| 4368 | return; |
| 4369 | } |
| 4370 | Immediate imm(shift); |
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4371 | if (op->IsShl()) { |
| 4372 | __ shll(first_reg, imm); |
| 4373 | } else if (op->IsShr()) { |
| 4374 | __ sarl(first_reg, imm); |
| 4375 | } else { |
| 4376 | __ shrl(first_reg, imm); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4377 | } |
| 4378 | } |
| 4379 | break; |
| 4380 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4381 | case DataType::Type::kInt64: { |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4382 | if (second.IsRegister()) { |
| 4383 | Register second_reg = second.AsRegister<Register>(); |
| 4384 | DCHECK_EQ(ECX, second_reg); |
| 4385 | if (op->IsShl()) { |
| 4386 | GenerateShlLong(first, second_reg); |
| 4387 | } else if (op->IsShr()) { |
| 4388 | GenerateShrLong(first, second_reg); |
| 4389 | } else { |
| 4390 | GenerateUShrLong(first, second_reg); |
| 4391 | } |
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4392 | } else { |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4393 | // Shift by a constant. |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4394 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4395 | // Nothing to do if the shift is 0, as the input is already the output. |
| 4396 | if (shift != 0) { |
| 4397 | if (op->IsShl()) { |
| 4398 | GenerateShlLong(first, shift); |
| 4399 | } else if (op->IsShr()) { |
| 4400 | GenerateShrLong(first, shift); |
| 4401 | } else { |
| 4402 | GenerateUShrLong(first, shift); |
| 4403 | } |
| 4404 | } |
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4405 | } |
| 4406 | break; |
| 4407 | } |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4408 | default: |
| 4409 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 4410 | } |
| 4411 | } |
| 4412 | |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4413 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 4414 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4415 | Register high = loc.AsRegisterPairHigh<Register>(); |
| Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 4416 | if (shift == 1) { |
| 4417 | // This is just an addition. |
| 4418 | __ addl(low, low); |
| 4419 | __ adcl(high, high); |
| 4420 | } else if (shift == 32) { |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4421 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 4422 | codegen_->EmitParallelMoves( |
| 4423 | loc.ToLow(), |
| 4424 | loc.ToHigh(), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4425 | DataType::Type::kInt32, |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4426 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 4427 | loc.ToLow(), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4428 | DataType::Type::kInt32); |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4429 | } else if (shift > 32) { |
| 4430 | // Low part becomes 0. High part is low part << (shift-32). |
| 4431 | __ movl(high, low); |
| 4432 | __ shll(high, Immediate(shift - 32)); |
| 4433 | __ xorl(low, low); |
| 4434 | } else { |
| 4435 | // Between 1 and 31. |
| 4436 | __ shld(high, low, Immediate(shift)); |
| 4437 | __ shll(low, Immediate(shift)); |
| 4438 | } |
| 4439 | } |
| 4440 | |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4441 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4442 | NearLabel done; |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4443 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 4444 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 4445 | __ testl(shifter, Immediate(32)); |
| 4446 | __ j(kEqual, &done); |
| 4447 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 4448 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 4449 | __ Bind(&done); |
| 4450 | } |
| 4451 | |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4452 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 4453 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4454 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 4455 | if (shift == 32) { |
| 4456 | // Need to copy the sign. |
| 4457 | DCHECK_NE(low, high); |
| 4458 | __ movl(low, high); |
| 4459 | __ sarl(high, Immediate(31)); |
| 4460 | } else if (shift > 32) { |
| 4461 | DCHECK_NE(low, high); |
| 4462 | // High part becomes sign. Low part is shifted by shift - 32. |
| 4463 | __ movl(low, high); |
| 4464 | __ sarl(high, Immediate(31)); |
| 4465 | __ sarl(low, Immediate(shift - 32)); |
| 4466 | } else { |
| 4467 | // Between 1 and 31. |
| 4468 | __ shrd(low, high, Immediate(shift)); |
| 4469 | __ sarl(high, Immediate(shift)); |
| 4470 | } |
| 4471 | } |
| 4472 | |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4473 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4474 | NearLabel done; |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4475 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4476 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4477 | __ testl(shifter, Immediate(32)); |
| 4478 | __ j(kEqual, &done); |
| 4479 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4480 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 4481 | __ Bind(&done); |
| 4482 | } |
| 4483 | |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4484 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 4485 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4486 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 4487 | if (shift == 32) { |
| 4488 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 4489 | codegen_->EmitParallelMoves( |
| 4490 | loc.ToHigh(), |
| 4491 | loc.ToLow(), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4492 | DataType::Type::kInt32, |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4493 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 4494 | loc.ToHigh(), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4495 | DataType::Type::kInt32); |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4496 | } else if (shift > 32) { |
| 4497 | // Low part is high >> (shift - 32). High part becomes 0. |
| 4498 | __ movl(low, high); |
| 4499 | __ shrl(low, Immediate(shift - 32)); |
| 4500 | __ xorl(high, high); |
| 4501 | } else { |
| 4502 | // Between 1 and 31. |
| 4503 | __ shrd(low, high, Immediate(shift)); |
| 4504 | __ shrl(high, Immediate(shift)); |
| 4505 | } |
| 4506 | } |
| 4507 | |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4508 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4509 | NearLabel done; |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4510 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4511 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4512 | __ testl(shifter, Immediate(32)); |
| 4513 | __ j(kEqual, &done); |
| 4514 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4515 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 4516 | __ Bind(&done); |
| 4517 | } |
| 4518 | |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4519 | void LocationsBuilderX86::VisitRor(HRor* ror) { |
| 4520 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4521 | new (GetGraph()->GetAllocator()) LocationSummary(ror, LocationSummary::kNoCall); |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4522 | |
| 4523 | switch (ror->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4524 | case DataType::Type::kInt64: |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4525 | // Add the temporary needed. |
| 4526 | locations->AddTemp(Location::RequiresRegister()); |
| 4527 | FALLTHROUGH_INTENDED; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4528 | case DataType::Type::kInt32: |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4529 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4530 | // The shift count needs to be in CL (unless it is a constant). |
| 4531 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); |
| 4532 | locations->SetOut(Location::SameAsFirstInput()); |
| 4533 | break; |
| 4534 | default: |
| 4535 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4536 | UNREACHABLE(); |
| 4537 | } |
| 4538 | } |
| 4539 | |
| 4540 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { |
| 4541 | LocationSummary* locations = ror->GetLocations(); |
| 4542 | Location first = locations->InAt(0); |
| 4543 | Location second = locations->InAt(1); |
| 4544 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4545 | if (ror->GetResultType() == DataType::Type::kInt32) { |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4546 | Register first_reg = first.AsRegister<Register>(); |
| 4547 | if (second.IsRegister()) { |
| 4548 | Register second_reg = second.AsRegister<Register>(); |
| 4549 | __ rorl(first_reg, second_reg); |
| 4550 | } else { |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4551 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4552 | __ rorl(first_reg, imm); |
| 4553 | } |
| 4554 | return; |
| 4555 | } |
| 4556 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4557 | DCHECK_EQ(ror->GetResultType(), DataType::Type::kInt64); |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4558 | Register first_reg_lo = first.AsRegisterPairLow<Register>(); |
| 4559 | Register first_reg_hi = first.AsRegisterPairHigh<Register>(); |
| 4560 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 4561 | if (second.IsRegister()) { |
| 4562 | Register second_reg = second.AsRegister<Register>(); |
| 4563 | DCHECK_EQ(second_reg, ECX); |
| 4564 | __ movl(temp_reg, first_reg_hi); |
| 4565 | __ shrd(first_reg_hi, first_reg_lo, second_reg); |
| 4566 | __ shrd(first_reg_lo, temp_reg, second_reg); |
| 4567 | __ movl(temp_reg, first_reg_hi); |
| 4568 | __ testl(second_reg, Immediate(32)); |
| 4569 | __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); |
| 4570 | __ cmovl(kNotEqual, first_reg_lo, temp_reg); |
| 4571 | } else { |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4572 | int32_t shift_amt = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4573 | if (shift_amt == 0) { |
| 4574 | // Already fine. |
| 4575 | return; |
| 4576 | } |
| 4577 | if (shift_amt == 32) { |
| 4578 | // Just swap. |
| 4579 | __ movl(temp_reg, first_reg_lo); |
| 4580 | __ movl(first_reg_lo, first_reg_hi); |
| 4581 | __ movl(first_reg_hi, temp_reg); |
| 4582 | return; |
| 4583 | } |
| 4584 | |
| 4585 | Immediate imm(shift_amt); |
| 4586 | // Save the constents of the low value. |
| 4587 | __ movl(temp_reg, first_reg_lo); |
| 4588 | |
| 4589 | // Shift right into low, feeding bits from high. |
| 4590 | __ shrd(first_reg_lo, first_reg_hi, imm); |
| 4591 | |
| 4592 | // Shift right into high, feeding bits from the original low. |
| 4593 | __ shrd(first_reg_hi, temp_reg, imm); |
| 4594 | |
| 4595 | // Swap if needed. |
| 4596 | if (shift_amt > 32) { |
| 4597 | __ movl(temp_reg, first_reg_lo); |
| 4598 | __ movl(first_reg_lo, first_reg_hi); |
| 4599 | __ movl(first_reg_hi, temp_reg); |
| 4600 | } |
| 4601 | } |
| 4602 | } |
| 4603 | |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4604 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 4605 | HandleShift(shl); |
| 4606 | } |
| 4607 | |
| 4608 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 4609 | HandleShift(shl); |
| 4610 | } |
| 4611 | |
| 4612 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 4613 | HandleShift(shr); |
| 4614 | } |
| 4615 | |
| 4616 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 4617 | HandleShift(shr); |
| 4618 | } |
| 4619 | |
| 4620 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 4621 | HandleShift(ushr); |
| 4622 | } |
| 4623 | |
| 4624 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 4625 | HandleShift(ushr); |
| 4626 | } |
| 4627 | |
| Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4628 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4629 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4630 | instruction, LocationSummary::kCallOnMainOnly); |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4631 | locations->SetOut(Location::RegisterLocation(EAX)); |
| Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 4632 | InvokeRuntimeCallingConvention calling_convention; |
| 4633 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4634 | } |
| 4635 | |
| 4636 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
| Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 4637 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
| 4638 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| 4639 | DCHECK(!codegen_->IsLeafMethod()); |
| Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4640 | } |
| 4641 | |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4642 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4643 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4644 | instruction, LocationSummary::kCallOnMainOnly); |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4645 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 4646 | InvokeRuntimeCallingConvention calling_convention; |
| Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4647 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4648 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4649 | } |
| 4650 | |
| 4651 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
| Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 4652 | // Note: if heap poisoning is enabled, the entry point takes care of poisoning the reference. |
| 4653 | QuickEntrypointEnum entrypoint = CodeGenerator::GetArrayAllocationEntrypoint(instruction); |
| Nicolas Geoffray | d095844 | 2017-01-30 14:57:16 +0000 | [diff] [blame] | 4654 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
| Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4655 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4656 | DCHECK(!codegen_->IsLeafMethod()); |
| 4657 | } |
| 4658 | |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4659 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4660 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4661 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4662 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4663 | if (location.IsStackSlot()) { |
| 4664 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4665 | } else if (location.IsDoubleStackSlot()) { |
| 4666 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4667 | } |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4668 | locations->SetOut(location); |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4669 | } |
| 4670 | |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4671 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 4672 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 4673 | } |
| 4674 | |
| 4675 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4676 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4677 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4678 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4679 | } |
| 4680 | |
| 4681 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4682 | } |
| 4683 | |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4684 | void LocationsBuilderX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4685 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4686 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4687 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4688 | locations->SetOut(Location::RequiresRegister()); |
| 4689 | } |
| 4690 | |
| 4691 | void InstructionCodeGeneratorX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4692 | LocationSummary* locations = instruction->GetLocations(); |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4693 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4694 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4695 | instruction->GetIndex(), kX86PointerSize).SizeValue(); |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4696 | __ movl(locations->Out().AsRegister<Register>(), |
| 4697 | Address(locations->InAt(0).AsRegister<Register>(), method_offset)); |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4698 | } else { |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4699 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4700 | instruction->GetIndex(), kX86PointerSize)); |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4701 | __ movl(locations->Out().AsRegister<Register>(), |
| 4702 | Address(locations->InAt(0).AsRegister<Register>(), |
| 4703 | mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
| 4704 | // temp = temp->GetImtEntryAt(method_offset); |
| 4705 | __ movl(locations->Out().AsRegister<Register>(), |
| 4706 | Address(locations->Out().AsRegister<Register>(), method_offset)); |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4707 | } |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4708 | } |
| 4709 | |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4710 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4711 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4712 | new (GetGraph()->GetAllocator()) LocationSummary(not_, LocationSummary::kNoCall); |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4713 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4714 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4715 | } |
| 4716 | |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4717 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 4718 | LocationSummary* locations = not_->GetLocations(); |
| Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4719 | Location in = locations->InAt(0); |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4720 | Location out = locations->Out(); |
| Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4721 | DCHECK(in.Equals(out)); |
| Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4722 | switch (not_->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4723 | case DataType::Type::kInt32: |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4724 | __ notl(out.AsRegister<Register>()); |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4725 | break; |
| 4726 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4727 | case DataType::Type::kInt64: |
| Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4728 | __ notl(out.AsRegisterPairLow<Register>()); |
| 4729 | __ notl(out.AsRegisterPairHigh<Register>()); |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4730 | break; |
| 4731 | |
| 4732 | default: |
| 4733 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4734 | } |
| Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4735 | } |
| 4736 | |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4737 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4738 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4739 | new (GetGraph()->GetAllocator()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4740 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4741 | locations->SetOut(Location::SameAsFirstInput()); |
| 4742 | } |
| 4743 | |
| 4744 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4745 | LocationSummary* locations = bool_not->GetLocations(); |
| 4746 | Location in = locations->InAt(0); |
| 4747 | Location out = locations->Out(); |
| 4748 | DCHECK(in.Equals(out)); |
| 4749 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 4750 | } |
| 4751 | |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4752 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4753 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4754 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4755 | switch (compare->InputAt(0)->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4756 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4757 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4758 | case DataType::Type::kInt8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4759 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4760 | case DataType::Type::kInt16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4761 | case DataType::Type::kInt32: |
| 4762 | case DataType::Type::kInt64: { |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4763 | locations->SetInAt(0, Location::RequiresRegister()); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4764 | locations->SetInAt(1, Location::Any()); |
| 4765 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4766 | break; |
| 4767 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4768 | case DataType::Type::kFloat32: |
| 4769 | case DataType::Type::kFloat64: { |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4770 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4771 | if (compare->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4772 | DCHECK(compare->InputAt(1)->IsEmittedAtUseSite()); |
| 4773 | } else if (compare->InputAt(1)->IsConstant()) { |
| 4774 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4775 | } else { |
| 4776 | locations->SetInAt(1, Location::Any()); |
| 4777 | } |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4778 | locations->SetOut(Location::RequiresRegister()); |
| 4779 | break; |
| 4780 | } |
| 4781 | default: |
| 4782 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4783 | } |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4784 | } |
| 4785 | |
| 4786 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4787 | LocationSummary* locations = compare->GetLocations(); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4788 | Register out = locations->Out().AsRegister<Register>(); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4789 | Location left = locations->InAt(0); |
| 4790 | Location right = locations->InAt(1); |
| 4791 | |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4792 | NearLabel less, greater, done; |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4793 | Condition less_cond = kLess; |
| 4794 | |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4795 | switch (compare->InputAt(0)->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4796 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4797 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4798 | case DataType::Type::kInt8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4799 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4800 | case DataType::Type::kInt16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4801 | case DataType::Type::kInt32: { |
| Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 4802 | codegen_->GenerateIntCompare(left, right); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4803 | break; |
| 4804 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4805 | case DataType::Type::kInt64: { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4806 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 4807 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 4808 | int32_t val_low = 0; |
| 4809 | int32_t val_high = 0; |
| 4810 | bool right_is_const = false; |
| 4811 | |
| 4812 | if (right.IsConstant()) { |
| 4813 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 4814 | right_is_const = true; |
| 4815 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 4816 | val_low = Low32Bits(val); |
| 4817 | val_high = High32Bits(val); |
| 4818 | } |
| 4819 | |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4820 | if (right.IsRegisterPair()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4821 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4822 | } else if (right.IsDoubleStackSlot()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4823 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4824 | } else { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4825 | DCHECK(right_is_const) << right; |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4826 | codegen_->Compare32BitValue(left_high, val_high); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4827 | } |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4828 | __ j(kLess, &less); // Signed compare. |
| 4829 | __ j(kGreater, &greater); // Signed compare. |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4830 | if (right.IsRegisterPair()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4831 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4832 | } else if (right.IsDoubleStackSlot()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4833 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4834 | } else { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4835 | DCHECK(right_is_const) << right; |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4836 | codegen_->Compare32BitValue(left_low, val_low); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4837 | } |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4838 | less_cond = kBelow; // for CF (unsigned). |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4839 | break; |
| 4840 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4841 | case DataType::Type::kFloat32: { |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4842 | GenerateFPCompare(left, right, compare, false); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4843 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4844 | less_cond = kBelow; // for CF (floats). |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4845 | break; |
| 4846 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4847 | case DataType::Type::kFloat64: { |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4848 | GenerateFPCompare(left, right, compare, true); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4849 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4850 | less_cond = kBelow; // for CF (floats). |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4851 | break; |
| 4852 | } |
| 4853 | default: |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4854 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4855 | } |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4856 | |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4857 | __ movl(out, Immediate(0)); |
| 4858 | __ j(kEqual, &done); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4859 | __ j(less_cond, &less); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4860 | |
| 4861 | __ Bind(&greater); |
| 4862 | __ movl(out, Immediate(1)); |
| 4863 | __ jmp(&done); |
| 4864 | |
| 4865 | __ Bind(&less); |
| 4866 | __ movl(out, Immediate(-1)); |
| 4867 | |
| 4868 | __ Bind(&done); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4869 | } |
| 4870 | |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4871 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4872 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4873 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4874 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
| Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4875 | locations->SetInAt(i, Location::Any()); |
| 4876 | } |
| 4877 | locations->SetOut(Location::Any()); |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4878 | } |
| 4879 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4880 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4881 | LOG(FATAL) << "Unreachable"; |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4882 | } |
| 4883 | |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4884 | void CodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4885 | /* |
| 4886 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 4887 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 4888 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4889 | */ |
| 4890 | switch (kind) { |
| 4891 | case MemBarrierKind::kAnyAny: { |
| Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4892 | MemoryFence(); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4893 | break; |
| 4894 | } |
| 4895 | case MemBarrierKind::kAnyStore: |
| 4896 | case MemBarrierKind::kLoadAny: |
| 4897 | case MemBarrierKind::kStoreStore: { |
| 4898 | // nop |
| 4899 | break; |
| 4900 | } |
| Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4901 | case MemBarrierKind::kNTStoreStore: |
| 4902 | // Non-Temporal Store/Store needs an explicit fence. |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4903 | MemoryFence(/* non-temporal= */ true); |
| Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4904 | break; |
| Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4905 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4906 | } |
| 4907 | |
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4908 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( |
| 4909 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| Nicolas Geoffray | bdb2ecc | 2018-09-18 14:33:55 +0100 | [diff] [blame] | 4910 | ArtMethod* method ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4911 | return desired_dispatch_info; |
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4912 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4913 | |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4914 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 4915 | Register temp) { |
| 4916 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4917 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4918 | if (!invoke->GetLocations()->Intrinsified()) { |
| 4919 | return location.AsRegister<Register>(); |
| 4920 | } |
| 4921 | // For intrinsics we allow any location, so it may be on the stack. |
| 4922 | if (!location.IsRegister()) { |
| 4923 | __ movl(temp, Address(ESP, location.GetStackIndex())); |
| 4924 | return temp; |
| 4925 | } |
| 4926 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 4927 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 4928 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 4929 | // simple and more robust approach rather that trying to determine if that's the case. |
| 4930 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| Vladimir Marko | 4ee8e29 | 2017-06-02 15:39:30 +0000 | [diff] [blame] | 4931 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 4932 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 4933 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 4934 | __ movl(temp, Address(ESP, stack_offset)); |
| 4935 | return temp; |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4936 | } |
| 4937 | return location.AsRegister<Register>(); |
| 4938 | } |
| 4939 | |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4940 | void CodeGeneratorX86::GenerateStaticOrDirectCall( |
| 4941 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4942 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4943 | switch (invoke->GetMethodLoadKind()) { |
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4944 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4945 | // temp = thread->string_init_entrypoint |
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4946 | uint32_t offset = |
| 4947 | GetThreadOffset<kX86PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 4948 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(offset)); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4949 | break; |
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4950 | } |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4951 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
| Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4952 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4953 | break; |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4954 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 4955 | DCHECK(GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4956 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4957 | temp.AsRegister<Register>()); |
| 4958 | __ leal(temp.AsRegister<Register>(), Address(base_reg, CodeGeneratorX86::kDummy32BitOffset)); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4959 | RecordBootImageMethodPatch(invoke); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4960 | break; |
| 4961 | } |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4962 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageRelRo: { |
| 4963 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4964 | temp.AsRegister<Register>()); |
| 4965 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
| 4966 | RecordBootImageRelRoPatch( |
| 4967 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(), |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4968 | GetBootImageOffset(invoke)); |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4969 | break; |
| 4970 | } |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4971 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4972 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4973 | temp.AsRegister<Register>()); |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4974 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4975 | RecordMethodBssEntryPatch(invoke); |
| Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 4976 | // No need for memory fence, thanks to the x86 memory model. |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4977 | break; |
| 4978 | } |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4979 | case HInvokeStaticOrDirect::MethodLoadKind::kJitDirectAddress: |
| 4980 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 4981 | break; |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4982 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 4983 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 4984 | return; // No code pointer retrieval; the runtime performs the call directly. |
| Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4985 | } |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4986 | } |
| 4987 | |
| 4988 | switch (invoke->GetCodePtrLocation()) { |
| 4989 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 4990 | __ call(GetFrameEntryLabel()); |
| 4991 | break; |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4992 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4993 | // (callee_method + offset_of_quick_compiled_code)() |
| 4994 | __ call(Address(callee_method.AsRegister<Register>(), |
| 4995 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4996 | kX86PointerSize).Int32Value())); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4997 | break; |
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4998 | } |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4999 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 5000 | |
| 5001 | DCHECK(!IsLeafMethod()); |
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 5002 | } |
| 5003 | |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5004 | void CodeGeneratorX86::GenerateVirtualCall( |
| 5005 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5006 | Register temp = temp_in.AsRegister<Register>(); |
| 5007 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 5008 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
| Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 5009 | |
| 5010 | // Use the calling convention instead of the location of the receiver, as |
| 5011 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 5012 | // slow path, the arguments have been moved to the right place, so here we are |
| 5013 | // guaranteed that the receiver is the first register of the calling convention. |
| 5014 | InvokeDexCallingConvention calling_convention; |
| 5015 | Register receiver = calling_convention.GetRegisterAt(0); |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5016 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5017 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 5018 | __ movl(temp, Address(receiver, class_offset)); |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5019 | MaybeRecordImplicitNullCheck(invoke); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5020 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 5021 | // emit a read barrier for the previous class reference load. |
| 5022 | // However this is not required in practice, as this is an |
| 5023 | // intermediate/temporary reference and because the current |
| 5024 | // concurrent copying collector keeps the from-space memory |
| 5025 | // intact/accessible until the end of the marking phase (the |
| 5026 | // concurrent copying collector may not in the future). |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5027 | __ MaybeUnpoisonHeapReference(temp); |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 5028 | |
| 5029 | MaybeGenerateInlineCacheCheck(invoke, temp); |
| 5030 | |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5031 | // temp = temp->GetMethodAt(method_offset); |
| 5032 | __ movl(temp, Address(temp, method_offset)); |
| 5033 | // call temp->GetEntryPoint(); |
| 5034 | __ call(Address( |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5035 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5036 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5037 | } |
| 5038 | |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5039 | void CodeGeneratorX86::RecordBootImageIntrinsicPatch(HX86ComputeBaseMethodAddress* method_address, |
| 5040 | uint32_t intrinsic_data) { |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5041 | boot_image_other_patches_.emplace_back( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5042 | method_address, /* target_dex_file= */ nullptr, intrinsic_data); |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5043 | __ Bind(&boot_image_other_patches_.back().label); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5044 | } |
| 5045 | |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 5046 | void CodeGeneratorX86::RecordBootImageRelRoPatch(HX86ComputeBaseMethodAddress* method_address, |
| 5047 | uint32_t boot_image_offset) { |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5048 | boot_image_other_patches_.emplace_back( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5049 | method_address, /* target_dex_file= */ nullptr, boot_image_offset); |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5050 | __ Bind(&boot_image_other_patches_.back().label); |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 5051 | } |
| 5052 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5053 | void CodeGeneratorX86::RecordBootImageMethodPatch(HInvokeStaticOrDirect* invoke) { |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5054 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5055 | HX86ComputeBaseMethodAddress* method_address = |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5056 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5057 | boot_image_method_patches_.emplace_back( |
| 5058 | method_address, invoke->GetTargetMethod().dex_file, invoke->GetTargetMethod().index); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5059 | __ Bind(&boot_image_method_patches_.back().label); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5060 | } |
| 5061 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5062 | void CodeGeneratorX86::RecordMethodBssEntryPatch(HInvokeStaticOrDirect* invoke) { |
| 5063 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 5064 | HX86ComputeBaseMethodAddress* method_address = |
| 5065 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5066 | // 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] | 5067 | method_bss_entry_patches_.emplace_back( |
| 5068 | method_address, &GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()); |
| 5069 | __ Bind(&method_bss_entry_patches_.back().label); |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5070 | } |
| 5071 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5072 | void CodeGeneratorX86::RecordBootImageTypePatch(HLoadClass* load_class) { |
| 5073 | HX86ComputeBaseMethodAddress* method_address = |
| 5074 | load_class->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 5075 | boot_image_type_patches_.emplace_back( |
| 5076 | method_address, &load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5077 | __ Bind(&boot_image_type_patches_.back().label); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5078 | } |
| 5079 | |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5080 | Label* CodeGeneratorX86::NewTypeBssEntryPatch(HLoadClass* load_class) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5081 | HX86ComputeBaseMethodAddress* method_address = |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 5082 | load_class->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 5083 | type_bss_entry_patches_.emplace_back( |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5084 | method_address, &load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5085 | return &type_bss_entry_patches_.back().label; |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5086 | } |
| 5087 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5088 | void CodeGeneratorX86::RecordBootImageStringPatch(HLoadString* load_string) { |
| 5089 | HX86ComputeBaseMethodAddress* method_address = |
| 5090 | load_string->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 5091 | boot_image_string_patches_.emplace_back( |
| 5092 | method_address, &load_string->GetDexFile(), load_string->GetStringIndex().index_); |
| 5093 | __ Bind(&boot_image_string_patches_.back().label); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5094 | } |
| 5095 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5096 | Label* CodeGeneratorX86::NewStringBssEntryPatch(HLoadString* load_string) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5097 | HX86ComputeBaseMethodAddress* method_address = |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 5098 | load_string->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5099 | string_bss_entry_patches_.emplace_back( |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5100 | method_address, &load_string->GetDexFile(), load_string->GetStringIndex().index_); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5101 | return &string_bss_entry_patches_.back().label; |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5102 | } |
| 5103 | |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5104 | void CodeGeneratorX86::LoadBootImageAddress(Register reg, |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5105 | uint32_t boot_image_reference, |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5106 | HInvokeStaticOrDirect* invoke) { |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5107 | if (GetCompilerOptions().IsBootImage()) { |
| 5108 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 5109 | HX86ComputeBaseMethodAddress* method_address = |
| 5110 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
| 5111 | DCHECK(method_address != nullptr); |
| 5112 | Register method_address_reg = |
| 5113 | invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()).AsRegister<Register>(); |
| 5114 | __ leal(reg, Address(method_address_reg, CodeGeneratorX86::kDummy32BitOffset)); |
| 5115 | RecordBootImageIntrinsicPatch(method_address, boot_image_reference); |
| Vladimir Marko | a2da9b9 | 2018-10-10 14:21:55 +0100 | [diff] [blame] | 5116 | } else if (GetCompilerOptions().GetCompilePic()) { |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5117 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 5118 | HX86ComputeBaseMethodAddress* method_address = |
| 5119 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
| 5120 | DCHECK(method_address != nullptr); |
| 5121 | Register method_address_reg = |
| 5122 | invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()).AsRegister<Register>(); |
| 5123 | __ movl(reg, Address(method_address_reg, CodeGeneratorX86::kDummy32BitOffset)); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5124 | RecordBootImageRelRoPatch(method_address, boot_image_reference); |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5125 | } else { |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5126 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5127 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 5128 | DCHECK(!heap->GetBootImageSpaces().empty()); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5129 | const uint8_t* address = heap->GetBootImageSpaces()[0]->Begin() + boot_image_reference; |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5130 | __ movl(reg, Immediate(dchecked_integral_cast<uint32_t>(reinterpret_cast<uintptr_t>(address)))); |
| 5131 | } |
| 5132 | } |
| 5133 | |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5134 | void CodeGeneratorX86::AllocateInstanceForIntrinsic(HInvokeStaticOrDirect* invoke, |
| 5135 | uint32_t boot_image_offset) { |
| 5136 | DCHECK(invoke->IsStatic()); |
| 5137 | InvokeRuntimeCallingConvention calling_convention; |
| 5138 | Register argument = calling_convention.GetRegisterAt(0); |
| 5139 | if (GetCompilerOptions().IsBootImage()) { |
| 5140 | DCHECK_EQ(boot_image_offset, IntrinsicVisitor::IntegerValueOfInfo::kInvalidReference); |
| 5141 | // Load the class the same way as for HLoadClass::LoadKind::kBootImageLinkTimePcRelative. |
| 5142 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 5143 | HX86ComputeBaseMethodAddress* method_address = |
| 5144 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
| 5145 | DCHECK(method_address != nullptr); |
| 5146 | Register method_address_reg = |
| 5147 | invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()).AsRegister<Register>(); |
| 5148 | __ leal(argument, Address(method_address_reg, CodeGeneratorX86::kDummy32BitOffset)); |
| 5149 | MethodReference target_method = invoke->GetTargetMethod(); |
| 5150 | dex::TypeIndex type_idx = target_method.dex_file->GetMethodId(target_method.index).class_idx_; |
| 5151 | boot_image_type_patches_.emplace_back(method_address, target_method.dex_file, type_idx.index_); |
| 5152 | __ Bind(&boot_image_type_patches_.back().label); |
| 5153 | } else { |
| 5154 | LoadBootImageAddress(argument, boot_image_offset, invoke); |
| 5155 | } |
| 5156 | InvokeRuntime(kQuickAllocObjectInitialized, invoke, invoke->GetDexPc()); |
| 5157 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| 5158 | } |
| 5159 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5160 | // The label points to the end of the "movl" or another instruction but the literal offset |
| 5161 | // for method patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 5162 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
| 5163 | |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5164 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5165 | inline void CodeGeneratorX86::EmitPcRelativeLinkerPatches( |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 5166 | const ArenaDeque<X86PcRelativePatchInfo>& infos, |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5167 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 5168 | for (const X86PcRelativePatchInfo& info : infos) { |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5169 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5170 | linker_patches->push_back(Factory(literal_offset, |
| 5171 | info.target_dex_file, |
| 5172 | GetMethodAddressOffset(info.method_address), |
| 5173 | info.offset_or_index)); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5174 | } |
| 5175 | } |
| 5176 | |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5177 | template <linker::LinkerPatch (*Factory)(size_t, uint32_t, uint32_t)> |
| 5178 | linker::LinkerPatch NoDexFileAdapter(size_t literal_offset, |
| 5179 | const DexFile* target_dex_file, |
| 5180 | uint32_t pc_insn_offset, |
| 5181 | uint32_t boot_image_offset) { |
| 5182 | DCHECK(target_dex_file == nullptr); // Unused for these patches, should be null. |
| 5183 | return Factory(literal_offset, pc_insn_offset, boot_image_offset); |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 5184 | } |
| 5185 | |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5186 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5187 | DCHECK(linker_patches->empty()); |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 5188 | size_t size = |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5189 | boot_image_method_patches_.size() + |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5190 | method_bss_entry_patches_.size() + |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5191 | boot_image_type_patches_.size() + |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5192 | type_bss_entry_patches_.size() + |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5193 | boot_image_string_patches_.size() + |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5194 | string_bss_entry_patches_.size() + |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5195 | boot_image_other_patches_.size(); |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 5196 | linker_patches->reserve(size); |
| Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 5197 | if (GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()) { |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5198 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
| 5199 | boot_image_method_patches_, linker_patches); |
| 5200 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
| 5201 | boot_image_type_patches_, linker_patches); |
| 5202 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5203 | boot_image_string_patches_, linker_patches); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5204 | } else { |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5205 | DCHECK(boot_image_method_patches_.empty()); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5206 | DCHECK(boot_image_type_patches_.empty()); |
| 5207 | DCHECK(boot_image_string_patches_.empty()); |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5208 | } |
| 5209 | if (GetCompilerOptions().IsBootImage()) { |
| 5210 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::IntrinsicReferencePatch>>( |
| 5211 | boot_image_other_patches_, linker_patches); |
| 5212 | } else { |
| 5213 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::DataBimgRelRoPatch>>( |
| 5214 | boot_image_other_patches_, linker_patches); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5215 | } |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5216 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 5217 | method_bss_entry_patches_, linker_patches); |
| 5218 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 5219 | type_bss_entry_patches_, linker_patches); |
| 5220 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 5221 | string_bss_entry_patches_, linker_patches); |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5222 | DCHECK_EQ(size, linker_patches->size()); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5223 | } |
| 5224 | |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5225 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 5226 | Register card, |
| 5227 | Register object, |
| 5228 | Register value, |
| 5229 | bool value_can_be_null) { |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 5230 | NearLabel is_null; |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5231 | if (value_can_be_null) { |
| 5232 | __ testl(value, value); |
| 5233 | __ j(kEqual, &is_null); |
| 5234 | } |
| Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5235 | // Load the address of the card table into `card`. |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5236 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86PointerSize>().Int32Value())); |
| Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5237 | // Calculate the offset (in the card table) of the card corresponding to |
| 5238 | // `object`. |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5239 | __ movl(temp, object); |
| 5240 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
| Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5241 | // Write the `art::gc::accounting::CardTable::kCardDirty` value into the |
| 5242 | // `object`'s card. |
| 5243 | // |
| 5244 | // Register `card` contains the address of the card table. Note that the card |
| 5245 | // table's base is biased during its creation so that it always starts at an |
| 5246 | // address whose least-significant byte is equal to `kCardDirty` (see |
| 5247 | // art::gc::accounting::CardTable::Create). Therefore the MOVB instruction |
| 5248 | // below writes the `kCardDirty` (byte) value into the `object`'s card |
| 5249 | // (located at `card + object >> kCardShift`). |
| 5250 | // |
| 5251 | // This dual use of the value in register `card` (1. to calculate the location |
| 5252 | // of the card to mark; and 2. to load the `kCardDirty` value) saves a load |
| 5253 | // (no need to explicitly load `kCardDirty` as an immediate value). |
| Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 5254 | __ movb(Address(temp, card, TIMES_1, 0), |
| 5255 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5256 | if (value_can_be_null) { |
| 5257 | __ Bind(&is_null); |
| 5258 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5259 | } |
| 5260 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5261 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 5262 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5263 | |
| 5264 | bool object_field_get_with_read_barrier = |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5265 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5266 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5267 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 5268 | kEmitCompilerReadBarrier |
| 5269 | ? LocationSummary::kCallOnSlowPath |
| 5270 | : LocationSummary::kNoCall); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5271 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5272 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5273 | } |
| Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5274 | locations->SetInAt(0, Location::RequiresRegister()); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5275 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5276 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5277 | locations->SetOut(Location::RequiresFpuRegister()); |
| 5278 | } else { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5279 | // The output overlaps in case of long: we don't want the low move |
| 5280 | // to overwrite the object's location. Likewise, in the case of |
| 5281 | // an object field get with read barriers enabled, we do not want |
| 5282 | // the move to overwrite the object's location, as we need it to emit |
| 5283 | // the read barrier. |
| 5284 | locations->SetOut( |
| 5285 | Location::RequiresRegister(), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5286 | (object_field_get_with_read_barrier || instruction->GetType() == DataType::Type::kInt64) ? |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5287 | Location::kOutputOverlap : |
| 5288 | Location::kNoOutputOverlap); |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5289 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5290 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5291 | if (field_info.IsVolatile() && (field_info.GetFieldType() == DataType::Type::kInt64)) { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5292 | // Long values can be loaded atomically into an XMM using movsd. |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5293 | // So we use an XMM register as a temp to achieve atomicity (first |
| 5294 | // load the temp into the XMM and then copy the XMM into the |
| 5295 | // output, 32 bits at a time). |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5296 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 5297 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5298 | } |
| 5299 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5300 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 5301 | const FieldInfo& field_info) { |
| 5302 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5303 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5304 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5305 | Location base_loc = locations->InAt(0); |
| 5306 | Register base = base_loc.AsRegister<Register>(); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5307 | Location out = locations->Out(); |
| 5308 | bool is_volatile = field_info.IsVolatile(); |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5309 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 5310 | DataType::Type load_type = instruction->GetType(); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5311 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5312 | |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5313 | switch (load_type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5314 | case DataType::Type::kBool: |
| 5315 | case DataType::Type::kUint8: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5316 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5317 | break; |
| 5318 | } |
| 5319 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5320 | case DataType::Type::kInt8: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5321 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5322 | break; |
| 5323 | } |
| 5324 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5325 | case DataType::Type::kUint16: { |
| 5326 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5327 | break; |
| 5328 | } |
| 5329 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5330 | case DataType::Type::kInt16: { |
| 5331 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5332 | break; |
| 5333 | } |
| 5334 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5335 | case DataType::Type::kInt32: |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5336 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5337 | break; |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5338 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5339 | case DataType::Type::kReference: { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5340 | // /* HeapReference<Object> */ out = *(base + offset) |
| 5341 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5342 | // Note that a potential implicit null check is handled in this |
| 5343 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 5344 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5345 | instruction, out, base, offset, /* needs_null_check= */ true); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5346 | if (is_volatile) { |
| 5347 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5348 | } |
| 5349 | } else { |
| 5350 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| 5351 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5352 | if (is_volatile) { |
| 5353 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5354 | } |
| 5355 | // If read barriers are enabled, emit read barriers other than |
| 5356 | // Baker's using a slow path (and also unpoison the loaded |
| 5357 | // reference, if heap poisoning is enabled). |
| 5358 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 5359 | } |
| 5360 | break; |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5361 | } |
| 5362 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5363 | case DataType::Type::kInt64: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5364 | if (is_volatile) { |
| 5365 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 5366 | __ movsd(temp, Address(base, offset)); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5367 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5368 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 5369 | __ psrlq(temp, Immediate(32)); |
| 5370 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 5371 | } else { |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5372 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5373 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5374 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5375 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 5376 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5377 | break; |
| 5378 | } |
| 5379 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5380 | case DataType::Type::kFloat32: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5381 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5382 | break; |
| 5383 | } |
| 5384 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5385 | case DataType::Type::kFloat64: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5386 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5387 | break; |
| 5388 | } |
| 5389 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5390 | case DataType::Type::kUint32: |
| 5391 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5392 | case DataType::Type::kVoid: |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5393 | LOG(FATAL) << "Unreachable type " << load_type; |
| Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5394 | UNREACHABLE(); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5395 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5396 | |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5397 | if (load_type == DataType::Type::kReference || load_type == DataType::Type::kInt64) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5398 | // Potential implicit null checks, in the case of reference or |
| 5399 | // long fields, are handled in the previous switch statement. |
| 5400 | } else { |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5401 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5402 | } |
| 5403 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5404 | if (is_volatile) { |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5405 | if (load_type == DataType::Type::kReference) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5406 | // Memory barriers, in the case of references, are also handled |
| 5407 | // in the previous switch statement. |
| 5408 | } else { |
| 5409 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5410 | } |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5411 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5412 | } |
| 5413 | |
| 5414 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 5415 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5416 | |
| 5417 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5418 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5419 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5420 | bool is_volatile = field_info.IsVolatile(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5421 | DataType::Type field_type = field_info.GetFieldType(); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5422 | bool is_byte_type = DataType::Size(field_type) == 1u; |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5423 | |
| 5424 | // The register allocator does not support multiple |
| 5425 | // inputs that die at entry with one in a specific register. |
| 5426 | if (is_byte_type) { |
| 5427 | // Ensure the value is in a byte register. |
| 5428 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5429 | } else if (DataType::IsFloatingPointType(field_type)) { |
| 5430 | if (is_volatile && field_type == DataType::Type::kFloat64) { |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5431 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 5432 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 5433 | } else { |
| 5434 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 5435 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5436 | } else if (is_volatile && field_type == DataType::Type::kInt64) { |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5437 | // 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] | 5438 | locations->SetInAt(1, Location::RequiresRegister()); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5439 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5440 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 5441 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 5442 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 5443 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 5444 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 5445 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 5446 | locations->AddTemp(Location::RequiresFpuRegister()); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5447 | } else { |
| 5448 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5449 | |
| 5450 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 5451 | // Temporary registers for the write barrier. |
| 5452 | locations->AddTemp(Location::RequiresRegister()); // May be used for reference poisoning too. |
| 5453 | // Ensure the card is in a byte register. |
| 5454 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 5455 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5456 | } |
| 5457 | } |
| 5458 | |
| 5459 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5460 | const FieldInfo& field_info, |
| 5461 | bool value_can_be_null) { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5462 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5463 | |
| 5464 | LocationSummary* locations = instruction->GetLocations(); |
| 5465 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 5466 | Location value = locations->InAt(1); |
| 5467 | bool is_volatile = field_info.IsVolatile(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5468 | DataType::Type field_type = field_info.GetFieldType(); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5469 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5470 | bool needs_write_barrier = |
| 5471 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5472 | |
| 5473 | if (is_volatile) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5474 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5475 | } |
| 5476 | |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5477 | bool maybe_record_implicit_null_check_done = false; |
| 5478 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5479 | switch (field_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5480 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5481 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5482 | case DataType::Type::kInt8: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5483 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 5484 | break; |
| 5485 | } |
| 5486 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5487 | case DataType::Type::kUint16: |
| 5488 | case DataType::Type::kInt16: { |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5489 | if (value.IsConstant()) { |
| Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5490 | __ movw(Address(base, offset), |
| 5491 | Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5492 | } else { |
| 5493 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 5494 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5495 | break; |
| 5496 | } |
| 5497 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5498 | case DataType::Type::kInt32: |
| 5499 | case DataType::Type::kReference: { |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5500 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 5501 | // Note that in the case where `value` is a null reference, |
| 5502 | // we do not enter this block, as the reference does not |
| 5503 | // need poisoning. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5504 | DCHECK_EQ(field_type, DataType::Type::kReference); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5505 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5506 | __ movl(temp, value.AsRegister<Register>()); |
| 5507 | __ PoisonHeapReference(temp); |
| 5508 | __ movl(Address(base, offset), temp); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5509 | } else if (value.IsConstant()) { |
| 5510 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5511 | __ movl(Address(base, offset), Immediate(v)); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5512 | } else { |
| Nicolas Geoffray | 0397163 | 2016-03-17 10:44:24 +0000 | [diff] [blame] | 5513 | DCHECK(value.IsRegister()) << value; |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5514 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 5515 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5516 | break; |
| 5517 | } |
| 5518 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5519 | case DataType::Type::kInt64: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5520 | if (is_volatile) { |
| 5521 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 5522 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 5523 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 5524 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 5525 | __ punpckldq(temp1, temp2); |
| 5526 | __ movsd(Address(base, offset), temp1); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5527 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5528 | } else if (value.IsConstant()) { |
| 5529 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 5530 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 5531 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5532 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5533 | } else { |
| 5534 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5535 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5536 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 5537 | } |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5538 | maybe_record_implicit_null_check_done = true; |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5539 | break; |
| 5540 | } |
| 5541 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5542 | case DataType::Type::kFloat32: { |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5543 | if (value.IsConstant()) { |
| 5544 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5545 | __ movl(Address(base, offset), Immediate(v)); |
| 5546 | } else { |
| 5547 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 5548 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5549 | break; |
| 5550 | } |
| 5551 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5552 | case DataType::Type::kFloat64: { |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5553 | if (value.IsConstant()) { |
| 5554 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 5555 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 5556 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5557 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
| 5558 | maybe_record_implicit_null_check_done = true; |
| 5559 | } else { |
| 5560 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 5561 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5562 | break; |
| 5563 | } |
| 5564 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5565 | case DataType::Type::kUint32: |
| 5566 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5567 | case DataType::Type::kVoid: |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5568 | LOG(FATAL) << "Unreachable type " << field_type; |
| 5569 | UNREACHABLE(); |
| 5570 | } |
| 5571 | |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5572 | if (!maybe_record_implicit_null_check_done) { |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5573 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5574 | } |
| 5575 | |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5576 | if (needs_write_barrier) { |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5577 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5578 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5579 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5580 | } |
| 5581 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5582 | if (is_volatile) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5583 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5584 | } |
| 5585 | } |
| 5586 | |
| 5587 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5588 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5589 | } |
| 5590 | |
| 5591 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5592 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5593 | } |
| 5594 | |
| 5595 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 5596 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5597 | } |
| 5598 | |
| 5599 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5600 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5601 | } |
| 5602 | |
| 5603 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5604 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5605 | } |
| 5606 | |
| 5607 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5608 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5609 | } |
| 5610 | |
| 5611 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5612 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5613 | } |
| 5614 | |
| 5615 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5616 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5617 | } |
| 5618 | |
| Vladimir Marko | 552a134 | 2017-10-31 10:56:47 +0000 | [diff] [blame] | 5619 | void LocationsBuilderX86::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 5620 | codegen_->CreateStringBuilderAppendLocations(instruction, Location::RegisterLocation(EAX)); |
| 5621 | } |
| 5622 | |
| 5623 | void InstructionCodeGeneratorX86::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 5624 | __ movl(EAX, Immediate(instruction->GetFormat()->GetValue())); |
| 5625 | codegen_->InvokeRuntime(kQuickStringBuilderAppend, instruction, instruction->GetDexPc()); |
| 5626 | } |
| 5627 | |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5628 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 5629 | HUnresolvedInstanceFieldGet* instruction) { |
| 5630 | FieldAccessCallingConventionX86 calling_convention; |
| 5631 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5632 | instruction, instruction->GetFieldType(), calling_convention); |
| 5633 | } |
| 5634 | |
| 5635 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 5636 | HUnresolvedInstanceFieldGet* instruction) { |
| 5637 | FieldAccessCallingConventionX86 calling_convention; |
| 5638 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5639 | instruction->GetFieldType(), |
| 5640 | instruction->GetFieldIndex(), |
| 5641 | instruction->GetDexPc(), |
| 5642 | calling_convention); |
| 5643 | } |
| 5644 | |
| 5645 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 5646 | HUnresolvedInstanceFieldSet* instruction) { |
| 5647 | FieldAccessCallingConventionX86 calling_convention; |
| 5648 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5649 | instruction, instruction->GetFieldType(), calling_convention); |
| 5650 | } |
| 5651 | |
| 5652 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 5653 | HUnresolvedInstanceFieldSet* instruction) { |
| 5654 | FieldAccessCallingConventionX86 calling_convention; |
| 5655 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5656 | instruction->GetFieldType(), |
| 5657 | instruction->GetFieldIndex(), |
| 5658 | instruction->GetDexPc(), |
| 5659 | calling_convention); |
| 5660 | } |
| 5661 | |
| 5662 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 5663 | HUnresolvedStaticFieldGet* instruction) { |
| 5664 | FieldAccessCallingConventionX86 calling_convention; |
| 5665 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5666 | instruction, instruction->GetFieldType(), calling_convention); |
| 5667 | } |
| 5668 | |
| 5669 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 5670 | HUnresolvedStaticFieldGet* instruction) { |
| 5671 | FieldAccessCallingConventionX86 calling_convention; |
| 5672 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5673 | instruction->GetFieldType(), |
| 5674 | instruction->GetFieldIndex(), |
| 5675 | instruction->GetDexPc(), |
| 5676 | calling_convention); |
| 5677 | } |
| 5678 | |
| 5679 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 5680 | HUnresolvedStaticFieldSet* instruction) { |
| 5681 | FieldAccessCallingConventionX86 calling_convention; |
| 5682 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5683 | instruction, instruction->GetFieldType(), calling_convention); |
| 5684 | } |
| 5685 | |
| 5686 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 5687 | HUnresolvedStaticFieldSet* instruction) { |
| 5688 | FieldAccessCallingConventionX86 calling_convention; |
| 5689 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5690 | instruction->GetFieldType(), |
| 5691 | instruction->GetFieldIndex(), |
| 5692 | instruction->GetDexPc(), |
| 5693 | calling_convention); |
| 5694 | } |
| 5695 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5696 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5697 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5698 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 5699 | ? Location::RequiresRegister() |
| 5700 | : Location::Any(); |
| 5701 | locations->SetInAt(0, loc); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5702 | } |
| 5703 | |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5704 | void CodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5705 | if (CanMoveNullCheckToUser(instruction)) { |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5706 | return; |
| 5707 | } |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5708 | LocationSummary* locations = instruction->GetLocations(); |
| 5709 | Location obj = locations->InAt(0); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5710 | |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5711 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5712 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5713 | } |
| 5714 | |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5715 | void CodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5716 | SlowPathCode* slow_path = new (GetScopedAllocator()) NullCheckSlowPathX86(instruction); |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5717 | AddSlowPath(slow_path); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5718 | |
| 5719 | LocationSummary* locations = instruction->GetLocations(); |
| 5720 | Location obj = locations->InAt(0); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5721 | |
| 5722 | if (obj.IsRegister()) { |
| Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 5723 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5724 | } else if (obj.IsStackSlot()) { |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5725 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5726 | } else { |
| 5727 | DCHECK(obj.IsConstant()) << obj; |
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5728 | DCHECK(obj.GetConstant()->IsNullConstant()); |
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5729 | __ jmp(slow_path->GetEntryLabel()); |
| 5730 | return; |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5731 | } |
| 5732 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5733 | } |
| 5734 | |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5735 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5736 | codegen_->GenerateNullCheck(instruction); |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5737 | } |
| 5738 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5739 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5740 | bool object_array_get_with_read_barrier = |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5741 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5742 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5743 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 5744 | object_array_get_with_read_barrier |
| 5745 | ? LocationSummary::kCallOnSlowPath |
| 5746 | : LocationSummary::kNoCall); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5747 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5748 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5749 | } |
| Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5750 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5751 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5752 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5753 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5754 | } else { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5755 | // The output overlaps in case of long: we don't want the low move |
| 5756 | // to overwrite the array's location. Likewise, in the case of an |
| 5757 | // object array get with read barriers enabled, we do not want the |
| 5758 | // move to overwrite the array's location, as we need it to emit |
| 5759 | // the read barrier. |
| 5760 | locations->SetOut( |
| 5761 | Location::RequiresRegister(), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5762 | (instruction->GetType() == DataType::Type::kInt64 || object_array_get_with_read_barrier) |
| 5763 | ? Location::kOutputOverlap |
| 5764 | : Location::kNoOutputOverlap); |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5765 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5766 | } |
| 5767 | |
| 5768 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 5769 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5770 | Location obj_loc = locations->InAt(0); |
| 5771 | Register obj = obj_loc.AsRegister<Register>(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5772 | Location index = locations->InAt(1); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5773 | Location out_loc = locations->Out(); |
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5774 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5775 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5776 | DataType::Type type = instruction->GetType(); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5777 | switch (type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5778 | case DataType::Type::kBool: |
| 5779 | case DataType::Type::kUint8: { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5780 | Register out = out_loc.AsRegister<Register>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5781 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5782 | break; |
| 5783 | } |
| 5784 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5785 | case DataType::Type::kInt8: { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5786 | Register out = out_loc.AsRegister<Register>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5787 | __ movsxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5788 | break; |
| 5789 | } |
| 5790 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5791 | case DataType::Type::kUint16: { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5792 | Register out = out_loc.AsRegister<Register>(); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5793 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5794 | // Branch cases into compressed and uncompressed for each index's type. |
| 5795 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 5796 | NearLabel done, not_compressed; |
| Vladimir Marko | 3c89d42 | 2017-02-17 11:30:23 +0000 | [diff] [blame] | 5797 | __ testb(Address(obj, count_offset), Immediate(1)); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5798 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5799 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 5800 | "Expecting 0=compressed, 1=uncompressed"); |
| 5801 | __ j(kNotZero, ¬_compressed); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5802 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| 5803 | __ jmp(&done); |
| 5804 | __ Bind(¬_compressed); |
| 5805 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5806 | __ Bind(&done); |
| 5807 | } else { |
| 5808 | // Common case for charAt of array of char or when string compression's |
| 5809 | // feature is turned off. |
| 5810 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5811 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5812 | break; |
| 5813 | } |
| 5814 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5815 | case DataType::Type::kInt16: { |
| 5816 | Register out = out_loc.AsRegister<Register>(); |
| 5817 | __ movsxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5818 | break; |
| 5819 | } |
| 5820 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5821 | case DataType::Type::kInt32: { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5822 | Register out = out_loc.AsRegister<Register>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5823 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5824 | break; |
| 5825 | } |
| 5826 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5827 | case DataType::Type::kReference: { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5828 | static_assert( |
| 5829 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5830 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5831 | // /* HeapReference<Object> */ out = |
| 5832 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5833 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5834 | // Note that a potential implicit null check is handled in this |
| 5835 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 5836 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5837 | instruction, out_loc, obj, data_offset, index, /* needs_null_check= */ true); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5838 | } else { |
| 5839 | Register out = out_loc.AsRegister<Register>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5840 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| 5841 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5842 | // If read barriers are enabled, emit read barriers other than |
| 5843 | // Baker's using a slow path (and also unpoison the loaded |
| 5844 | // reference, if heap poisoning is enabled). |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5845 | if (index.IsConstant()) { |
| 5846 | uint32_t offset = |
| 5847 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5848 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5849 | } else { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5850 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5851 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5852 | } |
| 5853 | } |
| 5854 | break; |
| 5855 | } |
| 5856 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5857 | case DataType::Type::kInt64: { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5858 | DCHECK_NE(obj, out_loc.AsRegisterPairLow<Register>()); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5859 | __ movl(out_loc.AsRegisterPairLow<Register>(), |
| 5860 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
| 5861 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5862 | __ movl(out_loc.AsRegisterPairHigh<Register>(), |
| 5863 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset + kX86WordSize)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5864 | break; |
| 5865 | } |
| 5866 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5867 | case DataType::Type::kFloat32: { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5868 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5869 | __ movss(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5870 | break; |
| 5871 | } |
| 5872 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5873 | case DataType::Type::kFloat64: { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5874 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5875 | __ movsd(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5876 | break; |
| 5877 | } |
| 5878 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5879 | case DataType::Type::kUint32: |
| 5880 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5881 | case DataType::Type::kVoid: |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5882 | LOG(FATAL) << "Unreachable type " << type; |
| Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5883 | UNREACHABLE(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5884 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5885 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5886 | if (type == DataType::Type::kReference || type == DataType::Type::kInt64) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5887 | // Potential implicit null checks, in the case of reference or |
| 5888 | // long arrays, are handled in the previous switch statement. |
| 5889 | } else { |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5890 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5891 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5892 | } |
| 5893 | |
| 5894 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5895 | DataType::Type value_type = instruction->GetComponentType(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5896 | |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5897 | bool needs_write_barrier = |
| 5898 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5899 | bool needs_type_check = instruction->NeedsTypeCheck(); |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5900 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5901 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5902 | instruction, |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5903 | needs_type_check ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5904 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5905 | bool is_byte_type = DataType::Size(value_type) == 1u; |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5906 | // We need the inputs to be different than the output in case of long operation. |
| 5907 | // In case of a byte operation, the register allocator does not support multiple |
| 5908 | // inputs that die at entry with one in a specific register. |
| 5909 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5910 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5911 | if (is_byte_type) { |
| 5912 | // Ensure the value is in a byte register. |
| 5913 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5914 | } else if (DataType::IsFloatingPointType(value_type)) { |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5915 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5916 | } else { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5917 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 5918 | } |
| 5919 | if (needs_write_barrier) { |
| 5920 | // Temporary registers for the write barrier. |
| 5921 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 5922 | // Ensure the card is in a byte register. |
| Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5923 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5924 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5925 | } |
| 5926 | |
| 5927 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 5928 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5929 | Location array_loc = locations->InAt(0); |
| 5930 | Register array = array_loc.AsRegister<Register>(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5931 | Location index = locations->InAt(1); |
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5932 | Location value = locations->InAt(2); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5933 | DataType::Type value_type = instruction->GetComponentType(); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5934 | bool needs_type_check = instruction->NeedsTypeCheck(); |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5935 | bool needs_write_barrier = |
| 5936 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5937 | |
| 5938 | switch (value_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5939 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5940 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5941 | case DataType::Type::kInt8: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5942 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5943 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_1, offset); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5944 | if (value.IsRegister()) { |
| 5945 | __ movb(address, value.AsRegister<ByteRegister>()); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5946 | } else { |
| Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5947 | __ movb(address, Immediate(CodeGenerator::GetInt8ValueOf(value.GetConstant()))); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5948 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5949 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5950 | break; |
| 5951 | } |
| 5952 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5953 | case DataType::Type::kUint16: |
| 5954 | case DataType::Type::kInt16: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5955 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5956 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_2, offset); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5957 | if (value.IsRegister()) { |
| 5958 | __ movw(address, value.AsRegister<Register>()); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5959 | } else { |
| Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5960 | __ movw(address, Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5961 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5962 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5963 | break; |
| 5964 | } |
| 5965 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5966 | case DataType::Type::kReference: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5967 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5968 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5969 | |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5970 | if (!value.IsRegister()) { |
| 5971 | // Just setting null. |
| 5972 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5973 | DCHECK(value.IsConstant()) << value; |
| 5974 | __ movl(address, Immediate(0)); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5975 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5976 | DCHECK(!needs_write_barrier); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5977 | DCHECK(!needs_type_check); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5978 | break; |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5979 | } |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5980 | |
| 5981 | DCHECK(needs_write_barrier); |
| 5982 | Register register_value = value.AsRegister<Register>(); |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5983 | Location temp_loc = locations->GetTemp(0); |
| 5984 | Register temp = temp_loc.AsRegister<Register>(); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5985 | |
| 5986 | bool can_value_be_null = instruction->GetValueCanBeNull(); |
| 5987 | NearLabel do_store; |
| 5988 | if (can_value_be_null) { |
| 5989 | __ testl(register_value, register_value); |
| 5990 | __ j(kEqual, &do_store); |
| 5991 | } |
| 5992 | |
| 5993 | SlowPathCode* slow_path = nullptr; |
| 5994 | if (needs_type_check) { |
| Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 5995 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathX86(instruction); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5996 | codegen_->AddSlowPath(slow_path); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5997 | |
| 5998 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5999 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6000 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6001 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6002 | // Note that when Baker read barriers are enabled, the type |
| 6003 | // checks are performed without read barriers. This is fine, |
| 6004 | // even in the case where a class object is in the from-space |
| 6005 | // after the flip, as a comparison involving such a type would |
| 6006 | // not produce a false positive; it may of course produce a |
| 6007 | // false negative, in which case we would take the ArraySet |
| 6008 | // slow path. |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6009 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6010 | // /* HeapReference<Class> */ temp = array->klass_ |
| 6011 | __ movl(temp, Address(array, class_offset)); |
| 6012 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6013 | __ MaybeUnpoisonHeapReference(temp); |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6014 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6015 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 6016 | __ movl(temp, Address(temp, component_offset)); |
| 6017 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 6018 | // nor the object reference in `register_value->klass`, as |
| 6019 | // we are comparing two poisoned references. |
| 6020 | __ cmpl(temp, Address(register_value, class_offset)); |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6021 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6022 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6023 | NearLabel do_put; |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6024 | __ j(kEqual, &do_put); |
| 6025 | // If heap poisoning is enabled, the `temp` reference has |
| 6026 | // not been unpoisoned yet; unpoison it now. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6027 | __ MaybeUnpoisonHeapReference(temp); |
| 6028 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6029 | // If heap poisoning is enabled, no need to unpoison the |
| 6030 | // heap reference loaded below, as it is only used for a |
| 6031 | // comparison with null. |
| 6032 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 6033 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6034 | __ Bind(&do_put); |
| 6035 | } else { |
| 6036 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6037 | } |
| Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6038 | } |
| 6039 | |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6040 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 6041 | codegen_->MarkGCCard( |
| 6042 | temp, card, array, value.AsRegister<Register>(), /* value_can_be_null= */ false); |
| 6043 | |
| 6044 | if (can_value_be_null) { |
| 6045 | DCHECK(do_store.IsLinked()); |
| 6046 | __ Bind(&do_store); |
| 6047 | } |
| 6048 | |
| 6049 | Register source = register_value; |
| Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6050 | if (kPoisonHeapReferences) { |
| 6051 | __ movl(temp, register_value); |
| 6052 | __ PoisonHeapReference(temp); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6053 | source = temp; |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6054 | } |
| 6055 | |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6056 | __ movl(address, source); |
| 6057 | |
| 6058 | if (can_value_be_null || !needs_type_check) { |
| 6059 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6060 | } |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6061 | |
| Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6062 | if (slow_path != nullptr) { |
| 6063 | __ Bind(slow_path->GetExitLabel()); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6064 | } |
| 6065 | |
| 6066 | break; |
| 6067 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6068 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6069 | case DataType::Type::kInt32: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6070 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6071 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6072 | if (value.IsRegister()) { |
| 6073 | __ movl(address, value.AsRegister<Register>()); |
| 6074 | } else { |
| 6075 | DCHECK(value.IsConstant()) << value; |
| 6076 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 6077 | __ movl(address, Immediate(v)); |
| 6078 | } |
| 6079 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6080 | break; |
| 6081 | } |
| 6082 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6083 | case DataType::Type::kInt64: { |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6084 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6085 | if (value.IsRegisterPair()) { |
| 6086 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 6087 | value.AsRegisterPairLow<Register>()); |
| 6088 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6089 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 6090 | value.AsRegisterPairHigh<Register>()); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6091 | } else { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6092 | DCHECK(value.IsConstant()); |
| 6093 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
| 6094 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 6095 | Immediate(Low32Bits(val))); |
| 6096 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6097 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 6098 | Immediate(High32Bits(val))); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6099 | } |
| 6100 | break; |
| 6101 | } |
| 6102 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6103 | case DataType::Type::kFloat32: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6104 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6105 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6106 | if (value.IsFpuRegister()) { |
| 6107 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 6108 | } else { |
| 6109 | DCHECK(value.IsConstant()); |
| 6110 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 6111 | __ movl(address, Immediate(v)); |
| 6112 | } |
| 6113 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6114 | break; |
| 6115 | } |
| 6116 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6117 | case DataType::Type::kFloat64: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6118 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6119 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6120 | if (value.IsFpuRegister()) { |
| 6121 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 6122 | } else { |
| 6123 | DCHECK(value.IsConstant()); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6124 | Address address_hi = |
| 6125 | CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset + kX86WordSize); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6126 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 6127 | __ movl(address, Immediate(Low32Bits(v))); |
| 6128 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6129 | __ movl(address_hi, Immediate(High32Bits(v))); |
| 6130 | } |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6131 | break; |
| 6132 | } |
| 6133 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 6134 | case DataType::Type::kUint32: |
| 6135 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6136 | case DataType::Type::kVoid: |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6137 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 6138 | UNREACHABLE(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6139 | } |
| 6140 | } |
| 6141 | |
| 6142 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6143 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 6144 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6145 | if (!instruction->IsEmittedAtUseSite()) { |
| 6146 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6147 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6148 | } |
| 6149 | |
| 6150 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6151 | if (instruction->IsEmittedAtUseSite()) { |
| 6152 | return; |
| 6153 | } |
| 6154 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6155 | LocationSummary* locations = instruction->GetLocations(); |
| Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 6156 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6157 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 6158 | Register out = locations->Out().AsRegister<Register>(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6159 | __ movl(out, Address(obj, offset)); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6160 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6161 | // Mask out most significant bit in case the array is String's array of char. |
| 6162 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6163 | __ shrl(out, Immediate(1)); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6164 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6165 | } |
| 6166 | |
| 6167 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6168 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6169 | InvokeRuntimeCallingConvention calling_convention; |
| 6170 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6171 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 6172 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 6173 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6174 | HInstruction* length = instruction->InputAt(1); |
| 6175 | if (!length->IsEmittedAtUseSite()) { |
| 6176 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 6177 | } |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6178 | // Need register to see array's length. |
| 6179 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 6180 | locations->AddTemp(Location::RequiresRegister()); |
| 6181 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6182 | } |
| 6183 | |
| 6184 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6185 | const bool is_string_compressed_char_at = |
| 6186 | mirror::kUseStringCompression && instruction->IsStringCharAt(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6187 | LocationSummary* locations = instruction->GetLocations(); |
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 6188 | Location index_loc = locations->InAt(0); |
| 6189 | Location length_loc = locations->InAt(1); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6190 | SlowPathCode* slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6191 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathX86(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6192 | |
| Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 6193 | if (length_loc.IsConstant()) { |
| 6194 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 6195 | if (index_loc.IsConstant()) { |
| 6196 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 6197 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 6198 | if (index < 0 || index >= length) { |
| 6199 | codegen_->AddSlowPath(slow_path); |
| 6200 | __ jmp(slow_path->GetEntryLabel()); |
| 6201 | } else { |
| 6202 | // Some optimization after BCE may have generated this, and we should not |
| 6203 | // generate a bounds check if it is a valid range. |
| 6204 | } |
| 6205 | return; |
| 6206 | } |
| 6207 | |
| 6208 | // We have to reverse the jump condition because the length is the constant. |
| 6209 | Register index_reg = index_loc.AsRegister<Register>(); |
| 6210 | __ cmpl(index_reg, Immediate(length)); |
| 6211 | codegen_->AddSlowPath(slow_path); |
| 6212 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 6213 | } else { |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6214 | HInstruction* array_length = instruction->InputAt(1); |
| 6215 | if (array_length->IsEmittedAtUseSite()) { |
| 6216 | // Address the length field in the array. |
| 6217 | DCHECK(array_length->IsArrayLength()); |
| 6218 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 6219 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 6220 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6221 | if (is_string_compressed_char_at) { |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6222 | // TODO: if index_loc.IsConstant(), compare twice the index (to compensate for |
| 6223 | // the string compression flag) with the in-memory length and avoid the temporary. |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6224 | Register length_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 6225 | __ movl(length_reg, array_len); |
| 6226 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6227 | __ shrl(length_reg, Immediate(1)); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6228 | codegen_->GenerateIntCompare(length_reg, index_loc); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6229 | } else { |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6230 | // Checking bounds for general case: |
| 6231 | // Array of char or string's array with feature compression off. |
| 6232 | if (index_loc.IsConstant()) { |
| 6233 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 6234 | __ cmpl(array_len, Immediate(value)); |
| 6235 | } else { |
| 6236 | __ cmpl(array_len, index_loc.AsRegister<Register>()); |
| 6237 | } |
| 6238 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6239 | } |
| Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 6240 | } else { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6241 | codegen_->GenerateIntCompare(length_loc, index_loc); |
| Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 6242 | } |
| 6243 | codegen_->AddSlowPath(slow_path); |
| 6244 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 6245 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6246 | } |
| 6247 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6248 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6249 | LOG(FATAL) << "Unreachable"; |
| Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6250 | } |
| 6251 | |
| 6252 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
| Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 6253 | if (instruction->GetNext()->IsSuspendCheck() && |
| 6254 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 6255 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 6256 | // The back edge will generate the suspend check. |
| 6257 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 6258 | } |
| 6259 | |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6260 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 6261 | } |
| 6262 | |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6263 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6264 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6265 | instruction, LocationSummary::kCallOnSlowPath); |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 6266 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 6267 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 6268 | // registers in full width (since the runtime only saves/restores lower part). |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6269 | locations->SetCustomSlowPathCallerSaves( |
| 6270 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6271 | } |
| 6272 | |
| 6273 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6274 | HBasicBlock* block = instruction->GetBlock(); |
| 6275 | if (block->GetLoopInformation() != nullptr) { |
| 6276 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 6277 | // The back edge will generate the suspend check. |
| 6278 | return; |
| 6279 | } |
| 6280 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 6281 | // The goto will generate the suspend check. |
| 6282 | return; |
| 6283 | } |
| 6284 | GenerateSuspendCheck(instruction, nullptr); |
| 6285 | } |
| 6286 | |
| 6287 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 6288 | HBasicBlock* successor) { |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6289 | SuspendCheckSlowPathX86* slow_path = |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6290 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 6291 | if (slow_path == nullptr) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6292 | slow_path = |
| 6293 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathX86(instruction, successor); |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6294 | instruction->SetSlowPath(slow_path); |
| 6295 | codegen_->AddSlowPath(slow_path); |
| 6296 | if (successor != nullptr) { |
| 6297 | DCHECK(successor->IsLoopHeader()); |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6298 | } |
| 6299 | } else { |
| 6300 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 6301 | } |
| 6302 | |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6303 | __ fs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86PointerSize>().Int32Value()), |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6304 | Immediate(0)); |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6305 | if (successor == nullptr) { |
| 6306 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6307 | __ Bind(slow_path->GetReturnLabel()); |
| 6308 | } else { |
| 6309 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 6310 | __ jmp(slow_path->GetEntryLabel()); |
| 6311 | } |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6312 | } |
| 6313 | |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6314 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 6315 | return codegen_->GetAssembler(); |
| 6316 | } |
| 6317 | |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6318 | void ParallelMoveResolverX86::MoveMemoryToMemory(int dst, int src, int number_of_words) { |
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6319 | ScratchRegisterScope ensure_scratch( |
| 6320 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 6321 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 6322 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6323 | |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6324 | // Now that temp register is available (possibly spilled), move blocks of memory. |
| 6325 | for (int i = 0; i < number_of_words; i++) { |
| 6326 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 6327 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 6328 | stack_offset += kX86WordSize; |
| 6329 | } |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6330 | } |
| 6331 | |
| 6332 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6333 | MoveOperands* move = moves_[index]; |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6334 | Location source = move->GetSource(); |
| 6335 | Location destination = move->GetDestination(); |
| 6336 | |
| 6337 | if (source.IsRegister()) { |
| 6338 | if (destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6339 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6340 | } else if (destination.IsFpuRegister()) { |
| 6341 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6342 | } else { |
| 6343 | DCHECK(destination.IsStackSlot()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6344 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6345 | } |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6346 | } else if (source.IsRegisterPair()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6347 | size_t elem_size = DataType::Size(DataType::Type::kInt32); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6348 | // Create stack space for 2 elements. |
| 6349 | __ subl(ESP, Immediate(2 * elem_size)); |
| 6350 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 6351 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 6352 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 6353 | // And remove the temporary stack space we allocated. |
| 6354 | __ addl(ESP, Immediate(2 * elem_size)); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6355 | } else if (source.IsFpuRegister()) { |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6356 | if (destination.IsRegister()) { |
| 6357 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
| 6358 | } else if (destination.IsFpuRegister()) { |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6359 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6360 | } else if (destination.IsRegisterPair()) { |
| 6361 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 6362 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 6363 | __ psrlq(src_reg, Immediate(32)); |
| 6364 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6365 | } else if (destination.IsStackSlot()) { |
| 6366 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6367 | } else if (destination.IsDoubleStackSlot()) { |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6368 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6369 | } else { |
| 6370 | DCHECK(destination.IsSIMDStackSlot()); |
| 6371 | __ movups(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6372 | } |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6373 | } else if (source.IsStackSlot()) { |
| 6374 | if (destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6375 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6376 | } else if (destination.IsFpuRegister()) { |
| 6377 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6378 | } else { |
| 6379 | DCHECK(destination.IsStackSlot()); |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6380 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 1); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6381 | } |
| 6382 | } else if (source.IsDoubleStackSlot()) { |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6383 | if (destination.IsRegisterPair()) { |
| 6384 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 6385 | __ movl(destination.AsRegisterPairHigh<Register>(), |
| 6386 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 6387 | } else if (destination.IsFpuRegister()) { |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6388 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 6389 | } else { |
| 6390 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6391 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 2); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6392 | } |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6393 | } else if (source.IsSIMDStackSlot()) { |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6394 | if (destination.IsFpuRegister()) { |
| 6395 | __ movups(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 6396 | } else { |
| 6397 | DCHECK(destination.IsSIMDStackSlot()); |
| 6398 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 4); |
| 6399 | } |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 6400 | } else if (source.IsConstant()) { |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6401 | HConstant* constant = source.GetConstant(); |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 6402 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 6403 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6404 | if (destination.IsRegister()) { |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 6405 | if (value == 0) { |
| 6406 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 6407 | } else { |
| 6408 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 6409 | } |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6410 | } else { |
| 6411 | DCHECK(destination.IsStackSlot()) << destination; |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 6412 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6413 | } |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6414 | } else if (constant->IsFloatConstant()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6415 | float fp_value = constant->AsFloatConstant()->GetValue(); |
| Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 6416 | int32_t value = bit_cast<int32_t, float>(fp_value); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6417 | Immediate imm(value); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6418 | if (destination.IsFpuRegister()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6419 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 6420 | if (value == 0) { |
| 6421 | // Easy handling of 0.0. |
| 6422 | __ xorps(dest, dest); |
| 6423 | } else { |
| 6424 | ScratchRegisterScope ensure_scratch( |
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6425 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 6426 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 6427 | __ movl(temp, Immediate(value)); |
| 6428 | __ movd(dest, temp); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6429 | } |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6430 | } else { |
| 6431 | DCHECK(destination.IsStackSlot()) << destination; |
| 6432 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 6433 | } |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6434 | } else if (constant->IsLongConstant()) { |
| 6435 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 6436 | int32_t low_value = Low32Bits(value); |
| 6437 | int32_t high_value = High32Bits(value); |
| 6438 | Immediate low(low_value); |
| 6439 | Immediate high(high_value); |
| 6440 | if (destination.IsDoubleStackSlot()) { |
| 6441 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 6442 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 6443 | } else { |
| 6444 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 6445 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 6446 | } |
| 6447 | } else { |
| 6448 | DCHECK(constant->IsDoubleConstant()); |
| 6449 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
| Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 6450 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6451 | int32_t low_value = Low32Bits(value); |
| 6452 | int32_t high_value = High32Bits(value); |
| 6453 | Immediate low(low_value); |
| 6454 | Immediate high(high_value); |
| 6455 | if (destination.IsFpuRegister()) { |
| 6456 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 6457 | if (value == 0) { |
| 6458 | // Easy handling of 0.0. |
| 6459 | __ xorpd(dest, dest); |
| 6460 | } else { |
| 6461 | __ pushl(high); |
| 6462 | __ pushl(low); |
| 6463 | __ movsd(dest, Address(ESP, 0)); |
| 6464 | __ addl(ESP, Immediate(8)); |
| 6465 | } |
| 6466 | } else { |
| 6467 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6468 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 6469 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 6470 | } |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 6471 | } |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6472 | } else { |
| Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 6473 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6474 | } |
| 6475 | } |
| 6476 | |
| Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 6477 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6478 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 6479 | ScratchRegisterScope ensure_scratch( |
| 6480 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 6481 | |
| 6482 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 6483 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 6484 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 6485 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6486 | } |
| 6487 | |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6488 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6489 | ScratchRegisterScope ensure_scratch( |
| 6490 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 6491 | |
| 6492 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 6493 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 6494 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 6495 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 6496 | __ movd(reg, temp_reg); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6497 | } |
| 6498 | |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6499 | void ParallelMoveResolverX86::Exchange128(XmmRegister reg, int mem) { |
| 6500 | size_t extra_slot = 4 * kX86WordSize; |
| 6501 | __ subl(ESP, Immediate(extra_slot)); |
| 6502 | __ movups(Address(ESP, 0), XmmRegister(reg)); |
| 6503 | ExchangeMemory(0, mem + extra_slot, 4); |
| 6504 | __ movups(XmmRegister(reg), Address(ESP, 0)); |
| 6505 | __ addl(ESP, Immediate(extra_slot)); |
| 6506 | } |
| 6507 | |
| 6508 | void ParallelMoveResolverX86::ExchangeMemory(int mem1, int mem2, int number_of_words) { |
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6509 | ScratchRegisterScope ensure_scratch1( |
| 6510 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6511 | |
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6512 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 6513 | ScratchRegisterScope ensure_scratch2( |
| 6514 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6515 | |
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6516 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 6517 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6518 | |
| 6519 | // Now that temp registers are available (possibly spilled), exchange blocks of memory. |
| 6520 | for (int i = 0; i < number_of_words; i++) { |
| 6521 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 6522 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 6523 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 6524 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
| 6525 | stack_offset += kX86WordSize; |
| 6526 | } |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6527 | } |
| 6528 | |
| 6529 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6530 | MoveOperands* move = moves_[index]; |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6531 | Location source = move->GetSource(); |
| 6532 | Location destination = move->GetDestination(); |
| 6533 | |
| 6534 | if (source.IsRegister() && destination.IsRegister()) { |
| Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 6535 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 6536 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 6537 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 6538 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 6539 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6540 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6541 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6542 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6543 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6544 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6545 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 1); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6546 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 6547 | // Use XOR Swap algorithm to avoid a temporary. |
| 6548 | DCHECK_NE(source.reg(), destination.reg()); |
| 6549 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 6550 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 6551 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 6552 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 6553 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 6554 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 6555 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6556 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 6557 | // Take advantage of the 16 bytes in the XMM register. |
| 6558 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 6559 | Address stack(ESP, destination.GetStackIndex()); |
| 6560 | // Load the double into the high doubleword. |
| 6561 | __ movhpd(reg, stack); |
| 6562 | |
| 6563 | // Store the low double into the destination. |
| 6564 | __ movsd(stack, reg); |
| 6565 | |
| 6566 | // Move the high double to the low double. |
| 6567 | __ psrldq(reg, Immediate(8)); |
| 6568 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 6569 | // Take advantage of the 16 bytes in the XMM register. |
| 6570 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 6571 | Address stack(ESP, source.GetStackIndex()); |
| 6572 | // Load the double into the high doubleword. |
| 6573 | __ movhpd(reg, stack); |
| 6574 | |
| 6575 | // Store the low double into the destination. |
| 6576 | __ movsd(stack, reg); |
| 6577 | |
| 6578 | // Move the high double to the low double. |
| 6579 | __ psrldq(reg, Immediate(8)); |
| 6580 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6581 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 2); |
| 6582 | } else if (source.IsSIMDStackSlot() && destination.IsSIMDStackSlot()) { |
| 6583 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 4); |
| 6584 | } else if (source.IsFpuRegister() && destination.IsSIMDStackSlot()) { |
| 6585 | Exchange128(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 6586 | } else if (destination.IsFpuRegister() && source.IsSIMDStackSlot()) { |
| 6587 | Exchange128(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6588 | } else { |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6589 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6590 | } |
| 6591 | } |
| 6592 | |
| 6593 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 6594 | __ pushl(static_cast<Register>(reg)); |
| 6595 | } |
| 6596 | |
| 6597 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 6598 | __ popl(static_cast<Register>(reg)); |
| Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6599 | } |
| 6600 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6601 | HLoadClass::LoadKind CodeGeneratorX86::GetSupportedLoadClassKind( |
| 6602 | HLoadClass::LoadKind desired_class_load_kind) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6603 | switch (desired_class_load_kind) { |
| Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6604 | case HLoadClass::LoadKind::kInvalid: |
| 6605 | LOG(FATAL) << "UNREACHABLE"; |
| 6606 | UNREACHABLE(); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6607 | case HLoadClass::LoadKind::kReferrersClass: |
| 6608 | break; |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6609 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6610 | case HLoadClass::LoadKind::kBootImageRelRo: |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6611 | case HLoadClass::LoadKind::kBssEntry: |
| Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6612 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6613 | break; |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6614 | case HLoadClass::LoadKind::kJitBootImageAddress: |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6615 | case HLoadClass::LoadKind::kJitTableAddress: |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6616 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6617 | break; |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6618 | case HLoadClass::LoadKind::kRuntimeCall: |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6619 | break; |
| 6620 | } |
| 6621 | return desired_class_load_kind; |
| 6622 | } |
| 6623 | |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6624 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6625 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6626 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6627 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6628 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6629 | cls, |
| 6630 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6631 | Location::RegisterLocation(EAX)); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6632 | DCHECK_EQ(calling_convention.GetRegisterAt(0), EAX); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6633 | return; |
| 6634 | } |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6635 | DCHECK(!cls->NeedsAccessCheck()); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6636 | |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6637 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 6638 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6639 | ? LocationSummary::kCallOnSlowPath |
| 6640 | : LocationSummary::kNoCall; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6641 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6642 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6643 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6644 | } |
| 6645 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6646 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6647 | load_kind == HLoadClass::LoadKind::kBootImageLinkTimePcRelative || |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6648 | load_kind == HLoadClass::LoadKind::kBootImageRelRo || |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6649 | load_kind == HLoadClass::LoadKind::kBssEntry) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6650 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6651 | } |
| 6652 | locations->SetOut(Location::RequiresRegister()); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6653 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 6654 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 6655 | // Rely on the type resolution and/or initialization to save everything. |
| Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 6656 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6657 | } else { |
| 6658 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6659 | } |
| 6660 | } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6661 | } |
| 6662 | |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6663 | Label* CodeGeneratorX86::NewJitRootClassPatch(const DexFile& dex_file, |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6664 | dex::TypeIndex type_index, |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6665 | Handle<mirror::Class> handle) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6666 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6667 | // Add a patch entry and return the label. |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6668 | jit_class_patches_.emplace_back(&dex_file, type_index.index_); |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6669 | PatchInfo<Label>* info = &jit_class_patches_.back(); |
| 6670 | return &info->label; |
| 6671 | } |
| 6672 | |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6673 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6674 | // move. |
| 6675 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6676 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6677 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6678 | codegen_->GenerateLoadClassRuntimeCall(cls); |
| Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6679 | return; |
| 6680 | } |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6681 | DCHECK(!cls->NeedsAccessCheck()); |
| Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6682 | |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6683 | LocationSummary* locations = cls->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6684 | Location out_loc = locations->Out(); |
| 6685 | Register out = out_loc.AsRegister<Register>(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6686 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6687 | bool generate_null_check = false; |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6688 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 6689 | ? kWithoutReadBarrier |
| 6690 | : kCompilerReadBarrierOption; |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6691 | switch (load_kind) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6692 | case HLoadClass::LoadKind::kReferrersClass: { |
| 6693 | DCHECK(!cls->CanCallRuntime()); |
| 6694 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 6695 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6696 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 6697 | GenerateGcRootFieldLoad( |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6698 | cls, |
| 6699 | out_loc, |
| 6700 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6701 | /* fixup_label= */ nullptr, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6702 | read_barrier_option); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6703 | break; |
| 6704 | } |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6705 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
| Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 6706 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 6707 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6708 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6709 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6710 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6711 | codegen_->RecordBootImageTypePatch(cls); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6712 | break; |
| 6713 | } |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6714 | case HLoadClass::LoadKind::kBootImageRelRo: { |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6715 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 6716 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6717 | __ movl(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6718 | codegen_->RecordBootImageRelRoPatch(cls->InputAt(0)->AsX86ComputeBaseMethodAddress(), |
| 6719 | codegen_->GetBootImageOffset(cls)); |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6720 | break; |
| 6721 | } |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6722 | case HLoadClass::LoadKind::kBssEntry: { |
| 6723 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6724 | Address address(method_address, CodeGeneratorX86::kDummy32BitOffset); |
| 6725 | Label* fixup_label = codegen_->NewTypeBssEntryPatch(cls); |
| 6726 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
| Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 6727 | // No need for memory fence, thanks to the x86 memory model. |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6728 | generate_null_check = true; |
| 6729 | break; |
| 6730 | } |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6731 | case HLoadClass::LoadKind::kJitBootImageAddress: { |
| 6732 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 6733 | uint32_t address = reinterpret_cast32<uint32_t>(cls->GetClass().Get()); |
| 6734 | DCHECK_NE(address, 0u); |
| 6735 | __ movl(out, Immediate(address)); |
| 6736 | break; |
| 6737 | } |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6738 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 6739 | Address address = Address::Absolute(CodeGeneratorX86::kDummy32BitOffset); |
| 6740 | Label* fixup_label = codegen_->NewJitRootClassPatch( |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6741 | cls->GetDexFile(), cls->GetTypeIndex(), cls->GetClass()); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6742 | // /* GcRoot<mirror::Class> */ out = *address |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6743 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6744 | break; |
| 6745 | } |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6746 | case HLoadClass::LoadKind::kRuntimeCall: |
| Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6747 | case HLoadClass::LoadKind::kInvalid: |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6748 | LOG(FATAL) << "UNREACHABLE"; |
| 6749 | UNREACHABLE(); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6750 | } |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6751 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6752 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6753 | DCHECK(cls->CanCallRuntime()); |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 6754 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86(cls, cls); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6755 | codegen_->AddSlowPath(slow_path); |
| Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6756 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6757 | if (generate_null_check) { |
| 6758 | __ testl(out, out); |
| 6759 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6760 | } |
| Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6761 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6762 | if (cls->MustGenerateClinitCheck()) { |
| 6763 | GenerateClassInitializationCheck(slow_path, out); |
| 6764 | } else { |
| 6765 | __ Bind(slow_path->GetExitLabel()); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6766 | } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6767 | } |
| 6768 | } |
| 6769 | |
| Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 6770 | void LocationsBuilderX86::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 6771 | InvokeRuntimeCallingConvention calling_convention; |
| 6772 | Location location = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 6773 | CodeGenerator::CreateLoadMethodHandleRuntimeCallLocationSummary(load, location, location); |
| 6774 | } |
| 6775 | |
| 6776 | void InstructionCodeGeneratorX86::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 6777 | codegen_->GenerateLoadMethodHandleRuntimeCall(load); |
| 6778 | } |
| 6779 | |
| Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6780 | void LocationsBuilderX86::VisitLoadMethodType(HLoadMethodType* load) { |
| 6781 | InvokeRuntimeCallingConvention calling_convention; |
| 6782 | Location location = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 6783 | CodeGenerator::CreateLoadMethodTypeRuntimeCallLocationSummary(load, location, location); |
| 6784 | } |
| 6785 | |
| 6786 | void InstructionCodeGeneratorX86::VisitLoadMethodType(HLoadMethodType* load) { |
| 6787 | codegen_->GenerateLoadMethodTypeRuntimeCall(load); |
| 6788 | } |
| 6789 | |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6790 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 6791 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6792 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6793 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6794 | if (check->HasUses()) { |
| 6795 | locations->SetOut(Location::SameAsFirstInput()); |
| 6796 | } |
| Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 6797 | // Rely on the type initialization to save everything we need. |
| 6798 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6799 | } |
| 6800 | |
| 6801 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6802 | // We assume the class to not be null. |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 6803 | SlowPathCode* slow_path = |
| 6804 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86(check->GetLoadClass(), check); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6805 | codegen_->AddSlowPath(slow_path); |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6806 | GenerateClassInitializationCheck(slow_path, |
| 6807 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6808 | } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6809 | |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6810 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6811 | SlowPathCode* slow_path, Register class_reg) { |
| Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 6812 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
| 6813 | const size_t status_byte_offset = |
| 6814 | mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte); |
| Vladimir Marko | bf12191 | 2019-06-04 13:49:05 +0100 | [diff] [blame] | 6815 | constexpr uint32_t shifted_visibly_initialized_value = |
| 6816 | enum_cast<uint32_t>(ClassStatus::kVisiblyInitialized) << (status_lsb_position % kBitsPerByte); |
| Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 6817 | |
| Vladimir Marko | bf12191 | 2019-06-04 13:49:05 +0100 | [diff] [blame] | 6818 | __ cmpb(Address(class_reg, status_byte_offset), Immediate(shifted_visibly_initialized_value)); |
| Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 6819 | __ j(kBelow, slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6820 | __ Bind(slow_path->GetExitLabel()); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6821 | } |
| 6822 | |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6823 | void InstructionCodeGeneratorX86::GenerateBitstringTypeCheckCompare(HTypeCheckInstruction* check, |
| 6824 | Register temp) { |
| 6825 | uint32_t path_to_root = check->GetBitstringPathToRoot(); |
| 6826 | uint32_t mask = check->GetBitstringMask(); |
| 6827 | DCHECK(IsPowerOfTwo(mask + 1)); |
| 6828 | size_t mask_bits = WhichPowerOf2(mask + 1); |
| 6829 | |
| 6830 | if (mask_bits == 16u) { |
| 6831 | // Compare the bitstring in memory. |
| 6832 | __ cmpw(Address(temp, mirror::Class::StatusOffset()), Immediate(path_to_root)); |
| 6833 | } else { |
| 6834 | // /* uint32_t */ temp = temp->status_ |
| 6835 | __ movl(temp, Address(temp, mirror::Class::StatusOffset())); |
| 6836 | // Compare the bitstring bits using SUB. |
| 6837 | __ subl(temp, Immediate(path_to_root)); |
| 6838 | // Shift out bits that do not contribute to the comparison. |
| 6839 | __ shll(temp, Immediate(32u - mask_bits)); |
| 6840 | } |
| 6841 | } |
| 6842 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6843 | HLoadString::LoadKind CodeGeneratorX86::GetSupportedLoadStringKind( |
| 6844 | HLoadString::LoadKind desired_string_load_kind) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6845 | switch (desired_string_load_kind) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6846 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6847 | case HLoadString::LoadKind::kBootImageRelRo: |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6848 | case HLoadString::LoadKind::kBssEntry: |
| Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6849 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6850 | break; |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6851 | case HLoadString::LoadKind::kJitBootImageAddress: |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6852 | case HLoadString::LoadKind::kJitTableAddress: |
| 6853 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6854 | break; |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6855 | case HLoadString::LoadKind::kRuntimeCall: |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6856 | break; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6857 | } |
| 6858 | return desired_string_load_kind; |
| 6859 | } |
| 6860 | |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6861 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6862 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6863 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6864 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6865 | if (load_kind == HLoadString::LoadKind::kBootImageLinkTimePcRelative || |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6866 | load_kind == HLoadString::LoadKind::kBootImageRelRo || |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6867 | load_kind == HLoadString::LoadKind::kBssEntry) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6868 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6869 | } |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6870 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
| Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6871 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 6872 | } else { |
| 6873 | locations->SetOut(Location::RequiresRegister()); |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6874 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 6875 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6876 | // Rely on the pResolveString to save everything. |
| Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 6877 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6878 | } else { |
| 6879 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6880 | } |
| 6881 | } |
| Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6882 | } |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6883 | } |
| 6884 | |
| Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6885 | Label* CodeGeneratorX86::NewJitRootStringPatch(const DexFile& dex_file, |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6886 | dex::StringIndex string_index, |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6887 | Handle<mirror::String> handle) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6888 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6889 | // Add a patch entry and return the label. |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6890 | jit_string_patches_.emplace_back(&dex_file, string_index.index_); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6891 | PatchInfo<Label>* info = &jit_string_patches_.back(); |
| 6892 | return &info->label; |
| 6893 | } |
| 6894 | |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6895 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6896 | // move. |
| 6897 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
| Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6898 | LocationSummary* locations = load->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6899 | Location out_loc = locations->Out(); |
| 6900 | Register out = out_loc.AsRegister<Register>(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6901 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6902 | switch (load->GetLoadKind()) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6903 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 6904 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 6905 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6906 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6907 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6908 | codegen_->RecordBootImageStringPatch(load); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6909 | return; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6910 | } |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6911 | case HLoadString::LoadKind::kBootImageRelRo: { |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6912 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 6913 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6914 | __ movl(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6915 | codegen_->RecordBootImageRelRoPatch(load->InputAt(0)->AsX86ComputeBaseMethodAddress(), |
| 6916 | codegen_->GetBootImageOffset(load)); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6917 | return; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6918 | } |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6919 | case HLoadString::LoadKind::kBssEntry: { |
| 6920 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6921 | Address address = Address(method_address, CodeGeneratorX86::kDummy32BitOffset); |
| 6922 | Label* fixup_label = codegen_->NewStringBssEntryPatch(load); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6923 | // /* GcRoot<mirror::String> */ out = *address /* PC-relative */ |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6924 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
| Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 6925 | // No need for memory fence, thanks to the x86 memory model. |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6926 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadStringSlowPathX86(load); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6927 | codegen_->AddSlowPath(slow_path); |
| 6928 | __ testl(out, out); |
| 6929 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6930 | __ Bind(slow_path->GetExitLabel()); |
| 6931 | return; |
| 6932 | } |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6933 | case HLoadString::LoadKind::kJitBootImageAddress: { |
| 6934 | uint32_t address = reinterpret_cast32<uint32_t>(load->GetString().Get()); |
| 6935 | DCHECK_NE(address, 0u); |
| 6936 | __ movl(out, Immediate(address)); |
| 6937 | return; |
| 6938 | } |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6939 | case HLoadString::LoadKind::kJitTableAddress: { |
| 6940 | Address address = Address::Absolute(CodeGeneratorX86::kDummy32BitOffset); |
| 6941 | Label* fixup_label = codegen_->NewJitRootStringPatch( |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6942 | load->GetDexFile(), load->GetStringIndex(), load->GetString()); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6943 | // /* GcRoot<mirror::String> */ out = *address |
| 6944 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
| 6945 | return; |
| 6946 | } |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6947 | default: |
| Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6948 | break; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6949 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6950 | |
| Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6951 | // 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] | 6952 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6953 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
| Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6954 | __ movl(calling_convention.GetRegisterAt(0), Immediate(load->GetStringIndex().index_)); |
| Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6955 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 6956 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6957 | } |
| 6958 | |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6959 | static Address GetExceptionTlsAddress() { |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6960 | return Address::Absolute(Thread::ExceptionOffset<kX86PointerSize>().Int32Value()); |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6961 | } |
| 6962 | |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6963 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 6964 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6965 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6966 | locations->SetOut(Location::RequiresRegister()); |
| 6967 | } |
| 6968 | |
| 6969 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6970 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 6971 | } |
| 6972 | |
| 6973 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6974 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6975 | } |
| 6976 | |
| 6977 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6978 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6979 | } |
| 6980 | |
| 6981 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6982 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6983 | instruction, LocationSummary::kCallOnMainOnly); |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6984 | InvokeRuntimeCallingConvention calling_convention; |
| 6985 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6986 | } |
| 6987 | |
| 6988 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6989 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6990 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6991 | } |
| 6992 | |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6993 | // Temp is used for read barrier. |
| 6994 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 6995 | if (kEmitCompilerReadBarrier && |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6996 | !kUseBakerReadBarrier && |
| 6997 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6998 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6999 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 7000 | return 1; |
| 7001 | } |
| 7002 | return 0; |
| 7003 | } |
| 7004 | |
| Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 7005 | // Interface case has 2 temps, one for holding the number of interfaces, one for the current |
| 7006 | // interface pointer, the current interface is compared in memory. |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7007 | // The other checks have one temp for loading the object's class. |
| 7008 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 7009 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7010 | return 2; |
| 7011 | } |
| 7012 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7013 | } |
| 7014 | |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7015 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7016 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7017 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7018 | bool baker_read_barrier_slow_path = false; |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7019 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7020 | case TypeCheckKind::kExactCheck: |
| 7021 | case TypeCheckKind::kAbstractClassCheck: |
| 7022 | case TypeCheckKind::kClassHierarchyCheck: |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7023 | case TypeCheckKind::kArrayObjectCheck: { |
| 7024 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 7025 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 7026 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7027 | break; |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7028 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7029 | case TypeCheckKind::kArrayCheck: |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7030 | case TypeCheckKind::kUnresolvedCheck: |
| 7031 | case TypeCheckKind::kInterfaceCheck: |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7032 | call_kind = LocationSummary::kCallOnSlowPath; |
| 7033 | break; |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7034 | case TypeCheckKind::kBitstringCheck: |
| 7035 | break; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7036 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7037 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7038 | LocationSummary* locations = |
| 7039 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7040 | if (baker_read_barrier_slow_path) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 7041 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7042 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7043 | locations->SetInAt(0, Location::RequiresRegister()); |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7044 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 7045 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 7046 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 7047 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 7048 | } else { |
| 7049 | locations->SetInAt(1, Location::Any()); |
| 7050 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7051 | // Note that TypeCheckSlowPathX86 uses this "out" register too. |
| 7052 | locations->SetOut(Location::RequiresRegister()); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7053 | // When read barriers are enabled, we need a temporary register for some cases. |
| 7054 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7055 | } |
| 7056 | |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7057 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7058 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7059 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7060 | Location obj_loc = locations->InAt(0); |
| 7061 | Register obj = obj_loc.AsRegister<Register>(); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7062 | Location cls = locations->InAt(1); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7063 | Location out_loc = locations->Out(); |
| 7064 | Register out = out_loc.AsRegister<Register>(); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7065 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 7066 | DCHECK_LE(num_temps, 1u); |
| 7067 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7068 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7069 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7070 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7071 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7072 | SlowPathCode* slow_path = nullptr; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7073 | NearLabel done, zero; |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7074 | |
| 7075 | // Return 0 if `obj` is null. |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7076 | // Avoid null check if we know obj is not null. |
| 7077 | if (instruction->MustDoNullCheck()) { |
| 7078 | __ testl(obj, obj); |
| 7079 | __ j(kEqual, &zero); |
| 7080 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7081 | |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7082 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7083 | case TypeCheckKind::kExactCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7084 | ReadBarrierOption read_barrier_option = |
| 7085 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7086 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7087 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7088 | out_loc, |
| 7089 | obj_loc, |
| 7090 | class_offset, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7091 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7092 | if (cls.IsRegister()) { |
| 7093 | __ cmpl(out, cls.AsRegister<Register>()); |
| 7094 | } else { |
| 7095 | DCHECK(cls.IsStackSlot()) << cls; |
| 7096 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 7097 | } |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7098 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7099 | // Classes must be equal for the instanceof to succeed. |
| 7100 | __ j(kNotEqual, &zero); |
| 7101 | __ movl(out, Immediate(1)); |
| 7102 | __ jmp(&done); |
| 7103 | break; |
| 7104 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7105 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7106 | case TypeCheckKind::kAbstractClassCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7107 | ReadBarrierOption read_barrier_option = |
| 7108 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7109 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7110 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7111 | out_loc, |
| 7112 | obj_loc, |
| 7113 | class_offset, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7114 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7115 | // If the class is abstract, we eagerly fetch the super class of the |
| 7116 | // object to avoid doing a comparison we know will fail. |
| 7117 | NearLabel loop; |
| 7118 | __ Bind(&loop); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7119 | // /* HeapReference<Class> */ out = out->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7120 | GenerateReferenceLoadOneRegister(instruction, |
| 7121 | out_loc, |
| 7122 | super_offset, |
| 7123 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7124 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7125 | __ testl(out, out); |
| 7126 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7127 | __ j(kEqual, &done); |
| 7128 | if (cls.IsRegister()) { |
| 7129 | __ cmpl(out, cls.AsRegister<Register>()); |
| 7130 | } else { |
| 7131 | DCHECK(cls.IsStackSlot()) << cls; |
| 7132 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 7133 | } |
| 7134 | __ j(kNotEqual, &loop); |
| 7135 | __ movl(out, Immediate(1)); |
| 7136 | if (zero.IsLinked()) { |
| 7137 | __ jmp(&done); |
| 7138 | } |
| 7139 | break; |
| 7140 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7141 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7142 | case TypeCheckKind::kClassHierarchyCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7143 | ReadBarrierOption read_barrier_option = |
| 7144 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7145 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7146 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7147 | out_loc, |
| 7148 | obj_loc, |
| 7149 | class_offset, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7150 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7151 | // Walk over the class hierarchy to find a match. |
| 7152 | NearLabel loop, success; |
| 7153 | __ Bind(&loop); |
| 7154 | if (cls.IsRegister()) { |
| 7155 | __ cmpl(out, cls.AsRegister<Register>()); |
| 7156 | } else { |
| 7157 | DCHECK(cls.IsStackSlot()) << cls; |
| 7158 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 7159 | } |
| 7160 | __ j(kEqual, &success); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7161 | // /* HeapReference<Class> */ out = out->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7162 | GenerateReferenceLoadOneRegister(instruction, |
| 7163 | out_loc, |
| 7164 | super_offset, |
| 7165 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7166 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7167 | __ testl(out, out); |
| 7168 | __ j(kNotEqual, &loop); |
| 7169 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7170 | __ jmp(&done); |
| 7171 | __ Bind(&success); |
| 7172 | __ movl(out, Immediate(1)); |
| 7173 | if (zero.IsLinked()) { |
| 7174 | __ jmp(&done); |
| 7175 | } |
| 7176 | break; |
| 7177 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7178 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7179 | case TypeCheckKind::kArrayObjectCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7180 | ReadBarrierOption read_barrier_option = |
| 7181 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7182 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7183 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7184 | out_loc, |
| 7185 | obj_loc, |
| 7186 | class_offset, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7187 | read_barrier_option); |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7188 | // Do an exact check. |
| 7189 | NearLabel exact_check; |
| 7190 | if (cls.IsRegister()) { |
| 7191 | __ cmpl(out, cls.AsRegister<Register>()); |
| 7192 | } else { |
| 7193 | DCHECK(cls.IsStackSlot()) << cls; |
| 7194 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 7195 | } |
| 7196 | __ j(kEqual, &exact_check); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7197 | // 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] | 7198 | // /* HeapReference<Class> */ out = out->component_type_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7199 | GenerateReferenceLoadOneRegister(instruction, |
| 7200 | out_loc, |
| 7201 | component_offset, |
| 7202 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7203 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7204 | __ testl(out, out); |
| 7205 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7206 | __ j(kEqual, &done); |
| 7207 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 7208 | __ j(kNotEqual, &zero); |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7209 | __ Bind(&exact_check); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7210 | __ movl(out, Immediate(1)); |
| 7211 | __ jmp(&done); |
| 7212 | break; |
| 7213 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7214 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7215 | case TypeCheckKind::kArrayCheck: { |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7216 | // No read barrier since the slow path will retry upon failure. |
| 7217 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7218 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7219 | out_loc, |
| 7220 | obj_loc, |
| 7221 | class_offset, |
| 7222 | kWithoutReadBarrier); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7223 | if (cls.IsRegister()) { |
| 7224 | __ cmpl(out, cls.AsRegister<Register>()); |
| 7225 | } else { |
| 7226 | DCHECK(cls.IsStackSlot()) << cls; |
| 7227 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 7228 | } |
| 7229 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7230 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7231 | instruction, /* is_fatal= */ false); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7232 | codegen_->AddSlowPath(slow_path); |
| 7233 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 7234 | __ movl(out, Immediate(1)); |
| 7235 | if (zero.IsLinked()) { |
| 7236 | __ jmp(&done); |
| 7237 | } |
| 7238 | break; |
| 7239 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7240 | |
| Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 7241 | case TypeCheckKind::kUnresolvedCheck: |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7242 | case TypeCheckKind::kInterfaceCheck: { |
| 7243 | // 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] | 7244 | // into the slow path for the unresolved and interface check |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7245 | // cases. |
| 7246 | // |
| 7247 | // We cannot directly call the InstanceofNonTrivial runtime |
| 7248 | // entry point without resorting to a type checking slow path |
| 7249 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 7250 | // require to assign fixed registers for the inputs of this |
| 7251 | // HInstanceOf instruction (following the runtime calling |
| 7252 | // convention), which might be cluttered by the potential first |
| 7253 | // read barrier emission at the beginning of this method. |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7254 | // |
| 7255 | // TODO: Introduce a new runtime entry point taking the object |
| 7256 | // to test (instead of its class) as argument, and let it deal |
| 7257 | // with the read barrier issues. This will let us refactor this |
| 7258 | // case of the `switch` code as it was previously (with a direct |
| 7259 | // call to the runtime not using a type checking slow path). |
| 7260 | // This should also be beneficial for the other cases above. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7261 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7262 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7263 | instruction, /* is_fatal= */ false); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7264 | codegen_->AddSlowPath(slow_path); |
| 7265 | __ jmp(slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7266 | if (zero.IsLinked()) { |
| 7267 | __ jmp(&done); |
| 7268 | } |
| 7269 | break; |
| 7270 | } |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7271 | |
| 7272 | case TypeCheckKind::kBitstringCheck: { |
| 7273 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7274 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7275 | out_loc, |
| 7276 | obj_loc, |
| 7277 | class_offset, |
| 7278 | kWithoutReadBarrier); |
| 7279 | |
| 7280 | GenerateBitstringTypeCheckCompare(instruction, out); |
| 7281 | __ j(kNotEqual, &zero); |
| 7282 | __ movl(out, Immediate(1)); |
| 7283 | __ jmp(&done); |
| 7284 | break; |
| 7285 | } |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7286 | } |
| 7287 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7288 | if (zero.IsLinked()) { |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7289 | __ Bind(&zero); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7290 | __ xorl(out, out); |
| 7291 | } |
| 7292 | |
| 7293 | if (done.IsLinked()) { |
| 7294 | __ Bind(&done); |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7295 | } |
| 7296 | |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7297 | if (slow_path != nullptr) { |
| 7298 | __ Bind(slow_path->GetExitLabel()); |
| 7299 | } |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7300 | } |
| 7301 | |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7302 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7303 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7304 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7305 | LocationSummary* locations = |
| 7306 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7307 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7308 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 7309 | // Require a register for the interface check since there is a loop that compares the class to |
| 7310 | // a memory address. |
| 7311 | locations->SetInAt(1, Location::RequiresRegister()); |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7312 | } else if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 7313 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 7314 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 7315 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7316 | } else { |
| 7317 | locations->SetInAt(1, Location::Any()); |
| 7318 | } |
| Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 7319 | // 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] | 7320 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
| 7321 | } |
| 7322 | |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7323 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7324 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7325 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7326 | Location obj_loc = locations->InAt(0); |
| 7327 | Register obj = obj_loc.AsRegister<Register>(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7328 | Location cls = locations->InAt(1); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7329 | Location temp_loc = locations->GetTemp(0); |
| 7330 | Register temp = temp_loc.AsRegister<Register>(); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7331 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 7332 | DCHECK_GE(num_temps, 1u); |
| 7333 | DCHECK_LE(num_temps, 2u); |
| 7334 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 7335 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7336 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7337 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7338 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 7339 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 7340 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 7341 | const uint32_t object_array_data_offset = |
| 7342 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7343 | |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7344 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7345 | SlowPathCode* type_check_slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7346 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
| 7347 | instruction, is_type_check_slow_path_fatal); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7348 | codegen_->AddSlowPath(type_check_slow_path); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7349 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7350 | NearLabel done; |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7351 | // Avoid null check if we know obj is not null. |
| 7352 | if (instruction->MustDoNullCheck()) { |
| 7353 | __ testl(obj, obj); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7354 | __ j(kEqual, &done); |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7355 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7356 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7357 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7358 | case TypeCheckKind::kExactCheck: |
| 7359 | case TypeCheckKind::kArrayCheck: { |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7360 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7361 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7362 | temp_loc, |
| 7363 | obj_loc, |
| 7364 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7365 | kWithoutReadBarrier); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7366 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7367 | if (cls.IsRegister()) { |
| 7368 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 7369 | } else { |
| 7370 | DCHECK(cls.IsStackSlot()) << cls; |
| 7371 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 7372 | } |
| 7373 | // Jump to slow path for throwing the exception or doing a |
| 7374 | // more involved array check. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7375 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7376 | break; |
| 7377 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7378 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7379 | case TypeCheckKind::kAbstractClassCheck: { |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7380 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7381 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7382 | temp_loc, |
| 7383 | obj_loc, |
| 7384 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7385 | kWithoutReadBarrier); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7386 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7387 | // If the class is abstract, we eagerly fetch the super class of the |
| 7388 | // object to avoid doing a comparison we know will fail. |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7389 | NearLabel loop; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7390 | __ Bind(&loop); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7391 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7392 | GenerateReferenceLoadOneRegister(instruction, |
| 7393 | temp_loc, |
| 7394 | super_offset, |
| 7395 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7396 | kWithoutReadBarrier); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7397 | |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7398 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 7399 | // exception. |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7400 | __ testl(temp, temp); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7401 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7402 | |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7403 | // Otherwise, compare the classes |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7404 | if (cls.IsRegister()) { |
| 7405 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 7406 | } else { |
| 7407 | DCHECK(cls.IsStackSlot()) << cls; |
| 7408 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 7409 | } |
| 7410 | __ j(kNotEqual, &loop); |
| 7411 | break; |
| 7412 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7413 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7414 | case TypeCheckKind::kClassHierarchyCheck: { |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7415 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7416 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7417 | temp_loc, |
| 7418 | obj_loc, |
| 7419 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7420 | kWithoutReadBarrier); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7421 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7422 | // Walk over the class hierarchy to find a match. |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7423 | NearLabel loop; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7424 | __ Bind(&loop); |
| 7425 | if (cls.IsRegister()) { |
| 7426 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 7427 | } else { |
| 7428 | DCHECK(cls.IsStackSlot()) << cls; |
| 7429 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 7430 | } |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7431 | __ j(kEqual, &done); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7432 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7433 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7434 | GenerateReferenceLoadOneRegister(instruction, |
| 7435 | temp_loc, |
| 7436 | super_offset, |
| 7437 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7438 | kWithoutReadBarrier); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7439 | |
| 7440 | // If the class reference currently in `temp` is not null, jump |
| 7441 | // back at the beginning of the loop. |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7442 | __ testl(temp, temp); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7443 | __ j(kNotZero, &loop); |
| 7444 | // Otherwise, jump to the slow path to throw the exception.; |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7445 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7446 | break; |
| 7447 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7448 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7449 | case TypeCheckKind::kArrayObjectCheck: { |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7450 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7451 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7452 | temp_loc, |
| 7453 | obj_loc, |
| 7454 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7455 | kWithoutReadBarrier); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7456 | |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7457 | // Do an exact check. |
| 7458 | if (cls.IsRegister()) { |
| 7459 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 7460 | } else { |
| 7461 | DCHECK(cls.IsStackSlot()) << cls; |
| 7462 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 7463 | } |
| 7464 | __ j(kEqual, &done); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7465 | |
| 7466 | // 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] | 7467 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7468 | GenerateReferenceLoadOneRegister(instruction, |
| 7469 | temp_loc, |
| 7470 | component_offset, |
| 7471 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7472 | kWithoutReadBarrier); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7473 | |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7474 | // If the component type is null (i.e. the object not an array), jump to the slow path to |
| 7475 | // throw the exception. Otherwise proceed with the check. |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7476 | __ testl(temp, temp); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7477 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7478 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7479 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7480 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7481 | break; |
| 7482 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7483 | |
| Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 7484 | case TypeCheckKind::kUnresolvedCheck: |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7485 | // 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] | 7486 | // We cannot directly call the CheckCast runtime entry point |
| 7487 | // without resorting to a type checking slow path here (i.e. by |
| 7488 | // calling InvokeRuntime directly), as it would require to |
| 7489 | // assign fixed registers for the inputs of this HInstanceOf |
| 7490 | // instruction (following the runtime calling convention), which |
| 7491 | // might be cluttered by the potential first read barrier |
| 7492 | // emission at the beginning of this method. |
| 7493 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7494 | break; |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7495 | |
| 7496 | case TypeCheckKind::kInterfaceCheck: { |
| Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 7497 | // Fast path for the interface check. Try to avoid read barriers to improve the fast path. |
| 7498 | // We can not get false positives by doing this. |
| 7499 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7500 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7501 | temp_loc, |
| 7502 | obj_loc, |
| 7503 | class_offset, |
| 7504 | kWithoutReadBarrier); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7505 | |
| Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 7506 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 7507 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7508 | temp_loc, |
| 7509 | temp_loc, |
| 7510 | iftable_offset, |
| 7511 | kWithoutReadBarrier); |
| 7512 | // Iftable is never null. |
| 7513 | __ movl(maybe_temp2_loc.AsRegister<Register>(), Address(temp, array_length_offset)); |
| 7514 | // Maybe poison the `cls` for direct comparison with memory. |
| 7515 | __ MaybePoisonHeapReference(cls.AsRegister<Register>()); |
| 7516 | // Loop through the iftable and check if any class matches. |
| 7517 | NearLabel start_loop; |
| 7518 | __ Bind(&start_loop); |
| 7519 | // Need to subtract first to handle the empty array case. |
| 7520 | __ subl(maybe_temp2_loc.AsRegister<Register>(), Immediate(2)); |
| 7521 | __ j(kNegative, type_check_slow_path->GetEntryLabel()); |
| 7522 | // Go to next interface if the classes do not match. |
| 7523 | __ cmpl(cls.AsRegister<Register>(), |
| 7524 | CodeGeneratorX86::ArrayAddress(temp, |
| 7525 | maybe_temp2_loc, |
| 7526 | TIMES_4, |
| 7527 | object_array_data_offset)); |
| 7528 | __ j(kNotEqual, &start_loop); |
| 7529 | // If `cls` was poisoned above, unpoison it. |
| 7530 | __ MaybeUnpoisonHeapReference(cls.AsRegister<Register>()); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7531 | break; |
| 7532 | } |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7533 | |
| 7534 | case TypeCheckKind::kBitstringCheck: { |
| 7535 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7536 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7537 | temp_loc, |
| 7538 | obj_loc, |
| 7539 | class_offset, |
| 7540 | kWithoutReadBarrier); |
| 7541 | |
| 7542 | GenerateBitstringTypeCheckCompare(instruction, temp); |
| 7543 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
| 7544 | break; |
| 7545 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7546 | } |
| 7547 | __ Bind(&done); |
| 7548 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7549 | __ Bind(type_check_slow_path->GetExitLabel()); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7550 | } |
| 7551 | |
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7552 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7553 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 7554 | instruction, LocationSummary::kCallOnMainOnly); |
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7555 | InvokeRuntimeCallingConvention calling_convention; |
| 7556 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 7557 | } |
| 7558 | |
| 7559 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 7560 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject |
| 7561 | : kQuickUnlockObject, |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 7562 | instruction, |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 7563 | instruction->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7564 | if (instruction->IsEnter()) { |
| 7565 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 7566 | } else { |
| 7567 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 7568 | } |
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7569 | } |
| 7570 | |
| Shalini Salomi Bodapati | dd121f6 | 2018-10-26 15:03:53 +0530 | [diff] [blame] | 7571 | void LocationsBuilderX86::VisitX86AndNot(HX86AndNot* instruction) { |
| 7572 | DCHECK(codegen_->GetInstructionSetFeatures().HasAVX2()); |
| 7573 | DCHECK(DataType::IsIntOrLongType(instruction->GetType())) << instruction->GetType(); |
| 7574 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| 7575 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7576 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7577 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7578 | } |
| 7579 | |
| 7580 | void InstructionCodeGeneratorX86::VisitX86AndNot(HX86AndNot* instruction) { |
| 7581 | LocationSummary* locations = instruction->GetLocations(); |
| 7582 | Location first = locations->InAt(0); |
| 7583 | Location second = locations->InAt(1); |
| 7584 | Location dest = locations->Out(); |
| 7585 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
| 7586 | __ andn(dest.AsRegister<Register>(), |
| 7587 | first.AsRegister<Register>(), |
| 7588 | second.AsRegister<Register>()); |
| 7589 | } else { |
| 7590 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
| 7591 | __ andn(dest.AsRegisterPairLow<Register>(), |
| 7592 | first.AsRegisterPairLow<Register>(), |
| 7593 | second.AsRegisterPairLow<Register>()); |
| 7594 | __ andn(dest.AsRegisterPairHigh<Register>(), |
| 7595 | first.AsRegisterPairHigh<Register>(), |
| 7596 | second.AsRegisterPairHigh<Register>()); |
| 7597 | } |
| 7598 | } |
| 7599 | |
| 7600 | void LocationsBuilderX86::VisitX86MaskOrResetLeastSetBit(HX86MaskOrResetLeastSetBit* instruction) { |
| 7601 | DCHECK(codegen_->GetInstructionSetFeatures().HasAVX2()); |
| 7602 | DCHECK(instruction->GetType() == DataType::Type::kInt32) << instruction->GetType(); |
| 7603 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| 7604 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7605 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7606 | } |
| 7607 | |
| 7608 | void InstructionCodeGeneratorX86::VisitX86MaskOrResetLeastSetBit( |
| 7609 | HX86MaskOrResetLeastSetBit* instruction) { |
| 7610 | LocationSummary* locations = instruction->GetLocations(); |
| 7611 | Location src = locations->InAt(0); |
| 7612 | Location dest = locations->Out(); |
| 7613 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
| 7614 | switch (instruction->GetOpKind()) { |
| 7615 | case HInstruction::kAnd: |
| 7616 | __ blsr(dest.AsRegister<Register>(), src.AsRegister<Register>()); |
| 7617 | break; |
| 7618 | case HInstruction::kXor: |
| 7619 | __ blsmsk(dest.AsRegister<Register>(), src.AsRegister<Register>()); |
| 7620 | break; |
| 7621 | default: |
| 7622 | LOG(FATAL) << "Unreachable"; |
| 7623 | } |
| 7624 | } |
| 7625 | |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7626 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 7627 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 7628 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 7629 | |
| 7630 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 7631 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7632 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7633 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 |
| 7634 | || instruction->GetResultType() == DataType::Type::kInt64); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7635 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7636 | locations->SetInAt(1, Location::Any()); |
| 7637 | locations->SetOut(Location::SameAsFirstInput()); |
| 7638 | } |
| 7639 | |
| 7640 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 7641 | HandleBitwiseOperation(instruction); |
| 7642 | } |
| 7643 | |
| 7644 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 7645 | HandleBitwiseOperation(instruction); |
| 7646 | } |
| 7647 | |
| 7648 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 7649 | HandleBitwiseOperation(instruction); |
| 7650 | } |
| 7651 | |
| 7652 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 7653 | LocationSummary* locations = instruction->GetLocations(); |
| 7654 | Location first = locations->InAt(0); |
| 7655 | Location second = locations->InAt(1); |
| 7656 | DCHECK(first.Equals(locations->Out())); |
| 7657 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7658 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7659 | if (second.IsRegister()) { |
| 7660 | if (instruction->IsAnd()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7661 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7662 | } else if (instruction->IsOr()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7663 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7664 | } else { |
| 7665 | DCHECK(instruction->IsXor()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7666 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7667 | } |
| 7668 | } else if (second.IsConstant()) { |
| 7669 | if (instruction->IsAnd()) { |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 7670 | __ andl(first.AsRegister<Register>(), |
| 7671 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7672 | } else if (instruction->IsOr()) { |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 7673 | __ orl(first.AsRegister<Register>(), |
| 7674 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7675 | } else { |
| 7676 | DCHECK(instruction->IsXor()); |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 7677 | __ xorl(first.AsRegister<Register>(), |
| 7678 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7679 | } |
| 7680 | } else { |
| 7681 | if (instruction->IsAnd()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7682 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7683 | } else if (instruction->IsOr()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7684 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7685 | } else { |
| 7686 | DCHECK(instruction->IsXor()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7687 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7688 | } |
| 7689 | } |
| 7690 | } else { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7691 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7692 | if (second.IsRegisterPair()) { |
| 7693 | if (instruction->IsAnd()) { |
| 7694 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 7695 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 7696 | } else if (instruction->IsOr()) { |
| 7697 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 7698 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 7699 | } else { |
| 7700 | DCHECK(instruction->IsXor()); |
| 7701 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 7702 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 7703 | } |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7704 | } else if (second.IsDoubleStackSlot()) { |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7705 | if (instruction->IsAnd()) { |
| 7706 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7707 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 7708 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7709 | } else if (instruction->IsOr()) { |
| 7710 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7711 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 7712 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7713 | } else { |
| 7714 | DCHECK(instruction->IsXor()); |
| 7715 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7716 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 7717 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7718 | } |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7719 | } else { |
| 7720 | DCHECK(second.IsConstant()) << second; |
| 7721 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7722 | int32_t low_value = Low32Bits(value); |
| 7723 | int32_t high_value = High32Bits(value); |
| 7724 | Immediate low(low_value); |
| 7725 | Immediate high(high_value); |
| 7726 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 7727 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7728 | if (instruction->IsAnd()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7729 | if (low_value == 0) { |
| 7730 | __ xorl(first_low, first_low); |
| 7731 | } else if (low_value != -1) { |
| 7732 | __ andl(first_low, low); |
| 7733 | } |
| 7734 | if (high_value == 0) { |
| 7735 | __ xorl(first_high, first_high); |
| 7736 | } else if (high_value != -1) { |
| 7737 | __ andl(first_high, high); |
| 7738 | } |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7739 | } else if (instruction->IsOr()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7740 | if (low_value != 0) { |
| 7741 | __ orl(first_low, low); |
| 7742 | } |
| 7743 | if (high_value != 0) { |
| 7744 | __ orl(first_high, high); |
| 7745 | } |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7746 | } else { |
| 7747 | DCHECK(instruction->IsXor()); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7748 | if (low_value != 0) { |
| 7749 | __ xorl(first_low, low); |
| 7750 | } |
| 7751 | if (high_value != 0) { |
| 7752 | __ xorl(first_high, high); |
| 7753 | } |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7754 | } |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7755 | } |
| 7756 | } |
| 7757 | } |
| 7758 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7759 | void InstructionCodeGeneratorX86::GenerateReferenceLoadOneRegister( |
| 7760 | HInstruction* instruction, |
| 7761 | Location out, |
| 7762 | uint32_t offset, |
| 7763 | Location maybe_temp, |
| 7764 | ReadBarrierOption read_barrier_option) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7765 | Register out_reg = out.AsRegister<Register>(); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7766 | if (read_barrier_option == kWithReadBarrier) { |
| 7767 | CHECK(kEmitCompilerReadBarrier); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7768 | if (kUseBakerReadBarrier) { |
| 7769 | // Load with fast path based Baker's read barrier. |
| 7770 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7771 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7772 | instruction, out, out_reg, offset, /* needs_null_check= */ false); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7773 | } else { |
| 7774 | // Load with slow path based read barrier. |
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7775 | // Save the value of `out` into `maybe_temp` before overwriting it |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7776 | // in the following move operation, as we will need it for the |
| 7777 | // read barrier below. |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7778 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7779 | __ movl(maybe_temp.AsRegister<Register>(), out_reg); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7780 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7781 | __ movl(out_reg, Address(out_reg, offset)); |
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7782 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7783 | } |
| 7784 | } else { |
| 7785 | // Plain load with no read barrier. |
| 7786 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7787 | __ movl(out_reg, Address(out_reg, offset)); |
| 7788 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7789 | } |
| 7790 | } |
| 7791 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7792 | void InstructionCodeGeneratorX86::GenerateReferenceLoadTwoRegisters( |
| 7793 | HInstruction* instruction, |
| 7794 | Location out, |
| 7795 | Location obj, |
| 7796 | uint32_t offset, |
| 7797 | ReadBarrierOption read_barrier_option) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7798 | Register out_reg = out.AsRegister<Register>(); |
| 7799 | Register obj_reg = obj.AsRegister<Register>(); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7800 | if (read_barrier_option == kWithReadBarrier) { |
| 7801 | CHECK(kEmitCompilerReadBarrier); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7802 | if (kUseBakerReadBarrier) { |
| 7803 | // Load with fast path based Baker's read barrier. |
| 7804 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7805 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7806 | instruction, out, obj_reg, offset, /* needs_null_check= */ false); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7807 | } else { |
| 7808 | // Load with slow path based read barrier. |
| 7809 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7810 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7811 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 7812 | } |
| 7813 | } else { |
| 7814 | // Plain load with no read barrier. |
| 7815 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7816 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7817 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7818 | } |
| 7819 | } |
| 7820 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7821 | void InstructionCodeGeneratorX86::GenerateGcRootFieldLoad( |
| 7822 | HInstruction* instruction, |
| 7823 | Location root, |
| 7824 | const Address& address, |
| 7825 | Label* fixup_label, |
| 7826 | ReadBarrierOption read_barrier_option) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7827 | Register root_reg = root.AsRegister<Register>(); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7828 | if (read_barrier_option == kWithReadBarrier) { |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7829 | DCHECK(kEmitCompilerReadBarrier); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7830 | if (kUseBakerReadBarrier) { |
| 7831 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 7832 | // Baker's read barrier are used: |
| 7833 | // |
| Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7834 | // root = obj.field; |
| 7835 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 7836 | // if (temp != null) { |
| 7837 | // root = temp(root) |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7838 | // } |
| 7839 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7840 | // /* GcRoot<mirror::Object> */ root = *address |
| 7841 | __ movl(root_reg, address); |
| 7842 | if (fixup_label != nullptr) { |
| 7843 | __ Bind(fixup_label); |
| 7844 | } |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7845 | static_assert( |
| 7846 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 7847 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 7848 | "have different sizes."); |
| 7849 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 7850 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 7851 | "have different sizes."); |
| 7852 | |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7853 | // Slow path marking the GC root `root`. |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7854 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathX86( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7855 | instruction, root, /* unpoison_ref_before_marking= */ false); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7856 | codegen_->AddSlowPath(slow_path); |
| 7857 | |
| Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7858 | // Test the entrypoint (`Thread::Current()->pReadBarrierMarkReg ## root.reg()`). |
| 7859 | const int32_t entry_point_offset = |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 7860 | Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(root.reg()); |
| Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7861 | __ fs()->cmpl(Address::Absolute(entry_point_offset), Immediate(0)); |
| 7862 | // The entrypoint is null when the GC is not marking. |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7863 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 7864 | __ Bind(slow_path->GetExitLabel()); |
| 7865 | } else { |
| 7866 | // GC root loaded through a slow path for read barriers other |
| 7867 | // than Baker's. |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7868 | // /* GcRoot<mirror::Object>* */ root = address |
| 7869 | __ leal(root_reg, address); |
| 7870 | if (fixup_label != nullptr) { |
| 7871 | __ Bind(fixup_label); |
| 7872 | } |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7873 | // /* mirror::Object* */ root = root->Read() |
| 7874 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 7875 | } |
| 7876 | } else { |
| 7877 | // Plain GC root load with no read barrier. |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7878 | // /* GcRoot<mirror::Object> */ root = *address |
| 7879 | __ movl(root_reg, address); |
| 7880 | if (fixup_label != nullptr) { |
| 7881 | __ Bind(fixup_label); |
| 7882 | } |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7883 | // Note that GC roots are not affected by heap poisoning, thus we |
| 7884 | // do not have to unpoison `root_reg` here. |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7885 | } |
| 7886 | } |
| 7887 | |
| 7888 | void CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7889 | Location ref, |
| 7890 | Register obj, |
| 7891 | uint32_t offset, |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7892 | bool needs_null_check) { |
| 7893 | DCHECK(kEmitCompilerReadBarrier); |
| 7894 | DCHECK(kUseBakerReadBarrier); |
| 7895 | |
| 7896 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7897 | Address src(obj, offset); |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7898 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7899 | } |
| 7900 | |
| 7901 | void CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7902 | Location ref, |
| 7903 | Register obj, |
| 7904 | uint32_t data_offset, |
| 7905 | Location index, |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7906 | bool needs_null_check) { |
| 7907 | DCHECK(kEmitCompilerReadBarrier); |
| 7908 | DCHECK(kUseBakerReadBarrier); |
| 7909 | |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 7910 | static_assert( |
| 7911 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 7912 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7913 | // /* HeapReference<Object> */ ref = |
| 7914 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7915 | Address src = CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset); |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7916 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7917 | } |
| 7918 | |
| 7919 | void CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7920 | Location ref, |
| 7921 | Register obj, |
| 7922 | const Address& src, |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7923 | bool needs_null_check, |
| 7924 | bool always_update_field, |
| 7925 | Register* temp) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7926 | DCHECK(kEmitCompilerReadBarrier); |
| 7927 | DCHECK(kUseBakerReadBarrier); |
| 7928 | |
| 7929 | // In slow path based read barriers, the read barrier call is |
| 7930 | // inserted after the original load. However, in fast path based |
| 7931 | // Baker's read barriers, we need to perform the load of |
| 7932 | // mirror::Object::monitor_ *before* the original reference load. |
| 7933 | // This load-load ordering is required by the read barrier. |
| 7934 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 7935 | // |
| 7936 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7937 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7938 | // HeapReference<Object> ref = *src; // Original reference load. |
| Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7939 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7940 | // if (is_gray) { |
| 7941 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 7942 | // } |
| 7943 | // |
| 7944 | // Note: the original implementation in ReadBarrier::Barrier is |
| 7945 | // slightly more complex as: |
| 7946 | // - it implements the load-load fence using a data dependency on |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7947 | // the high-bits of rb_state, which are expected to be all zeroes |
| 7948 | // (we use CodeGeneratorX86::GenerateMemoryBarrier instead here, |
| 7949 | // which is a no-op thanks to the x86 memory model); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7950 | // - it performs additional checks that we do not do here for |
| 7951 | // performance reasons. |
| 7952 | |
| 7953 | Register ref_reg = ref.AsRegister<Register>(); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7954 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 7955 | |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7956 | // 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] | 7957 | static_assert(ReadBarrier::NonGrayState() == 0, "Expecting non-gray to have value 0"); |
| Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7958 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7959 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 7960 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 7961 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 7962 | |
| Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7963 | // if (rb_state == ReadBarrier::GrayState()) |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7964 | // ref = ReadBarrier::Mark(ref); |
| 7965 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 7966 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7967 | if (needs_null_check) { |
| 7968 | MaybeRecordImplicitNullCheck(instruction); |
| 7969 | } |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7970 | |
| 7971 | // Load fence to prevent load-load reordering. |
| 7972 | // Note that this is a no-op, thanks to the x86 memory model. |
| 7973 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 7974 | |
| 7975 | // The actual reference load. |
| 7976 | // /* HeapReference<Object> */ ref = *src |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7977 | __ movl(ref_reg, src); // Flags are unaffected. |
| 7978 | |
| 7979 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 7980 | // Slow path marking the object `ref` when it is gray. |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7981 | SlowPathCode* slow_path; |
| 7982 | if (always_update_field) { |
| 7983 | DCHECK(temp != nullptr); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7984 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkAndUpdateFieldSlowPathX86( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7985 | instruction, ref, obj, src, /* unpoison_ref_before_marking= */ true, *temp); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7986 | } else { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7987 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkSlowPathX86( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7988 | instruction, ref, /* unpoison_ref_before_marking= */ true); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7989 | } |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7990 | AddSlowPath(slow_path); |
| 7991 | |
| 7992 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 7993 | __ j(kNotZero, slow_path->GetEntryLabel()); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7994 | |
| 7995 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7996 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7997 | |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7998 | __ Bind(slow_path->GetExitLabel()); |
| 7999 | } |
| 8000 | |
| 8001 | void CodeGeneratorX86::GenerateReadBarrierSlow(HInstruction* instruction, |
| 8002 | Location out, |
| 8003 | Location ref, |
| 8004 | Location obj, |
| 8005 | uint32_t offset, |
| 8006 | Location index) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8007 | DCHECK(kEmitCompilerReadBarrier); |
| 8008 | |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8009 | // Insert a slow path based read barrier *after* the reference load. |
| 8010 | // |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8011 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 8012 | // reference will be carried out by the runtime within the slow |
| 8013 | // path. |
| 8014 | // |
| 8015 | // Note that `ref` currently does not get unpoisoned (when heap |
| 8016 | // poisoning is enabled), which is alright as the `ref` argument is |
| 8017 | // not used by the artReadBarrierSlow entry point. |
| 8018 | // |
| 8019 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8020 | SlowPathCode* slow_path = new (GetScopedAllocator()) |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8021 | ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); |
| 8022 | AddSlowPath(slow_path); |
| 8023 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8024 | __ jmp(slow_path->GetEntryLabel()); |
| 8025 | __ Bind(slow_path->GetExitLabel()); |
| 8026 | } |
| 8027 | |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8028 | void CodeGeneratorX86::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 8029 | Location out, |
| 8030 | Location ref, |
| 8031 | Location obj, |
| 8032 | uint32_t offset, |
| 8033 | Location index) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8034 | if (kEmitCompilerReadBarrier) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8035 | // Baker's read barriers shall be handled by the fast path |
| 8036 | // (CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier). |
| 8037 | DCHECK(!kUseBakerReadBarrier); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8038 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 8039 | // by the runtime within the slow path. |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8040 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8041 | } else if (kPoisonHeapReferences) { |
| 8042 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 8043 | } |
| 8044 | } |
| 8045 | |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8046 | void CodeGeneratorX86::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 8047 | Location out, |
| 8048 | Location root) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8049 | DCHECK(kEmitCompilerReadBarrier); |
| 8050 | |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8051 | // Insert a slow path based read barrier *after* the GC root load. |
| 8052 | // |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8053 | // Note that GC roots are not affected by heap poisoning, so we do |
| 8054 | // not need to do anything special for this here. |
| 8055 | SlowPathCode* slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8056 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathX86(instruction, out, root); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8057 | AddSlowPath(slow_path); |
| 8058 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8059 | __ jmp(slow_path->GetEntryLabel()); |
| 8060 | __ Bind(slow_path->GetExitLabel()); |
| 8061 | } |
| 8062 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 8063 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8064 | // Nothing to do, this should be removed during prepare for register allocator. |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8065 | LOG(FATAL) << "Unreachable"; |
| 8066 | } |
| 8067 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 8068 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8069 | // Nothing to do, this should be removed during prepare for register allocator. |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8070 | LOG(FATAL) << "Unreachable"; |
| 8071 | } |
| 8072 | |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8073 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 8074 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 8075 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8076 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8077 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8078 | } |
| 8079 | |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8080 | void InstructionCodeGeneratorX86::GenPackedSwitchWithCompares(Register value_reg, |
| 8081 | int32_t lower_bound, |
| 8082 | uint32_t num_entries, |
| 8083 | HBasicBlock* switch_block, |
| 8084 | HBasicBlock* default_block) { |
| 8085 | // Figure out the correct compare values and jump conditions. |
| 8086 | // Handle the first compare/branch as a special case because it might |
| 8087 | // jump to the default case. |
| 8088 | DCHECK_GT(num_entries, 2u); |
| 8089 | Condition first_condition; |
| 8090 | uint32_t index; |
| 8091 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 8092 | if (lower_bound != 0) { |
| 8093 | first_condition = kLess; |
| 8094 | __ cmpl(value_reg, Immediate(lower_bound)); |
| 8095 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 8096 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8097 | |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8098 | index = 1; |
| 8099 | } else { |
| 8100 | // Handle all the compare/jumps below. |
| 8101 | first_condition = kBelow; |
| 8102 | index = 0; |
| 8103 | } |
| 8104 | |
| 8105 | // Handle the rest of the compare/jumps. |
| 8106 | for (; index + 1 < num_entries; index += 2) { |
| 8107 | int32_t compare_to_value = lower_bound + index + 1; |
| 8108 | __ cmpl(value_reg, Immediate(compare_to_value)); |
| 8109 | // Jump to successors[index] if value < case_value[index]. |
| 8110 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 8111 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 8112 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 8113 | } |
| 8114 | |
| 8115 | if (index != num_entries) { |
| 8116 | // There are an odd number of entries. Handle the last one. |
| 8117 | DCHECK_EQ(index + 1, num_entries); |
| 8118 | __ cmpl(value_reg, Immediate(lower_bound + index)); |
| 8119 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8120 | } |
| 8121 | |
| 8122 | // And the default for any other value. |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8123 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
| 8124 | __ jmp(codegen_->GetLabelOf(default_block)); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8125 | } |
| 8126 | } |
| 8127 | |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8128 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 8129 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 8130 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 8131 | LocationSummary* locations = switch_instr->GetLocations(); |
| 8132 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 8133 | |
| 8134 | GenPackedSwitchWithCompares(value_reg, |
| 8135 | lower_bound, |
| 8136 | num_entries, |
| 8137 | switch_instr->GetBlock(), |
| 8138 | switch_instr->GetDefaultBlock()); |
| 8139 | } |
| 8140 | |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8141 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 8142 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8143 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8144 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8145 | |
| 8146 | // Constant area pointer. |
| 8147 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8148 | |
| 8149 | // And the temporary we need. |
| 8150 | locations->AddTemp(Location::RequiresRegister()); |
| 8151 | } |
| 8152 | |
| 8153 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 8154 | int32_t lower_bound = switch_instr->GetStartValue(); |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8155 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8156 | LocationSummary* locations = switch_instr->GetLocations(); |
| 8157 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 8158 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 8159 | |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8160 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 8161 | GenPackedSwitchWithCompares(value_reg, |
| 8162 | lower_bound, |
| 8163 | num_entries, |
| 8164 | switch_instr->GetBlock(), |
| 8165 | default_block); |
| 8166 | return; |
| 8167 | } |
| 8168 | |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8169 | // Optimizing has a jump area. |
| 8170 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 8171 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 8172 | |
| 8173 | // Remove the bias, if needed. |
| 8174 | if (lower_bound != 0) { |
| 8175 | __ leal(temp_reg, Address(value_reg, -lower_bound)); |
| 8176 | value_reg = temp_reg; |
| 8177 | } |
| 8178 | |
| 8179 | // Is the value in range? |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8180 | DCHECK_GE(num_entries, 1u); |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8181 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 8182 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| 8183 | |
| 8184 | // We are in the range of the table. |
| 8185 | // Load (target-constant_area) from the jump table, indexing by the value. |
| 8186 | __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); |
| 8187 | |
| 8188 | // Compute the actual target address by adding in constant_area. |
| 8189 | __ addl(temp_reg, constant_area); |
| 8190 | |
| 8191 | // And jump. |
| 8192 | __ jmp(temp_reg); |
| 8193 | } |
| 8194 | |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8195 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 8196 | HX86ComputeBaseMethodAddress* insn) { |
| 8197 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8198 | new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8199 | locations->SetOut(Location::RequiresRegister()); |
| 8200 | } |
| 8201 | |
| 8202 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 8203 | HX86ComputeBaseMethodAddress* insn) { |
| 8204 | LocationSummary* locations = insn->GetLocations(); |
| 8205 | Register reg = locations->Out().AsRegister<Register>(); |
| 8206 | |
| 8207 | // Generate call to next instruction. |
| 8208 | Label next_instruction; |
| 8209 | __ call(&next_instruction); |
| 8210 | __ Bind(&next_instruction); |
| 8211 | |
| 8212 | // Remember this offset for later use with constant area. |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8213 | codegen_->AddMethodAddressOffset(insn, GetAssembler()->CodeSize()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8214 | |
| 8215 | // Grab the return address off the stack. |
| 8216 | __ popl(reg); |
| 8217 | } |
| 8218 | |
| 8219 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 8220 | HX86LoadFromConstantTable* insn) { |
| 8221 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8222 | new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8223 | |
| 8224 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8225 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 8226 | |
| 8227 | // 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] | 8228 | if (insn->IsEmittedAtUseSite()) { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8229 | return; |
| 8230 | } |
| 8231 | |
| 8232 | switch (insn->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8233 | case DataType::Type::kFloat32: |
| 8234 | case DataType::Type::kFloat64: |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8235 | locations->SetOut(Location::RequiresFpuRegister()); |
| 8236 | break; |
| 8237 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8238 | case DataType::Type::kInt32: |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8239 | locations->SetOut(Location::RequiresRegister()); |
| 8240 | break; |
| 8241 | |
| 8242 | default: |
| 8243 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 8244 | } |
| 8245 | } |
| 8246 | |
| 8247 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 8248 | if (insn->IsEmittedAtUseSite()) { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8249 | return; |
| 8250 | } |
| 8251 | |
| 8252 | LocationSummary* locations = insn->GetLocations(); |
| 8253 | Location out = locations->Out(); |
| 8254 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 8255 | HConstant *value = insn->GetConstant(); |
| 8256 | |
| 8257 | switch (insn->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8258 | case DataType::Type::kFloat32: |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8259 | __ movss(out.AsFpuRegister<XmmRegister>(), |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8260 | codegen_->LiteralFloatAddress( |
| 8261 | value->AsFloatConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8262 | break; |
| 8263 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8264 | case DataType::Type::kFloat64: |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8265 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8266 | codegen_->LiteralDoubleAddress( |
| 8267 | value->AsDoubleConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8268 | break; |
| 8269 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8270 | case DataType::Type::kInt32: |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8271 | __ movl(out.AsRegister<Register>(), |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8272 | codegen_->LiteralInt32Address( |
| 8273 | value->AsIntConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8274 | break; |
| 8275 | |
| 8276 | default: |
| 8277 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 8278 | } |
| 8279 | } |
| 8280 | |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8281 | /** |
| 8282 | * Class to handle late fixup of offsets into constant area. |
| 8283 | */ |
| Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 8284 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8285 | public: |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8286 | RIPFixup(CodeGeneratorX86& codegen, |
| 8287 | HX86ComputeBaseMethodAddress* base_method_address, |
| 8288 | size_t offset) |
| 8289 | : codegen_(&codegen), |
| 8290 | base_method_address_(base_method_address), |
| 8291 | offset_into_constant_area_(offset) {} |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8292 | |
| 8293 | protected: |
| 8294 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 8295 | |
| 8296 | CodeGeneratorX86* codegen_; |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8297 | HX86ComputeBaseMethodAddress* base_method_address_; |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8298 | |
| 8299 | private: |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8300 | void Process(const MemoryRegion& region, int pos) override { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8301 | // Patch the correct offset for the instruction. The place to patch is the |
| 8302 | // last 4 bytes of the instruction. |
| 8303 | // The value to patch is the distance from the offset in the constant area |
| 8304 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8305 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8306 | int32_t relative_position = |
| 8307 | constant_offset - codegen_->GetMethodAddressOffset(base_method_address_); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8308 | |
| 8309 | // Patch in the right value. |
| 8310 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 8311 | } |
| 8312 | |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8313 | // Location in constant area that the fixup refers to. |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8314 | int32_t offset_into_constant_area_; |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8315 | }; |
| 8316 | |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8317 | /** |
| 8318 | * Class to handle late fixup of offsets to a jump table that will be created in the |
| 8319 | * constant area. |
| 8320 | */ |
| 8321 | class JumpTableRIPFixup : public RIPFixup { |
| 8322 | public: |
| 8323 | JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8324 | : RIPFixup(codegen, switch_instr->GetBaseMethodAddress(), static_cast<size_t>(-1)), |
| 8325 | switch_instr_(switch_instr) {} |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8326 | |
| 8327 | void CreateJumpTable() { |
| 8328 | X86Assembler* assembler = codegen_->GetAssembler(); |
| 8329 | |
| 8330 | // Ensure that the reference to the jump table has the correct offset. |
| 8331 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 8332 | SetOffset(offset_in_constant_table); |
| 8333 | |
| 8334 | // The label values in the jump table are computed relative to the |
| 8335 | // instruction addressing the constant area. |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8336 | const int32_t relative_offset = codegen_->GetMethodAddressOffset(base_method_address_); |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8337 | |
| 8338 | // Populate the jump table with the correct values for the jump table. |
| 8339 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 8340 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 8341 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 8342 | // The value that we want is the target offset - the position of the table. |
| 8343 | for (int32_t i = 0; i < num_entries; i++) { |
| 8344 | HBasicBlock* b = successors[i]; |
| 8345 | Label* l = codegen_->GetLabelOf(b); |
| 8346 | DCHECK(l->IsBound()); |
| 8347 | int32_t offset_to_block = l->Position() - relative_offset; |
| 8348 | assembler->AppendInt32(offset_to_block); |
| 8349 | } |
| 8350 | } |
| 8351 | |
| 8352 | private: |
| 8353 | const HX86PackedSwitch* switch_instr_; |
| 8354 | }; |
| 8355 | |
| 8356 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 8357 | // Generate the constant area if needed. |
| 8358 | X86Assembler* assembler = GetAssembler(); |
| jaishank | 20d1c94 | 2019-03-08 15:08:17 +0530 | [diff] [blame] | 8359 | |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8360 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 8361 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 8362 | // byte values. |
| 8363 | assembler->Align(4, 0); |
| 8364 | constant_area_start_ = assembler->CodeSize(); |
| 8365 | |
| 8366 | // Populate any jump tables. |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 8367 | for (JumpTableRIPFixup* jump_table : fixups_to_jump_tables_) { |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8368 | jump_table->CreateJumpTable(); |
| 8369 | } |
| 8370 | |
| 8371 | // And now add the constant area to the generated code. |
| 8372 | assembler->AddConstantArea(); |
| 8373 | } |
| 8374 | |
| 8375 | // And finish up. |
| 8376 | CodeGenerator::Finalize(allocator); |
| 8377 | } |
| 8378 | |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8379 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, |
| 8380 | HX86ComputeBaseMethodAddress* method_base, |
| 8381 | Register reg) { |
| 8382 | AssemblerFixup* fixup = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8383 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddDouble(v)); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8384 | return Address(reg, kDummy32BitOffset, fixup); |
| 8385 | } |
| 8386 | |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8387 | Address CodeGeneratorX86::LiteralFloatAddress(float v, |
| 8388 | HX86ComputeBaseMethodAddress* method_base, |
| 8389 | Register reg) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8390 | AssemblerFixup* fixup = |
| 8391 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddFloat(v)); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8392 | return Address(reg, kDummy32BitOffset, fixup); |
| 8393 | } |
| 8394 | |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8395 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, |
| 8396 | HX86ComputeBaseMethodAddress* method_base, |
| 8397 | Register reg) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8398 | AssemblerFixup* fixup = |
| 8399 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddInt32(v)); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8400 | return Address(reg, kDummy32BitOffset, fixup); |
| 8401 | } |
| 8402 | |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8403 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, |
| 8404 | HX86ComputeBaseMethodAddress* method_base, |
| 8405 | Register reg) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8406 | AssemblerFixup* fixup = |
| 8407 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddInt64(v)); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8408 | return Address(reg, kDummy32BitOffset, fixup); |
| 8409 | } |
| 8410 | |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 8411 | void CodeGeneratorX86::Load32BitValue(Register dest, int32_t value) { |
| 8412 | if (value == 0) { |
| 8413 | __ xorl(dest, dest); |
| 8414 | } else { |
| 8415 | __ movl(dest, Immediate(value)); |
| 8416 | } |
| 8417 | } |
| 8418 | |
| 8419 | void CodeGeneratorX86::Compare32BitValue(Register dest, int32_t value) { |
| 8420 | if (value == 0) { |
| 8421 | __ testl(dest, dest); |
| 8422 | } else { |
| 8423 | __ cmpl(dest, Immediate(value)); |
| 8424 | } |
| 8425 | } |
| 8426 | |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8427 | void CodeGeneratorX86::GenerateIntCompare(Location lhs, Location rhs) { |
| 8428 | Register lhs_reg = lhs.AsRegister<Register>(); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8429 | GenerateIntCompare(lhs_reg, rhs); |
| 8430 | } |
| 8431 | |
| 8432 | void CodeGeneratorX86::GenerateIntCompare(Register lhs, Location rhs) { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8433 | if (rhs.IsConstant()) { |
| 8434 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8435 | Compare32BitValue(lhs, value); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8436 | } else if (rhs.IsStackSlot()) { |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8437 | __ cmpl(lhs, Address(ESP, rhs.GetStackIndex())); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8438 | } else { |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8439 | __ cmpl(lhs, rhs.AsRegister<Register>()); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8440 | } |
| 8441 | } |
| 8442 | |
| 8443 | Address CodeGeneratorX86::ArrayAddress(Register obj, |
| 8444 | Location index, |
| 8445 | ScaleFactor scale, |
| 8446 | uint32_t data_offset) { |
| 8447 | return index.IsConstant() ? |
| 8448 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) : |
| 8449 | Address(obj, index.AsRegister<Register>(), scale, data_offset); |
| 8450 | } |
| 8451 | |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8452 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, |
| 8453 | Register reg, |
| 8454 | Register value) { |
| 8455 | // Create a fixup to be used to create and address the jump table. |
| 8456 | JumpTableRIPFixup* table_fixup = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8457 | new (GetGraph()->GetAllocator()) JumpTableRIPFixup(*this, switch_instr); |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8458 | |
| 8459 | // We have to populate the jump tables. |
| 8460 | fixups_to_jump_tables_.push_back(table_fixup); |
| 8461 | |
| 8462 | // We want a scaled address, as we are extracting the correct offset from the table. |
| 8463 | return Address(reg, value, TIMES_4, kDummy32BitOffset, table_fixup); |
| 8464 | } |
| 8465 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8466 | // TODO: target as memory. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8467 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, DataType::Type type) { |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8468 | if (!target.IsValid()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8469 | DCHECK_EQ(type, DataType::Type::kVoid); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8470 | return; |
| 8471 | } |
| 8472 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8473 | DCHECK_NE(type, DataType::Type::kVoid); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8474 | |
| 8475 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 8476 | if (target.Equals(return_loc)) { |
| 8477 | return; |
| 8478 | } |
| 8479 | |
| 8480 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 8481 | // with the else branch. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8482 | if (type == DataType::Type::kInt64) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8483 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8484 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), DataType::Type::kInt32, nullptr); |
| 8485 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), DataType::Type::kInt32, nullptr); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8486 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 8487 | } else { |
| 8488 | // Let the parallel move resolver take care of all of this. |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8489 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8490 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 8491 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 8492 | } |
| 8493 | } |
| 8494 | |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8495 | void CodeGeneratorX86::PatchJitRootUse(uint8_t* code, |
| 8496 | const uint8_t* roots_data, |
| 8497 | const PatchInfo<Label>& info, |
| 8498 | uint64_t index_in_table) const { |
| 8499 | uint32_t code_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 8500 | uintptr_t address = |
| 8501 | 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] | 8502 | using unaligned_uint32_t __attribute__((__aligned__(1))) = uint32_t; |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8503 | reinterpret_cast<unaligned_uint32_t*>(code + code_offset)[0] = |
| 8504 | dchecked_integral_cast<uint32_t>(address); |
| 8505 | } |
| 8506 | |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 8507 | void CodeGeneratorX86::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 8508 | for (const PatchInfo<Label>& info : jit_string_patches_) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8509 | 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] | 8510 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 8511 | PatchJitRootUse(code, roots_data, info, index_in_table); |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8512 | } |
| 8513 | |
| 8514 | for (const PatchInfo<Label>& info : jit_class_patches_) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8515 | 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] | 8516 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 8517 | PatchJitRootUse(code, roots_data, info, index_in_table); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 8518 | } |
| 8519 | } |
| 8520 | |
| xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 8521 | void LocationsBuilderX86::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 8522 | ATTRIBUTE_UNUSED) { |
| 8523 | LOG(FATAL) << "Unreachable"; |
| 8524 | } |
| 8525 | |
| 8526 | void InstructionCodeGeneratorX86::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 8527 | ATTRIBUTE_UNUSED) { |
| 8528 | LOG(FATAL) << "Unreachable"; |
| 8529 | } |
| 8530 | |
| Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 8531 | bool LocationsBuilderX86::CpuHasAvxFeatureFlag() { |
| 8532 | return codegen_->GetInstructionSetFeatures().HasAVX(); |
| 8533 | } |
| 8534 | bool LocationsBuilderX86::CpuHasAvx2FeatureFlag() { |
| 8535 | return codegen_->GetInstructionSetFeatures().HasAVX2(); |
| 8536 | } |
| 8537 | bool InstructionCodeGeneratorX86::CpuHasAvxFeatureFlag() { |
| 8538 | return codegen_->GetInstructionSetFeatures().HasAVX(); |
| 8539 | } |
| 8540 | bool InstructionCodeGeneratorX86::CpuHasAvx2FeatureFlag() { |
| 8541 | return codegen_->GetInstructionSetFeatures().HasAVX2(); |
| 8542 | } |
| 8543 | |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 8544 | #undef __ |
| 8545 | |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 8546 | } // namespace x86 |
| 8547 | } // namespace art |