| 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 | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1075 | void CodeGeneratorX86::GenerateFrameEntry() { |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1076 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
| Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1077 | __ Bind(&frame_entry_label_); |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1078 | bool skip_overflow_check = |
| 1079 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1080 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
| Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 1081 | |
| Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 1082 | if (GetCompilerOptions().CountHotnessInCompiledCode()) { |
| Mathieu Chartier | 7f8678e | 2019-08-30 16:22:28 -0700 | [diff] [blame] | 1083 | NearLabel overflow; |
| 1084 | __ cmpw(Address(kMethodRegisterArgument, |
| 1085 | ArtMethod::HotnessCountOffset().Int32Value()), |
| 1086 | Immediate(ArtMethod::MaxCounter())); |
| 1087 | __ j(kEqual, &overflow); |
| 1088 | __ addw(Address(kMethodRegisterArgument, |
| 1089 | ArtMethod::HotnessCountOffset().Int32Value()), |
| Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 1090 | Immediate(1)); |
| Mathieu Chartier | 7f8678e | 2019-08-30 16:22:28 -0700 | [diff] [blame] | 1091 | __ Bind(&overflow); |
| Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 1092 | } |
| 1093 | |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1094 | if (!skip_overflow_check) { |
| Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1095 | size_t reserved_bytes = GetStackOverflowReservedBytes(InstructionSet::kX86); |
| 1096 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(reserved_bytes))); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1097 | RecordPcInfo(nullptr, 0); |
| Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 1098 | } |
| 1099 | |
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1100 | if (HasEmptyFrame()) { |
| 1101 | return; |
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1102 | } |
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1103 | |
| 1104 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 1105 | Register reg = kCoreCalleeSaves[i]; |
| 1106 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1107 | __ pushl(reg); |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1108 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 1109 | __ cfi().RelOffset(DWARFReg(reg), 0); |
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1110 | } |
| 1111 | } |
| 1112 | |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1113 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1114 | __ subl(ESP, Immediate(adjust)); |
| 1115 | __ cfi().AdjustCFAOffset(adjust); |
| Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1116 | // Save the current method if we need it. Note that we do not |
| 1117 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1118 | // in the SSA graph. |
| 1119 | if (RequiresCurrentMethod()) { |
| 1120 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
| 1121 | } |
| Nicolas Geoffray | f789353 | 2017-06-15 12:34:36 +0100 | [diff] [blame] | 1122 | |
| 1123 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1124 | // Initialize should_deoptimize flag to 0. |
| 1125 | __ movl(Address(ESP, GetStackOffsetOfShouldDeoptimizeFlag()), Immediate(0)); |
| 1126 | } |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1127 | } |
| 1128 | |
| 1129 | void CodeGeneratorX86::GenerateFrameExit() { |
| David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1130 | __ cfi().RememberState(); |
| 1131 | if (!HasEmptyFrame()) { |
| 1132 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1133 | __ addl(ESP, Immediate(adjust)); |
| 1134 | __ cfi().AdjustCFAOffset(-adjust); |
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1135 | |
| David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1136 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1137 | Register reg = kCoreCalleeSaves[i]; |
| 1138 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1139 | __ popl(reg); |
| 1140 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 1141 | __ cfi().Restore(DWARFReg(reg)); |
| 1142 | } |
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1143 | } |
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1144 | } |
| David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1145 | __ ret(); |
| 1146 | __ cfi().RestoreState(); |
| 1147 | __ cfi().DefCFAOffset(GetFrameSize()); |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1148 | } |
| 1149 | |
| Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1150 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 1151 | __ Bind(GetLabelOf(block)); |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1152 | } |
| 1153 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1154 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(DataType::Type type) const { |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1155 | switch (type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1156 | case DataType::Type::kReference: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1157 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1158 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1159 | case DataType::Type::kInt8: |
| 1160 | case DataType::Type::kUint16: |
| 1161 | case DataType::Type::kInt16: |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1162 | case DataType::Type::kUint32: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1163 | case DataType::Type::kInt32: |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1164 | return Location::RegisterLocation(EAX); |
| 1165 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1166 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1167 | case DataType::Type::kInt64: |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1168 | return Location::RegisterPairLocation(EAX, EDX); |
| 1169 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1170 | case DataType::Type::kVoid: |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1171 | return Location::NoLocation(); |
| 1172 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1173 | case DataType::Type::kFloat64: |
| 1174 | case DataType::Type::kFloat32: |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1175 | return Location::FpuRegisterLocation(XMM0); |
| 1176 | } |
| Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1177 | |
| 1178 | UNREACHABLE(); |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1179 | } |
| 1180 | |
| 1181 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 1182 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1183 | } |
| 1184 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1185 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(DataType::Type type) { |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1186 | switch (type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1187 | case DataType::Type::kReference: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1188 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1189 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1190 | case DataType::Type::kInt8: |
| 1191 | case DataType::Type::kUint16: |
| 1192 | case DataType::Type::kInt16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1193 | case DataType::Type::kInt32: { |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1194 | uint32_t index = gp_index_++; |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1195 | stack_index_++; |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1196 | if (index < calling_convention.GetNumberOfRegisters()) { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1197 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1198 | } else { |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1199 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1200 | } |
| Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1201 | } |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1202 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1203 | case DataType::Type::kInt64: { |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1204 | uint32_t index = gp_index_; |
| 1205 | gp_index_ += 2; |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1206 | stack_index_ += 2; |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1207 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1208 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 1209 | calling_convention.GetRegisterPairAt(index)); |
| 1210 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1211 | } else { |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1212 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1213 | } |
| 1214 | } |
| 1215 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1216 | case DataType::Type::kFloat32: { |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1217 | uint32_t index = float_index_++; |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1218 | stack_index_++; |
| 1219 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1220 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1221 | } else { |
| 1222 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1223 | } |
| 1224 | } |
| 1225 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1226 | case DataType::Type::kFloat64: { |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1227 | uint32_t index = float_index_++; |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1228 | stack_index_ += 2; |
| 1229 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1230 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1231 | } else { |
| 1232 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1233 | } |
| 1234 | } |
| 1235 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1236 | case DataType::Type::kUint32: |
| 1237 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1238 | case DataType::Type::kVoid: |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1239 | LOG(FATAL) << "Unexpected parameter type " << type; |
| Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 1240 | UNREACHABLE(); |
| Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1241 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1242 | return Location::NoLocation(); |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1243 | } |
| Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1244 | |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1245 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 1246 | if (source.Equals(destination)) { |
| 1247 | return; |
| 1248 | } |
| 1249 | if (destination.IsRegister()) { |
| 1250 | if (source.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1251 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1252 | } else if (source.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1253 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1254 | } else { |
| 1255 | DCHECK(source.IsStackSlot()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1256 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1257 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1258 | } else if (destination.IsFpuRegister()) { |
| 1259 | if (source.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1260 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1261 | } else if (source.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1262 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1263 | } else { |
| 1264 | DCHECK(source.IsStackSlot()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1265 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1266 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1267 | } else { |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1268 | DCHECK(destination.IsStackSlot()) << destination; |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1269 | if (source.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1270 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1271 | } else if (source.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1272 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1273 | } else if (source.IsConstant()) { |
| 1274 | HConstant* constant = source.GetConstant(); |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1275 | int32_t value = GetInt32ValueOf(constant); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1276 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1277 | } else { |
| 1278 | DCHECK(source.IsStackSlot()); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1279 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 1280 | __ popl(Address(ESP, destination.GetStackIndex())); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1281 | } |
| 1282 | } |
| 1283 | } |
| 1284 | |
| 1285 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 1286 | if (source.Equals(destination)) { |
| 1287 | return; |
| 1288 | } |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1289 | if (destination.IsRegisterPair()) { |
| 1290 | if (source.IsRegisterPair()) { |
| Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1291 | EmitParallelMoves( |
| 1292 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1293 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1294 | DataType::Type::kInt32, |
| Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1295 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
| Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1296 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1297 | DataType::Type::kInt32); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1298 | } else if (source.IsFpuRegister()) { |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1299 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 1300 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 1301 | __ psrlq(src_reg, Immediate(32)); |
| 1302 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1303 | } else { |
| Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1304 | // No conflict possible, so just do the moves. |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1305 | DCHECK(source.IsDoubleStackSlot()); |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1306 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 1307 | __ movl(destination.AsRegisterPairHigh<Register>(), |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1308 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 1309 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1310 | } else if (destination.IsFpuRegister()) { |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1311 | if (source.IsFpuRegister()) { |
| 1312 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 1313 | } else if (source.IsDoubleStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1314 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1315 | } else if (source.IsRegisterPair()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1316 | size_t elem_size = DataType::Size(DataType::Type::kInt32); |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1317 | // Create stack space for 2 elements. |
| 1318 | __ subl(ESP, Immediate(2 * elem_size)); |
| 1319 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 1320 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 1321 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 1322 | // And remove the temporary stack space we allocated. |
| 1323 | __ addl(ESP, Immediate(2 * elem_size)); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1324 | } else { |
| 1325 | LOG(FATAL) << "Unimplemented"; |
| 1326 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1327 | } else { |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1328 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1329 | if (source.IsRegisterPair()) { |
| Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1330 | // No conflict possible, so just do the moves. |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1331 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1332 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1333 | source.AsRegisterPairHigh<Register>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1334 | } else if (source.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1335 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1336 | } else if (source.IsConstant()) { |
| 1337 | HConstant* constant = source.GetConstant(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1338 | DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant()); |
| 1339 | int64_t value = GetInt64ValueOf(constant); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1340 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1341 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
| 1342 | Immediate(High32Bits(value))); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1343 | } else { |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1344 | DCHECK(source.IsDoubleStackSlot()) << source; |
| Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1345 | EmitParallelMoves( |
| 1346 | Location::StackSlot(source.GetStackIndex()), |
| 1347 | Location::StackSlot(destination.GetStackIndex()), |
| 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::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
| Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1350 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1351 | DataType::Type::kInt32); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1352 | } |
| 1353 | } |
| 1354 | } |
| 1355 | |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1356 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { |
| 1357 | DCHECK(location.IsRegister()); |
| 1358 | __ movl(location.AsRegister<Register>(), Immediate(value)); |
| 1359 | } |
| 1360 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1361 | void CodeGeneratorX86::MoveLocation(Location dst, Location src, DataType::Type dst_type) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1362 | HParallelMove move(GetGraph()->GetAllocator()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1363 | if (dst_type == DataType::Type::kInt64 && !src.IsConstant() && !src.IsFpuRegister()) { |
| 1364 | move.AddMove(src.ToLow(), dst.ToLow(), DataType::Type::kInt32, nullptr); |
| 1365 | move.AddMove(src.ToHigh(), dst.ToHigh(), DataType::Type::kInt32, nullptr); |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1366 | } else { |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1367 | move.AddMove(src, dst, dst_type, nullptr); |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1368 | } |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1369 | GetMoveResolver()->EmitNativeCode(&move); |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1370 | } |
| 1371 | |
| 1372 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1373 | if (location.IsRegister()) { |
| 1374 | locations->AddTemp(location); |
| 1375 | } else if (location.IsRegisterPair()) { |
| 1376 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1377 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1378 | } else { |
| 1379 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1380 | } |
| 1381 | } |
| 1382 | |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1383 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
| Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 1384 | if (successor->IsExitBlock()) { |
| 1385 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 1386 | return; // no code needed |
| 1387 | } |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1388 | |
| 1389 | HBasicBlock* block = got->GetBlock(); |
| 1390 | HInstruction* previous = got->GetPrevious(); |
| 1391 | |
| 1392 | HLoopInformation* info = block->GetLoopInformation(); |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1393 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
| Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 1394 | if (codegen_->GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 1395 | __ pushl(EAX); |
| 1396 | __ movl(EAX, Address(ESP, kX86WordSize)); |
| Mathieu Chartier | 7f8678e | 2019-08-30 16:22:28 -0700 | [diff] [blame] | 1397 | NearLabel overflow; |
| 1398 | __ cmpw(Address(EAX, ArtMethod::HotnessCountOffset().Int32Value()), |
| 1399 | Immediate(ArtMethod::MaxCounter())); |
| 1400 | __ j(kEqual, &overflow); |
| 1401 | __ addw(Address(EAX, ArtMethod::HotnessCountOffset().Int32Value()), |
| 1402 | Immediate(1)); |
| 1403 | __ Bind(&overflow); |
| Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 1404 | __ popl(EAX); |
| 1405 | } |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1406 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1407 | return; |
| 1408 | } |
| 1409 | |
| 1410 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1411 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1412 | } |
| 1413 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1414 | __ jmp(codegen_->GetLabelOf(successor)); |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1415 | } |
| 1416 | } |
| 1417 | |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1418 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 1419 | got->SetLocations(nullptr); |
| 1420 | } |
| 1421 | |
| 1422 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 1423 | HandleGoto(got, got->GetSuccessor()); |
| 1424 | } |
| 1425 | |
| 1426 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1427 | try_boundary->SetLocations(nullptr); |
| 1428 | } |
| 1429 | |
| 1430 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1431 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1432 | if (!successor->IsExitBlock()) { |
| 1433 | HandleGoto(try_boundary, successor); |
| 1434 | } |
| 1435 | } |
| 1436 | |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1437 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1438 | exit->SetLocations(nullptr); |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1439 | } |
| 1440 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1441 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1442 | } |
| 1443 | |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1444 | template<class LabelType> |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1445 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1446 | LabelType* true_label, |
| 1447 | LabelType* false_label) { |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1448 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1449 | __ j(kUnordered, true_label); |
| 1450 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1451 | __ j(kUnordered, false_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1452 | } |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1453 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1454 | } |
| 1455 | |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1456 | template<class LabelType> |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1457 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1458 | LabelType* true_label, |
| 1459 | LabelType* false_label) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1460 | LocationSummary* locations = cond->GetLocations(); |
| 1461 | Location left = locations->InAt(0); |
| 1462 | Location right = locations->InAt(1); |
| 1463 | IfCondition if_cond = cond->GetCondition(); |
| 1464 | |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1465 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1466 | Register left_low = left.AsRegisterPairLow<Register>(); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1467 | IfCondition true_high_cond = if_cond; |
| 1468 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1469 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); // unsigned on lower part |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1470 | |
| 1471 | // Set the conditions for the test, remembering that == needs to be |
| 1472 | // decided using the low words. |
| 1473 | switch (if_cond) { |
| 1474 | case kCondEQ: |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1475 | case kCondNE: |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1476 | // Nothing to do. |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1477 | break; |
| 1478 | case kCondLT: |
| 1479 | false_high_cond = kCondGT; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1480 | break; |
| 1481 | case kCondLE: |
| 1482 | true_high_cond = kCondLT; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1483 | break; |
| 1484 | case kCondGT: |
| 1485 | false_high_cond = kCondLT; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1486 | break; |
| 1487 | case kCondGE: |
| 1488 | true_high_cond = kCondGT; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1489 | break; |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1490 | case kCondB: |
| 1491 | false_high_cond = kCondA; |
| 1492 | break; |
| 1493 | case kCondBE: |
| 1494 | true_high_cond = kCondB; |
| 1495 | break; |
| 1496 | case kCondA: |
| 1497 | false_high_cond = kCondB; |
| 1498 | break; |
| 1499 | case kCondAE: |
| 1500 | true_high_cond = kCondA; |
| 1501 | break; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1502 | } |
| 1503 | |
| 1504 | if (right.IsConstant()) { |
| 1505 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1506 | int32_t val_high = High32Bits(value); |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1507 | int32_t val_low = Low32Bits(value); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1508 | |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1509 | codegen_->Compare32BitValue(left_high, val_high); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1510 | if (if_cond == kCondNE) { |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1511 | __ j(X86Condition(true_high_cond), true_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1512 | } else if (if_cond == kCondEQ) { |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1513 | __ j(X86Condition(false_high_cond), false_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1514 | } else { |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1515 | __ j(X86Condition(true_high_cond), true_label); |
| 1516 | __ j(X86Condition(false_high_cond), false_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1517 | } |
| 1518 | // Must be equal high, so compare the lows. |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1519 | codegen_->Compare32BitValue(left_low, val_low); |
| Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1520 | } else if (right.IsRegisterPair()) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1521 | Register right_high = right.AsRegisterPairHigh<Register>(); |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1522 | Register right_low = right.AsRegisterPairLow<Register>(); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1523 | |
| 1524 | __ cmpl(left_high, right_high); |
| 1525 | if (if_cond == kCondNE) { |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1526 | __ j(X86Condition(true_high_cond), true_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1527 | } else if (if_cond == kCondEQ) { |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1528 | __ j(X86Condition(false_high_cond), false_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1529 | } else { |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1530 | __ j(X86Condition(true_high_cond), true_label); |
| 1531 | __ j(X86Condition(false_high_cond), false_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1532 | } |
| 1533 | // Must be equal high, so compare the lows. |
| 1534 | __ cmpl(left_low, right_low); |
| Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1535 | } else { |
| 1536 | DCHECK(right.IsDoubleStackSlot()); |
| 1537 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
| 1538 | if (if_cond == kCondNE) { |
| 1539 | __ j(X86Condition(true_high_cond), true_label); |
| 1540 | } else if (if_cond == kCondEQ) { |
| 1541 | __ j(X86Condition(false_high_cond), false_label); |
| 1542 | } else { |
| 1543 | __ j(X86Condition(true_high_cond), true_label); |
| 1544 | __ j(X86Condition(false_high_cond), false_label); |
| 1545 | } |
| 1546 | // Must be equal high, so compare the lows. |
| 1547 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1548 | } |
| 1549 | // The last comparison might be unsigned. |
| 1550 | __ j(final_condition, true_label); |
| 1551 | } |
| 1552 | |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1553 | void InstructionCodeGeneratorX86::GenerateFPCompare(Location lhs, |
| 1554 | Location rhs, |
| 1555 | HInstruction* insn, |
| 1556 | bool is_double) { |
| 1557 | HX86LoadFromConstantTable* const_area = insn->InputAt(1)->AsX86LoadFromConstantTable(); |
| 1558 | if (is_double) { |
| 1559 | if (rhs.IsFpuRegister()) { |
| 1560 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1561 | } else if (const_area != nullptr) { |
| 1562 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1563 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), |
| 1564 | codegen_->LiteralDoubleAddress( |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1565 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 1566 | const_area->GetBaseMethodAddress(), |
| 1567 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1568 | } else { |
| 1569 | DCHECK(rhs.IsDoubleStackSlot()); |
| 1570 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1571 | } |
| 1572 | } else { |
| 1573 | if (rhs.IsFpuRegister()) { |
| 1574 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1575 | } else if (const_area != nullptr) { |
| 1576 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1577 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), |
| 1578 | codegen_->LiteralFloatAddress( |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1579 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 1580 | const_area->GetBaseMethodAddress(), |
| 1581 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1582 | } else { |
| 1583 | DCHECK(rhs.IsStackSlot()); |
| 1584 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1585 | } |
| 1586 | } |
| 1587 | } |
| 1588 | |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1589 | template<class LabelType> |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1590 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1591 | LabelType* true_target_in, |
| 1592 | LabelType* false_target_in) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1593 | // Generated branching requires both targets to be explicit. If either of the |
| 1594 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1595 | LabelType fallthrough_target; |
| 1596 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1597 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1598 | |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1599 | LocationSummary* locations = condition->GetLocations(); |
| 1600 | Location left = locations->InAt(0); |
| 1601 | Location right = locations->InAt(1); |
| 1602 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1603 | DataType::Type type = condition->InputAt(0)->GetType(); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1604 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1605 | case DataType::Type::kInt64: |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1606 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1607 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1608 | case DataType::Type::kFloat32: |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1609 | GenerateFPCompare(left, right, condition, false); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1610 | GenerateFPJumps(condition, true_target, false_target); |
| 1611 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1612 | case DataType::Type::kFloat64: |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1613 | GenerateFPCompare(left, right, condition, true); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1614 | GenerateFPJumps(condition, true_target, false_target); |
| 1615 | break; |
| 1616 | default: |
| 1617 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1618 | } |
| 1619 | |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1620 | if (false_target != &fallthrough_target) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1621 | __ jmp(false_target); |
| 1622 | } |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1623 | |
| 1624 | if (fallthrough_target.IsLinked()) { |
| 1625 | __ Bind(&fallthrough_target); |
| 1626 | } |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1627 | } |
| 1628 | |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1629 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1630 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1631 | // are set only strictly before `branch`. We can't use the eflags on long/FP |
| 1632 | // conditions if they are materialized due to the complex branching. |
| 1633 | return cond->IsCondition() && |
| 1634 | cond->GetNext() == branch && |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1635 | cond->InputAt(0)->GetType() != DataType::Type::kInt64 && |
| 1636 | !DataType::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1637 | } |
| 1638 | |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1639 | template<class LabelType> |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1640 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1641 | size_t condition_input_index, |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1642 | LabelType* true_target, |
| 1643 | LabelType* false_target) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1644 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1645 | |
| 1646 | if (true_target == nullptr && false_target == nullptr) { |
| 1647 | // Nothing to do. The code always falls through. |
| 1648 | return; |
| 1649 | } else if (cond->IsIntConstant()) { |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1650 | // Constant condition, statically compared against "true" (integer value 1). |
| 1651 | if (cond->AsIntConstant()->IsTrue()) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1652 | if (true_target != nullptr) { |
| 1653 | __ jmp(true_target); |
| Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1654 | } |
| Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1655 | } else { |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1656 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1657 | if (false_target != nullptr) { |
| 1658 | __ jmp(false_target); |
| 1659 | } |
| 1660 | } |
| 1661 | return; |
| 1662 | } |
| 1663 | |
| 1664 | // The following code generates these patterns: |
| 1665 | // (1) true_target == nullptr && false_target != nullptr |
| 1666 | // - opposite condition true => branch to false_target |
| 1667 | // (2) true_target != nullptr && false_target == nullptr |
| 1668 | // - condition true => branch to true_target |
| 1669 | // (3) true_target != nullptr && false_target != nullptr |
| 1670 | // - condition true => branch to true_target |
| 1671 | // - branch to false_target |
| 1672 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1673 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1674 | if (true_target == nullptr) { |
| 1675 | __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1676 | } else { |
| 1677 | __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); |
| 1678 | } |
| 1679 | } else { |
| 1680 | // Materialized condition, compare against 0. |
| 1681 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1682 | if (lhs.IsRegister()) { |
| 1683 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1684 | } else { |
| 1685 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1686 | } |
| 1687 | if (true_target == nullptr) { |
| 1688 | __ j(kEqual, false_target); |
| 1689 | } else { |
| 1690 | __ j(kNotEqual, true_target); |
| 1691 | } |
| Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1692 | } |
| 1693 | } else { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1694 | // Condition has not been materialized, use its inputs as the comparison and |
| 1695 | // its condition as the branch condition. |
| Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1696 | HCondition* condition = cond->AsCondition(); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1697 | |
| 1698 | // If this is a long or FP comparison that has been folded into |
| 1699 | // the HCondition, generate the comparison directly. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1700 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 1701 | if (type == DataType::Type::kInt64 || DataType::IsFloatingPointType(type)) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1702 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1703 | return; |
| 1704 | } |
| 1705 | |
| 1706 | Location lhs = condition->GetLocations()->InAt(0); |
| 1707 | Location rhs = condition->GetLocations()->InAt(1); |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1708 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition). |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1709 | codegen_->GenerateIntCompare(lhs, rhs); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1710 | if (true_target == nullptr) { |
| 1711 | __ j(X86Condition(condition->GetOppositeCondition()), false_target); |
| 1712 | } else { |
| Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1713 | __ j(X86Condition(condition->GetCondition()), true_target); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1714 | } |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1715 | } |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1716 | |
| 1717 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1718 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1719 | if (true_target != nullptr && false_target != nullptr) { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1720 | __ jmp(false_target); |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1721 | } |
| 1722 | } |
| 1723 | |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1724 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1725 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1726 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1727 | locations->SetInAt(0, Location::Any()); |
| 1728 | } |
| 1729 | } |
| 1730 | |
| 1731 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1732 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1733 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1734 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1735 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1736 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1737 | nullptr : codegen_->GetLabelOf(false_successor); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1738 | GenerateTestAndBranch(if_instr, /* condition_input_index= */ 0, true_target, false_target); |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1739 | } |
| 1740 | |
| 1741 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1742 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1743 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 1744 | InvokeRuntimeCallingConvention calling_convention; |
| 1745 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 1746 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1747 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1748 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1749 | locations->SetInAt(0, Location::Any()); |
| 1750 | } |
| 1751 | } |
| 1752 | |
| 1753 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1754 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86>(deoptimize); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1755 | GenerateTestAndBranch<Label>(deoptimize, |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1756 | /* condition_input_index= */ 0, |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1757 | slow_path->GetEntryLabel(), |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1758 | /* false_target= */ nullptr); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1759 | } |
| 1760 | |
| Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1761 | void LocationsBuilderX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1762 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
| Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1763 | LocationSummary(flag, LocationSummary::kNoCall); |
| 1764 | locations->SetOut(Location::RequiresRegister()); |
| 1765 | } |
| 1766 | |
| 1767 | void InstructionCodeGeneratorX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1768 | __ movl(flag->GetLocations()->Out().AsRegister<Register>(), |
| 1769 | Address(ESP, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1770 | } |
| 1771 | |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1772 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1773 | // There are no conditional move instructions for XMMs. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1774 | if (DataType::IsFloatingPointType(select->GetType())) { |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1775 | return false; |
| 1776 | } |
| 1777 | |
| 1778 | // A FP condition doesn't generate the single CC that we need. |
| 1779 | // In 32 bit mode, a long condition doesn't generate a single CC either. |
| 1780 | HInstruction* condition = select->GetCondition(); |
| 1781 | if (condition->IsCondition()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1782 | DataType::Type compare_type = condition->InputAt(0)->GetType(); |
| 1783 | if (compare_type == DataType::Type::kInt64 || |
| 1784 | DataType::IsFloatingPointType(compare_type)) { |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1785 | return false; |
| 1786 | } |
| 1787 | } |
| 1788 | |
| 1789 | // We can generate a CMOV for this Select. |
| 1790 | return true; |
| 1791 | } |
| 1792 | |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1793 | void LocationsBuilderX86::VisitSelect(HSelect* select) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1794 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1795 | if (DataType::IsFloatingPointType(select->GetType())) { |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1796 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1797 | locations->SetInAt(1, Location::Any()); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1798 | } else { |
| 1799 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1800 | if (SelectCanUseCMOV(select)) { |
| 1801 | if (select->InputAt(1)->IsConstant()) { |
| 1802 | // Cmov can't handle a constant value. |
| 1803 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1804 | } else { |
| 1805 | locations->SetInAt(1, Location::Any()); |
| 1806 | } |
| 1807 | } else { |
| 1808 | locations->SetInAt(1, Location::Any()); |
| 1809 | } |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1810 | } |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1811 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1812 | locations->SetInAt(2, Location::RequiresRegister()); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1813 | } |
| 1814 | locations->SetOut(Location::SameAsFirstInput()); |
| 1815 | } |
| 1816 | |
| 1817 | void InstructionCodeGeneratorX86::VisitSelect(HSelect* select) { |
| 1818 | LocationSummary* locations = select->GetLocations(); |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1819 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1820 | if (SelectCanUseCMOV(select)) { |
| 1821 | // If both the condition and the source types are integer, we can generate |
| 1822 | // a CMOV to implement Select. |
| 1823 | |
| 1824 | HInstruction* select_condition = select->GetCondition(); |
| 1825 | Condition cond = kNotEqual; |
| 1826 | |
| 1827 | // Figure out how to test the 'condition'. |
| 1828 | if (select_condition->IsCondition()) { |
| 1829 | HCondition* condition = select_condition->AsCondition(); |
| 1830 | if (!condition->IsEmittedAtUseSite()) { |
| 1831 | // This was a previously materialized condition. |
| 1832 | // Can we use the existing condition code? |
| 1833 | if (AreEflagsSetFrom(condition, select)) { |
| 1834 | // Materialization was the previous instruction. Condition codes are right. |
| 1835 | cond = X86Condition(condition->GetCondition()); |
| 1836 | } else { |
| 1837 | // No, we have to recreate the condition code. |
| 1838 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1839 | __ testl(cond_reg, cond_reg); |
| 1840 | } |
| 1841 | } else { |
| 1842 | // We can't handle FP or long here. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1843 | DCHECK_NE(condition->InputAt(0)->GetType(), DataType::Type::kInt64); |
| 1844 | DCHECK(!DataType::IsFloatingPointType(condition->InputAt(0)->GetType())); |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1845 | LocationSummary* cond_locations = condition->GetLocations(); |
| Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1846 | codegen_->GenerateIntCompare(cond_locations->InAt(0), cond_locations->InAt(1)); |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1847 | cond = X86Condition(condition->GetCondition()); |
| 1848 | } |
| 1849 | } else { |
| Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 1850 | // Must be a Boolean condition, which needs to be compared to 0. |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1851 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1852 | __ testl(cond_reg, cond_reg); |
| 1853 | } |
| 1854 | |
| 1855 | // If the condition is true, overwrite the output, which already contains false. |
| 1856 | Location false_loc = locations->InAt(0); |
| 1857 | Location true_loc = locations->InAt(1); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1858 | if (select->GetType() == DataType::Type::kInt64) { |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1859 | // 64 bit conditional move. |
| 1860 | Register false_high = false_loc.AsRegisterPairHigh<Register>(); |
| 1861 | Register false_low = false_loc.AsRegisterPairLow<Register>(); |
| 1862 | if (true_loc.IsRegisterPair()) { |
| 1863 | __ cmovl(cond, false_high, true_loc.AsRegisterPairHigh<Register>()); |
| 1864 | __ cmovl(cond, false_low, true_loc.AsRegisterPairLow<Register>()); |
| 1865 | } else { |
| 1866 | __ cmovl(cond, false_high, Address(ESP, true_loc.GetHighStackIndex(kX86WordSize))); |
| 1867 | __ cmovl(cond, false_low, Address(ESP, true_loc.GetStackIndex())); |
| 1868 | } |
| 1869 | } else { |
| 1870 | // 32 bit conditional move. |
| 1871 | Register false_reg = false_loc.AsRegister<Register>(); |
| 1872 | if (true_loc.IsRegister()) { |
| 1873 | __ cmovl(cond, false_reg, true_loc.AsRegister<Register>()); |
| 1874 | } else { |
| 1875 | __ cmovl(cond, false_reg, Address(ESP, true_loc.GetStackIndex())); |
| 1876 | } |
| 1877 | } |
| 1878 | } else { |
| 1879 | NearLabel false_target; |
| 1880 | GenerateTestAndBranch<NearLabel>( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1881 | select, /* condition_input_index= */ 2, /* true_target= */ nullptr, &false_target); |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1882 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1883 | __ Bind(&false_target); |
| 1884 | } |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1885 | } |
| 1886 | |
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1887 | void LocationsBuilderX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1888 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1889 | } |
| 1890 | |
| David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1891 | void InstructionCodeGeneratorX86::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1892 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
| David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1893 | } |
| 1894 | |
| 1895 | void CodeGeneratorX86::GenerateNop() { |
| 1896 | __ nop(); |
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1897 | } |
| 1898 | |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1899 | void LocationsBuilderX86::HandleCondition(HCondition* cond) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1900 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1901 | new (GetGraph()->GetAllocator()) LocationSummary(cond, LocationSummary::kNoCall); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1902 | // Handle the long/FP comparisons made in instruction simplification. |
| 1903 | switch (cond->InputAt(0)->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1904 | case DataType::Type::kInt64: { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1905 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1906 | locations->SetInAt(1, Location::Any()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1907 | if (!cond->IsEmittedAtUseSite()) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1908 | locations->SetOut(Location::RequiresRegister()); |
| 1909 | } |
| 1910 | break; |
| 1911 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1912 | case DataType::Type::kFloat32: |
| 1913 | case DataType::Type::kFloat64: { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1914 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1915 | if (cond->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 1916 | DCHECK(cond->InputAt(1)->IsEmittedAtUseSite()); |
| 1917 | } else if (cond->InputAt(1)->IsConstant()) { |
| 1918 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1919 | } else { |
| 1920 | locations->SetInAt(1, Location::Any()); |
| 1921 | } |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1922 | if (!cond->IsEmittedAtUseSite()) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1923 | locations->SetOut(Location::RequiresRegister()); |
| 1924 | } |
| 1925 | break; |
| 1926 | } |
| 1927 | default: |
| 1928 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1929 | locations->SetInAt(1, Location::Any()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1930 | if (!cond->IsEmittedAtUseSite()) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1931 | // We need a byte register. |
| 1932 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1933 | } |
| 1934 | break; |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1935 | } |
| Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1936 | } |
| 1937 | |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1938 | void InstructionCodeGeneratorX86::HandleCondition(HCondition* cond) { |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1939 | if (cond->IsEmittedAtUseSite()) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1940 | return; |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1941 | } |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1942 | |
| 1943 | LocationSummary* locations = cond->GetLocations(); |
| 1944 | Location lhs = locations->InAt(0); |
| 1945 | Location rhs = locations->InAt(1); |
| 1946 | Register reg = locations->Out().AsRegister<Register>(); |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1947 | NearLabel true_label, false_label; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1948 | |
| 1949 | switch (cond->InputAt(0)->GetType()) { |
| 1950 | default: { |
| 1951 | // Integer case. |
| 1952 | |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 1953 | // Clear output register: setb only sets the low byte. |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1954 | __ xorl(reg, reg); |
| Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1955 | codegen_->GenerateIntCompare(lhs, rhs); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1956 | __ setb(X86Condition(cond->GetCondition()), reg); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1957 | return; |
| 1958 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1959 | case DataType::Type::kInt64: |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1960 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1961 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1962 | case DataType::Type::kFloat32: |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1963 | GenerateFPCompare(lhs, rhs, cond, false); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1964 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1965 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1966 | case DataType::Type::kFloat64: |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1967 | GenerateFPCompare(lhs, rhs, cond, true); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1968 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1969 | break; |
| 1970 | } |
| 1971 | |
| 1972 | // Convert the jumps into the result. |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1973 | NearLabel done_label; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1974 | |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1975 | // False case: result = 0. |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1976 | __ Bind(&false_label); |
| 1977 | __ xorl(reg, reg); |
| 1978 | __ jmp(&done_label); |
| 1979 | |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1980 | // True case: result = 1. |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1981 | __ Bind(&true_label); |
| 1982 | __ movl(reg, Immediate(1)); |
| 1983 | __ Bind(&done_label); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1984 | } |
| 1985 | |
| 1986 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1987 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1988 | } |
| 1989 | |
| 1990 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1991 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1992 | } |
| 1993 | |
| 1994 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1995 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1996 | } |
| 1997 | |
| 1998 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1999 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2000 | } |
| 2001 | |
| 2002 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2003 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2004 | } |
| 2005 | |
| 2006 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2007 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2008 | } |
| 2009 | |
| 2010 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2011 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2012 | } |
| 2013 | |
| 2014 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2015 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2016 | } |
| 2017 | |
| 2018 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2019 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2020 | } |
| 2021 | |
| 2022 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2023 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2024 | } |
| 2025 | |
| 2026 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2027 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2028 | } |
| 2029 | |
| 2030 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2031 | HandleCondition(comp); |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2032 | } |
| 2033 | |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2034 | void LocationsBuilderX86::VisitBelow(HBelow* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2035 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2036 | } |
| 2037 | |
| 2038 | void InstructionCodeGeneratorX86::VisitBelow(HBelow* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2039 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2040 | } |
| 2041 | |
| 2042 | void LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2043 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2044 | } |
| 2045 | |
| 2046 | void InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2047 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2048 | } |
| 2049 | |
| 2050 | void LocationsBuilderX86::VisitAbove(HAbove* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2051 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2052 | } |
| 2053 | |
| 2054 | void InstructionCodeGeneratorX86::VisitAbove(HAbove* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2055 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2056 | } |
| 2057 | |
| 2058 | void LocationsBuilderX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2059 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2060 | } |
| 2061 | |
| 2062 | void InstructionCodeGeneratorX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2063 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2064 | } |
| 2065 | |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2066 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2067 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2068 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2069 | locations->SetOut(Location::ConstantLocation(constant)); |
| Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2070 | } |
| 2071 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2072 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2073 | // Will be generated at use site. |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2074 | } |
| 2075 | |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2076 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 2077 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2078 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2079 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2080 | } |
| 2081 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2082 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2083 | // Will be generated at use site. |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2084 | } |
| 2085 | |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2086 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2087 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2088 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2089 | locations->SetOut(Location::ConstantLocation(constant)); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2090 | } |
| 2091 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2092 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2093 | // Will be generated at use site. |
| 2094 | } |
| 2095 | |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2096 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 2097 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2098 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2099 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2100 | } |
| 2101 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2102 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2103 | // Will be generated at use site. |
| 2104 | } |
| 2105 | |
| 2106 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2107 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2108 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2109 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2110 | } |
| 2111 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2112 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2113 | // Will be generated at use site. |
| 2114 | } |
| 2115 | |
| Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2116 | void LocationsBuilderX86::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 2117 | constructor_fence->SetLocations(nullptr); |
| 2118 | } |
| 2119 | |
| 2120 | void InstructionCodeGeneratorX86::VisitConstructorFence( |
| 2121 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 2122 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 2123 | } |
| 2124 | |
| Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2125 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2126 | memory_barrier->SetLocations(nullptr); |
| 2127 | } |
| 2128 | |
| 2129 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 2130 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2131 | } |
| 2132 | |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2133 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2134 | ret->SetLocations(nullptr); |
| Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2135 | } |
| 2136 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2137 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2138 | codegen_->GenerateFrameExit(); |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2139 | } |
| 2140 | |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2141 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2142 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2143 | new (GetGraph()->GetAllocator()) LocationSummary(ret, LocationSummary::kNoCall); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2144 | switch (ret->InputAt(0)->GetType()) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2145 | case DataType::Type::kReference: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2146 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2147 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2148 | case DataType::Type::kInt8: |
| 2149 | case DataType::Type::kUint16: |
| 2150 | case DataType::Type::kInt16: |
| 2151 | case DataType::Type::kInt32: |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2152 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2153 | break; |
| 2154 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2155 | case DataType::Type::kInt64: |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2156 | locations->SetInAt( |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2157 | 0, Location::RegisterPairLocation(EAX, EDX)); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2158 | break; |
| 2159 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2160 | case DataType::Type::kFloat32: |
| 2161 | case DataType::Type::kFloat64: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2162 | locations->SetInAt( |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2163 | 0, Location::FpuRegisterLocation(XMM0)); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2164 | break; |
| 2165 | |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2166 | default: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2167 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2168 | } |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2169 | } |
| 2170 | |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2171 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2172 | if (kIsDebugBuild) { |
| 2173 | switch (ret->InputAt(0)->GetType()) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2174 | case DataType::Type::kReference: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2175 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2176 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2177 | case DataType::Type::kInt8: |
| 2178 | case DataType::Type::kUint16: |
| 2179 | case DataType::Type::kInt16: |
| 2180 | case DataType::Type::kInt32: |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2181 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2182 | break; |
| 2183 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2184 | case DataType::Type::kInt64: |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2185 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 2186 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2187 | break; |
| 2188 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2189 | case DataType::Type::kFloat32: |
| 2190 | case DataType::Type::kFloat64: |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2191 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2192 | break; |
| 2193 | |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2194 | default: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2195 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2196 | } |
| 2197 | } |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2198 | codegen_->GenerateFrameExit(); |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2199 | } |
| 2200 | |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2201 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2202 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2203 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2204 | // the method_idx. |
| 2205 | HandleInvoke(invoke); |
| 2206 | } |
| 2207 | |
| 2208 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2209 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2210 | } |
| 2211 | |
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2212 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2213 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2214 | // art::PrepareForRegisterAllocation. |
| 2215 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2216 | |
| Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2217 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2218 | if (intrinsic.TryDispatch(invoke)) { |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 2219 | if (invoke->GetLocations()->CanCall() && |
| 2220 | invoke->HasPcRelativeMethodLoadKind() && |
| 2221 | invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()).IsInvalid()) { |
| Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 2222 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2223 | } |
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2224 | return; |
| 2225 | } |
| 2226 | |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2227 | HandleInvoke(invoke); |
| Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2228 | |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2229 | // 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] | 2230 | if (invoke->HasPcRelativeMethodLoadKind()) { |
| Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2231 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2232 | } |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2233 | } |
| 2234 | |
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2235 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 2236 | if (invoke->GetLocations()->Intrinsified()) { |
| 2237 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 2238 | intrinsic.Dispatch(invoke); |
| 2239 | return true; |
| 2240 | } |
| 2241 | return false; |
| 2242 | } |
| 2243 | |
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2244 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2245 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2246 | // art::PrepareForRegisterAllocation. |
| 2247 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2248 | |
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2249 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2250 | return; |
| Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2251 | } |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2252 | |
| Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2253 | LocationSummary* locations = invoke->GetLocations(); |
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2254 | codegen_->GenerateStaticOrDirectCall( |
| Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2255 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2256 | } |
| 2257 | |
| 2258 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 2259 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 2260 | if (intrinsic.TryDispatch(invoke)) { |
| 2261 | return; |
| 2262 | } |
| 2263 | |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2264 | HandleInvoke(invoke); |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2265 | if (codegen_->GetCompilerOptions().IsBaseline() && !Runtime::Current()->IsAotCompiler()) { |
| 2266 | // Add one temporary for inline cache update. |
| 2267 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(EBP)); |
| 2268 | } |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2269 | } |
| 2270 | |
| 2271 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2272 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2273 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2274 | } |
| 2275 | |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2276 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2277 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2278 | return; |
| 2279 | } |
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2280 | |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2281 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2282 | DCHECK(!codegen_->IsLeafMethod()); |
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2283 | } |
| 2284 | |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2285 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2286 | // This call to HandleInvoke allocates a temporary (core) register |
| 2287 | // which is also used to transfer the hidden argument from FP to |
| 2288 | // core register. |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2289 | HandleInvoke(invoke); |
| 2290 | // Add the hidden argument. |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2291 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2292 | |
| 2293 | if (codegen_->GetCompilerOptions().IsBaseline() && !Runtime::Current()->IsAotCompiler()) { |
| 2294 | // Add one temporary for inline cache update. |
| 2295 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(EBP)); |
| 2296 | } |
| 2297 | } |
| 2298 | |
| 2299 | void CodeGeneratorX86::MaybeGenerateInlineCacheCheck(HInstruction* instruction, Register klass) { |
| 2300 | DCHECK_EQ(EAX, klass); |
| 2301 | if (GetCompilerOptions().IsBaseline() && !Runtime::Current()->IsAotCompiler()) { |
| 2302 | DCHECK(!instruction->GetEnvironment()->IsFromInlinedInvoke()); |
| 2303 | ScopedObjectAccess soa(Thread::Current()); |
| 2304 | ProfilingInfo* info = GetGraph()->GetArtMethod()->GetProfilingInfo(kRuntimePointerSize); |
| 2305 | InlineCache* cache = info->GetInlineCache(instruction->GetDexPc()); |
| 2306 | uint32_t address = reinterpret_cast32<uint32_t>(cache); |
| 2307 | if (kIsDebugBuild) { |
| 2308 | uint32_t temp_index = instruction->GetLocations()->GetTempCount() - 1u; |
| 2309 | CHECK_EQ(EBP, instruction->GetLocations()->GetTemp(temp_index).AsRegister<Register>()); |
| 2310 | } |
| 2311 | Register temp = EBP; |
| 2312 | NearLabel done; |
| 2313 | __ movl(temp, Immediate(address)); |
| 2314 | // Fast path for a monomorphic cache. |
| 2315 | __ cmpl(klass, Address(temp, InlineCache::ClassesOffset().Int32Value())); |
| 2316 | __ j(kEqual, &done); |
| 2317 | GenerateInvokeRuntime(GetThreadOffset<kX86PointerSize>(kQuickUpdateInlineCache).Int32Value()); |
| 2318 | __ Bind(&done); |
| 2319 | } |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2320 | } |
| 2321 | |
| 2322 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2323 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2324 | LocationSummary* locations = invoke->GetLocations(); |
| 2325 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2326 | XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2327 | Location receiver = locations->InAt(0); |
| 2328 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2329 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2330 | // Set the hidden argument. This is safe to do this here, as XMM7 |
| 2331 | // won't be modified thereafter, before the `call` instruction. |
| 2332 | DCHECK_EQ(XMM7, hidden_reg); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2333 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2334 | __ movd(hidden_reg, temp); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2335 | |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2336 | if (receiver.IsStackSlot()) { |
| 2337 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2338 | // /* HeapReference<Class> */ temp = temp->klass_ |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2339 | __ movl(temp, Address(temp, class_offset)); |
| 2340 | } else { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2341 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2342 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2343 | } |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2344 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2345 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2346 | // emit a read barrier for the previous class reference load. |
| 2347 | // However this is not required in practice, as this is an |
| 2348 | // intermediate/temporary reference and because the current |
| 2349 | // concurrent copying collector keeps the from-space memory |
| 2350 | // intact/accessible until the end of the marking phase (the |
| 2351 | // concurrent copying collector may not in the future). |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2352 | __ MaybeUnpoisonHeapReference(temp); |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2353 | |
| 2354 | codegen_->MaybeGenerateInlineCacheCheck(invoke, temp); |
| 2355 | |
| Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2356 | // temp = temp->GetAddressOfIMT() |
| 2357 | __ movl(temp, |
| 2358 | Address(temp, mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2359 | // temp = temp->GetImtEntryAt(method_offset); |
| Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2360 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2361 | invoke->GetImtIndex(), kX86PointerSize)); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2362 | __ movl(temp, Address(temp, method_offset)); |
| 2363 | // call temp->GetEntryPoint(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2364 | __ call(Address(temp, |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2365 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2366 | |
| 2367 | DCHECK(!codegen_->IsLeafMethod()); |
| 2368 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2369 | } |
| 2370 | |
| Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2371 | void LocationsBuilderX86::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2372 | HandleInvoke(invoke); |
| 2373 | } |
| 2374 | |
| 2375 | void InstructionCodeGeneratorX86::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2376 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 2377 | } |
| 2378 | |
| Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 2379 | void LocationsBuilderX86::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 2380 | HandleInvoke(invoke); |
| 2381 | } |
| 2382 | |
| 2383 | void InstructionCodeGeneratorX86::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 2384 | codegen_->GenerateInvokeCustomCall(invoke); |
| 2385 | } |
| 2386 | |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2387 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 2388 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2389 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2390 | switch (neg->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2391 | case DataType::Type::kInt32: |
| 2392 | case DataType::Type::kInt64: |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2393 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2394 | locations->SetOut(Location::SameAsFirstInput()); |
| 2395 | break; |
| 2396 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2397 | case DataType::Type::kFloat32: |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2398 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2399 | locations->SetOut(Location::SameAsFirstInput()); |
| 2400 | locations->AddTemp(Location::RequiresRegister()); |
| 2401 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2402 | break; |
| 2403 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2404 | case DataType::Type::kFloat64: |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2405 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2406 | locations->SetOut(Location::SameAsFirstInput()); |
| 2407 | locations->AddTemp(Location::RequiresFpuRegister()); |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2408 | break; |
| 2409 | |
| 2410 | default: |
| 2411 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2412 | } |
| 2413 | } |
| 2414 | |
| 2415 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 2416 | LocationSummary* locations = neg->GetLocations(); |
| 2417 | Location out = locations->Out(); |
| 2418 | Location in = locations->InAt(0); |
| 2419 | switch (neg->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2420 | case DataType::Type::kInt32: |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2421 | DCHECK(in.IsRegister()); |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2422 | DCHECK(in.Equals(out)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2423 | __ negl(out.AsRegister<Register>()); |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2424 | break; |
| 2425 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2426 | case DataType::Type::kInt64: |
| Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2427 | DCHECK(in.IsRegisterPair()); |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2428 | DCHECK(in.Equals(out)); |
| Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2429 | __ negl(out.AsRegisterPairLow<Register>()); |
| 2430 | // Negation is similar to subtraction from zero. The least |
| 2431 | // significant byte triggers a borrow when it is different from |
| 2432 | // zero; to take it into account, add 1 to the most significant |
| 2433 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 2434 | // operation. |
| 2435 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2436 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 2437 | break; |
| 2438 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2439 | case DataType::Type::kFloat32: { |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2440 | DCHECK(in.Equals(out)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2441 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 2442 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2443 | // Implement float negation with an exclusive or with value |
| 2444 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2445 | // single-precision floating-point number). |
| 2446 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 2447 | __ movd(mask, constant); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2448 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2449 | break; |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2450 | } |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2451 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2452 | case DataType::Type::kFloat64: { |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2453 | DCHECK(in.Equals(out)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2454 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2455 | // Implement double negation with an exclusive or with value |
| 2456 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 2457 | // a double-precision floating-point number). |
| 2458 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2459 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2460 | break; |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2461 | } |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2462 | |
| 2463 | default: |
| 2464 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2465 | } |
| 2466 | } |
| 2467 | |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2468 | void LocationsBuilderX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2469 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2470 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2471 | DCHECK(DataType::IsFloatingPointType(neg->GetType())); |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2472 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2473 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2474 | locations->SetOut(Location::SameAsFirstInput()); |
| 2475 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2476 | } |
| 2477 | |
| 2478 | void InstructionCodeGeneratorX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2479 | LocationSummary* locations = neg->GetLocations(); |
| 2480 | Location out = locations->Out(); |
| 2481 | DCHECK(locations->InAt(0).Equals(out)); |
| 2482 | |
| 2483 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 2484 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2485 | if (neg->GetType() == DataType::Type::kFloat32) { |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 2486 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x80000000), |
| 2487 | neg->GetBaseMethodAddress(), |
| 2488 | constant_area)); |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2489 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| 2490 | } else { |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 2491 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000), |
| 2492 | neg->GetBaseMethodAddress(), |
| 2493 | constant_area)); |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2494 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| 2495 | } |
| 2496 | } |
| 2497 | |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2498 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2499 | DataType::Type result_type = conversion->GetResultType(); |
| 2500 | DataType::Type input_type = conversion->GetInputType(); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2501 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 2502 | << input_type << " -> " << result_type; |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2503 | |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2504 | // The float-to-long and double-to-long type conversions rely on a |
| 2505 | // call to the runtime. |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2506 | LocationSummary::CallKind call_kind = |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2507 | ((input_type == DataType::Type::kFloat32 || input_type == DataType::Type::kFloat64) |
| 2508 | && result_type == DataType::Type::kInt64) |
| Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2509 | ? LocationSummary::kCallOnMainOnly |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2510 | : LocationSummary::kNoCall; |
| 2511 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2512 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, call_kind); |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2513 | |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2514 | switch (result_type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2515 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2516 | case DataType::Type::kInt8: |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2517 | switch (input_type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2518 | case DataType::Type::kUint8: |
| 2519 | case DataType::Type::kInt8: |
| 2520 | case DataType::Type::kUint16: |
| 2521 | case DataType::Type::kInt16: |
| 2522 | case DataType::Type::kInt32: |
| 2523 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 2524 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2525 | // the validation of the linear scan implementation |
| 2526 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2527 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2528 | case DataType::Type::kInt64: { |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2529 | HInstruction* input = conversion->InputAt(0); |
| 2530 | Location input_location = input->IsConstant() |
| 2531 | ? Location::ConstantLocation(input->AsConstant()) |
| 2532 | : Location::RegisterPairLocation(EAX, EDX); |
| 2533 | locations->SetInAt(0, input_location); |
| 2534 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2535 | // the validation of the linear scan implementation |
| 2536 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2537 | break; |
| 2538 | } |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2539 | |
| 2540 | default: |
| 2541 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2542 | << " to " << result_type; |
| 2543 | } |
| 2544 | break; |
| 2545 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2546 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2547 | case DataType::Type::kInt16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2548 | DCHECK(DataType::IsIntegralType(input_type)) << input_type; |
| 2549 | locations->SetInAt(0, Location::Any()); |
| 2550 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2551 | break; |
| 2552 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2553 | case DataType::Type::kInt32: |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2554 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2555 | case DataType::Type::kInt64: |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2556 | locations->SetInAt(0, Location::Any()); |
| 2557 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2558 | break; |
| 2559 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2560 | case DataType::Type::kFloat32: |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2561 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2562 | locations->SetOut(Location::RequiresRegister()); |
| 2563 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2564 | break; |
| 2565 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2566 | case DataType::Type::kFloat64: |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2567 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2568 | locations->SetOut(Location::RequiresRegister()); |
| 2569 | locations->AddTemp(Location::RequiresFpuRegister()); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2570 | break; |
| 2571 | |
| 2572 | default: |
| 2573 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2574 | << " to " << result_type; |
| 2575 | } |
| 2576 | break; |
| 2577 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2578 | case DataType::Type::kInt64: |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2579 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2580 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2581 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2582 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2583 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2584 | case DataType::Type::kInt16: |
| 2585 | case DataType::Type::kInt32: |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2586 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 2587 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2588 | break; |
| 2589 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2590 | case DataType::Type::kFloat32: |
| 2591 | case DataType::Type::kFloat64: { |
| Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2592 | InvokeRuntimeCallingConvention calling_convention; |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2593 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 2594 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 2595 | |
| Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2596 | // The runtime helper puts the result in EAX, EDX. |
| 2597 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2598 | } |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2599 | break; |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2600 | |
| 2601 | default: |
| 2602 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2603 | << " to " << result_type; |
| 2604 | } |
| 2605 | break; |
| 2606 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2607 | case DataType::Type::kFloat32: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2608 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2609 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2610 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2611 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2612 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2613 | case DataType::Type::kInt16: |
| 2614 | case DataType::Type::kInt32: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2615 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2616 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2617 | break; |
| 2618 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2619 | case DataType::Type::kInt64: |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2620 | locations->SetInAt(0, Location::Any()); |
| 2621 | locations->SetOut(Location::Any()); |
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2622 | break; |
| 2623 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2624 | case DataType::Type::kFloat64: |
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2625 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2626 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2627 | break; |
| 2628 | |
| 2629 | default: |
| 2630 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2631 | << " to " << result_type; |
| Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 2632 | } |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2633 | break; |
| 2634 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2635 | case DataType::Type::kFloat64: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2636 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2637 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2638 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2639 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2640 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2641 | case DataType::Type::kInt16: |
| 2642 | case DataType::Type::kInt32: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2643 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2644 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2645 | break; |
| 2646 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2647 | case DataType::Type::kInt64: |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2648 | locations->SetInAt(0, Location::Any()); |
| 2649 | locations->SetOut(Location::Any()); |
| Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2650 | break; |
| 2651 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2652 | case DataType::Type::kFloat32: |
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2653 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2654 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2655 | break; |
| 2656 | |
| 2657 | default: |
| 2658 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2659 | << " to " << result_type; |
| 2660 | } |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2661 | break; |
| 2662 | |
| 2663 | default: |
| 2664 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2665 | << " to " << result_type; |
| 2666 | } |
| 2667 | } |
| 2668 | |
| 2669 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 2670 | LocationSummary* locations = conversion->GetLocations(); |
| 2671 | Location out = locations->Out(); |
| 2672 | Location in = locations->InAt(0); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2673 | DataType::Type result_type = conversion->GetResultType(); |
| 2674 | DataType::Type input_type = conversion->GetInputType(); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2675 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 2676 | << input_type << " -> " << result_type; |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2677 | switch (result_type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2678 | case DataType::Type::kUint8: |
| 2679 | switch (input_type) { |
| 2680 | case DataType::Type::kInt8: |
| 2681 | case DataType::Type::kUint16: |
| 2682 | case DataType::Type::kInt16: |
| 2683 | case DataType::Type::kInt32: |
| 2684 | if (in.IsRegister()) { |
| 2685 | __ movzxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
| 2686 | } else { |
| 2687 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2688 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2689 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint8_t>(value))); |
| 2690 | } |
| 2691 | break; |
| 2692 | case DataType::Type::kInt64: |
| 2693 | if (in.IsRegisterPair()) { |
| 2694 | __ movzxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 2695 | } else { |
| 2696 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2697 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2698 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint8_t>(value))); |
| 2699 | } |
| 2700 | break; |
| 2701 | |
| 2702 | default: |
| 2703 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2704 | << " to " << result_type; |
| 2705 | } |
| 2706 | break; |
| 2707 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2708 | case DataType::Type::kInt8: |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2709 | switch (input_type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2710 | case DataType::Type::kUint8: |
| 2711 | case DataType::Type::kUint16: |
| 2712 | case DataType::Type::kInt16: |
| 2713 | case DataType::Type::kInt32: |
| 2714 | if (in.IsRegister()) { |
| 2715 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
| 2716 | } else { |
| 2717 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2718 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2719 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2720 | } |
| 2721 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2722 | case DataType::Type::kInt64: |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2723 | if (in.IsRegisterPair()) { |
| 2724 | __ movsxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 2725 | } else { |
| 2726 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2727 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2728 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2729 | } |
| 2730 | break; |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2731 | |
| 2732 | default: |
| 2733 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2734 | << " to " << result_type; |
| 2735 | } |
| 2736 | break; |
| 2737 | |
| 2738 | case DataType::Type::kUint16: |
| 2739 | switch (input_type) { |
| 2740 | case DataType::Type::kInt8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2741 | case DataType::Type::kInt16: |
| 2742 | case DataType::Type::kInt32: |
| Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2743 | if (in.IsRegister()) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2744 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
| 2745 | } else if (in.IsStackSlot()) { |
| 2746 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2747 | } else { |
| 2748 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2749 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2750 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
| 2751 | } |
| 2752 | break; |
| 2753 | case DataType::Type::kInt64: |
| 2754 | if (in.IsRegisterPair()) { |
| 2755 | __ movzxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2756 | } else if (in.IsDoubleStackSlot()) { |
| 2757 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2758 | } else { |
| 2759 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2760 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2761 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
| Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2762 | } |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2763 | break; |
| 2764 | |
| 2765 | default: |
| 2766 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2767 | << " to " << result_type; |
| 2768 | } |
| 2769 | break; |
| 2770 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2771 | case DataType::Type::kInt16: |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2772 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2773 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2774 | case DataType::Type::kInt32: |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2775 | if (in.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2776 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2777 | } else if (in.IsStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2778 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2779 | } else { |
| 2780 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2781 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2782 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2783 | } |
| 2784 | break; |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2785 | case DataType::Type::kInt64: |
| 2786 | if (in.IsRegisterPair()) { |
| 2787 | __ movsxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2788 | } else if (in.IsDoubleStackSlot()) { |
| 2789 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2790 | } else { |
| 2791 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2792 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2793 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
| 2794 | } |
| 2795 | break; |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2796 | |
| 2797 | default: |
| 2798 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2799 | << " to " << result_type; |
| 2800 | } |
| 2801 | break; |
| 2802 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2803 | case DataType::Type::kInt32: |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2804 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2805 | case DataType::Type::kInt64: |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2806 | if (in.IsRegisterPair()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2807 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2808 | } else if (in.IsDoubleStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2809 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2810 | } else { |
| 2811 | DCHECK(in.IsConstant()); |
| 2812 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2813 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2814 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2815 | } |
| 2816 | break; |
| 2817 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2818 | case DataType::Type::kFloat32: { |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2819 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2820 | Register output = out.AsRegister<Register>(); |
| 2821 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2822 | NearLabel done, nan; |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2823 | |
| 2824 | __ movl(output, Immediate(kPrimIntMax)); |
| 2825 | // temp = int-to-float(output) |
| 2826 | __ cvtsi2ss(temp, output); |
| 2827 | // if input >= temp goto done |
| 2828 | __ comiss(input, temp); |
| 2829 | __ j(kAboveEqual, &done); |
| 2830 | // if input == NaN goto nan |
| 2831 | __ j(kUnordered, &nan); |
| 2832 | // output = float-to-int-truncate(input) |
| 2833 | __ cvttss2si(output, input); |
| 2834 | __ jmp(&done); |
| 2835 | __ Bind(&nan); |
| 2836 | // output = 0 |
| 2837 | __ xorl(output, output); |
| 2838 | __ Bind(&done); |
| 2839 | break; |
| 2840 | } |
| 2841 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2842 | case DataType::Type::kFloat64: { |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2843 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2844 | Register output = out.AsRegister<Register>(); |
| 2845 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2846 | NearLabel done, nan; |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2847 | |
| 2848 | __ movl(output, Immediate(kPrimIntMax)); |
| 2849 | // temp = int-to-double(output) |
| 2850 | __ cvtsi2sd(temp, output); |
| 2851 | // if input >= temp goto done |
| 2852 | __ comisd(input, temp); |
| 2853 | __ j(kAboveEqual, &done); |
| 2854 | // if input == NaN goto nan |
| 2855 | __ j(kUnordered, &nan); |
| 2856 | // output = double-to-int-truncate(input) |
| 2857 | __ cvttsd2si(output, input); |
| 2858 | __ jmp(&done); |
| 2859 | __ Bind(&nan); |
| 2860 | // output = 0 |
| 2861 | __ xorl(output, output); |
| 2862 | __ Bind(&done); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2863 | break; |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2864 | } |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2865 | |
| 2866 | default: |
| 2867 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2868 | << " to " << result_type; |
| 2869 | } |
| 2870 | break; |
| 2871 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2872 | case DataType::Type::kInt64: |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2873 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2874 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2875 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2876 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2877 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2878 | case DataType::Type::kInt16: |
| 2879 | case DataType::Type::kInt32: |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2880 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2881 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2882 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2883 | __ cdq(); |
| 2884 | break; |
| 2885 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2886 | case DataType::Type::kFloat32: |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2887 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2888 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2889 | break; |
| 2890 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2891 | case DataType::Type::kFloat64: |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2892 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2893 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2894 | break; |
| 2895 | |
| 2896 | default: |
| 2897 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2898 | << " to " << result_type; |
| 2899 | } |
| 2900 | break; |
| 2901 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2902 | case DataType::Type::kFloat32: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2903 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2904 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2905 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2906 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2907 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2908 | case DataType::Type::kInt16: |
| 2909 | case DataType::Type::kInt32: |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2910 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2911 | break; |
| 2912 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2913 | case DataType::Type::kInt64: { |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2914 | size_t adjustment = 0; |
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2915 | |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2916 | // Create stack space for the call to |
| 2917 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2918 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2919 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2920 | adjustment = DataType::Size(DataType::Type::kInt64); |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2921 | __ subl(ESP, Immediate(adjustment)); |
| 2922 | } |
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2923 | |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2924 | // Load the value to the FP stack, using temporaries if needed. |
| 2925 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2926 | |
| 2927 | if (out.IsStackSlot()) { |
| 2928 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2929 | } else { |
| 2930 | __ fstps(Address(ESP, 0)); |
| 2931 | Location stack_temp = Location::StackSlot(0); |
| 2932 | codegen_->Move32(out, stack_temp); |
| 2933 | } |
| 2934 | |
| 2935 | // Remove the temporary stack space we allocated. |
| 2936 | if (adjustment != 0) { |
| 2937 | __ addl(ESP, Immediate(adjustment)); |
| 2938 | } |
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2939 | break; |
| 2940 | } |
| 2941 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2942 | case DataType::Type::kFloat64: |
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2943 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2944 | break; |
| 2945 | |
| 2946 | default: |
| 2947 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2948 | << " to " << result_type; |
| Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 2949 | } |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2950 | break; |
| 2951 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2952 | case DataType::Type::kFloat64: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2953 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2954 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2955 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2956 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2957 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2958 | case DataType::Type::kInt16: |
| 2959 | case DataType::Type::kInt32: |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2960 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2961 | break; |
| 2962 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2963 | case DataType::Type::kInt64: { |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2964 | size_t adjustment = 0; |
| Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2965 | |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2966 | // Create stack space for the call to |
| 2967 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2968 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2969 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2970 | adjustment = DataType::Size(DataType::Type::kInt64); |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2971 | __ subl(ESP, Immediate(adjustment)); |
| 2972 | } |
| 2973 | |
| 2974 | // Load the value to the FP stack, using temporaries if needed. |
| 2975 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2976 | |
| 2977 | if (out.IsDoubleStackSlot()) { |
| 2978 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2979 | } else { |
| 2980 | __ fstpl(Address(ESP, 0)); |
| 2981 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2982 | codegen_->Move64(out, stack_temp); |
| 2983 | } |
| 2984 | |
| 2985 | // Remove the temporary stack space we allocated. |
| 2986 | if (adjustment != 0) { |
| 2987 | __ addl(ESP, Immediate(adjustment)); |
| 2988 | } |
| Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2989 | break; |
| 2990 | } |
| 2991 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2992 | case DataType::Type::kFloat32: |
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2993 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2994 | break; |
| 2995 | |
| 2996 | default: |
| 2997 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2998 | << " to " << result_type; |
| Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 2999 | } |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3000 | break; |
| 3001 | |
| 3002 | default: |
| 3003 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3004 | << " to " << result_type; |
| 3005 | } |
| 3006 | } |
| 3007 | |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3008 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3009 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3010 | new (GetGraph()->GetAllocator()) LocationSummary(add, LocationSummary::kNoCall); |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3011 | switch (add->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3012 | case DataType::Type::kInt32: { |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3013 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3014 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 3015 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3016 | break; |
| 3017 | } |
| 3018 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3019 | case DataType::Type::kInt64: { |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3020 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3021 | locations->SetInAt(1, Location::Any()); |
| 3022 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3023 | break; |
| 3024 | } |
| 3025 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3026 | case DataType::Type::kFloat32: |
| 3027 | case DataType::Type::kFloat64: { |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3028 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3029 | if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3030 | DCHECK(add->InputAt(1)->IsEmittedAtUseSite()); |
| Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3031 | } else if (add->InputAt(1)->IsConstant()) { |
| 3032 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3033 | } else { |
| 3034 | locations->SetInAt(1, Location::Any()); |
| 3035 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3036 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3037 | break; |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3038 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3039 | |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3040 | default: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3041 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 3042 | UNREACHABLE(); |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3043 | } |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3044 | } |
| 3045 | |
| 3046 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 3047 | LocationSummary* locations = add->GetLocations(); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3048 | Location first = locations->InAt(0); |
| 3049 | Location second = locations->InAt(1); |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3050 | Location out = locations->Out(); |
| 3051 | |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3052 | switch (add->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3053 | case DataType::Type::kInt32: { |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3054 | if (second.IsRegister()) { |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3055 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3056 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
| Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 3057 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 3058 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3059 | } else { |
| 3060 | __ leal(out.AsRegister<Register>(), Address( |
| 3061 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 3062 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3063 | } else if (second.IsConstant()) { |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3064 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3065 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3066 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 3067 | } else { |
| 3068 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 3069 | } |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3070 | } else { |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3071 | DCHECK(first.Equals(locations->Out())); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3072 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3073 | } |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3074 | break; |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3075 | } |
| 3076 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3077 | case DataType::Type::kInt64: { |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3078 | if (second.IsRegisterPair()) { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3079 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3080 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3081 | } else if (second.IsDoubleStackSlot()) { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3082 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 3083 | __ adcl(first.AsRegisterPairHigh<Register>(), |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3084 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3085 | } else { |
| 3086 | DCHECK(second.IsConstant()) << second; |
| 3087 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3088 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 3089 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3090 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3091 | break; |
| 3092 | } |
| 3093 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3094 | case DataType::Type::kFloat32: { |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3095 | if (second.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3096 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3097 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3098 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3099 | DCHECK(const_area->IsEmittedAtUseSite()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3100 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 3101 | codegen_->LiteralFloatAddress( |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3102 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3103 | const_area->GetBaseMethodAddress(), |
| 3104 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3105 | } else { |
| 3106 | DCHECK(second.IsStackSlot()); |
| 3107 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3108 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3109 | break; |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3110 | } |
| 3111 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3112 | case DataType::Type::kFloat64: { |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3113 | if (second.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3114 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3115 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3116 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3117 | DCHECK(const_area->IsEmittedAtUseSite()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3118 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 3119 | codegen_->LiteralDoubleAddress( |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3120 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3121 | const_area->GetBaseMethodAddress(), |
| 3122 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3123 | } else { |
| 3124 | DCHECK(second.IsDoubleStackSlot()); |
| 3125 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3126 | } |
| 3127 | break; |
| 3128 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3129 | |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3130 | default: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3131 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3132 | } |
| 3133 | } |
| 3134 | |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3135 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3136 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3137 | new (GetGraph()->GetAllocator()) LocationSummary(sub, LocationSummary::kNoCall); |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3138 | switch (sub->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3139 | case DataType::Type::kInt32: |
| 3140 | case DataType::Type::kInt64: { |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3141 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3142 | locations->SetInAt(1, Location::Any()); |
| 3143 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3144 | break; |
| 3145 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3146 | case DataType::Type::kFloat32: |
| 3147 | case DataType::Type::kFloat64: { |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3148 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3149 | if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3150 | DCHECK(sub->InputAt(1)->IsEmittedAtUseSite()); |
| Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3151 | } else if (sub->InputAt(1)->IsConstant()) { |
| 3152 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3153 | } else { |
| 3154 | locations->SetInAt(1, Location::Any()); |
| 3155 | } |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3156 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3157 | break; |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3158 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3159 | |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3160 | default: |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3161 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3162 | } |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3163 | } |
| 3164 | |
| 3165 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 3166 | LocationSummary* locations = sub->GetLocations(); |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3167 | Location first = locations->InAt(0); |
| 3168 | Location second = locations->InAt(1); |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3169 | DCHECK(first.Equals(locations->Out())); |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3170 | switch (sub->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3171 | case DataType::Type::kInt32: { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3172 | if (second.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3173 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3174 | } else if (second.IsConstant()) { |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3175 | __ subl(first.AsRegister<Register>(), |
| 3176 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3177 | } else { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3178 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3179 | } |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3180 | break; |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3181 | } |
| 3182 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3183 | case DataType::Type::kInt64: { |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3184 | if (second.IsRegisterPair()) { |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3185 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3186 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3187 | } else if (second.IsDoubleStackSlot()) { |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3188 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3189 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 3190 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3191 | } else { |
| 3192 | DCHECK(second.IsConstant()) << second; |
| 3193 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3194 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 3195 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3196 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3197 | break; |
| 3198 | } |
| 3199 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3200 | case DataType::Type::kFloat32: { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3201 | if (second.IsFpuRegister()) { |
| 3202 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3203 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3204 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3205 | DCHECK(const_area->IsEmittedAtUseSite()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3206 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3207 | codegen_->LiteralFloatAddress( |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3208 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3209 | const_area->GetBaseMethodAddress(), |
| 3210 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3211 | } else { |
| 3212 | DCHECK(second.IsStackSlot()); |
| 3213 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3214 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3215 | break; |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3216 | } |
| 3217 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3218 | case DataType::Type::kFloat64: { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3219 | if (second.IsFpuRegister()) { |
| 3220 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3221 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3222 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3223 | DCHECK(const_area->IsEmittedAtUseSite()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3224 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3225 | codegen_->LiteralDoubleAddress( |
| 3226 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3227 | const_area->GetBaseMethodAddress(), |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3228 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3229 | } else { |
| 3230 | DCHECK(second.IsDoubleStackSlot()); |
| 3231 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3232 | } |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3233 | break; |
| 3234 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3235 | |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3236 | default: |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3237 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3238 | } |
| 3239 | } |
| 3240 | |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3241 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 3242 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3243 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3244 | switch (mul->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3245 | case DataType::Type::kInt32: |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3246 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3247 | locations->SetInAt(1, Location::Any()); |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3248 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3249 | // Can use 3 operand multiply. |
| 3250 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3251 | } else { |
| 3252 | locations->SetOut(Location::SameAsFirstInput()); |
| 3253 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3254 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3255 | case DataType::Type::kInt64: { |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3256 | locations->SetInAt(0, Location::RequiresRegister()); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3257 | locations->SetInAt(1, Location::Any()); |
| 3258 | locations->SetOut(Location::SameAsFirstInput()); |
| 3259 | // Needed for imul on 32bits with 64bits output. |
| 3260 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 3261 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 3262 | break; |
| 3263 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3264 | case DataType::Type::kFloat32: |
| 3265 | case DataType::Type::kFloat64: { |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3266 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3267 | if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3268 | DCHECK(mul->InputAt(1)->IsEmittedAtUseSite()); |
| Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3269 | } else if (mul->InputAt(1)->IsConstant()) { |
| 3270 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3271 | } else { |
| 3272 | locations->SetInAt(1, Location::Any()); |
| 3273 | } |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3274 | locations->SetOut(Location::SameAsFirstInput()); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3275 | break; |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3276 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3277 | |
| 3278 | default: |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3279 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3280 | } |
| 3281 | } |
| 3282 | |
| 3283 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 3284 | LocationSummary* locations = mul->GetLocations(); |
| 3285 | Location first = locations->InAt(0); |
| 3286 | Location second = locations->InAt(1); |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3287 | Location out = locations->Out(); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3288 | |
| 3289 | switch (mul->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3290 | case DataType::Type::kInt32: |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3291 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3292 | // problems where the output may not be the same as the first operand. |
| 3293 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3294 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3295 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 3296 | } else if (second.IsRegister()) { |
| 3297 | DCHECK(first.Equals(out)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3298 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3299 | } else { |
| 3300 | DCHECK(second.IsStackSlot()); |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3301 | DCHECK(first.Equals(out)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3302 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3303 | } |
| 3304 | break; |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3305 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3306 | case DataType::Type::kInt64: { |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3307 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 3308 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3309 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 3310 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3311 | |
| 3312 | DCHECK_EQ(EAX, eax); |
| 3313 | DCHECK_EQ(EDX, edx); |
| 3314 | |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3315 | // input: in1 - 64 bits, in2 - 64 bits. |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3316 | // output: in1 |
| 3317 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3318 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3319 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3320 | if (second.IsConstant()) { |
| 3321 | DCHECK(second.GetConstant()->IsLongConstant()); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3322 | |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3323 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3324 | int32_t low_value = Low32Bits(value); |
| 3325 | int32_t high_value = High32Bits(value); |
| 3326 | Immediate low(low_value); |
| 3327 | Immediate high(high_value); |
| 3328 | |
| 3329 | __ movl(eax, high); |
| 3330 | // eax <- in1.lo * in2.hi |
| 3331 | __ imull(eax, in1_lo); |
| 3332 | // in1.hi <- in1.hi * in2.lo |
| 3333 | __ imull(in1_hi, low); |
| 3334 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3335 | __ addl(in1_hi, eax); |
| 3336 | // move in2_lo to eax to prepare for double precision |
| 3337 | __ movl(eax, low); |
| 3338 | // edx:eax <- in1.lo * in2.lo |
| 3339 | __ mull(in1_lo); |
| 3340 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3341 | __ addl(in1_hi, edx); |
| 3342 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3343 | __ movl(in1_lo, eax); |
| 3344 | } else if (second.IsRegisterPair()) { |
| 3345 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3346 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3347 | |
| 3348 | __ movl(eax, in2_hi); |
| 3349 | // eax <- in1.lo * in2.hi |
| 3350 | __ imull(eax, in1_lo); |
| 3351 | // in1.hi <- in1.hi * in2.lo |
| 3352 | __ imull(in1_hi, in2_lo); |
| 3353 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3354 | __ addl(in1_hi, eax); |
| 3355 | // move in1_lo to eax to prepare for double precision |
| 3356 | __ movl(eax, in1_lo); |
| 3357 | // edx:eax <- in1.lo * in2.lo |
| 3358 | __ mull(in2_lo); |
| 3359 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3360 | __ addl(in1_hi, edx); |
| 3361 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3362 | __ movl(in1_lo, eax); |
| 3363 | } else { |
| 3364 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 3365 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 3366 | Address in2_lo(ESP, second.GetStackIndex()); |
| 3367 | |
| 3368 | __ movl(eax, in2_hi); |
| 3369 | // eax <- in1.lo * in2.hi |
| 3370 | __ imull(eax, in1_lo); |
| 3371 | // in1.hi <- in1.hi * in2.lo |
| 3372 | __ imull(in1_hi, in2_lo); |
| 3373 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3374 | __ addl(in1_hi, eax); |
| 3375 | // move in1_lo to eax to prepare for double precision |
| 3376 | __ movl(eax, in1_lo); |
| 3377 | // edx:eax <- in1.lo * in2.lo |
| 3378 | __ mull(in2_lo); |
| 3379 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3380 | __ addl(in1_hi, edx); |
| 3381 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3382 | __ movl(in1_lo, eax); |
| 3383 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3384 | |
| 3385 | break; |
| 3386 | } |
| 3387 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3388 | case DataType::Type::kFloat32: { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3389 | DCHECK(first.Equals(locations->Out())); |
| 3390 | if (second.IsFpuRegister()) { |
| 3391 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3392 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3393 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3394 | DCHECK(const_area->IsEmittedAtUseSite()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3395 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3396 | codegen_->LiteralFloatAddress( |
| 3397 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3398 | const_area->GetBaseMethodAddress(), |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3399 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3400 | } else { |
| 3401 | DCHECK(second.IsStackSlot()); |
| 3402 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3403 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3404 | break; |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3405 | } |
| 3406 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3407 | case DataType::Type::kFloat64: { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3408 | DCHECK(first.Equals(locations->Out())); |
| 3409 | if (second.IsFpuRegister()) { |
| 3410 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3411 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3412 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3413 | DCHECK(const_area->IsEmittedAtUseSite()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3414 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3415 | codegen_->LiteralDoubleAddress( |
| 3416 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3417 | const_area->GetBaseMethodAddress(), |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3418 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3419 | } else { |
| 3420 | DCHECK(second.IsDoubleStackSlot()); |
| 3421 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3422 | } |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3423 | break; |
| 3424 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3425 | |
| 3426 | default: |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3427 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3428 | } |
| 3429 | } |
| 3430 | |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3431 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 3432 | uint32_t temp_offset, |
| 3433 | uint32_t stack_adjustment, |
| 3434 | bool is_fp, |
| 3435 | bool is_wide) { |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3436 | if (source.IsStackSlot()) { |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3437 | DCHECK(!is_wide); |
| 3438 | if (is_fp) { |
| 3439 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3440 | } else { |
| 3441 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3442 | } |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3443 | } else if (source.IsDoubleStackSlot()) { |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3444 | DCHECK(is_wide); |
| 3445 | if (is_fp) { |
| 3446 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3447 | } else { |
| 3448 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3449 | } |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3450 | } else { |
| 3451 | // 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] | 3452 | if (!is_wide) { |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3453 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3454 | codegen_->Move32(stack_temp, source); |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3455 | if (is_fp) { |
| 3456 | __ flds(Address(ESP, temp_offset)); |
| 3457 | } else { |
| 3458 | __ filds(Address(ESP, temp_offset)); |
| 3459 | } |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3460 | } else { |
| 3461 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3462 | codegen_->Move64(stack_temp, source); |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3463 | if (is_fp) { |
| 3464 | __ fldl(Address(ESP, temp_offset)); |
| 3465 | } else { |
| 3466 | __ fildl(Address(ESP, temp_offset)); |
| 3467 | } |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3468 | } |
| 3469 | } |
| 3470 | } |
| 3471 | |
| 3472 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3473 | DataType::Type type = rem->GetResultType(); |
| 3474 | bool is_float = type == DataType::Type::kFloat32; |
| 3475 | size_t elem_size = DataType::Size(type); |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3476 | LocationSummary* locations = rem->GetLocations(); |
| 3477 | Location first = locations->InAt(0); |
| 3478 | Location second = locations->InAt(1); |
| 3479 | Location out = locations->Out(); |
| 3480 | |
| 3481 | // Create stack space for 2 elements. |
| 3482 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3483 | __ subl(ESP, Immediate(2 * elem_size)); |
| 3484 | |
| 3485 | // 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] | 3486 | const bool is_wide = !is_float; |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3487 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp= */ true, is_wide); |
| 3488 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp= */ true, is_wide); |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3489 | |
| 3490 | // Loop doing FPREM until we stabilize. |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3491 | NearLabel retry; |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3492 | __ Bind(&retry); |
| 3493 | __ fprem(); |
| 3494 | |
| 3495 | // Move FP status to AX. |
| 3496 | __ fstsw(); |
| 3497 | |
| 3498 | // And see if the argument reduction is complete. This is signaled by the |
| 3499 | // C2 FPU flag bit set to 0. |
| 3500 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 3501 | __ j(kNotEqual, &retry); |
| 3502 | |
| 3503 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3504 | // Store FP top of stack to real stack. |
| 3505 | if (is_float) { |
| 3506 | __ fsts(Address(ESP, 0)); |
| 3507 | } else { |
| 3508 | __ fstl(Address(ESP, 0)); |
| 3509 | } |
| 3510 | |
| 3511 | // Pop the 2 items from the FP stack. |
| 3512 | __ fucompp(); |
| 3513 | |
| 3514 | // Load the value from the stack into an XMM register. |
| 3515 | DCHECK(out.IsFpuRegister()) << out; |
| 3516 | if (is_float) { |
| 3517 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3518 | } else { |
| 3519 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3520 | } |
| 3521 | |
| 3522 | // And remove the temporary stack space we allocated. |
| 3523 | __ addl(ESP, Immediate(2 * elem_size)); |
| 3524 | } |
| 3525 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3526 | |
| 3527 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3528 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3529 | |
| 3530 | LocationSummary* locations = instruction->GetLocations(); |
| 3531 | DCHECK(locations->InAt(1).IsConstant()); |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3532 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3533 | |
| 3534 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3535 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3536 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3537 | |
| 3538 | DCHECK(imm == 1 || imm == -1); |
| 3539 | |
| 3540 | if (instruction->IsRem()) { |
| 3541 | __ xorl(out_register, out_register); |
| 3542 | } else { |
| 3543 | __ movl(out_register, input_register); |
| 3544 | if (imm == -1) { |
| 3545 | __ negl(out_register); |
| 3546 | } |
| 3547 | } |
| 3548 | } |
| 3549 | |
| Shalini Salomi Bodapati | a66784b | 2018-11-06 13:05:44 +0530 | [diff] [blame] | 3550 | void InstructionCodeGeneratorX86::RemByPowerOfTwo(HRem* instruction) { |
| 3551 | LocationSummary* locations = instruction->GetLocations(); |
| 3552 | Location second = locations->InAt(1); |
| 3553 | |
| 3554 | Register out = locations->Out().AsRegister<Register>(); |
| 3555 | Register numerator = locations->InAt(0).AsRegister<Register>(); |
| 3556 | |
| 3557 | int32_t imm = Int64FromConstant(second.GetConstant()); |
| 3558 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3559 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
| 3560 | |
| 3561 | Register tmp = locations->GetTemp(0).AsRegister<Register>(); |
| 3562 | NearLabel done; |
| 3563 | __ movl(out, numerator); |
| 3564 | __ andl(out, Immediate(abs_imm-1)); |
| 3565 | __ j(Condition::kZero, &done); |
| 3566 | __ leal(tmp, Address(out, static_cast<int32_t>(~(abs_imm-1)))); |
| 3567 | __ testl(numerator, numerator); |
| 3568 | __ cmovl(Condition::kLess, out, tmp); |
| 3569 | __ Bind(&done); |
| 3570 | } |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3571 | |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3572 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3573 | LocationSummary* locations = instruction->GetLocations(); |
| 3574 | |
| 3575 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3576 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3577 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3578 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3579 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3580 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3581 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 3582 | |
| Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3583 | __ leal(num, Address(input_register, abs_imm - 1)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3584 | __ testl(input_register, input_register); |
| 3585 | __ cmovl(kGreaterEqual, num, input_register); |
| 3586 | int shift = CTZ(imm); |
| 3587 | __ sarl(num, Immediate(shift)); |
| 3588 | |
| 3589 | if (imm < 0) { |
| 3590 | __ negl(num); |
| 3591 | } |
| 3592 | |
| 3593 | __ movl(out_register, num); |
| 3594 | } |
| 3595 | |
| 3596 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3597 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3598 | |
| 3599 | LocationSummary* locations = instruction->GetLocations(); |
| 3600 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 3601 | |
| 3602 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 3603 | Register out = locations->Out().AsRegister<Register>(); |
| 3604 | Register num; |
| 3605 | Register edx; |
| 3606 | |
| 3607 | if (instruction->IsDiv()) { |
| 3608 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 3609 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 3610 | } else { |
| 3611 | edx = locations->Out().AsRegister<Register>(); |
| 3612 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 3613 | } |
| 3614 | |
| 3615 | DCHECK_EQ(EAX, eax); |
| 3616 | DCHECK_EQ(EDX, edx); |
| 3617 | if (instruction->IsDiv()) { |
| 3618 | DCHECK_EQ(EAX, out); |
| 3619 | } else { |
| 3620 | DCHECK_EQ(EDX, out); |
| 3621 | } |
| 3622 | |
| 3623 | int64_t magic; |
| 3624 | int shift; |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3625 | CalculateMagicAndShiftForDivRem(imm, /* is_long= */ false, &magic, &shift); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3626 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3627 | // Save the numerator. |
| 3628 | __ movl(num, eax); |
| 3629 | |
| 3630 | // EAX = magic |
| 3631 | __ movl(eax, Immediate(magic)); |
| 3632 | |
| 3633 | // EDX:EAX = magic * numerator |
| 3634 | __ imull(num); |
| 3635 | |
| 3636 | if (imm > 0 && magic < 0) { |
| 3637 | // EDX += num |
| 3638 | __ addl(edx, num); |
| 3639 | } else if (imm < 0 && magic > 0) { |
| 3640 | __ subl(edx, num); |
| 3641 | } |
| 3642 | |
| 3643 | // Shift if needed. |
| 3644 | if (shift != 0) { |
| 3645 | __ sarl(edx, Immediate(shift)); |
| 3646 | } |
| 3647 | |
| 3648 | // EDX += 1 if EDX < 0 |
| 3649 | __ movl(eax, edx); |
| 3650 | __ shrl(edx, Immediate(31)); |
| 3651 | __ addl(edx, eax); |
| 3652 | |
| 3653 | if (instruction->IsRem()) { |
| 3654 | __ movl(eax, num); |
| 3655 | __ imull(edx, Immediate(imm)); |
| 3656 | __ subl(eax, edx); |
| 3657 | __ movl(edx, eax); |
| 3658 | } else { |
| 3659 | __ movl(eax, edx); |
| 3660 | } |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3661 | } |
| 3662 | |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3663 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3664 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3665 | |
| 3666 | LocationSummary* locations = instruction->GetLocations(); |
| 3667 | Location out = locations->Out(); |
| 3668 | Location first = locations->InAt(0); |
| 3669 | Location second = locations->InAt(1); |
| 3670 | bool is_div = instruction->IsDiv(); |
| 3671 | |
| 3672 | switch (instruction->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3673 | case DataType::Type::kInt32: { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3674 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 3675 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3676 | |
| Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3677 | if (second.IsConstant()) { |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3678 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3679 | |
| 3680 | if (imm == 0) { |
| 3681 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 3682 | } else if (imm == 1 || imm == -1) { |
| 3683 | DivRemOneOrMinusOne(instruction); |
| Shalini Salomi Bodapati | a66784b | 2018-11-06 13:05:44 +0530 | [diff] [blame] | 3684 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 3685 | if (is_div) { |
| 3686 | DivByPowerOfTwo(instruction->AsDiv()); |
| 3687 | } else { |
| 3688 | RemByPowerOfTwo(instruction->AsRem()); |
| 3689 | } |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3690 | } else { |
| 3691 | DCHECK(imm <= -2 || imm >= 2); |
| 3692 | GenerateDivRemWithAnyConstant(instruction); |
| 3693 | } |
| 3694 | } else { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3695 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) DivRemMinusOneSlowPathX86( |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3696 | instruction, out.AsRegister<Register>(), is_div); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3697 | codegen_->AddSlowPath(slow_path); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3698 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3699 | Register second_reg = second.AsRegister<Register>(); |
| 3700 | // 0x80000000/-1 triggers an arithmetic exception! |
| 3701 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 3702 | // it's safe to just use negl instead of more complex comparisons. |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3703 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3704 | __ cmpl(second_reg, Immediate(-1)); |
| 3705 | __ j(kEqual, slow_path->GetEntryLabel()); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3706 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3707 | // edx:eax <- sign-extended of eax |
| 3708 | __ cdq(); |
| 3709 | // eax = quotient, edx = remainder |
| 3710 | __ idivl(second_reg); |
| 3711 | __ Bind(slow_path->GetExitLabel()); |
| 3712 | } |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3713 | break; |
| 3714 | } |
| 3715 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3716 | case DataType::Type::kInt64: { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3717 | InvokeRuntimeCallingConvention calling_convention; |
| 3718 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3719 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3720 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3721 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3722 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 3723 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 3724 | |
| 3725 | if (is_div) { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3726 | codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3727 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3728 | } else { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3729 | codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3730 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3731 | } |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3732 | break; |
| 3733 | } |
| 3734 | |
| 3735 | default: |
| 3736 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 3737 | } |
| 3738 | } |
| 3739 | |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3740 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3741 | LocationSummary::CallKind call_kind = (div->GetResultType() == DataType::Type::kInt64) |
| Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3742 | ? LocationSummary::kCallOnMainOnly |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3743 | : LocationSummary::kNoCall; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3744 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(div, call_kind); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3745 | |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3746 | switch (div->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3747 | case DataType::Type::kInt32: { |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3748 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3749 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3750 | locations->SetOut(Location::SameAsFirstInput()); |
| 3751 | // Intel uses edx:eax as the dividend. |
| 3752 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3753 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3754 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 3755 | // output and request another temp. |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3756 | if (div->InputAt(1)->IsIntConstant()) { |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3757 | locations->AddTemp(Location::RequiresRegister()); |
| 3758 | } |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3759 | break; |
| 3760 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3761 | case DataType::Type::kInt64: { |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3762 | InvokeRuntimeCallingConvention calling_convention; |
| 3763 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3764 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3765 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3766 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3767 | // Runtime helper puts the result in EAX, EDX. |
| 3768 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3769 | break; |
| 3770 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3771 | case DataType::Type::kFloat32: |
| 3772 | case DataType::Type::kFloat64: { |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3773 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3774 | if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3775 | DCHECK(div->InputAt(1)->IsEmittedAtUseSite()); |
| Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3776 | } else if (div->InputAt(1)->IsConstant()) { |
| 3777 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3778 | } else { |
| 3779 | locations->SetInAt(1, Location::Any()); |
| 3780 | } |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3781 | locations->SetOut(Location::SameAsFirstInput()); |
| 3782 | break; |
| 3783 | } |
| 3784 | |
| 3785 | default: |
| 3786 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3787 | } |
| 3788 | } |
| 3789 | |
| 3790 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 3791 | LocationSummary* locations = div->GetLocations(); |
| 3792 | Location first = locations->InAt(0); |
| 3793 | Location second = locations->InAt(1); |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3794 | |
| 3795 | switch (div->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3796 | case DataType::Type::kInt32: |
| 3797 | case DataType::Type::kInt64: { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3798 | GenerateDivRemIntegral(div); |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3799 | break; |
| 3800 | } |
| 3801 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3802 | case DataType::Type::kFloat32: { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3803 | if (second.IsFpuRegister()) { |
| 3804 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3805 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3806 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3807 | DCHECK(const_area->IsEmittedAtUseSite()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3808 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3809 | codegen_->LiteralFloatAddress( |
| 3810 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3811 | const_area->GetBaseMethodAddress(), |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3812 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3813 | } else { |
| 3814 | DCHECK(second.IsStackSlot()); |
| 3815 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3816 | } |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3817 | break; |
| 3818 | } |
| 3819 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3820 | case DataType::Type::kFloat64: { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3821 | if (second.IsFpuRegister()) { |
| 3822 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3823 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3824 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3825 | DCHECK(const_area->IsEmittedAtUseSite()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3826 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3827 | codegen_->LiteralDoubleAddress( |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3828 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3829 | const_area->GetBaseMethodAddress(), |
| 3830 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3831 | } else { |
| 3832 | DCHECK(second.IsDoubleStackSlot()); |
| 3833 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3834 | } |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3835 | break; |
| 3836 | } |
| 3837 | |
| 3838 | default: |
| 3839 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3840 | } |
| 3841 | } |
| 3842 | |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3843 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3844 | DataType::Type type = rem->GetResultType(); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3845 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3846 | LocationSummary::CallKind call_kind = (rem->GetResultType() == DataType::Type::kInt64) |
| Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3847 | ? LocationSummary::kCallOnMainOnly |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3848 | : LocationSummary::kNoCall; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3849 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3850 | |
| Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3851 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3852 | case DataType::Type::kInt32: { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3853 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3854 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3855 | locations->SetOut(Location::RegisterLocation(EDX)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3856 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3857 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 3858 | // output and request another temp. |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3859 | if (rem->InputAt(1)->IsIntConstant()) { |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3860 | locations->AddTemp(Location::RequiresRegister()); |
| 3861 | } |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3862 | break; |
| 3863 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3864 | case DataType::Type::kInt64: { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3865 | InvokeRuntimeCallingConvention calling_convention; |
| 3866 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3867 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3868 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3869 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3870 | // Runtime helper puts the result in EAX, EDX. |
| 3871 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3872 | break; |
| 3873 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3874 | case DataType::Type::kFloat64: |
| 3875 | case DataType::Type::kFloat32: { |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3876 | locations->SetInAt(0, Location::Any()); |
| 3877 | locations->SetInAt(1, Location::Any()); |
| 3878 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3879 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3880 | break; |
| 3881 | } |
| 3882 | |
| 3883 | default: |
| Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3884 | LOG(FATAL) << "Unexpected rem type " << type; |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3885 | } |
| 3886 | } |
| 3887 | |
| 3888 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3889 | DataType::Type type = rem->GetResultType(); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3890 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3891 | case DataType::Type::kInt32: |
| 3892 | case DataType::Type::kInt64: { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3893 | GenerateDivRemIntegral(rem); |
| 3894 | break; |
| 3895 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3896 | case DataType::Type::kFloat32: |
| 3897 | case DataType::Type::kFloat64: { |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3898 | GenerateRemFP(rem); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3899 | break; |
| 3900 | } |
| 3901 | default: |
| 3902 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3903 | } |
| 3904 | } |
| 3905 | |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 3906 | static void CreateMinMaxLocations(ArenaAllocator* allocator, HBinaryOperation* minmax) { |
| 3907 | LocationSummary* locations = new (allocator) LocationSummary(minmax); |
| 3908 | switch (minmax->GetResultType()) { |
| 3909 | case DataType::Type::kInt32: |
| 3910 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3911 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3912 | locations->SetOut(Location::SameAsFirstInput()); |
| 3913 | break; |
| 3914 | case DataType::Type::kInt64: |
| 3915 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3916 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3917 | locations->SetOut(Location::SameAsFirstInput()); |
| 3918 | // Register to use to perform a long subtract to set cc. |
| 3919 | locations->AddTemp(Location::RequiresRegister()); |
| 3920 | break; |
| 3921 | case DataType::Type::kFloat32: |
| 3922 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3923 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3924 | locations->SetOut(Location::SameAsFirstInput()); |
| 3925 | locations->AddTemp(Location::RequiresRegister()); |
| 3926 | break; |
| 3927 | case DataType::Type::kFloat64: |
| 3928 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3929 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3930 | locations->SetOut(Location::SameAsFirstInput()); |
| 3931 | break; |
| 3932 | default: |
| 3933 | LOG(FATAL) << "Unexpected type for HMinMax " << minmax->GetResultType(); |
| 3934 | } |
| 3935 | } |
| 3936 | |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 3937 | void InstructionCodeGeneratorX86::GenerateMinMaxInt(LocationSummary* locations, |
| 3938 | bool is_min, |
| 3939 | DataType::Type type) { |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 3940 | Location op1_loc = locations->InAt(0); |
| 3941 | Location op2_loc = locations->InAt(1); |
| 3942 | |
| 3943 | // Shortcut for same input locations. |
| 3944 | if (op1_loc.Equals(op2_loc)) { |
| 3945 | // Can return immediately, as op1_loc == out_loc. |
| 3946 | // Note: if we ever support separate registers, e.g., output into memory, we need to check for |
| 3947 | // a copy here. |
| 3948 | DCHECK(locations->Out().Equals(op1_loc)); |
| 3949 | return; |
| 3950 | } |
| 3951 | |
| 3952 | if (type == DataType::Type::kInt64) { |
| 3953 | // Need to perform a subtract to get the sign right. |
| 3954 | // op1 is already in the same location as the output. |
| 3955 | Location output = locations->Out(); |
| 3956 | Register output_lo = output.AsRegisterPairLow<Register>(); |
| 3957 | Register output_hi = output.AsRegisterPairHigh<Register>(); |
| 3958 | |
| 3959 | Register op2_lo = op2_loc.AsRegisterPairLow<Register>(); |
| 3960 | Register op2_hi = op2_loc.AsRegisterPairHigh<Register>(); |
| 3961 | |
| 3962 | // The comparison is performed by subtracting the second operand from |
| 3963 | // the first operand and then setting the status flags in the same |
| 3964 | // manner as the SUB instruction." |
| 3965 | __ cmpl(output_lo, op2_lo); |
| 3966 | |
| 3967 | // Now use a temp and the borrow to finish the subtraction of op2_hi. |
| 3968 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3969 | __ movl(temp, output_hi); |
| 3970 | __ sbbl(temp, op2_hi); |
| 3971 | |
| 3972 | // Now the condition code is correct. |
| 3973 | Condition cond = is_min ? Condition::kGreaterEqual : Condition::kLess; |
| 3974 | __ cmovl(cond, output_lo, op2_lo); |
| 3975 | __ cmovl(cond, output_hi, op2_hi); |
| 3976 | } else { |
| 3977 | DCHECK_EQ(type, DataType::Type::kInt32); |
| 3978 | Register out = locations->Out().AsRegister<Register>(); |
| 3979 | Register op2 = op2_loc.AsRegister<Register>(); |
| 3980 | |
| 3981 | // (out := op1) |
| 3982 | // out <=? op2 |
| 3983 | // if out is min jmp done |
| 3984 | // out := op2 |
| 3985 | // done: |
| 3986 | |
| 3987 | __ cmpl(out, op2); |
| 3988 | Condition cond = is_min ? Condition::kGreater : Condition::kLess; |
| 3989 | __ cmovl(cond, out, op2); |
| 3990 | } |
| 3991 | } |
| 3992 | |
| 3993 | void InstructionCodeGeneratorX86::GenerateMinMaxFP(LocationSummary* locations, |
| 3994 | bool is_min, |
| 3995 | DataType::Type type) { |
| 3996 | Location op1_loc = locations->InAt(0); |
| 3997 | Location op2_loc = locations->InAt(1); |
| 3998 | Location out_loc = locations->Out(); |
| 3999 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
| 4000 | |
| 4001 | // Shortcut for same input locations. |
| 4002 | if (op1_loc.Equals(op2_loc)) { |
| 4003 | DCHECK(out_loc.Equals(op1_loc)); |
| 4004 | return; |
| 4005 | } |
| 4006 | |
| 4007 | // (out := op1) |
| 4008 | // out <=? op2 |
| 4009 | // if Nan jmp Nan_label |
| 4010 | // if out is min jmp done |
| 4011 | // if op2 is min jmp op2_label |
| 4012 | // handle -0/+0 |
| 4013 | // jmp done |
| 4014 | // Nan_label: |
| 4015 | // out := NaN |
| 4016 | // op2_label: |
| 4017 | // out := op2 |
| 4018 | // done: |
| 4019 | // |
| 4020 | // This removes one jmp, but needs to copy one input (op1) to out. |
| 4021 | // |
| 4022 | // TODO: This is straight from Quick (except literal pool). Make NaN an out-of-line slowpath? |
| 4023 | |
| 4024 | XmmRegister op2 = op2_loc.AsFpuRegister<XmmRegister>(); |
| 4025 | |
| 4026 | NearLabel nan, done, op2_label; |
| 4027 | if (type == DataType::Type::kFloat64) { |
| 4028 | __ ucomisd(out, op2); |
| 4029 | } else { |
| 4030 | DCHECK_EQ(type, DataType::Type::kFloat32); |
| 4031 | __ ucomiss(out, op2); |
| 4032 | } |
| 4033 | |
| 4034 | __ j(Condition::kParityEven, &nan); |
| 4035 | |
| 4036 | __ j(is_min ? Condition::kAbove : Condition::kBelow, &op2_label); |
| 4037 | __ j(is_min ? Condition::kBelow : Condition::kAbove, &done); |
| 4038 | |
| 4039 | // Handle 0.0/-0.0. |
| 4040 | if (is_min) { |
| 4041 | if (type == DataType::Type::kFloat64) { |
| 4042 | __ orpd(out, op2); |
| 4043 | } else { |
| 4044 | __ orps(out, op2); |
| 4045 | } |
| 4046 | } else { |
| 4047 | if (type == DataType::Type::kFloat64) { |
| 4048 | __ andpd(out, op2); |
| 4049 | } else { |
| 4050 | __ andps(out, op2); |
| 4051 | } |
| 4052 | } |
| 4053 | __ jmp(&done); |
| 4054 | |
| 4055 | // NaN handling. |
| 4056 | __ Bind(&nan); |
| 4057 | if (type == DataType::Type::kFloat64) { |
| 4058 | // TODO: Use a constant from the constant table (requires extra input). |
| 4059 | __ LoadLongConstant(out, kDoubleNaN); |
| 4060 | } else { |
| 4061 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 4062 | __ movl(constant, Immediate(kFloatNaN)); |
| 4063 | __ movd(out, constant); |
| 4064 | } |
| 4065 | __ jmp(&done); |
| 4066 | |
| 4067 | // out := op2; |
| 4068 | __ Bind(&op2_label); |
| 4069 | if (type == DataType::Type::kFloat64) { |
| 4070 | __ movsd(out, op2); |
| 4071 | } else { |
| 4072 | __ movss(out, op2); |
| 4073 | } |
| 4074 | |
| 4075 | // Done. |
| 4076 | __ Bind(&done); |
| 4077 | } |
| 4078 | |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4079 | void InstructionCodeGeneratorX86::GenerateMinMax(HBinaryOperation* minmax, bool is_min) { |
| 4080 | DataType::Type type = minmax->GetResultType(); |
| 4081 | switch (type) { |
| 4082 | case DataType::Type::kInt32: |
| 4083 | case DataType::Type::kInt64: |
| 4084 | GenerateMinMaxInt(minmax->GetLocations(), is_min, type); |
| 4085 | break; |
| 4086 | case DataType::Type::kFloat32: |
| 4087 | case DataType::Type::kFloat64: |
| 4088 | GenerateMinMaxFP(minmax->GetLocations(), is_min, type); |
| 4089 | break; |
| 4090 | default: |
| 4091 | LOG(FATAL) << "Unexpected type for HMinMax " << type; |
| 4092 | } |
| 4093 | } |
| 4094 | |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4095 | void LocationsBuilderX86::VisitMin(HMin* min) { |
| 4096 | CreateMinMaxLocations(GetGraph()->GetAllocator(), min); |
| 4097 | } |
| 4098 | |
| 4099 | void InstructionCodeGeneratorX86::VisitMin(HMin* min) { |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4100 | GenerateMinMax(min, /*is_min*/ true); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4101 | } |
| 4102 | |
| 4103 | void LocationsBuilderX86::VisitMax(HMax* max) { |
| 4104 | CreateMinMaxLocations(GetGraph()->GetAllocator(), max); |
| 4105 | } |
| 4106 | |
| 4107 | void InstructionCodeGeneratorX86::VisitMax(HMax* max) { |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4108 | GenerateMinMax(max, /*is_min*/ false); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4109 | } |
| 4110 | |
| Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 4111 | void LocationsBuilderX86::VisitAbs(HAbs* abs) { |
| 4112 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 4113 | switch (abs->GetResultType()) { |
| 4114 | case DataType::Type::kInt32: |
| 4115 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 4116 | locations->SetOut(Location::SameAsFirstInput()); |
| 4117 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 4118 | break; |
| 4119 | case DataType::Type::kInt64: |
| 4120 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4121 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4122 | locations->AddTemp(Location::RequiresRegister()); |
| 4123 | break; |
| 4124 | case DataType::Type::kFloat32: |
| 4125 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4126 | locations->SetOut(Location::SameAsFirstInput()); |
| 4127 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4128 | locations->AddTemp(Location::RequiresRegister()); |
| 4129 | break; |
| 4130 | case DataType::Type::kFloat64: |
| 4131 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4132 | locations->SetOut(Location::SameAsFirstInput()); |
| 4133 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4134 | break; |
| 4135 | default: |
| 4136 | LOG(FATAL) << "Unexpected type for HAbs " << abs->GetResultType(); |
| 4137 | } |
| 4138 | } |
| 4139 | |
| 4140 | void InstructionCodeGeneratorX86::VisitAbs(HAbs* abs) { |
| 4141 | LocationSummary* locations = abs->GetLocations(); |
| 4142 | switch (abs->GetResultType()) { |
| 4143 | case DataType::Type::kInt32: { |
| 4144 | Register out = locations->Out().AsRegister<Register>(); |
| 4145 | DCHECK_EQ(out, EAX); |
| 4146 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4147 | DCHECK_EQ(temp, EDX); |
| 4148 | // Sign extend EAX into EDX. |
| 4149 | __ cdq(); |
| 4150 | // XOR EAX with sign. |
| 4151 | __ xorl(EAX, EDX); |
| 4152 | // Subtract out sign to correct. |
| 4153 | __ subl(EAX, EDX); |
| 4154 | // The result is in EAX. |
| 4155 | break; |
| 4156 | } |
| 4157 | case DataType::Type::kInt64: { |
| 4158 | Location input = locations->InAt(0); |
| 4159 | Register input_lo = input.AsRegisterPairLow<Register>(); |
| 4160 | Register input_hi = input.AsRegisterPairHigh<Register>(); |
| 4161 | Location output = locations->Out(); |
| 4162 | Register output_lo = output.AsRegisterPairLow<Register>(); |
| 4163 | Register output_hi = output.AsRegisterPairHigh<Register>(); |
| 4164 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4165 | // Compute the sign into the temporary. |
| 4166 | __ movl(temp, input_hi); |
| 4167 | __ sarl(temp, Immediate(31)); |
| 4168 | // Store the sign into the output. |
| 4169 | __ movl(output_lo, temp); |
| 4170 | __ movl(output_hi, temp); |
| 4171 | // XOR the input to the output. |
| 4172 | __ xorl(output_lo, input_lo); |
| 4173 | __ xorl(output_hi, input_hi); |
| 4174 | // Subtract the sign. |
| 4175 | __ subl(output_lo, temp); |
| 4176 | __ sbbl(output_hi, temp); |
| 4177 | break; |
| 4178 | } |
| 4179 | case DataType::Type::kFloat32: { |
| 4180 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4181 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4182 | Register constant = locations->GetTemp(1).AsRegister<Register>(); |
| 4183 | __ movl(constant, Immediate(INT32_C(0x7FFFFFFF))); |
| 4184 | __ movd(temp, constant); |
| 4185 | __ andps(out, temp); |
| 4186 | break; |
| 4187 | } |
| 4188 | case DataType::Type::kFloat64: { |
| 4189 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4190 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4191 | // TODO: Use a constant from the constant table (requires extra input). |
| 4192 | __ LoadLongConstant(temp, INT64_C(0x7FFFFFFFFFFFFFFF)); |
| 4193 | __ andpd(out, temp); |
| 4194 | break; |
| 4195 | } |
| 4196 | default: |
| 4197 | LOG(FATAL) << "Unexpected type for HAbs " << abs->GetResultType(); |
| 4198 | } |
| 4199 | } |
| 4200 | |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4201 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4202 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4203 | switch (instruction->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4204 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4205 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4206 | case DataType::Type::kInt8: |
| 4207 | case DataType::Type::kUint16: |
| 4208 | case DataType::Type::kInt16: |
| 4209 | case DataType::Type::kInt32: { |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4210 | locations->SetInAt(0, Location::Any()); |
| 4211 | break; |
| 4212 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4213 | case DataType::Type::kInt64: { |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4214 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 4215 | if (!instruction->IsConstant()) { |
| 4216 | locations->AddTemp(Location::RequiresRegister()); |
| 4217 | } |
| 4218 | break; |
| 4219 | } |
| 4220 | default: |
| 4221 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 4222 | } |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4223 | } |
| 4224 | |
| 4225 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4226 | SlowPathCode* slow_path = |
| 4227 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathX86(instruction); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4228 | codegen_->AddSlowPath(slow_path); |
| 4229 | |
| 4230 | LocationSummary* locations = instruction->GetLocations(); |
| 4231 | Location value = locations->InAt(0); |
| 4232 | |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4233 | switch (instruction->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4234 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4235 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4236 | case DataType::Type::kInt8: |
| 4237 | case DataType::Type::kUint16: |
| 4238 | case DataType::Type::kInt16: |
| 4239 | case DataType::Type::kInt32: { |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4240 | if (value.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4241 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4242 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4243 | } else if (value.IsStackSlot()) { |
| 4244 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 4245 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4246 | } else { |
| 4247 | DCHECK(value.IsConstant()) << value; |
| 4248 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4249 | __ jmp(slow_path->GetEntryLabel()); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4250 | } |
| 4251 | } |
| 4252 | break; |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4253 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4254 | case DataType::Type::kInt64: { |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4255 | if (value.IsRegisterPair()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4256 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4257 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 4258 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 4259 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4260 | } else { |
| 4261 | DCHECK(value.IsConstant()) << value; |
| 4262 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 4263 | __ jmp(slow_path->GetEntryLabel()); |
| 4264 | } |
| 4265 | } |
| 4266 | break; |
| 4267 | } |
| 4268 | default: |
| 4269 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4270 | } |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4271 | } |
| 4272 | |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4273 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 4274 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4275 | |
| 4276 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4277 | new (GetGraph()->GetAllocator()) LocationSummary(op, LocationSummary::kNoCall); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4278 | |
| 4279 | switch (op->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4280 | case DataType::Type::kInt32: |
| 4281 | case DataType::Type::kInt64: { |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4282 | // Can't have Location::Any() and output SameAsFirstInput() |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4283 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4284 | // The shift count needs to be in CL or a constant. |
| 4285 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4286 | locations->SetOut(Location::SameAsFirstInput()); |
| 4287 | break; |
| 4288 | } |
| 4289 | default: |
| 4290 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 4291 | } |
| 4292 | } |
| 4293 | |
| 4294 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 4295 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4296 | |
| 4297 | LocationSummary* locations = op->GetLocations(); |
| 4298 | Location first = locations->InAt(0); |
| 4299 | Location second = locations->InAt(1); |
| 4300 | DCHECK(first.Equals(locations->Out())); |
| 4301 | |
| 4302 | switch (op->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4303 | case DataType::Type::kInt32: { |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4304 | DCHECK(first.IsRegister()); |
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4305 | Register first_reg = first.AsRegister<Register>(); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4306 | if (second.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4307 | Register second_reg = second.AsRegister<Register>(); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4308 | DCHECK_EQ(ECX, second_reg); |
| 4309 | if (op->IsShl()) { |
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4310 | __ shll(first_reg, second_reg); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4311 | } else if (op->IsShr()) { |
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4312 | __ sarl(first_reg, second_reg); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4313 | } else { |
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4314 | __ shrl(first_reg, second_reg); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4315 | } |
| 4316 | } else { |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4317 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance; |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4318 | if (shift == 0) { |
| 4319 | return; |
| 4320 | } |
| 4321 | Immediate imm(shift); |
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4322 | if (op->IsShl()) { |
| 4323 | __ shll(first_reg, imm); |
| 4324 | } else if (op->IsShr()) { |
| 4325 | __ sarl(first_reg, imm); |
| 4326 | } else { |
| 4327 | __ shrl(first_reg, imm); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4328 | } |
| 4329 | } |
| 4330 | break; |
| 4331 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4332 | case DataType::Type::kInt64: { |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4333 | if (second.IsRegister()) { |
| 4334 | Register second_reg = second.AsRegister<Register>(); |
| 4335 | DCHECK_EQ(ECX, second_reg); |
| 4336 | if (op->IsShl()) { |
| 4337 | GenerateShlLong(first, second_reg); |
| 4338 | } else if (op->IsShr()) { |
| 4339 | GenerateShrLong(first, second_reg); |
| 4340 | } else { |
| 4341 | GenerateUShrLong(first, second_reg); |
| 4342 | } |
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4343 | } else { |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4344 | // Shift by a constant. |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4345 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4346 | // Nothing to do if the shift is 0, as the input is already the output. |
| 4347 | if (shift != 0) { |
| 4348 | if (op->IsShl()) { |
| 4349 | GenerateShlLong(first, shift); |
| 4350 | } else if (op->IsShr()) { |
| 4351 | GenerateShrLong(first, shift); |
| 4352 | } else { |
| 4353 | GenerateUShrLong(first, shift); |
| 4354 | } |
| 4355 | } |
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4356 | } |
| 4357 | break; |
| 4358 | } |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4359 | default: |
| 4360 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 4361 | } |
| 4362 | } |
| 4363 | |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4364 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 4365 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4366 | Register high = loc.AsRegisterPairHigh<Register>(); |
| Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 4367 | if (shift == 1) { |
| 4368 | // This is just an addition. |
| 4369 | __ addl(low, low); |
| 4370 | __ adcl(high, high); |
| 4371 | } else if (shift == 32) { |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4372 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 4373 | codegen_->EmitParallelMoves( |
| 4374 | loc.ToLow(), |
| 4375 | loc.ToHigh(), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4376 | DataType::Type::kInt32, |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4377 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 4378 | loc.ToLow(), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4379 | DataType::Type::kInt32); |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4380 | } else if (shift > 32) { |
| 4381 | // Low part becomes 0. High part is low part << (shift-32). |
| 4382 | __ movl(high, low); |
| 4383 | __ shll(high, Immediate(shift - 32)); |
| 4384 | __ xorl(low, low); |
| 4385 | } else { |
| 4386 | // Between 1 and 31. |
| 4387 | __ shld(high, low, Immediate(shift)); |
| 4388 | __ shll(low, Immediate(shift)); |
| 4389 | } |
| 4390 | } |
| 4391 | |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4392 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4393 | NearLabel done; |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4394 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 4395 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 4396 | __ testl(shifter, Immediate(32)); |
| 4397 | __ j(kEqual, &done); |
| 4398 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 4399 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 4400 | __ Bind(&done); |
| 4401 | } |
| 4402 | |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4403 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 4404 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4405 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 4406 | if (shift == 32) { |
| 4407 | // Need to copy the sign. |
| 4408 | DCHECK_NE(low, high); |
| 4409 | __ movl(low, high); |
| 4410 | __ sarl(high, Immediate(31)); |
| 4411 | } else if (shift > 32) { |
| 4412 | DCHECK_NE(low, high); |
| 4413 | // High part becomes sign. Low part is shifted by shift - 32. |
| 4414 | __ movl(low, high); |
| 4415 | __ sarl(high, Immediate(31)); |
| 4416 | __ sarl(low, Immediate(shift - 32)); |
| 4417 | } else { |
| 4418 | // Between 1 and 31. |
| 4419 | __ shrd(low, high, Immediate(shift)); |
| 4420 | __ sarl(high, Immediate(shift)); |
| 4421 | } |
| 4422 | } |
| 4423 | |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4424 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4425 | NearLabel done; |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4426 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4427 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4428 | __ testl(shifter, Immediate(32)); |
| 4429 | __ j(kEqual, &done); |
| 4430 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4431 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 4432 | __ Bind(&done); |
| 4433 | } |
| 4434 | |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4435 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 4436 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4437 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 4438 | if (shift == 32) { |
| 4439 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 4440 | codegen_->EmitParallelMoves( |
| 4441 | loc.ToHigh(), |
| 4442 | loc.ToLow(), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4443 | DataType::Type::kInt32, |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4444 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 4445 | loc.ToHigh(), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4446 | DataType::Type::kInt32); |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4447 | } else if (shift > 32) { |
| 4448 | // Low part is high >> (shift - 32). High part becomes 0. |
| 4449 | __ movl(low, high); |
| 4450 | __ shrl(low, Immediate(shift - 32)); |
| 4451 | __ xorl(high, high); |
| 4452 | } else { |
| 4453 | // Between 1 and 31. |
| 4454 | __ shrd(low, high, Immediate(shift)); |
| 4455 | __ shrl(high, Immediate(shift)); |
| 4456 | } |
| 4457 | } |
| 4458 | |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4459 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4460 | NearLabel done; |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4461 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4462 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4463 | __ testl(shifter, Immediate(32)); |
| 4464 | __ j(kEqual, &done); |
| 4465 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4466 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 4467 | __ Bind(&done); |
| 4468 | } |
| 4469 | |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4470 | void LocationsBuilderX86::VisitRor(HRor* ror) { |
| 4471 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4472 | new (GetGraph()->GetAllocator()) LocationSummary(ror, LocationSummary::kNoCall); |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4473 | |
| 4474 | switch (ror->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4475 | case DataType::Type::kInt64: |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4476 | // Add the temporary needed. |
| 4477 | locations->AddTemp(Location::RequiresRegister()); |
| 4478 | FALLTHROUGH_INTENDED; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4479 | case DataType::Type::kInt32: |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4480 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4481 | // The shift count needs to be in CL (unless it is a constant). |
| 4482 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); |
| 4483 | locations->SetOut(Location::SameAsFirstInput()); |
| 4484 | break; |
| 4485 | default: |
| 4486 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4487 | UNREACHABLE(); |
| 4488 | } |
| 4489 | } |
| 4490 | |
| 4491 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { |
| 4492 | LocationSummary* locations = ror->GetLocations(); |
| 4493 | Location first = locations->InAt(0); |
| 4494 | Location second = locations->InAt(1); |
| 4495 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4496 | if (ror->GetResultType() == DataType::Type::kInt32) { |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4497 | Register first_reg = first.AsRegister<Register>(); |
| 4498 | if (second.IsRegister()) { |
| 4499 | Register second_reg = second.AsRegister<Register>(); |
| 4500 | __ rorl(first_reg, second_reg); |
| 4501 | } else { |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4502 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4503 | __ rorl(first_reg, imm); |
| 4504 | } |
| 4505 | return; |
| 4506 | } |
| 4507 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4508 | DCHECK_EQ(ror->GetResultType(), DataType::Type::kInt64); |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4509 | Register first_reg_lo = first.AsRegisterPairLow<Register>(); |
| 4510 | Register first_reg_hi = first.AsRegisterPairHigh<Register>(); |
| 4511 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 4512 | if (second.IsRegister()) { |
| 4513 | Register second_reg = second.AsRegister<Register>(); |
| 4514 | DCHECK_EQ(second_reg, ECX); |
| 4515 | __ movl(temp_reg, first_reg_hi); |
| 4516 | __ shrd(first_reg_hi, first_reg_lo, second_reg); |
| 4517 | __ shrd(first_reg_lo, temp_reg, second_reg); |
| 4518 | __ movl(temp_reg, first_reg_hi); |
| 4519 | __ testl(second_reg, Immediate(32)); |
| 4520 | __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); |
| 4521 | __ cmovl(kNotEqual, first_reg_lo, temp_reg); |
| 4522 | } else { |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4523 | int32_t shift_amt = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4524 | if (shift_amt == 0) { |
| 4525 | // Already fine. |
| 4526 | return; |
| 4527 | } |
| 4528 | if (shift_amt == 32) { |
| 4529 | // Just swap. |
| 4530 | __ movl(temp_reg, first_reg_lo); |
| 4531 | __ movl(first_reg_lo, first_reg_hi); |
| 4532 | __ movl(first_reg_hi, temp_reg); |
| 4533 | return; |
| 4534 | } |
| 4535 | |
| 4536 | Immediate imm(shift_amt); |
| 4537 | // Save the constents of the low value. |
| 4538 | __ movl(temp_reg, first_reg_lo); |
| 4539 | |
| 4540 | // Shift right into low, feeding bits from high. |
| 4541 | __ shrd(first_reg_lo, first_reg_hi, imm); |
| 4542 | |
| 4543 | // Shift right into high, feeding bits from the original low. |
| 4544 | __ shrd(first_reg_hi, temp_reg, imm); |
| 4545 | |
| 4546 | // Swap if needed. |
| 4547 | if (shift_amt > 32) { |
| 4548 | __ movl(temp_reg, first_reg_lo); |
| 4549 | __ movl(first_reg_lo, first_reg_hi); |
| 4550 | __ movl(first_reg_hi, temp_reg); |
| 4551 | } |
| 4552 | } |
| 4553 | } |
| 4554 | |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4555 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 4556 | HandleShift(shl); |
| 4557 | } |
| 4558 | |
| 4559 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 4560 | HandleShift(shl); |
| 4561 | } |
| 4562 | |
| 4563 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 4564 | HandleShift(shr); |
| 4565 | } |
| 4566 | |
| 4567 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 4568 | HandleShift(shr); |
| 4569 | } |
| 4570 | |
| 4571 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 4572 | HandleShift(ushr); |
| 4573 | } |
| 4574 | |
| 4575 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 4576 | HandleShift(ushr); |
| 4577 | } |
| 4578 | |
| Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4579 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4580 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4581 | instruction, LocationSummary::kCallOnMainOnly); |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4582 | locations->SetOut(Location::RegisterLocation(EAX)); |
| Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 4583 | InvokeRuntimeCallingConvention calling_convention; |
| 4584 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4585 | } |
| 4586 | |
| 4587 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
| Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 4588 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
| 4589 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| 4590 | DCHECK(!codegen_->IsLeafMethod()); |
| Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4591 | } |
| 4592 | |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4593 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4594 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4595 | instruction, LocationSummary::kCallOnMainOnly); |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4596 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 4597 | InvokeRuntimeCallingConvention calling_convention; |
| Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4598 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4599 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4600 | } |
| 4601 | |
| 4602 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
| Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 4603 | // Note: if heap poisoning is enabled, the entry point takes care of poisoning the reference. |
| 4604 | QuickEntrypointEnum entrypoint = CodeGenerator::GetArrayAllocationEntrypoint(instruction); |
| Nicolas Geoffray | d095844 | 2017-01-30 14:57:16 +0000 | [diff] [blame] | 4605 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
| Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4606 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4607 | DCHECK(!codegen_->IsLeafMethod()); |
| 4608 | } |
| 4609 | |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4610 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4611 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4612 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4613 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4614 | if (location.IsStackSlot()) { |
| 4615 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4616 | } else if (location.IsDoubleStackSlot()) { |
| 4617 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4618 | } |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4619 | locations->SetOut(location); |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4620 | } |
| 4621 | |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4622 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 4623 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 4624 | } |
| 4625 | |
| 4626 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4627 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4628 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4629 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4630 | } |
| 4631 | |
| 4632 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4633 | } |
| 4634 | |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4635 | void LocationsBuilderX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4636 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4637 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4638 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4639 | locations->SetOut(Location::RequiresRegister()); |
| 4640 | } |
| 4641 | |
| 4642 | void InstructionCodeGeneratorX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4643 | LocationSummary* locations = instruction->GetLocations(); |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4644 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4645 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4646 | instruction->GetIndex(), kX86PointerSize).SizeValue(); |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4647 | __ movl(locations->Out().AsRegister<Register>(), |
| 4648 | Address(locations->InAt(0).AsRegister<Register>(), method_offset)); |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4649 | } else { |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4650 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4651 | instruction->GetIndex(), kX86PointerSize)); |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4652 | __ movl(locations->Out().AsRegister<Register>(), |
| 4653 | Address(locations->InAt(0).AsRegister<Register>(), |
| 4654 | mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
| 4655 | // temp = temp->GetImtEntryAt(method_offset); |
| 4656 | __ movl(locations->Out().AsRegister<Register>(), |
| 4657 | Address(locations->Out().AsRegister<Register>(), method_offset)); |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4658 | } |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4659 | } |
| 4660 | |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4661 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4662 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4663 | new (GetGraph()->GetAllocator()) LocationSummary(not_, LocationSummary::kNoCall); |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4664 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4665 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4666 | } |
| 4667 | |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4668 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 4669 | LocationSummary* locations = not_->GetLocations(); |
| Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4670 | Location in = locations->InAt(0); |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4671 | Location out = locations->Out(); |
| Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4672 | DCHECK(in.Equals(out)); |
| Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4673 | switch (not_->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4674 | case DataType::Type::kInt32: |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4675 | __ notl(out.AsRegister<Register>()); |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4676 | break; |
| 4677 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4678 | case DataType::Type::kInt64: |
| Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4679 | __ notl(out.AsRegisterPairLow<Register>()); |
| 4680 | __ notl(out.AsRegisterPairHigh<Register>()); |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4681 | break; |
| 4682 | |
| 4683 | default: |
| 4684 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4685 | } |
| Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4686 | } |
| 4687 | |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4688 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4689 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4690 | new (GetGraph()->GetAllocator()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4691 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4692 | locations->SetOut(Location::SameAsFirstInput()); |
| 4693 | } |
| 4694 | |
| 4695 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4696 | LocationSummary* locations = bool_not->GetLocations(); |
| 4697 | Location in = locations->InAt(0); |
| 4698 | Location out = locations->Out(); |
| 4699 | DCHECK(in.Equals(out)); |
| 4700 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 4701 | } |
| 4702 | |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4703 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4704 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4705 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4706 | switch (compare->InputAt(0)->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4707 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4708 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4709 | case DataType::Type::kInt8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4710 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4711 | case DataType::Type::kInt16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4712 | case DataType::Type::kInt32: |
| 4713 | case DataType::Type::kInt64: { |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4714 | locations->SetInAt(0, Location::RequiresRegister()); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4715 | locations->SetInAt(1, Location::Any()); |
| 4716 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4717 | break; |
| 4718 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4719 | case DataType::Type::kFloat32: |
| 4720 | case DataType::Type::kFloat64: { |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4721 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4722 | if (compare->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4723 | DCHECK(compare->InputAt(1)->IsEmittedAtUseSite()); |
| 4724 | } else if (compare->InputAt(1)->IsConstant()) { |
| 4725 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4726 | } else { |
| 4727 | locations->SetInAt(1, Location::Any()); |
| 4728 | } |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4729 | locations->SetOut(Location::RequiresRegister()); |
| 4730 | break; |
| 4731 | } |
| 4732 | default: |
| 4733 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4734 | } |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4735 | } |
| 4736 | |
| 4737 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4738 | LocationSummary* locations = compare->GetLocations(); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4739 | Register out = locations->Out().AsRegister<Register>(); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4740 | Location left = locations->InAt(0); |
| 4741 | Location right = locations->InAt(1); |
| 4742 | |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4743 | NearLabel less, greater, done; |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4744 | Condition less_cond = kLess; |
| 4745 | |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4746 | switch (compare->InputAt(0)->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4747 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4748 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4749 | case DataType::Type::kInt8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4750 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4751 | case DataType::Type::kInt16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4752 | case DataType::Type::kInt32: { |
| Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 4753 | codegen_->GenerateIntCompare(left, right); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4754 | break; |
| 4755 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4756 | case DataType::Type::kInt64: { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4757 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 4758 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 4759 | int32_t val_low = 0; |
| 4760 | int32_t val_high = 0; |
| 4761 | bool right_is_const = false; |
| 4762 | |
| 4763 | if (right.IsConstant()) { |
| 4764 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 4765 | right_is_const = true; |
| 4766 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 4767 | val_low = Low32Bits(val); |
| 4768 | val_high = High32Bits(val); |
| 4769 | } |
| 4770 | |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4771 | if (right.IsRegisterPair()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4772 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4773 | } else if (right.IsDoubleStackSlot()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4774 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4775 | } else { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4776 | DCHECK(right_is_const) << right; |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4777 | codegen_->Compare32BitValue(left_high, val_high); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4778 | } |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4779 | __ j(kLess, &less); // Signed compare. |
| 4780 | __ j(kGreater, &greater); // Signed compare. |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4781 | if (right.IsRegisterPair()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4782 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4783 | } else if (right.IsDoubleStackSlot()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4784 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4785 | } else { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4786 | DCHECK(right_is_const) << right; |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4787 | codegen_->Compare32BitValue(left_low, val_low); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4788 | } |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4789 | less_cond = kBelow; // for CF (unsigned). |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4790 | break; |
| 4791 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4792 | case DataType::Type::kFloat32: { |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4793 | GenerateFPCompare(left, right, compare, false); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4794 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4795 | less_cond = kBelow; // for CF (floats). |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4796 | break; |
| 4797 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4798 | case DataType::Type::kFloat64: { |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4799 | GenerateFPCompare(left, right, compare, true); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4800 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4801 | less_cond = kBelow; // for CF (floats). |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4802 | break; |
| 4803 | } |
| 4804 | default: |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4805 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4806 | } |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4807 | |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4808 | __ movl(out, Immediate(0)); |
| 4809 | __ j(kEqual, &done); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4810 | __ j(less_cond, &less); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4811 | |
| 4812 | __ Bind(&greater); |
| 4813 | __ movl(out, Immediate(1)); |
| 4814 | __ jmp(&done); |
| 4815 | |
| 4816 | __ Bind(&less); |
| 4817 | __ movl(out, Immediate(-1)); |
| 4818 | |
| 4819 | __ Bind(&done); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4820 | } |
| 4821 | |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4822 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4823 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4824 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4825 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
| Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4826 | locations->SetInAt(i, Location::Any()); |
| 4827 | } |
| 4828 | locations->SetOut(Location::Any()); |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4829 | } |
| 4830 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4831 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4832 | LOG(FATAL) << "Unreachable"; |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4833 | } |
| 4834 | |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4835 | void CodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4836 | /* |
| 4837 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 4838 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 4839 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4840 | */ |
| 4841 | switch (kind) { |
| 4842 | case MemBarrierKind::kAnyAny: { |
| Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4843 | MemoryFence(); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4844 | break; |
| 4845 | } |
| 4846 | case MemBarrierKind::kAnyStore: |
| 4847 | case MemBarrierKind::kLoadAny: |
| 4848 | case MemBarrierKind::kStoreStore: { |
| 4849 | // nop |
| 4850 | break; |
| 4851 | } |
| Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4852 | case MemBarrierKind::kNTStoreStore: |
| 4853 | // Non-Temporal Store/Store needs an explicit fence. |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4854 | MemoryFence(/* non-temporal= */ true); |
| Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4855 | break; |
| Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4856 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4857 | } |
| 4858 | |
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4859 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( |
| 4860 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| Nicolas Geoffray | bdb2ecc | 2018-09-18 14:33:55 +0100 | [diff] [blame] | 4861 | ArtMethod* method ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4862 | return desired_dispatch_info; |
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4863 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4864 | |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4865 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 4866 | Register temp) { |
| 4867 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4868 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4869 | if (!invoke->GetLocations()->Intrinsified()) { |
| 4870 | return location.AsRegister<Register>(); |
| 4871 | } |
| 4872 | // For intrinsics we allow any location, so it may be on the stack. |
| 4873 | if (!location.IsRegister()) { |
| 4874 | __ movl(temp, Address(ESP, location.GetStackIndex())); |
| 4875 | return temp; |
| 4876 | } |
| 4877 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 4878 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 4879 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 4880 | // simple and more robust approach rather that trying to determine if that's the case. |
| 4881 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| Vladimir Marko | 4ee8e29 | 2017-06-02 15:39:30 +0000 | [diff] [blame] | 4882 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 4883 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 4884 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 4885 | __ movl(temp, Address(ESP, stack_offset)); |
| 4886 | return temp; |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4887 | } |
| 4888 | return location.AsRegister<Register>(); |
| 4889 | } |
| 4890 | |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4891 | void CodeGeneratorX86::GenerateStaticOrDirectCall( |
| 4892 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4893 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4894 | switch (invoke->GetMethodLoadKind()) { |
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4895 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4896 | // temp = thread->string_init_entrypoint |
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4897 | uint32_t offset = |
| 4898 | GetThreadOffset<kX86PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 4899 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(offset)); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4900 | break; |
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4901 | } |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4902 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
| Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4903 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4904 | break; |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4905 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 4906 | DCHECK(GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4907 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4908 | temp.AsRegister<Register>()); |
| 4909 | __ leal(temp.AsRegister<Register>(), Address(base_reg, CodeGeneratorX86::kDummy32BitOffset)); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4910 | RecordBootImageMethodPatch(invoke); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4911 | break; |
| 4912 | } |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4913 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageRelRo: { |
| 4914 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4915 | temp.AsRegister<Register>()); |
| 4916 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
| 4917 | RecordBootImageRelRoPatch( |
| 4918 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(), |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4919 | GetBootImageOffset(invoke)); |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4920 | break; |
| 4921 | } |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4922 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4923 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4924 | temp.AsRegister<Register>()); |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4925 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4926 | RecordMethodBssEntryPatch(invoke); |
| Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 4927 | // No need for memory fence, thanks to the x86 memory model. |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4928 | break; |
| 4929 | } |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4930 | case HInvokeStaticOrDirect::MethodLoadKind::kJitDirectAddress: |
| 4931 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 4932 | break; |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4933 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 4934 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 4935 | return; // No code pointer retrieval; the runtime performs the call directly. |
| Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4936 | } |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4937 | } |
| 4938 | |
| 4939 | switch (invoke->GetCodePtrLocation()) { |
| 4940 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 4941 | __ call(GetFrameEntryLabel()); |
| 4942 | break; |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4943 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4944 | // (callee_method + offset_of_quick_compiled_code)() |
| 4945 | __ call(Address(callee_method.AsRegister<Register>(), |
| 4946 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4947 | kX86PointerSize).Int32Value())); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4948 | break; |
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4949 | } |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4950 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4951 | |
| 4952 | DCHECK(!IsLeafMethod()); |
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4953 | } |
| 4954 | |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4955 | void CodeGeneratorX86::GenerateVirtualCall( |
| 4956 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4957 | Register temp = temp_in.AsRegister<Register>(); |
| 4958 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4959 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
| Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4960 | |
| 4961 | // Use the calling convention instead of the location of the receiver, as |
| 4962 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4963 | // slow path, the arguments have been moved to the right place, so here we are |
| 4964 | // guaranteed that the receiver is the first register of the calling convention. |
| 4965 | InvokeDexCallingConvention calling_convention; |
| 4966 | Register receiver = calling_convention.GetRegisterAt(0); |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4967 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4968 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4969 | __ movl(temp, Address(receiver, class_offset)); |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4970 | MaybeRecordImplicitNullCheck(invoke); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4971 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4972 | // emit a read barrier for the previous class reference load. |
| 4973 | // However this is not required in practice, as this is an |
| 4974 | // intermediate/temporary reference and because the current |
| 4975 | // concurrent copying collector keeps the from-space memory |
| 4976 | // intact/accessible until the end of the marking phase (the |
| 4977 | // concurrent copying collector may not in the future). |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4978 | __ MaybeUnpoisonHeapReference(temp); |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4979 | |
| 4980 | MaybeGenerateInlineCacheCheck(invoke, temp); |
| 4981 | |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4982 | // temp = temp->GetMethodAt(method_offset); |
| 4983 | __ movl(temp, Address(temp, method_offset)); |
| 4984 | // call temp->GetEntryPoint(); |
| 4985 | __ call(Address( |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4986 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4987 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4988 | } |
| 4989 | |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4990 | void CodeGeneratorX86::RecordBootImageIntrinsicPatch(HX86ComputeBaseMethodAddress* method_address, |
| 4991 | uint32_t intrinsic_data) { |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 4992 | boot_image_other_patches_.emplace_back( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4993 | method_address, /* target_dex_file= */ nullptr, intrinsic_data); |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 4994 | __ Bind(&boot_image_other_patches_.back().label); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4995 | } |
| 4996 | |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4997 | void CodeGeneratorX86::RecordBootImageRelRoPatch(HX86ComputeBaseMethodAddress* method_address, |
| 4998 | uint32_t boot_image_offset) { |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 4999 | boot_image_other_patches_.emplace_back( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5000 | method_address, /* target_dex_file= */ nullptr, boot_image_offset); |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5001 | __ Bind(&boot_image_other_patches_.back().label); |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 5002 | } |
| 5003 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5004 | void CodeGeneratorX86::RecordBootImageMethodPatch(HInvokeStaticOrDirect* invoke) { |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5005 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5006 | HX86ComputeBaseMethodAddress* method_address = |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5007 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5008 | boot_image_method_patches_.emplace_back( |
| 5009 | method_address, invoke->GetTargetMethod().dex_file, invoke->GetTargetMethod().index); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5010 | __ Bind(&boot_image_method_patches_.back().label); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5011 | } |
| 5012 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5013 | void CodeGeneratorX86::RecordMethodBssEntryPatch(HInvokeStaticOrDirect* invoke) { |
| 5014 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 5015 | HX86ComputeBaseMethodAddress* method_address = |
| 5016 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5017 | // 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] | 5018 | method_bss_entry_patches_.emplace_back( |
| 5019 | method_address, &GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()); |
| 5020 | __ Bind(&method_bss_entry_patches_.back().label); |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5021 | } |
| 5022 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5023 | void CodeGeneratorX86::RecordBootImageTypePatch(HLoadClass* load_class) { |
| 5024 | HX86ComputeBaseMethodAddress* method_address = |
| 5025 | load_class->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 5026 | boot_image_type_patches_.emplace_back( |
| 5027 | method_address, &load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5028 | __ Bind(&boot_image_type_patches_.back().label); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5029 | } |
| 5030 | |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5031 | Label* CodeGeneratorX86::NewTypeBssEntryPatch(HLoadClass* load_class) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5032 | HX86ComputeBaseMethodAddress* method_address = |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 5033 | load_class->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 5034 | type_bss_entry_patches_.emplace_back( |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5035 | method_address, &load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5036 | return &type_bss_entry_patches_.back().label; |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5037 | } |
| 5038 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5039 | void CodeGeneratorX86::RecordBootImageStringPatch(HLoadString* load_string) { |
| 5040 | HX86ComputeBaseMethodAddress* method_address = |
| 5041 | load_string->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 5042 | boot_image_string_patches_.emplace_back( |
| 5043 | method_address, &load_string->GetDexFile(), load_string->GetStringIndex().index_); |
| 5044 | __ Bind(&boot_image_string_patches_.back().label); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5045 | } |
| 5046 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5047 | Label* CodeGeneratorX86::NewStringBssEntryPatch(HLoadString* load_string) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5048 | HX86ComputeBaseMethodAddress* method_address = |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 5049 | load_string->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5050 | string_bss_entry_patches_.emplace_back( |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5051 | method_address, &load_string->GetDexFile(), load_string->GetStringIndex().index_); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5052 | return &string_bss_entry_patches_.back().label; |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5053 | } |
| 5054 | |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5055 | void CodeGeneratorX86::LoadBootImageAddress(Register reg, |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5056 | uint32_t boot_image_reference, |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5057 | HInvokeStaticOrDirect* invoke) { |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5058 | if (GetCompilerOptions().IsBootImage()) { |
| 5059 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 5060 | HX86ComputeBaseMethodAddress* method_address = |
| 5061 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
| 5062 | DCHECK(method_address != nullptr); |
| 5063 | Register method_address_reg = |
| 5064 | invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()).AsRegister<Register>(); |
| 5065 | __ leal(reg, Address(method_address_reg, CodeGeneratorX86::kDummy32BitOffset)); |
| 5066 | RecordBootImageIntrinsicPatch(method_address, boot_image_reference); |
| Vladimir Marko | a2da9b9 | 2018-10-10 14:21:55 +0100 | [diff] [blame] | 5067 | } else if (GetCompilerOptions().GetCompilePic()) { |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5068 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 5069 | HX86ComputeBaseMethodAddress* method_address = |
| 5070 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
| 5071 | DCHECK(method_address != nullptr); |
| 5072 | Register method_address_reg = |
| 5073 | invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()).AsRegister<Register>(); |
| 5074 | __ movl(reg, Address(method_address_reg, CodeGeneratorX86::kDummy32BitOffset)); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5075 | RecordBootImageRelRoPatch(method_address, boot_image_reference); |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5076 | } else { |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5077 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5078 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 5079 | DCHECK(!heap->GetBootImageSpaces().empty()); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5080 | const uint8_t* address = heap->GetBootImageSpaces()[0]->Begin() + boot_image_reference; |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5081 | __ movl(reg, Immediate(dchecked_integral_cast<uint32_t>(reinterpret_cast<uintptr_t>(address)))); |
| 5082 | } |
| 5083 | } |
| 5084 | |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5085 | void CodeGeneratorX86::AllocateInstanceForIntrinsic(HInvokeStaticOrDirect* invoke, |
| 5086 | uint32_t boot_image_offset) { |
| 5087 | DCHECK(invoke->IsStatic()); |
| 5088 | InvokeRuntimeCallingConvention calling_convention; |
| 5089 | Register argument = calling_convention.GetRegisterAt(0); |
| 5090 | if (GetCompilerOptions().IsBootImage()) { |
| 5091 | DCHECK_EQ(boot_image_offset, IntrinsicVisitor::IntegerValueOfInfo::kInvalidReference); |
| 5092 | // Load the class the same way as for HLoadClass::LoadKind::kBootImageLinkTimePcRelative. |
| 5093 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 5094 | HX86ComputeBaseMethodAddress* method_address = |
| 5095 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
| 5096 | DCHECK(method_address != nullptr); |
| 5097 | Register method_address_reg = |
| 5098 | invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()).AsRegister<Register>(); |
| 5099 | __ leal(argument, Address(method_address_reg, CodeGeneratorX86::kDummy32BitOffset)); |
| 5100 | MethodReference target_method = invoke->GetTargetMethod(); |
| 5101 | dex::TypeIndex type_idx = target_method.dex_file->GetMethodId(target_method.index).class_idx_; |
| 5102 | boot_image_type_patches_.emplace_back(method_address, target_method.dex_file, type_idx.index_); |
| 5103 | __ Bind(&boot_image_type_patches_.back().label); |
| 5104 | } else { |
| 5105 | LoadBootImageAddress(argument, boot_image_offset, invoke); |
| 5106 | } |
| 5107 | InvokeRuntime(kQuickAllocObjectInitialized, invoke, invoke->GetDexPc()); |
| 5108 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| 5109 | } |
| 5110 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5111 | // The label points to the end of the "movl" or another instruction but the literal offset |
| 5112 | // for method patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 5113 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
| 5114 | |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5115 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5116 | inline void CodeGeneratorX86::EmitPcRelativeLinkerPatches( |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 5117 | const ArenaDeque<X86PcRelativePatchInfo>& infos, |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5118 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 5119 | for (const X86PcRelativePatchInfo& info : infos) { |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5120 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5121 | linker_patches->push_back(Factory(literal_offset, |
| 5122 | info.target_dex_file, |
| 5123 | GetMethodAddressOffset(info.method_address), |
| 5124 | info.offset_or_index)); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5125 | } |
| 5126 | } |
| 5127 | |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5128 | template <linker::LinkerPatch (*Factory)(size_t, uint32_t, uint32_t)> |
| 5129 | linker::LinkerPatch NoDexFileAdapter(size_t literal_offset, |
| 5130 | const DexFile* target_dex_file, |
| 5131 | uint32_t pc_insn_offset, |
| 5132 | uint32_t boot_image_offset) { |
| 5133 | DCHECK(target_dex_file == nullptr); // Unused for these patches, should be null. |
| 5134 | return Factory(literal_offset, pc_insn_offset, boot_image_offset); |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 5135 | } |
| 5136 | |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5137 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5138 | DCHECK(linker_patches->empty()); |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 5139 | size_t size = |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5140 | boot_image_method_patches_.size() + |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5141 | method_bss_entry_patches_.size() + |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5142 | boot_image_type_patches_.size() + |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5143 | type_bss_entry_patches_.size() + |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5144 | boot_image_string_patches_.size() + |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5145 | string_bss_entry_patches_.size() + |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5146 | boot_image_other_patches_.size(); |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 5147 | linker_patches->reserve(size); |
| Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 5148 | if (GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()) { |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5149 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
| 5150 | boot_image_method_patches_, linker_patches); |
| 5151 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
| 5152 | boot_image_type_patches_, linker_patches); |
| 5153 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5154 | boot_image_string_patches_, linker_patches); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5155 | } else { |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5156 | DCHECK(boot_image_method_patches_.empty()); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5157 | DCHECK(boot_image_type_patches_.empty()); |
| 5158 | DCHECK(boot_image_string_patches_.empty()); |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5159 | } |
| 5160 | if (GetCompilerOptions().IsBootImage()) { |
| 5161 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::IntrinsicReferencePatch>>( |
| 5162 | boot_image_other_patches_, linker_patches); |
| 5163 | } else { |
| 5164 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::DataBimgRelRoPatch>>( |
| 5165 | boot_image_other_patches_, linker_patches); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5166 | } |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5167 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 5168 | method_bss_entry_patches_, linker_patches); |
| 5169 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 5170 | type_bss_entry_patches_, linker_patches); |
| 5171 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 5172 | string_bss_entry_patches_, linker_patches); |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5173 | DCHECK_EQ(size, linker_patches->size()); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5174 | } |
| 5175 | |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5176 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 5177 | Register card, |
| 5178 | Register object, |
| 5179 | Register value, |
| 5180 | bool value_can_be_null) { |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 5181 | NearLabel is_null; |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5182 | if (value_can_be_null) { |
| 5183 | __ testl(value, value); |
| 5184 | __ j(kEqual, &is_null); |
| 5185 | } |
| Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5186 | // Load the address of the card table into `card`. |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5187 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86PointerSize>().Int32Value())); |
| Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5188 | // Calculate the offset (in the card table) of the card corresponding to |
| 5189 | // `object`. |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5190 | __ movl(temp, object); |
| 5191 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
| Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5192 | // Write the `art::gc::accounting::CardTable::kCardDirty` value into the |
| 5193 | // `object`'s card. |
| 5194 | // |
| 5195 | // Register `card` contains the address of the card table. Note that the card |
| 5196 | // table's base is biased during its creation so that it always starts at an |
| 5197 | // address whose least-significant byte is equal to `kCardDirty` (see |
| 5198 | // art::gc::accounting::CardTable::Create). Therefore the MOVB instruction |
| 5199 | // below writes the `kCardDirty` (byte) value into the `object`'s card |
| 5200 | // (located at `card + object >> kCardShift`). |
| 5201 | // |
| 5202 | // This dual use of the value in register `card` (1. to calculate the location |
| 5203 | // of the card to mark; and 2. to load the `kCardDirty` value) saves a load |
| 5204 | // (no need to explicitly load `kCardDirty` as an immediate value). |
| Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 5205 | __ movb(Address(temp, card, TIMES_1, 0), |
| 5206 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5207 | if (value_can_be_null) { |
| 5208 | __ Bind(&is_null); |
| 5209 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5210 | } |
| 5211 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5212 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 5213 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5214 | |
| 5215 | bool object_field_get_with_read_barrier = |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5216 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5217 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5218 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 5219 | kEmitCompilerReadBarrier |
| 5220 | ? LocationSummary::kCallOnSlowPath |
| 5221 | : LocationSummary::kNoCall); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5222 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5223 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5224 | } |
| Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5225 | locations->SetInAt(0, Location::RequiresRegister()); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5226 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5227 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5228 | locations->SetOut(Location::RequiresFpuRegister()); |
| 5229 | } else { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5230 | // The output overlaps in case of long: we don't want the low move |
| 5231 | // to overwrite the object's location. Likewise, in the case of |
| 5232 | // an object field get with read barriers enabled, we do not want |
| 5233 | // the move to overwrite the object's location, as we need it to emit |
| 5234 | // the read barrier. |
| 5235 | locations->SetOut( |
| 5236 | Location::RequiresRegister(), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5237 | (object_field_get_with_read_barrier || instruction->GetType() == DataType::Type::kInt64) ? |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5238 | Location::kOutputOverlap : |
| 5239 | Location::kNoOutputOverlap); |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5240 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5241 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5242 | if (field_info.IsVolatile() && (field_info.GetFieldType() == DataType::Type::kInt64)) { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5243 | // Long values can be loaded atomically into an XMM using movsd. |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5244 | // So we use an XMM register as a temp to achieve atomicity (first |
| 5245 | // load the temp into the XMM and then copy the XMM into the |
| 5246 | // output, 32 bits at a time). |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5247 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 5248 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5249 | } |
| 5250 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5251 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 5252 | const FieldInfo& field_info) { |
| 5253 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5254 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5255 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5256 | Location base_loc = locations->InAt(0); |
| 5257 | Register base = base_loc.AsRegister<Register>(); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5258 | Location out = locations->Out(); |
| 5259 | bool is_volatile = field_info.IsVolatile(); |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5260 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 5261 | DataType::Type load_type = instruction->GetType(); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5262 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5263 | |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5264 | switch (load_type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5265 | case DataType::Type::kBool: |
| 5266 | case DataType::Type::kUint8: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5267 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5268 | break; |
| 5269 | } |
| 5270 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5271 | case DataType::Type::kInt8: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5272 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5273 | break; |
| 5274 | } |
| 5275 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5276 | case DataType::Type::kUint16: { |
| 5277 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5278 | break; |
| 5279 | } |
| 5280 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5281 | case DataType::Type::kInt16: { |
| 5282 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5283 | break; |
| 5284 | } |
| 5285 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5286 | case DataType::Type::kInt32: |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5287 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5288 | break; |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5289 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5290 | case DataType::Type::kReference: { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5291 | // /* HeapReference<Object> */ out = *(base + offset) |
| 5292 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5293 | // Note that a potential implicit null check is handled in this |
| 5294 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 5295 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5296 | instruction, out, base, offset, /* needs_null_check= */ true); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5297 | if (is_volatile) { |
| 5298 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5299 | } |
| 5300 | } else { |
| 5301 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| 5302 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5303 | if (is_volatile) { |
| 5304 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5305 | } |
| 5306 | // If read barriers are enabled, emit read barriers other than |
| 5307 | // Baker's using a slow path (and also unpoison the loaded |
| 5308 | // reference, if heap poisoning is enabled). |
| 5309 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 5310 | } |
| 5311 | break; |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5312 | } |
| 5313 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5314 | case DataType::Type::kInt64: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5315 | if (is_volatile) { |
| 5316 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 5317 | __ movsd(temp, Address(base, offset)); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5318 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5319 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 5320 | __ psrlq(temp, Immediate(32)); |
| 5321 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 5322 | } else { |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5323 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5324 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5325 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5326 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 5327 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5328 | break; |
| 5329 | } |
| 5330 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5331 | case DataType::Type::kFloat32: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5332 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5333 | break; |
| 5334 | } |
| 5335 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5336 | case DataType::Type::kFloat64: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5337 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5338 | break; |
| 5339 | } |
| 5340 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5341 | case DataType::Type::kUint32: |
| 5342 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5343 | case DataType::Type::kVoid: |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5344 | LOG(FATAL) << "Unreachable type " << load_type; |
| Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5345 | UNREACHABLE(); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5346 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5347 | |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5348 | if (load_type == DataType::Type::kReference || load_type == DataType::Type::kInt64) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5349 | // Potential implicit null checks, in the case of reference or |
| 5350 | // long fields, are handled in the previous switch statement. |
| 5351 | } else { |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5352 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5353 | } |
| 5354 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5355 | if (is_volatile) { |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5356 | if (load_type == DataType::Type::kReference) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5357 | // Memory barriers, in the case of references, are also handled |
| 5358 | // in the previous switch statement. |
| 5359 | } else { |
| 5360 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5361 | } |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5362 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5363 | } |
| 5364 | |
| 5365 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 5366 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5367 | |
| 5368 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5369 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5370 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5371 | bool is_volatile = field_info.IsVolatile(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5372 | DataType::Type field_type = field_info.GetFieldType(); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5373 | bool is_byte_type = DataType::Size(field_type) == 1u; |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5374 | |
| 5375 | // The register allocator does not support multiple |
| 5376 | // inputs that die at entry with one in a specific register. |
| 5377 | if (is_byte_type) { |
| 5378 | // Ensure the value is in a byte register. |
| 5379 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5380 | } else if (DataType::IsFloatingPointType(field_type)) { |
| 5381 | if (is_volatile && field_type == DataType::Type::kFloat64) { |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5382 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 5383 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 5384 | } else { |
| 5385 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 5386 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5387 | } else if (is_volatile && field_type == DataType::Type::kInt64) { |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5388 | // 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] | 5389 | locations->SetInAt(1, Location::RequiresRegister()); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5390 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5391 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 5392 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 5393 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 5394 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 5395 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 5396 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 5397 | locations->AddTemp(Location::RequiresFpuRegister()); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5398 | } else { |
| 5399 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5400 | |
| 5401 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 5402 | // Temporary registers for the write barrier. |
| 5403 | locations->AddTemp(Location::RequiresRegister()); // May be used for reference poisoning too. |
| 5404 | // Ensure the card is in a byte register. |
| 5405 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 5406 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5407 | } |
| 5408 | } |
| 5409 | |
| 5410 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5411 | const FieldInfo& field_info, |
| 5412 | bool value_can_be_null) { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5413 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5414 | |
| 5415 | LocationSummary* locations = instruction->GetLocations(); |
| 5416 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 5417 | Location value = locations->InAt(1); |
| 5418 | bool is_volatile = field_info.IsVolatile(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5419 | DataType::Type field_type = field_info.GetFieldType(); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5420 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5421 | bool needs_write_barrier = |
| 5422 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5423 | |
| 5424 | if (is_volatile) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5425 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5426 | } |
| 5427 | |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5428 | bool maybe_record_implicit_null_check_done = false; |
| 5429 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5430 | switch (field_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5431 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5432 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5433 | case DataType::Type::kInt8: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5434 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 5435 | break; |
| 5436 | } |
| 5437 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5438 | case DataType::Type::kUint16: |
| 5439 | case DataType::Type::kInt16: { |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5440 | if (value.IsConstant()) { |
| Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5441 | __ movw(Address(base, offset), |
| 5442 | Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5443 | } else { |
| 5444 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 5445 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5446 | break; |
| 5447 | } |
| 5448 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5449 | case DataType::Type::kInt32: |
| 5450 | case DataType::Type::kReference: { |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5451 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 5452 | // Note that in the case where `value` is a null reference, |
| 5453 | // we do not enter this block, as the reference does not |
| 5454 | // need poisoning. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5455 | DCHECK_EQ(field_type, DataType::Type::kReference); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5456 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5457 | __ movl(temp, value.AsRegister<Register>()); |
| 5458 | __ PoisonHeapReference(temp); |
| 5459 | __ movl(Address(base, offset), temp); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5460 | } else if (value.IsConstant()) { |
| 5461 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5462 | __ movl(Address(base, offset), Immediate(v)); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5463 | } else { |
| Nicolas Geoffray | 0397163 | 2016-03-17 10:44:24 +0000 | [diff] [blame] | 5464 | DCHECK(value.IsRegister()) << value; |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5465 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 5466 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5467 | break; |
| 5468 | } |
| 5469 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5470 | case DataType::Type::kInt64: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5471 | if (is_volatile) { |
| 5472 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 5473 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 5474 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 5475 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 5476 | __ punpckldq(temp1, temp2); |
| 5477 | __ movsd(Address(base, offset), temp1); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5478 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5479 | } else if (value.IsConstant()) { |
| 5480 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 5481 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 5482 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5483 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5484 | } else { |
| 5485 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5486 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5487 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 5488 | } |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5489 | maybe_record_implicit_null_check_done = true; |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5490 | break; |
| 5491 | } |
| 5492 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5493 | case DataType::Type::kFloat32: { |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5494 | if (value.IsConstant()) { |
| 5495 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5496 | __ movl(Address(base, offset), Immediate(v)); |
| 5497 | } else { |
| 5498 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 5499 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5500 | break; |
| 5501 | } |
| 5502 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5503 | case DataType::Type::kFloat64: { |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5504 | if (value.IsConstant()) { |
| 5505 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 5506 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 5507 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5508 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
| 5509 | maybe_record_implicit_null_check_done = true; |
| 5510 | } else { |
| 5511 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 5512 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5513 | break; |
| 5514 | } |
| 5515 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5516 | case DataType::Type::kUint32: |
| 5517 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5518 | case DataType::Type::kVoid: |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5519 | LOG(FATAL) << "Unreachable type " << field_type; |
| 5520 | UNREACHABLE(); |
| 5521 | } |
| 5522 | |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5523 | if (!maybe_record_implicit_null_check_done) { |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5524 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5525 | } |
| 5526 | |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5527 | if (needs_write_barrier) { |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5528 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5529 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5530 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5531 | } |
| 5532 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5533 | if (is_volatile) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5534 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5535 | } |
| 5536 | } |
| 5537 | |
| 5538 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5539 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5540 | } |
| 5541 | |
| 5542 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5543 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5544 | } |
| 5545 | |
| 5546 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 5547 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5548 | } |
| 5549 | |
| 5550 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5551 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5552 | } |
| 5553 | |
| 5554 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5555 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5556 | } |
| 5557 | |
| 5558 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5559 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5560 | } |
| 5561 | |
| 5562 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5563 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5564 | } |
| 5565 | |
| 5566 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5567 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5568 | } |
| 5569 | |
| Vladimir Marko | 552a134 | 2017-10-31 10:56:47 +0000 | [diff] [blame] | 5570 | void LocationsBuilderX86::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 5571 | codegen_->CreateStringBuilderAppendLocations(instruction, Location::RegisterLocation(EAX)); |
| 5572 | } |
| 5573 | |
| 5574 | void InstructionCodeGeneratorX86::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 5575 | __ movl(EAX, Immediate(instruction->GetFormat()->GetValue())); |
| 5576 | codegen_->InvokeRuntime(kQuickStringBuilderAppend, instruction, instruction->GetDexPc()); |
| 5577 | } |
| 5578 | |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5579 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 5580 | HUnresolvedInstanceFieldGet* instruction) { |
| 5581 | FieldAccessCallingConventionX86 calling_convention; |
| 5582 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5583 | instruction, instruction->GetFieldType(), calling_convention); |
| 5584 | } |
| 5585 | |
| 5586 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 5587 | HUnresolvedInstanceFieldGet* instruction) { |
| 5588 | FieldAccessCallingConventionX86 calling_convention; |
| 5589 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5590 | instruction->GetFieldType(), |
| 5591 | instruction->GetFieldIndex(), |
| 5592 | instruction->GetDexPc(), |
| 5593 | calling_convention); |
| 5594 | } |
| 5595 | |
| 5596 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 5597 | HUnresolvedInstanceFieldSet* instruction) { |
| 5598 | FieldAccessCallingConventionX86 calling_convention; |
| 5599 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5600 | instruction, instruction->GetFieldType(), calling_convention); |
| 5601 | } |
| 5602 | |
| 5603 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 5604 | HUnresolvedInstanceFieldSet* instruction) { |
| 5605 | FieldAccessCallingConventionX86 calling_convention; |
| 5606 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5607 | instruction->GetFieldType(), |
| 5608 | instruction->GetFieldIndex(), |
| 5609 | instruction->GetDexPc(), |
| 5610 | calling_convention); |
| 5611 | } |
| 5612 | |
| 5613 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 5614 | HUnresolvedStaticFieldGet* instruction) { |
| 5615 | FieldAccessCallingConventionX86 calling_convention; |
| 5616 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5617 | instruction, instruction->GetFieldType(), calling_convention); |
| 5618 | } |
| 5619 | |
| 5620 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 5621 | HUnresolvedStaticFieldGet* instruction) { |
| 5622 | FieldAccessCallingConventionX86 calling_convention; |
| 5623 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5624 | instruction->GetFieldType(), |
| 5625 | instruction->GetFieldIndex(), |
| 5626 | instruction->GetDexPc(), |
| 5627 | calling_convention); |
| 5628 | } |
| 5629 | |
| 5630 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 5631 | HUnresolvedStaticFieldSet* instruction) { |
| 5632 | FieldAccessCallingConventionX86 calling_convention; |
| 5633 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5634 | instruction, instruction->GetFieldType(), calling_convention); |
| 5635 | } |
| 5636 | |
| 5637 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 5638 | HUnresolvedStaticFieldSet* instruction) { |
| 5639 | FieldAccessCallingConventionX86 calling_convention; |
| 5640 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5641 | instruction->GetFieldType(), |
| 5642 | instruction->GetFieldIndex(), |
| 5643 | instruction->GetDexPc(), |
| 5644 | calling_convention); |
| 5645 | } |
| 5646 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5647 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5648 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5649 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 5650 | ? Location::RequiresRegister() |
| 5651 | : Location::Any(); |
| 5652 | locations->SetInAt(0, loc); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5653 | } |
| 5654 | |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5655 | void CodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5656 | if (CanMoveNullCheckToUser(instruction)) { |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5657 | return; |
| 5658 | } |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5659 | LocationSummary* locations = instruction->GetLocations(); |
| 5660 | Location obj = locations->InAt(0); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5661 | |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5662 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5663 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5664 | } |
| 5665 | |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5666 | void CodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5667 | SlowPathCode* slow_path = new (GetScopedAllocator()) NullCheckSlowPathX86(instruction); |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5668 | AddSlowPath(slow_path); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5669 | |
| 5670 | LocationSummary* locations = instruction->GetLocations(); |
| 5671 | Location obj = locations->InAt(0); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5672 | |
| 5673 | if (obj.IsRegister()) { |
| Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 5674 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5675 | } else if (obj.IsStackSlot()) { |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5676 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5677 | } else { |
| 5678 | DCHECK(obj.IsConstant()) << obj; |
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5679 | DCHECK(obj.GetConstant()->IsNullConstant()); |
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5680 | __ jmp(slow_path->GetEntryLabel()); |
| 5681 | return; |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5682 | } |
| 5683 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5684 | } |
| 5685 | |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5686 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5687 | codegen_->GenerateNullCheck(instruction); |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5688 | } |
| 5689 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5690 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5691 | bool object_array_get_with_read_barrier = |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5692 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5693 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5694 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 5695 | object_array_get_with_read_barrier |
| 5696 | ? LocationSummary::kCallOnSlowPath |
| 5697 | : LocationSummary::kNoCall); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5698 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5699 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5700 | } |
| Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5701 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5702 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5703 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5704 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5705 | } else { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5706 | // The output overlaps in case of long: we don't want the low move |
| 5707 | // to overwrite the array's location. Likewise, in the case of an |
| 5708 | // object array get with read barriers enabled, we do not want the |
| 5709 | // move to overwrite the array's location, as we need it to emit |
| 5710 | // the read barrier. |
| 5711 | locations->SetOut( |
| 5712 | Location::RequiresRegister(), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5713 | (instruction->GetType() == DataType::Type::kInt64 || object_array_get_with_read_barrier) |
| 5714 | ? Location::kOutputOverlap |
| 5715 | : Location::kNoOutputOverlap); |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5716 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5717 | } |
| 5718 | |
| 5719 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 5720 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5721 | Location obj_loc = locations->InAt(0); |
| 5722 | Register obj = obj_loc.AsRegister<Register>(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5723 | Location index = locations->InAt(1); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5724 | Location out_loc = locations->Out(); |
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5725 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5726 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5727 | DataType::Type type = instruction->GetType(); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5728 | switch (type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5729 | case DataType::Type::kBool: |
| 5730 | case DataType::Type::kUint8: { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5731 | Register out = out_loc.AsRegister<Register>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5732 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5733 | break; |
| 5734 | } |
| 5735 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5736 | case DataType::Type::kInt8: { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5737 | Register out = out_loc.AsRegister<Register>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5738 | __ movsxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5739 | break; |
| 5740 | } |
| 5741 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5742 | case DataType::Type::kUint16: { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5743 | Register out = out_loc.AsRegister<Register>(); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5744 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5745 | // Branch cases into compressed and uncompressed for each index's type. |
| 5746 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 5747 | NearLabel done, not_compressed; |
| Vladimir Marko | 3c89d42 | 2017-02-17 11:30:23 +0000 | [diff] [blame] | 5748 | __ testb(Address(obj, count_offset), Immediate(1)); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5749 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5750 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 5751 | "Expecting 0=compressed, 1=uncompressed"); |
| 5752 | __ j(kNotZero, ¬_compressed); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5753 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| 5754 | __ jmp(&done); |
| 5755 | __ Bind(¬_compressed); |
| 5756 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5757 | __ Bind(&done); |
| 5758 | } else { |
| 5759 | // Common case for charAt of array of char or when string compression's |
| 5760 | // feature is turned off. |
| 5761 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5762 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5763 | break; |
| 5764 | } |
| 5765 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5766 | case DataType::Type::kInt16: { |
| 5767 | Register out = out_loc.AsRegister<Register>(); |
| 5768 | __ movsxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5769 | break; |
| 5770 | } |
| 5771 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5772 | case DataType::Type::kInt32: { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5773 | Register out = out_loc.AsRegister<Register>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5774 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5775 | break; |
| 5776 | } |
| 5777 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5778 | case DataType::Type::kReference: { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5779 | static_assert( |
| 5780 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5781 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5782 | // /* HeapReference<Object> */ out = |
| 5783 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5784 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5785 | // Note that a potential implicit null check is handled in this |
| 5786 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 5787 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5788 | instruction, out_loc, obj, data_offset, index, /* needs_null_check= */ true); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5789 | } else { |
| 5790 | Register out = out_loc.AsRegister<Register>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5791 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| 5792 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5793 | // If read barriers are enabled, emit read barriers other than |
| 5794 | // Baker's using a slow path (and also unpoison the loaded |
| 5795 | // reference, if heap poisoning is enabled). |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5796 | if (index.IsConstant()) { |
| 5797 | uint32_t offset = |
| 5798 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5799 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5800 | } else { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5801 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5802 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5803 | } |
| 5804 | } |
| 5805 | break; |
| 5806 | } |
| 5807 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5808 | case DataType::Type::kInt64: { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5809 | DCHECK_NE(obj, out_loc.AsRegisterPairLow<Register>()); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5810 | __ movl(out_loc.AsRegisterPairLow<Register>(), |
| 5811 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
| 5812 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5813 | __ movl(out_loc.AsRegisterPairHigh<Register>(), |
| 5814 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset + kX86WordSize)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5815 | break; |
| 5816 | } |
| 5817 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5818 | case DataType::Type::kFloat32: { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5819 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5820 | __ movss(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5821 | break; |
| 5822 | } |
| 5823 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5824 | case DataType::Type::kFloat64: { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5825 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5826 | __ movsd(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5827 | break; |
| 5828 | } |
| 5829 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5830 | case DataType::Type::kUint32: |
| 5831 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5832 | case DataType::Type::kVoid: |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5833 | LOG(FATAL) << "Unreachable type " << type; |
| Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5834 | UNREACHABLE(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5835 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5836 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5837 | if (type == DataType::Type::kReference || type == DataType::Type::kInt64) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5838 | // Potential implicit null checks, in the case of reference or |
| 5839 | // long arrays, are handled in the previous switch statement. |
| 5840 | } else { |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5841 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5842 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5843 | } |
| 5844 | |
| 5845 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5846 | DataType::Type value_type = instruction->GetComponentType(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5847 | |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5848 | bool needs_write_barrier = |
| 5849 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5850 | bool needs_type_check = instruction->NeedsTypeCheck(); |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5851 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5852 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5853 | instruction, |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5854 | needs_type_check ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5855 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5856 | bool is_byte_type = DataType::Size(value_type) == 1u; |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5857 | // We need the inputs to be different than the output in case of long operation. |
| 5858 | // In case of a byte operation, the register allocator does not support multiple |
| 5859 | // inputs that die at entry with one in a specific register. |
| 5860 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5861 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5862 | if (is_byte_type) { |
| 5863 | // Ensure the value is in a byte register. |
| 5864 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5865 | } else if (DataType::IsFloatingPointType(value_type)) { |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5866 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5867 | } else { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5868 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 5869 | } |
| 5870 | if (needs_write_barrier) { |
| 5871 | // Temporary registers for the write barrier. |
| 5872 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 5873 | // Ensure the card is in a byte register. |
| Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5874 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5875 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5876 | } |
| 5877 | |
| 5878 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 5879 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5880 | Location array_loc = locations->InAt(0); |
| 5881 | Register array = array_loc.AsRegister<Register>(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5882 | Location index = locations->InAt(1); |
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5883 | Location value = locations->InAt(2); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5884 | DataType::Type value_type = instruction->GetComponentType(); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5885 | bool needs_type_check = instruction->NeedsTypeCheck(); |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5886 | bool needs_write_barrier = |
| 5887 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5888 | |
| 5889 | switch (value_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5890 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5891 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5892 | case DataType::Type::kInt8: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5893 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5894 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_1, offset); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5895 | if (value.IsRegister()) { |
| 5896 | __ movb(address, value.AsRegister<ByteRegister>()); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5897 | } else { |
| Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5898 | __ movb(address, Immediate(CodeGenerator::GetInt8ValueOf(value.GetConstant()))); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5899 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5900 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5901 | break; |
| 5902 | } |
| 5903 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5904 | case DataType::Type::kUint16: |
| 5905 | case DataType::Type::kInt16: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5906 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5907 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_2, offset); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5908 | if (value.IsRegister()) { |
| 5909 | __ movw(address, value.AsRegister<Register>()); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5910 | } else { |
| Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5911 | __ movw(address, Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5912 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5913 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5914 | break; |
| 5915 | } |
| 5916 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5917 | case DataType::Type::kReference: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5918 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5919 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5920 | |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5921 | if (!value.IsRegister()) { |
| 5922 | // Just setting null. |
| 5923 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5924 | DCHECK(value.IsConstant()) << value; |
| 5925 | __ movl(address, Immediate(0)); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5926 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5927 | DCHECK(!needs_write_barrier); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5928 | DCHECK(!needs_type_check); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5929 | break; |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5930 | } |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5931 | |
| 5932 | DCHECK(needs_write_barrier); |
| 5933 | Register register_value = value.AsRegister<Register>(); |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5934 | Location temp_loc = locations->GetTemp(0); |
| 5935 | Register temp = temp_loc.AsRegister<Register>(); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5936 | |
| 5937 | bool can_value_be_null = instruction->GetValueCanBeNull(); |
| 5938 | NearLabel do_store; |
| 5939 | if (can_value_be_null) { |
| 5940 | __ testl(register_value, register_value); |
| 5941 | __ j(kEqual, &do_store); |
| 5942 | } |
| 5943 | |
| 5944 | SlowPathCode* slow_path = nullptr; |
| 5945 | if (needs_type_check) { |
| Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 5946 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathX86(instruction); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5947 | codegen_->AddSlowPath(slow_path); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5948 | |
| 5949 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5950 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5951 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5952 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5953 | // Note that when Baker read barriers are enabled, the type |
| 5954 | // checks are performed without read barriers. This is fine, |
| 5955 | // even in the case where a class object is in the from-space |
| 5956 | // after the flip, as a comparison involving such a type would |
| 5957 | // not produce a false positive; it may of course produce a |
| 5958 | // false negative, in which case we would take the ArraySet |
| 5959 | // slow path. |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5960 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5961 | // /* HeapReference<Class> */ temp = array->klass_ |
| 5962 | __ movl(temp, Address(array, class_offset)); |
| 5963 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5964 | __ MaybeUnpoisonHeapReference(temp); |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5965 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5966 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5967 | __ movl(temp, Address(temp, component_offset)); |
| 5968 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 5969 | // nor the object reference in `register_value->klass`, as |
| 5970 | // we are comparing two poisoned references. |
| 5971 | __ cmpl(temp, Address(register_value, class_offset)); |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5972 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5973 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5974 | NearLabel do_put; |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5975 | __ j(kEqual, &do_put); |
| 5976 | // If heap poisoning is enabled, the `temp` reference has |
| 5977 | // not been unpoisoned yet; unpoison it now. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5978 | __ MaybeUnpoisonHeapReference(temp); |
| 5979 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5980 | // If heap poisoning is enabled, no need to unpoison the |
| 5981 | // heap reference loaded below, as it is only used for a |
| 5982 | // comparison with null. |
| 5983 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 5984 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5985 | __ Bind(&do_put); |
| 5986 | } else { |
| 5987 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5988 | } |
| Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 5989 | } |
| 5990 | |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5991 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 5992 | codegen_->MarkGCCard( |
| 5993 | temp, card, array, value.AsRegister<Register>(), /* value_can_be_null= */ false); |
| 5994 | |
| 5995 | if (can_value_be_null) { |
| 5996 | DCHECK(do_store.IsLinked()); |
| 5997 | __ Bind(&do_store); |
| 5998 | } |
| 5999 | |
| 6000 | Register source = register_value; |
| Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6001 | if (kPoisonHeapReferences) { |
| 6002 | __ movl(temp, register_value); |
| 6003 | __ PoisonHeapReference(temp); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6004 | source = temp; |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6005 | } |
| 6006 | |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6007 | __ movl(address, source); |
| 6008 | |
| 6009 | if (can_value_be_null || !needs_type_check) { |
| 6010 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6011 | } |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6012 | |
| Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6013 | if (slow_path != nullptr) { |
| 6014 | __ Bind(slow_path->GetExitLabel()); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6015 | } |
| 6016 | |
| 6017 | break; |
| 6018 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6019 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6020 | case DataType::Type::kInt32: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6021 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6022 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6023 | if (value.IsRegister()) { |
| 6024 | __ movl(address, value.AsRegister<Register>()); |
| 6025 | } else { |
| 6026 | DCHECK(value.IsConstant()) << value; |
| 6027 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 6028 | __ movl(address, Immediate(v)); |
| 6029 | } |
| 6030 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6031 | break; |
| 6032 | } |
| 6033 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6034 | case DataType::Type::kInt64: { |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6035 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6036 | if (value.IsRegisterPair()) { |
| 6037 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 6038 | value.AsRegisterPairLow<Register>()); |
| 6039 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6040 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 6041 | value.AsRegisterPairHigh<Register>()); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6042 | } else { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6043 | DCHECK(value.IsConstant()); |
| 6044 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
| 6045 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 6046 | Immediate(Low32Bits(val))); |
| 6047 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6048 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 6049 | Immediate(High32Bits(val))); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6050 | } |
| 6051 | break; |
| 6052 | } |
| 6053 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6054 | case DataType::Type::kFloat32: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6055 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6056 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6057 | if (value.IsFpuRegister()) { |
| 6058 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 6059 | } else { |
| 6060 | DCHECK(value.IsConstant()); |
| 6061 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 6062 | __ movl(address, Immediate(v)); |
| 6063 | } |
| 6064 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6065 | break; |
| 6066 | } |
| 6067 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6068 | case DataType::Type::kFloat64: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6069 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6070 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6071 | if (value.IsFpuRegister()) { |
| 6072 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 6073 | } else { |
| 6074 | DCHECK(value.IsConstant()); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6075 | Address address_hi = |
| 6076 | CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset + kX86WordSize); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6077 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 6078 | __ movl(address, Immediate(Low32Bits(v))); |
| 6079 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6080 | __ movl(address_hi, Immediate(High32Bits(v))); |
| 6081 | } |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6082 | break; |
| 6083 | } |
| 6084 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 6085 | case DataType::Type::kUint32: |
| 6086 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6087 | case DataType::Type::kVoid: |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6088 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 6089 | UNREACHABLE(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6090 | } |
| 6091 | } |
| 6092 | |
| 6093 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6094 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 6095 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6096 | if (!instruction->IsEmittedAtUseSite()) { |
| 6097 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6098 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6099 | } |
| 6100 | |
| 6101 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6102 | if (instruction->IsEmittedAtUseSite()) { |
| 6103 | return; |
| 6104 | } |
| 6105 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6106 | LocationSummary* locations = instruction->GetLocations(); |
| Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 6107 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6108 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 6109 | Register out = locations->Out().AsRegister<Register>(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6110 | __ movl(out, Address(obj, offset)); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6111 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6112 | // Mask out most significant bit in case the array is String's array of char. |
| 6113 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6114 | __ shrl(out, Immediate(1)); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6115 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6116 | } |
| 6117 | |
| 6118 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6119 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6120 | InvokeRuntimeCallingConvention calling_convention; |
| 6121 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6122 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 6123 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 6124 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6125 | HInstruction* length = instruction->InputAt(1); |
| 6126 | if (!length->IsEmittedAtUseSite()) { |
| 6127 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 6128 | } |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6129 | // Need register to see array's length. |
| 6130 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 6131 | locations->AddTemp(Location::RequiresRegister()); |
| 6132 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6133 | } |
| 6134 | |
| 6135 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6136 | const bool is_string_compressed_char_at = |
| 6137 | mirror::kUseStringCompression && instruction->IsStringCharAt(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6138 | LocationSummary* locations = instruction->GetLocations(); |
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 6139 | Location index_loc = locations->InAt(0); |
| 6140 | Location length_loc = locations->InAt(1); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6141 | SlowPathCode* slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6142 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathX86(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6143 | |
| Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 6144 | if (length_loc.IsConstant()) { |
| 6145 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 6146 | if (index_loc.IsConstant()) { |
| 6147 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 6148 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 6149 | if (index < 0 || index >= length) { |
| 6150 | codegen_->AddSlowPath(slow_path); |
| 6151 | __ jmp(slow_path->GetEntryLabel()); |
| 6152 | } else { |
| 6153 | // Some optimization after BCE may have generated this, and we should not |
| 6154 | // generate a bounds check if it is a valid range. |
| 6155 | } |
| 6156 | return; |
| 6157 | } |
| 6158 | |
| 6159 | // We have to reverse the jump condition because the length is the constant. |
| 6160 | Register index_reg = index_loc.AsRegister<Register>(); |
| 6161 | __ cmpl(index_reg, Immediate(length)); |
| 6162 | codegen_->AddSlowPath(slow_path); |
| 6163 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 6164 | } else { |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6165 | HInstruction* array_length = instruction->InputAt(1); |
| 6166 | if (array_length->IsEmittedAtUseSite()) { |
| 6167 | // Address the length field in the array. |
| 6168 | DCHECK(array_length->IsArrayLength()); |
| 6169 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 6170 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 6171 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6172 | if (is_string_compressed_char_at) { |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6173 | // TODO: if index_loc.IsConstant(), compare twice the index (to compensate for |
| 6174 | // the string compression flag) with the in-memory length and avoid the temporary. |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6175 | Register length_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 6176 | __ movl(length_reg, array_len); |
| 6177 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6178 | __ shrl(length_reg, Immediate(1)); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6179 | codegen_->GenerateIntCompare(length_reg, index_loc); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6180 | } else { |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6181 | // Checking bounds for general case: |
| 6182 | // Array of char or string's array with feature compression off. |
| 6183 | if (index_loc.IsConstant()) { |
| 6184 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 6185 | __ cmpl(array_len, Immediate(value)); |
| 6186 | } else { |
| 6187 | __ cmpl(array_len, index_loc.AsRegister<Register>()); |
| 6188 | } |
| 6189 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6190 | } |
| Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 6191 | } else { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6192 | codegen_->GenerateIntCompare(length_loc, index_loc); |
| Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 6193 | } |
| 6194 | codegen_->AddSlowPath(slow_path); |
| 6195 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 6196 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6197 | } |
| 6198 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6199 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6200 | LOG(FATAL) << "Unreachable"; |
| Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6201 | } |
| 6202 | |
| 6203 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
| Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 6204 | if (instruction->GetNext()->IsSuspendCheck() && |
| 6205 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 6206 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 6207 | // The back edge will generate the suspend check. |
| 6208 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 6209 | } |
| 6210 | |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6211 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 6212 | } |
| 6213 | |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6214 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6215 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6216 | instruction, LocationSummary::kCallOnSlowPath); |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 6217 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 6218 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 6219 | // registers in full width (since the runtime only saves/restores lower part). |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6220 | locations->SetCustomSlowPathCallerSaves( |
| 6221 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6222 | } |
| 6223 | |
| 6224 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6225 | HBasicBlock* block = instruction->GetBlock(); |
| 6226 | if (block->GetLoopInformation() != nullptr) { |
| 6227 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 6228 | // The back edge will generate the suspend check. |
| 6229 | return; |
| 6230 | } |
| 6231 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 6232 | // The goto will generate the suspend check. |
| 6233 | return; |
| 6234 | } |
| 6235 | GenerateSuspendCheck(instruction, nullptr); |
| 6236 | } |
| 6237 | |
| 6238 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 6239 | HBasicBlock* successor) { |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6240 | SuspendCheckSlowPathX86* slow_path = |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6241 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 6242 | if (slow_path == nullptr) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6243 | slow_path = |
| 6244 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathX86(instruction, successor); |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6245 | instruction->SetSlowPath(slow_path); |
| 6246 | codegen_->AddSlowPath(slow_path); |
| 6247 | if (successor != nullptr) { |
| 6248 | DCHECK(successor->IsLoopHeader()); |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6249 | } |
| 6250 | } else { |
| 6251 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 6252 | } |
| 6253 | |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6254 | __ fs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86PointerSize>().Int32Value()), |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6255 | Immediate(0)); |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6256 | if (successor == nullptr) { |
| 6257 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6258 | __ Bind(slow_path->GetReturnLabel()); |
| 6259 | } else { |
| 6260 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 6261 | __ jmp(slow_path->GetEntryLabel()); |
| 6262 | } |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6263 | } |
| 6264 | |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6265 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 6266 | return codegen_->GetAssembler(); |
| 6267 | } |
| 6268 | |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6269 | void ParallelMoveResolverX86::MoveMemoryToMemory(int dst, int src, int number_of_words) { |
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6270 | ScratchRegisterScope ensure_scratch( |
| 6271 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 6272 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 6273 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6274 | |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6275 | // Now that temp register is available (possibly spilled), move blocks of memory. |
| 6276 | for (int i = 0; i < number_of_words; i++) { |
| 6277 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 6278 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 6279 | stack_offset += kX86WordSize; |
| 6280 | } |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6281 | } |
| 6282 | |
| 6283 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6284 | MoveOperands* move = moves_[index]; |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6285 | Location source = move->GetSource(); |
| 6286 | Location destination = move->GetDestination(); |
| 6287 | |
| 6288 | if (source.IsRegister()) { |
| 6289 | if (destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6290 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6291 | } else if (destination.IsFpuRegister()) { |
| 6292 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6293 | } else { |
| 6294 | DCHECK(destination.IsStackSlot()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6295 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6296 | } |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6297 | } else if (source.IsRegisterPair()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6298 | size_t elem_size = DataType::Size(DataType::Type::kInt32); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6299 | // Create stack space for 2 elements. |
| 6300 | __ subl(ESP, Immediate(2 * elem_size)); |
| 6301 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 6302 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 6303 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 6304 | // And remove the temporary stack space we allocated. |
| 6305 | __ addl(ESP, Immediate(2 * elem_size)); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6306 | } else if (source.IsFpuRegister()) { |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6307 | if (destination.IsRegister()) { |
| 6308 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
| 6309 | } else if (destination.IsFpuRegister()) { |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6310 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6311 | } else if (destination.IsRegisterPair()) { |
| 6312 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 6313 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 6314 | __ psrlq(src_reg, Immediate(32)); |
| 6315 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6316 | } else if (destination.IsStackSlot()) { |
| 6317 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6318 | } else if (destination.IsDoubleStackSlot()) { |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6319 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6320 | } else { |
| 6321 | DCHECK(destination.IsSIMDStackSlot()); |
| 6322 | __ movups(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6323 | } |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6324 | } else if (source.IsStackSlot()) { |
| 6325 | if (destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6326 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6327 | } else if (destination.IsFpuRegister()) { |
| 6328 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6329 | } else { |
| 6330 | DCHECK(destination.IsStackSlot()); |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6331 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 1); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6332 | } |
| 6333 | } else if (source.IsDoubleStackSlot()) { |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6334 | if (destination.IsRegisterPair()) { |
| 6335 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 6336 | __ movl(destination.AsRegisterPairHigh<Register>(), |
| 6337 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 6338 | } else if (destination.IsFpuRegister()) { |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6339 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 6340 | } else { |
| 6341 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6342 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 2); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6343 | } |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6344 | } else if (source.IsSIMDStackSlot()) { |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6345 | if (destination.IsFpuRegister()) { |
| 6346 | __ movups(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 6347 | } else { |
| 6348 | DCHECK(destination.IsSIMDStackSlot()); |
| 6349 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 4); |
| 6350 | } |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 6351 | } else if (source.IsConstant()) { |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6352 | HConstant* constant = source.GetConstant(); |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 6353 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 6354 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6355 | if (destination.IsRegister()) { |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 6356 | if (value == 0) { |
| 6357 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 6358 | } else { |
| 6359 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 6360 | } |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6361 | } else { |
| 6362 | DCHECK(destination.IsStackSlot()) << destination; |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 6363 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6364 | } |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6365 | } else if (constant->IsFloatConstant()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6366 | float fp_value = constant->AsFloatConstant()->GetValue(); |
| Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 6367 | int32_t value = bit_cast<int32_t, float>(fp_value); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6368 | Immediate imm(value); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6369 | if (destination.IsFpuRegister()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6370 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 6371 | if (value == 0) { |
| 6372 | // Easy handling of 0.0. |
| 6373 | __ xorps(dest, dest); |
| 6374 | } else { |
| 6375 | ScratchRegisterScope ensure_scratch( |
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6376 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 6377 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 6378 | __ movl(temp, Immediate(value)); |
| 6379 | __ movd(dest, temp); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6380 | } |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6381 | } else { |
| 6382 | DCHECK(destination.IsStackSlot()) << destination; |
| 6383 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 6384 | } |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6385 | } else if (constant->IsLongConstant()) { |
| 6386 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 6387 | int32_t low_value = Low32Bits(value); |
| 6388 | int32_t high_value = High32Bits(value); |
| 6389 | Immediate low(low_value); |
| 6390 | Immediate high(high_value); |
| 6391 | if (destination.IsDoubleStackSlot()) { |
| 6392 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 6393 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 6394 | } else { |
| 6395 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 6396 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 6397 | } |
| 6398 | } else { |
| 6399 | DCHECK(constant->IsDoubleConstant()); |
| 6400 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
| Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 6401 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6402 | int32_t low_value = Low32Bits(value); |
| 6403 | int32_t high_value = High32Bits(value); |
| 6404 | Immediate low(low_value); |
| 6405 | Immediate high(high_value); |
| 6406 | if (destination.IsFpuRegister()) { |
| 6407 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 6408 | if (value == 0) { |
| 6409 | // Easy handling of 0.0. |
| 6410 | __ xorpd(dest, dest); |
| 6411 | } else { |
| 6412 | __ pushl(high); |
| 6413 | __ pushl(low); |
| 6414 | __ movsd(dest, Address(ESP, 0)); |
| 6415 | __ addl(ESP, Immediate(8)); |
| 6416 | } |
| 6417 | } else { |
| 6418 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6419 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 6420 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 6421 | } |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 6422 | } |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6423 | } else { |
| Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 6424 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6425 | } |
| 6426 | } |
| 6427 | |
| Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 6428 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6429 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 6430 | ScratchRegisterScope ensure_scratch( |
| 6431 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 6432 | |
| 6433 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 6434 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 6435 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 6436 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6437 | } |
| 6438 | |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6439 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6440 | ScratchRegisterScope ensure_scratch( |
| 6441 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 6442 | |
| 6443 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 6444 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 6445 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 6446 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 6447 | __ movd(reg, temp_reg); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6448 | } |
| 6449 | |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6450 | void ParallelMoveResolverX86::Exchange128(XmmRegister reg, int mem) { |
| 6451 | size_t extra_slot = 4 * kX86WordSize; |
| 6452 | __ subl(ESP, Immediate(extra_slot)); |
| 6453 | __ movups(Address(ESP, 0), XmmRegister(reg)); |
| 6454 | ExchangeMemory(0, mem + extra_slot, 4); |
| 6455 | __ movups(XmmRegister(reg), Address(ESP, 0)); |
| 6456 | __ addl(ESP, Immediate(extra_slot)); |
| 6457 | } |
| 6458 | |
| 6459 | void ParallelMoveResolverX86::ExchangeMemory(int mem1, int mem2, int number_of_words) { |
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6460 | ScratchRegisterScope ensure_scratch1( |
| 6461 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6462 | |
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6463 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 6464 | ScratchRegisterScope ensure_scratch2( |
| 6465 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6466 | |
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6467 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 6468 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6469 | |
| 6470 | // Now that temp registers are available (possibly spilled), exchange blocks of memory. |
| 6471 | for (int i = 0; i < number_of_words; i++) { |
| 6472 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 6473 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 6474 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 6475 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
| 6476 | stack_offset += kX86WordSize; |
| 6477 | } |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6478 | } |
| 6479 | |
| 6480 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6481 | MoveOperands* move = moves_[index]; |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6482 | Location source = move->GetSource(); |
| 6483 | Location destination = move->GetDestination(); |
| 6484 | |
| 6485 | if (source.IsRegister() && destination.IsRegister()) { |
| Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 6486 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 6487 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 6488 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 6489 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 6490 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6491 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6492 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6493 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6494 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6495 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6496 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 1); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6497 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 6498 | // Use XOR Swap algorithm to avoid a temporary. |
| 6499 | DCHECK_NE(source.reg(), destination.reg()); |
| 6500 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 6501 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 6502 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 6503 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 6504 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 6505 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 6506 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6507 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 6508 | // Take advantage of the 16 bytes in the XMM register. |
| 6509 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 6510 | Address stack(ESP, destination.GetStackIndex()); |
| 6511 | // Load the double into the high doubleword. |
| 6512 | __ movhpd(reg, stack); |
| 6513 | |
| 6514 | // Store the low double into the destination. |
| 6515 | __ movsd(stack, reg); |
| 6516 | |
| 6517 | // Move the high double to the low double. |
| 6518 | __ psrldq(reg, Immediate(8)); |
| 6519 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 6520 | // Take advantage of the 16 bytes in the XMM register. |
| 6521 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 6522 | Address stack(ESP, source.GetStackIndex()); |
| 6523 | // Load the double into the high doubleword. |
| 6524 | __ movhpd(reg, stack); |
| 6525 | |
| 6526 | // Store the low double into the destination. |
| 6527 | __ movsd(stack, reg); |
| 6528 | |
| 6529 | // Move the high double to the low double. |
| 6530 | __ psrldq(reg, Immediate(8)); |
| 6531 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6532 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 2); |
| 6533 | } else if (source.IsSIMDStackSlot() && destination.IsSIMDStackSlot()) { |
| 6534 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 4); |
| 6535 | } else if (source.IsFpuRegister() && destination.IsSIMDStackSlot()) { |
| 6536 | Exchange128(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 6537 | } else if (destination.IsFpuRegister() && source.IsSIMDStackSlot()) { |
| 6538 | Exchange128(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6539 | } else { |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6540 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6541 | } |
| 6542 | } |
| 6543 | |
| 6544 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 6545 | __ pushl(static_cast<Register>(reg)); |
| 6546 | } |
| 6547 | |
| 6548 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 6549 | __ popl(static_cast<Register>(reg)); |
| Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6550 | } |
| 6551 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6552 | HLoadClass::LoadKind CodeGeneratorX86::GetSupportedLoadClassKind( |
| 6553 | HLoadClass::LoadKind desired_class_load_kind) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6554 | switch (desired_class_load_kind) { |
| Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6555 | case HLoadClass::LoadKind::kInvalid: |
| 6556 | LOG(FATAL) << "UNREACHABLE"; |
| 6557 | UNREACHABLE(); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6558 | case HLoadClass::LoadKind::kReferrersClass: |
| 6559 | break; |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6560 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6561 | case HLoadClass::LoadKind::kBootImageRelRo: |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6562 | case HLoadClass::LoadKind::kBssEntry: |
| Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6563 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6564 | break; |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6565 | case HLoadClass::LoadKind::kJitBootImageAddress: |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6566 | case HLoadClass::LoadKind::kJitTableAddress: |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6567 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6568 | break; |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6569 | case HLoadClass::LoadKind::kRuntimeCall: |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6570 | break; |
| 6571 | } |
| 6572 | return desired_class_load_kind; |
| 6573 | } |
| 6574 | |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6575 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6576 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6577 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6578 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6579 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6580 | cls, |
| 6581 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6582 | Location::RegisterLocation(EAX)); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6583 | DCHECK_EQ(calling_convention.GetRegisterAt(0), EAX); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6584 | return; |
| 6585 | } |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6586 | DCHECK(!cls->NeedsAccessCheck()); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6587 | |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6588 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 6589 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6590 | ? LocationSummary::kCallOnSlowPath |
| 6591 | : LocationSummary::kNoCall; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6592 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6593 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6594 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6595 | } |
| 6596 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6597 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6598 | load_kind == HLoadClass::LoadKind::kBootImageLinkTimePcRelative || |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6599 | load_kind == HLoadClass::LoadKind::kBootImageRelRo || |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6600 | load_kind == HLoadClass::LoadKind::kBssEntry) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6601 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6602 | } |
| 6603 | locations->SetOut(Location::RequiresRegister()); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6604 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 6605 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 6606 | // Rely on the type resolution and/or initialization to save everything. |
| Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 6607 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6608 | } else { |
| 6609 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6610 | } |
| 6611 | } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6612 | } |
| 6613 | |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6614 | Label* CodeGeneratorX86::NewJitRootClassPatch(const DexFile& dex_file, |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6615 | dex::TypeIndex type_index, |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6616 | Handle<mirror::Class> handle) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6617 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6618 | // Add a patch entry and return the label. |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6619 | jit_class_patches_.emplace_back(&dex_file, type_index.index_); |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6620 | PatchInfo<Label>* info = &jit_class_patches_.back(); |
| 6621 | return &info->label; |
| 6622 | } |
| 6623 | |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6624 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6625 | // move. |
| 6626 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6627 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6628 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6629 | codegen_->GenerateLoadClassRuntimeCall(cls); |
| Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6630 | return; |
| 6631 | } |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6632 | DCHECK(!cls->NeedsAccessCheck()); |
| Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6633 | |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6634 | LocationSummary* locations = cls->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6635 | Location out_loc = locations->Out(); |
| 6636 | Register out = out_loc.AsRegister<Register>(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6637 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6638 | bool generate_null_check = false; |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6639 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 6640 | ? kWithoutReadBarrier |
| 6641 | : kCompilerReadBarrierOption; |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6642 | switch (load_kind) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6643 | case HLoadClass::LoadKind::kReferrersClass: { |
| 6644 | DCHECK(!cls->CanCallRuntime()); |
| 6645 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 6646 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6647 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 6648 | GenerateGcRootFieldLoad( |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6649 | cls, |
| 6650 | out_loc, |
| 6651 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6652 | /* fixup_label= */ nullptr, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6653 | read_barrier_option); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6654 | break; |
| 6655 | } |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6656 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
| Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 6657 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 6658 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6659 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6660 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6661 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6662 | codegen_->RecordBootImageTypePatch(cls); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6663 | break; |
| 6664 | } |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6665 | case HLoadClass::LoadKind::kBootImageRelRo: { |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6666 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 6667 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6668 | __ movl(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6669 | codegen_->RecordBootImageRelRoPatch(cls->InputAt(0)->AsX86ComputeBaseMethodAddress(), |
| 6670 | codegen_->GetBootImageOffset(cls)); |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6671 | break; |
| 6672 | } |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6673 | case HLoadClass::LoadKind::kBssEntry: { |
| 6674 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6675 | Address address(method_address, CodeGeneratorX86::kDummy32BitOffset); |
| 6676 | Label* fixup_label = codegen_->NewTypeBssEntryPatch(cls); |
| 6677 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
| Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 6678 | // No need for memory fence, thanks to the x86 memory model. |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6679 | generate_null_check = true; |
| 6680 | break; |
| 6681 | } |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6682 | case HLoadClass::LoadKind::kJitBootImageAddress: { |
| 6683 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 6684 | uint32_t address = reinterpret_cast32<uint32_t>(cls->GetClass().Get()); |
| 6685 | DCHECK_NE(address, 0u); |
| 6686 | __ movl(out, Immediate(address)); |
| 6687 | break; |
| 6688 | } |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6689 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 6690 | Address address = Address::Absolute(CodeGeneratorX86::kDummy32BitOffset); |
| 6691 | Label* fixup_label = codegen_->NewJitRootClassPatch( |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6692 | cls->GetDexFile(), cls->GetTypeIndex(), cls->GetClass()); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6693 | // /* GcRoot<mirror::Class> */ out = *address |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6694 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6695 | break; |
| 6696 | } |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6697 | case HLoadClass::LoadKind::kRuntimeCall: |
| Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6698 | case HLoadClass::LoadKind::kInvalid: |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6699 | LOG(FATAL) << "UNREACHABLE"; |
| 6700 | UNREACHABLE(); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6701 | } |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6702 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6703 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6704 | DCHECK(cls->CanCallRuntime()); |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 6705 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86(cls, cls); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6706 | codegen_->AddSlowPath(slow_path); |
| Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6707 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6708 | if (generate_null_check) { |
| 6709 | __ testl(out, out); |
| 6710 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6711 | } |
| Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6712 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6713 | if (cls->MustGenerateClinitCheck()) { |
| 6714 | GenerateClassInitializationCheck(slow_path, out); |
| 6715 | } else { |
| 6716 | __ Bind(slow_path->GetExitLabel()); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6717 | } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6718 | } |
| 6719 | } |
| 6720 | |
| Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 6721 | void LocationsBuilderX86::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 6722 | InvokeRuntimeCallingConvention calling_convention; |
| 6723 | Location location = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 6724 | CodeGenerator::CreateLoadMethodHandleRuntimeCallLocationSummary(load, location, location); |
| 6725 | } |
| 6726 | |
| 6727 | void InstructionCodeGeneratorX86::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 6728 | codegen_->GenerateLoadMethodHandleRuntimeCall(load); |
| 6729 | } |
| 6730 | |
| Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6731 | void LocationsBuilderX86::VisitLoadMethodType(HLoadMethodType* load) { |
| 6732 | InvokeRuntimeCallingConvention calling_convention; |
| 6733 | Location location = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 6734 | CodeGenerator::CreateLoadMethodTypeRuntimeCallLocationSummary(load, location, location); |
| 6735 | } |
| 6736 | |
| 6737 | void InstructionCodeGeneratorX86::VisitLoadMethodType(HLoadMethodType* load) { |
| 6738 | codegen_->GenerateLoadMethodTypeRuntimeCall(load); |
| 6739 | } |
| 6740 | |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6741 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 6742 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6743 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6744 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6745 | if (check->HasUses()) { |
| 6746 | locations->SetOut(Location::SameAsFirstInput()); |
| 6747 | } |
| Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 6748 | // Rely on the type initialization to save everything we need. |
| 6749 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6750 | } |
| 6751 | |
| 6752 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6753 | // We assume the class to not be null. |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 6754 | SlowPathCode* slow_path = |
| 6755 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86(check->GetLoadClass(), check); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6756 | codegen_->AddSlowPath(slow_path); |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6757 | GenerateClassInitializationCheck(slow_path, |
| 6758 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6759 | } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6760 | |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6761 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6762 | SlowPathCode* slow_path, Register class_reg) { |
| Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 6763 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
| 6764 | const size_t status_byte_offset = |
| 6765 | mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte); |
| Vladimir Marko | bf12191 | 2019-06-04 13:49:05 +0100 | [diff] [blame] | 6766 | constexpr uint32_t shifted_visibly_initialized_value = |
| 6767 | enum_cast<uint32_t>(ClassStatus::kVisiblyInitialized) << (status_lsb_position % kBitsPerByte); |
| Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 6768 | |
| Vladimir Marko | bf12191 | 2019-06-04 13:49:05 +0100 | [diff] [blame] | 6769 | __ cmpb(Address(class_reg, status_byte_offset), Immediate(shifted_visibly_initialized_value)); |
| Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 6770 | __ j(kBelow, slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6771 | __ Bind(slow_path->GetExitLabel()); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6772 | } |
| 6773 | |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6774 | void InstructionCodeGeneratorX86::GenerateBitstringTypeCheckCompare(HTypeCheckInstruction* check, |
| 6775 | Register temp) { |
| 6776 | uint32_t path_to_root = check->GetBitstringPathToRoot(); |
| 6777 | uint32_t mask = check->GetBitstringMask(); |
| 6778 | DCHECK(IsPowerOfTwo(mask + 1)); |
| 6779 | size_t mask_bits = WhichPowerOf2(mask + 1); |
| 6780 | |
| 6781 | if (mask_bits == 16u) { |
| 6782 | // Compare the bitstring in memory. |
| 6783 | __ cmpw(Address(temp, mirror::Class::StatusOffset()), Immediate(path_to_root)); |
| 6784 | } else { |
| 6785 | // /* uint32_t */ temp = temp->status_ |
| 6786 | __ movl(temp, Address(temp, mirror::Class::StatusOffset())); |
| 6787 | // Compare the bitstring bits using SUB. |
| 6788 | __ subl(temp, Immediate(path_to_root)); |
| 6789 | // Shift out bits that do not contribute to the comparison. |
| 6790 | __ shll(temp, Immediate(32u - mask_bits)); |
| 6791 | } |
| 6792 | } |
| 6793 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6794 | HLoadString::LoadKind CodeGeneratorX86::GetSupportedLoadStringKind( |
| 6795 | HLoadString::LoadKind desired_string_load_kind) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6796 | switch (desired_string_load_kind) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6797 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6798 | case HLoadString::LoadKind::kBootImageRelRo: |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6799 | case HLoadString::LoadKind::kBssEntry: |
| Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6800 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6801 | break; |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6802 | case HLoadString::LoadKind::kJitBootImageAddress: |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6803 | case HLoadString::LoadKind::kJitTableAddress: |
| 6804 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6805 | break; |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6806 | case HLoadString::LoadKind::kRuntimeCall: |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6807 | break; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6808 | } |
| 6809 | return desired_string_load_kind; |
| 6810 | } |
| 6811 | |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6812 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6813 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6814 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6815 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6816 | if (load_kind == HLoadString::LoadKind::kBootImageLinkTimePcRelative || |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6817 | load_kind == HLoadString::LoadKind::kBootImageRelRo || |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6818 | load_kind == HLoadString::LoadKind::kBssEntry) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6819 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6820 | } |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6821 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
| Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6822 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 6823 | } else { |
| 6824 | locations->SetOut(Location::RequiresRegister()); |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6825 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 6826 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6827 | // Rely on the pResolveString to save everything. |
| Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 6828 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6829 | } else { |
| 6830 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6831 | } |
| 6832 | } |
| Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6833 | } |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6834 | } |
| 6835 | |
| Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6836 | Label* CodeGeneratorX86::NewJitRootStringPatch(const DexFile& dex_file, |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6837 | dex::StringIndex string_index, |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6838 | Handle<mirror::String> handle) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6839 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6840 | // Add a patch entry and return the label. |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6841 | jit_string_patches_.emplace_back(&dex_file, string_index.index_); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6842 | PatchInfo<Label>* info = &jit_string_patches_.back(); |
| 6843 | return &info->label; |
| 6844 | } |
| 6845 | |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6846 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6847 | // move. |
| 6848 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
| Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6849 | LocationSummary* locations = load->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6850 | Location out_loc = locations->Out(); |
| 6851 | Register out = out_loc.AsRegister<Register>(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6852 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6853 | switch (load->GetLoadKind()) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6854 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 6855 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 6856 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6857 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6858 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6859 | codegen_->RecordBootImageStringPatch(load); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6860 | return; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6861 | } |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6862 | case HLoadString::LoadKind::kBootImageRelRo: { |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6863 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 6864 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6865 | __ movl(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6866 | codegen_->RecordBootImageRelRoPatch(load->InputAt(0)->AsX86ComputeBaseMethodAddress(), |
| 6867 | codegen_->GetBootImageOffset(load)); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6868 | return; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6869 | } |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6870 | case HLoadString::LoadKind::kBssEntry: { |
| 6871 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6872 | Address address = Address(method_address, CodeGeneratorX86::kDummy32BitOffset); |
| 6873 | Label* fixup_label = codegen_->NewStringBssEntryPatch(load); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6874 | // /* GcRoot<mirror::String> */ out = *address /* PC-relative */ |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6875 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
| Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 6876 | // No need for memory fence, thanks to the x86 memory model. |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6877 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadStringSlowPathX86(load); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6878 | codegen_->AddSlowPath(slow_path); |
| 6879 | __ testl(out, out); |
| 6880 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6881 | __ Bind(slow_path->GetExitLabel()); |
| 6882 | return; |
| 6883 | } |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6884 | case HLoadString::LoadKind::kJitBootImageAddress: { |
| 6885 | uint32_t address = reinterpret_cast32<uint32_t>(load->GetString().Get()); |
| 6886 | DCHECK_NE(address, 0u); |
| 6887 | __ movl(out, Immediate(address)); |
| 6888 | return; |
| 6889 | } |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6890 | case HLoadString::LoadKind::kJitTableAddress: { |
| 6891 | Address address = Address::Absolute(CodeGeneratorX86::kDummy32BitOffset); |
| 6892 | Label* fixup_label = codegen_->NewJitRootStringPatch( |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6893 | load->GetDexFile(), load->GetStringIndex(), load->GetString()); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6894 | // /* GcRoot<mirror::String> */ out = *address |
| 6895 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
| 6896 | return; |
| 6897 | } |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6898 | default: |
| Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6899 | break; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6900 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6901 | |
| Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6902 | // 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] | 6903 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6904 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
| Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6905 | __ movl(calling_convention.GetRegisterAt(0), Immediate(load->GetStringIndex().index_)); |
| Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6906 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 6907 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6908 | } |
| 6909 | |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6910 | static Address GetExceptionTlsAddress() { |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6911 | return Address::Absolute(Thread::ExceptionOffset<kX86PointerSize>().Int32Value()); |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6912 | } |
| 6913 | |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6914 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 6915 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6916 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6917 | locations->SetOut(Location::RequiresRegister()); |
| 6918 | } |
| 6919 | |
| 6920 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6921 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 6922 | } |
| 6923 | |
| 6924 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6925 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6926 | } |
| 6927 | |
| 6928 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6929 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6930 | } |
| 6931 | |
| 6932 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6933 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6934 | instruction, LocationSummary::kCallOnMainOnly); |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6935 | InvokeRuntimeCallingConvention calling_convention; |
| 6936 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6937 | } |
| 6938 | |
| 6939 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6940 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6941 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6942 | } |
| 6943 | |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6944 | // Temp is used for read barrier. |
| 6945 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 6946 | if (kEmitCompilerReadBarrier && |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6947 | !kUseBakerReadBarrier && |
| 6948 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6949 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6950 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 6951 | return 1; |
| 6952 | } |
| 6953 | return 0; |
| 6954 | } |
| 6955 | |
| Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6956 | // Interface case has 2 temps, one for holding the number of interfaces, one for the current |
| 6957 | // interface pointer, the current interface is compared in memory. |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6958 | // The other checks have one temp for loading the object's class. |
| 6959 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 6960 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6961 | return 2; |
| 6962 | } |
| 6963 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6964 | } |
| 6965 | |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6966 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6967 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6968 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6969 | bool baker_read_barrier_slow_path = false; |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6970 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6971 | case TypeCheckKind::kExactCheck: |
| 6972 | case TypeCheckKind::kAbstractClassCheck: |
| 6973 | case TypeCheckKind::kClassHierarchyCheck: |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6974 | case TypeCheckKind::kArrayObjectCheck: { |
| 6975 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 6976 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 6977 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6978 | break; |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6979 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6980 | case TypeCheckKind::kArrayCheck: |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6981 | case TypeCheckKind::kUnresolvedCheck: |
| 6982 | case TypeCheckKind::kInterfaceCheck: |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6983 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6984 | break; |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6985 | case TypeCheckKind::kBitstringCheck: |
| 6986 | break; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6987 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6988 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6989 | LocationSummary* locations = |
| 6990 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6991 | if (baker_read_barrier_slow_path) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6992 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6993 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6994 | locations->SetInAt(0, Location::RequiresRegister()); |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6995 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 6996 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 6997 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 6998 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 6999 | } else { |
| 7000 | locations->SetInAt(1, Location::Any()); |
| 7001 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7002 | // Note that TypeCheckSlowPathX86 uses this "out" register too. |
| 7003 | locations->SetOut(Location::RequiresRegister()); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7004 | // When read barriers are enabled, we need a temporary register for some cases. |
| 7005 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7006 | } |
| 7007 | |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7008 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7009 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7010 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7011 | Location obj_loc = locations->InAt(0); |
| 7012 | Register obj = obj_loc.AsRegister<Register>(); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7013 | Location cls = locations->InAt(1); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7014 | Location out_loc = locations->Out(); |
| 7015 | Register out = out_loc.AsRegister<Register>(); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7016 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 7017 | DCHECK_LE(num_temps, 1u); |
| 7018 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7019 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7020 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7021 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7022 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7023 | SlowPathCode* slow_path = nullptr; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7024 | NearLabel done, zero; |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7025 | |
| 7026 | // Return 0 if `obj` is null. |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7027 | // Avoid null check if we know obj is not null. |
| 7028 | if (instruction->MustDoNullCheck()) { |
| 7029 | __ testl(obj, obj); |
| 7030 | __ j(kEqual, &zero); |
| 7031 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7032 | |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7033 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7034 | case TypeCheckKind::kExactCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7035 | ReadBarrierOption read_barrier_option = |
| 7036 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7037 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7038 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7039 | out_loc, |
| 7040 | obj_loc, |
| 7041 | class_offset, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7042 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7043 | if (cls.IsRegister()) { |
| 7044 | __ cmpl(out, cls.AsRegister<Register>()); |
| 7045 | } else { |
| 7046 | DCHECK(cls.IsStackSlot()) << cls; |
| 7047 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 7048 | } |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7049 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7050 | // Classes must be equal for the instanceof to succeed. |
| 7051 | __ j(kNotEqual, &zero); |
| 7052 | __ movl(out, Immediate(1)); |
| 7053 | __ jmp(&done); |
| 7054 | break; |
| 7055 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7056 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7057 | case TypeCheckKind::kAbstractClassCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7058 | ReadBarrierOption read_barrier_option = |
| 7059 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7060 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7061 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7062 | out_loc, |
| 7063 | obj_loc, |
| 7064 | class_offset, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7065 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7066 | // If the class is abstract, we eagerly fetch the super class of the |
| 7067 | // object to avoid doing a comparison we know will fail. |
| 7068 | NearLabel loop; |
| 7069 | __ Bind(&loop); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7070 | // /* HeapReference<Class> */ out = out->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7071 | GenerateReferenceLoadOneRegister(instruction, |
| 7072 | out_loc, |
| 7073 | super_offset, |
| 7074 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7075 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7076 | __ testl(out, out); |
| 7077 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7078 | __ j(kEqual, &done); |
| 7079 | if (cls.IsRegister()) { |
| 7080 | __ cmpl(out, cls.AsRegister<Register>()); |
| 7081 | } else { |
| 7082 | DCHECK(cls.IsStackSlot()) << cls; |
| 7083 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 7084 | } |
| 7085 | __ j(kNotEqual, &loop); |
| 7086 | __ movl(out, Immediate(1)); |
| 7087 | if (zero.IsLinked()) { |
| 7088 | __ jmp(&done); |
| 7089 | } |
| 7090 | break; |
| 7091 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7092 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7093 | case TypeCheckKind::kClassHierarchyCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7094 | ReadBarrierOption read_barrier_option = |
| 7095 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7096 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7097 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7098 | out_loc, |
| 7099 | obj_loc, |
| 7100 | class_offset, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7101 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7102 | // Walk over the class hierarchy to find a match. |
| 7103 | NearLabel loop, success; |
| 7104 | __ Bind(&loop); |
| 7105 | if (cls.IsRegister()) { |
| 7106 | __ cmpl(out, cls.AsRegister<Register>()); |
| 7107 | } else { |
| 7108 | DCHECK(cls.IsStackSlot()) << cls; |
| 7109 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 7110 | } |
| 7111 | __ j(kEqual, &success); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7112 | // /* HeapReference<Class> */ out = out->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7113 | GenerateReferenceLoadOneRegister(instruction, |
| 7114 | out_loc, |
| 7115 | super_offset, |
| 7116 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7117 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7118 | __ testl(out, out); |
| 7119 | __ j(kNotEqual, &loop); |
| 7120 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7121 | __ jmp(&done); |
| 7122 | __ Bind(&success); |
| 7123 | __ movl(out, Immediate(1)); |
| 7124 | if (zero.IsLinked()) { |
| 7125 | __ jmp(&done); |
| 7126 | } |
| 7127 | break; |
| 7128 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7129 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7130 | case TypeCheckKind::kArrayObjectCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7131 | ReadBarrierOption read_barrier_option = |
| 7132 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7133 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7134 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7135 | out_loc, |
| 7136 | obj_loc, |
| 7137 | class_offset, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7138 | read_barrier_option); |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7139 | // Do an exact check. |
| 7140 | NearLabel exact_check; |
| 7141 | if (cls.IsRegister()) { |
| 7142 | __ cmpl(out, cls.AsRegister<Register>()); |
| 7143 | } else { |
| 7144 | DCHECK(cls.IsStackSlot()) << cls; |
| 7145 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 7146 | } |
| 7147 | __ j(kEqual, &exact_check); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7148 | // 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] | 7149 | // /* HeapReference<Class> */ out = out->component_type_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7150 | GenerateReferenceLoadOneRegister(instruction, |
| 7151 | out_loc, |
| 7152 | component_offset, |
| 7153 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7154 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7155 | __ testl(out, out); |
| 7156 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7157 | __ j(kEqual, &done); |
| 7158 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 7159 | __ j(kNotEqual, &zero); |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7160 | __ Bind(&exact_check); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7161 | __ movl(out, Immediate(1)); |
| 7162 | __ jmp(&done); |
| 7163 | break; |
| 7164 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7165 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7166 | case TypeCheckKind::kArrayCheck: { |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7167 | // No read barrier since the slow path will retry upon failure. |
| 7168 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7169 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7170 | out_loc, |
| 7171 | obj_loc, |
| 7172 | class_offset, |
| 7173 | kWithoutReadBarrier); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7174 | if (cls.IsRegister()) { |
| 7175 | __ cmpl(out, cls.AsRegister<Register>()); |
| 7176 | } else { |
| 7177 | DCHECK(cls.IsStackSlot()) << cls; |
| 7178 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 7179 | } |
| 7180 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7181 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7182 | instruction, /* is_fatal= */ false); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7183 | codegen_->AddSlowPath(slow_path); |
| 7184 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 7185 | __ movl(out, Immediate(1)); |
| 7186 | if (zero.IsLinked()) { |
| 7187 | __ jmp(&done); |
| 7188 | } |
| 7189 | break; |
| 7190 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7191 | |
| Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 7192 | case TypeCheckKind::kUnresolvedCheck: |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7193 | case TypeCheckKind::kInterfaceCheck: { |
| 7194 | // 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] | 7195 | // into the slow path for the unresolved and interface check |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7196 | // cases. |
| 7197 | // |
| 7198 | // We cannot directly call the InstanceofNonTrivial runtime |
| 7199 | // entry point without resorting to a type checking slow path |
| 7200 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 7201 | // require to assign fixed registers for the inputs of this |
| 7202 | // HInstanceOf instruction (following the runtime calling |
| 7203 | // convention), which might be cluttered by the potential first |
| 7204 | // read barrier emission at the beginning of this method. |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7205 | // |
| 7206 | // TODO: Introduce a new runtime entry point taking the object |
| 7207 | // to test (instead of its class) as argument, and let it deal |
| 7208 | // with the read barrier issues. This will let us refactor this |
| 7209 | // case of the `switch` code as it was previously (with a direct |
| 7210 | // call to the runtime not using a type checking slow path). |
| 7211 | // This should also be beneficial for the other cases above. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7212 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7213 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7214 | instruction, /* is_fatal= */ false); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7215 | codegen_->AddSlowPath(slow_path); |
| 7216 | __ jmp(slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7217 | if (zero.IsLinked()) { |
| 7218 | __ jmp(&done); |
| 7219 | } |
| 7220 | break; |
| 7221 | } |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7222 | |
| 7223 | case TypeCheckKind::kBitstringCheck: { |
| 7224 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7225 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7226 | out_loc, |
| 7227 | obj_loc, |
| 7228 | class_offset, |
| 7229 | kWithoutReadBarrier); |
| 7230 | |
| 7231 | GenerateBitstringTypeCheckCompare(instruction, out); |
| 7232 | __ j(kNotEqual, &zero); |
| 7233 | __ movl(out, Immediate(1)); |
| 7234 | __ jmp(&done); |
| 7235 | break; |
| 7236 | } |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7237 | } |
| 7238 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7239 | if (zero.IsLinked()) { |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7240 | __ Bind(&zero); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7241 | __ xorl(out, out); |
| 7242 | } |
| 7243 | |
| 7244 | if (done.IsLinked()) { |
| 7245 | __ Bind(&done); |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7246 | } |
| 7247 | |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7248 | if (slow_path != nullptr) { |
| 7249 | __ Bind(slow_path->GetExitLabel()); |
| 7250 | } |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7251 | } |
| 7252 | |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7253 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7254 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7255 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7256 | LocationSummary* locations = |
| 7257 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7258 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7259 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 7260 | // Require a register for the interface check since there is a loop that compares the class to |
| 7261 | // a memory address. |
| 7262 | locations->SetInAt(1, Location::RequiresRegister()); |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7263 | } else if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 7264 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 7265 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 7266 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7267 | } else { |
| 7268 | locations->SetInAt(1, Location::Any()); |
| 7269 | } |
| Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 7270 | // 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] | 7271 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
| 7272 | } |
| 7273 | |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7274 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7275 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7276 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7277 | Location obj_loc = locations->InAt(0); |
| 7278 | Register obj = obj_loc.AsRegister<Register>(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7279 | Location cls = locations->InAt(1); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7280 | Location temp_loc = locations->GetTemp(0); |
| 7281 | Register temp = temp_loc.AsRegister<Register>(); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7282 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 7283 | DCHECK_GE(num_temps, 1u); |
| 7284 | DCHECK_LE(num_temps, 2u); |
| 7285 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 7286 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7287 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7288 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7289 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 7290 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 7291 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 7292 | const uint32_t object_array_data_offset = |
| 7293 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7294 | |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7295 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7296 | SlowPathCode* type_check_slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7297 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
| 7298 | instruction, is_type_check_slow_path_fatal); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7299 | codegen_->AddSlowPath(type_check_slow_path); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7300 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7301 | NearLabel done; |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7302 | // Avoid null check if we know obj is not null. |
| 7303 | if (instruction->MustDoNullCheck()) { |
| 7304 | __ testl(obj, obj); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7305 | __ j(kEqual, &done); |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7306 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7307 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7308 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7309 | case TypeCheckKind::kExactCheck: |
| 7310 | case TypeCheckKind::kArrayCheck: { |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7311 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7312 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7313 | temp_loc, |
| 7314 | obj_loc, |
| 7315 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7316 | kWithoutReadBarrier); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7317 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7318 | if (cls.IsRegister()) { |
| 7319 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 7320 | } else { |
| 7321 | DCHECK(cls.IsStackSlot()) << cls; |
| 7322 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 7323 | } |
| 7324 | // Jump to slow path for throwing the exception or doing a |
| 7325 | // more involved array check. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7326 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7327 | break; |
| 7328 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7329 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7330 | case TypeCheckKind::kAbstractClassCheck: { |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7331 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7332 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7333 | temp_loc, |
| 7334 | obj_loc, |
| 7335 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7336 | kWithoutReadBarrier); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7337 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7338 | // If the class is abstract, we eagerly fetch the super class of the |
| 7339 | // object to avoid doing a comparison we know will fail. |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7340 | NearLabel loop; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7341 | __ Bind(&loop); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7342 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7343 | GenerateReferenceLoadOneRegister(instruction, |
| 7344 | temp_loc, |
| 7345 | super_offset, |
| 7346 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7347 | kWithoutReadBarrier); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7348 | |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7349 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 7350 | // exception. |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7351 | __ testl(temp, temp); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7352 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7353 | |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7354 | // Otherwise, compare the classes |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7355 | if (cls.IsRegister()) { |
| 7356 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 7357 | } else { |
| 7358 | DCHECK(cls.IsStackSlot()) << cls; |
| 7359 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 7360 | } |
| 7361 | __ j(kNotEqual, &loop); |
| 7362 | break; |
| 7363 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7364 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7365 | case TypeCheckKind::kClassHierarchyCheck: { |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7366 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7367 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7368 | temp_loc, |
| 7369 | obj_loc, |
| 7370 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7371 | kWithoutReadBarrier); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7372 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7373 | // Walk over the class hierarchy to find a match. |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7374 | NearLabel loop; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7375 | __ Bind(&loop); |
| 7376 | if (cls.IsRegister()) { |
| 7377 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 7378 | } else { |
| 7379 | DCHECK(cls.IsStackSlot()) << cls; |
| 7380 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 7381 | } |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7382 | __ j(kEqual, &done); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7383 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7384 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7385 | GenerateReferenceLoadOneRegister(instruction, |
| 7386 | temp_loc, |
| 7387 | super_offset, |
| 7388 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7389 | kWithoutReadBarrier); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7390 | |
| 7391 | // If the class reference currently in `temp` is not null, jump |
| 7392 | // back at the beginning of the loop. |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7393 | __ testl(temp, temp); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7394 | __ j(kNotZero, &loop); |
| 7395 | // Otherwise, jump to the slow path to throw the exception.; |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7396 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7397 | break; |
| 7398 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7399 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7400 | case TypeCheckKind::kArrayObjectCheck: { |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7401 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7402 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7403 | temp_loc, |
| 7404 | obj_loc, |
| 7405 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7406 | kWithoutReadBarrier); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7407 | |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7408 | // Do an exact check. |
| 7409 | if (cls.IsRegister()) { |
| 7410 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 7411 | } else { |
| 7412 | DCHECK(cls.IsStackSlot()) << cls; |
| 7413 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 7414 | } |
| 7415 | __ j(kEqual, &done); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7416 | |
| 7417 | // 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] | 7418 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7419 | GenerateReferenceLoadOneRegister(instruction, |
| 7420 | temp_loc, |
| 7421 | component_offset, |
| 7422 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7423 | kWithoutReadBarrier); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7424 | |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7425 | // If the component type is null (i.e. the object not an array), jump to the slow path to |
| 7426 | // throw the exception. Otherwise proceed with the check. |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7427 | __ testl(temp, temp); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7428 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7429 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7430 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7431 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7432 | break; |
| 7433 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7434 | |
| Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 7435 | case TypeCheckKind::kUnresolvedCheck: |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7436 | // 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] | 7437 | // We cannot directly call the CheckCast runtime entry point |
| 7438 | // without resorting to a type checking slow path here (i.e. by |
| 7439 | // calling InvokeRuntime directly), as it would require to |
| 7440 | // assign fixed registers for the inputs of this HInstanceOf |
| 7441 | // instruction (following the runtime calling convention), which |
| 7442 | // might be cluttered by the potential first read barrier |
| 7443 | // emission at the beginning of this method. |
| 7444 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7445 | break; |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7446 | |
| 7447 | case TypeCheckKind::kInterfaceCheck: { |
| Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 7448 | // Fast path for the interface check. Try to avoid read barriers to improve the fast path. |
| 7449 | // We can not get false positives by doing this. |
| 7450 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7451 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7452 | temp_loc, |
| 7453 | obj_loc, |
| 7454 | class_offset, |
| 7455 | kWithoutReadBarrier); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7456 | |
| Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 7457 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 7458 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7459 | temp_loc, |
| 7460 | temp_loc, |
| 7461 | iftable_offset, |
| 7462 | kWithoutReadBarrier); |
| 7463 | // Iftable is never null. |
| 7464 | __ movl(maybe_temp2_loc.AsRegister<Register>(), Address(temp, array_length_offset)); |
| 7465 | // Maybe poison the `cls` for direct comparison with memory. |
| 7466 | __ MaybePoisonHeapReference(cls.AsRegister<Register>()); |
| 7467 | // Loop through the iftable and check if any class matches. |
| 7468 | NearLabel start_loop; |
| 7469 | __ Bind(&start_loop); |
| 7470 | // Need to subtract first to handle the empty array case. |
| 7471 | __ subl(maybe_temp2_loc.AsRegister<Register>(), Immediate(2)); |
| 7472 | __ j(kNegative, type_check_slow_path->GetEntryLabel()); |
| 7473 | // Go to next interface if the classes do not match. |
| 7474 | __ cmpl(cls.AsRegister<Register>(), |
| 7475 | CodeGeneratorX86::ArrayAddress(temp, |
| 7476 | maybe_temp2_loc, |
| 7477 | TIMES_4, |
| 7478 | object_array_data_offset)); |
| 7479 | __ j(kNotEqual, &start_loop); |
| 7480 | // If `cls` was poisoned above, unpoison it. |
| 7481 | __ MaybeUnpoisonHeapReference(cls.AsRegister<Register>()); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7482 | break; |
| 7483 | } |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7484 | |
| 7485 | case TypeCheckKind::kBitstringCheck: { |
| 7486 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7487 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7488 | temp_loc, |
| 7489 | obj_loc, |
| 7490 | class_offset, |
| 7491 | kWithoutReadBarrier); |
| 7492 | |
| 7493 | GenerateBitstringTypeCheckCompare(instruction, temp); |
| 7494 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
| 7495 | break; |
| 7496 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7497 | } |
| 7498 | __ Bind(&done); |
| 7499 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7500 | __ Bind(type_check_slow_path->GetExitLabel()); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7501 | } |
| 7502 | |
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7503 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7504 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 7505 | instruction, LocationSummary::kCallOnMainOnly); |
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7506 | InvokeRuntimeCallingConvention calling_convention; |
| 7507 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 7508 | } |
| 7509 | |
| 7510 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 7511 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject |
| 7512 | : kQuickUnlockObject, |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 7513 | instruction, |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 7514 | instruction->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7515 | if (instruction->IsEnter()) { |
| 7516 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 7517 | } else { |
| 7518 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 7519 | } |
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7520 | } |
| 7521 | |
| Shalini Salomi Bodapati | dd121f6 | 2018-10-26 15:03:53 +0530 | [diff] [blame] | 7522 | void LocationsBuilderX86::VisitX86AndNot(HX86AndNot* instruction) { |
| 7523 | DCHECK(codegen_->GetInstructionSetFeatures().HasAVX2()); |
| 7524 | DCHECK(DataType::IsIntOrLongType(instruction->GetType())) << instruction->GetType(); |
| 7525 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| 7526 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7527 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7528 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7529 | } |
| 7530 | |
| 7531 | void InstructionCodeGeneratorX86::VisitX86AndNot(HX86AndNot* instruction) { |
| 7532 | LocationSummary* locations = instruction->GetLocations(); |
| 7533 | Location first = locations->InAt(0); |
| 7534 | Location second = locations->InAt(1); |
| 7535 | Location dest = locations->Out(); |
| 7536 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
| 7537 | __ andn(dest.AsRegister<Register>(), |
| 7538 | first.AsRegister<Register>(), |
| 7539 | second.AsRegister<Register>()); |
| 7540 | } else { |
| 7541 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
| 7542 | __ andn(dest.AsRegisterPairLow<Register>(), |
| 7543 | first.AsRegisterPairLow<Register>(), |
| 7544 | second.AsRegisterPairLow<Register>()); |
| 7545 | __ andn(dest.AsRegisterPairHigh<Register>(), |
| 7546 | first.AsRegisterPairHigh<Register>(), |
| 7547 | second.AsRegisterPairHigh<Register>()); |
| 7548 | } |
| 7549 | } |
| 7550 | |
| 7551 | void LocationsBuilderX86::VisitX86MaskOrResetLeastSetBit(HX86MaskOrResetLeastSetBit* instruction) { |
| 7552 | DCHECK(codegen_->GetInstructionSetFeatures().HasAVX2()); |
| 7553 | DCHECK(instruction->GetType() == DataType::Type::kInt32) << instruction->GetType(); |
| 7554 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| 7555 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7556 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7557 | } |
| 7558 | |
| 7559 | void InstructionCodeGeneratorX86::VisitX86MaskOrResetLeastSetBit( |
| 7560 | HX86MaskOrResetLeastSetBit* instruction) { |
| 7561 | LocationSummary* locations = instruction->GetLocations(); |
| 7562 | Location src = locations->InAt(0); |
| 7563 | Location dest = locations->Out(); |
| 7564 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
| 7565 | switch (instruction->GetOpKind()) { |
| 7566 | case HInstruction::kAnd: |
| 7567 | __ blsr(dest.AsRegister<Register>(), src.AsRegister<Register>()); |
| 7568 | break; |
| 7569 | case HInstruction::kXor: |
| 7570 | __ blsmsk(dest.AsRegister<Register>(), src.AsRegister<Register>()); |
| 7571 | break; |
| 7572 | default: |
| 7573 | LOG(FATAL) << "Unreachable"; |
| 7574 | } |
| 7575 | } |
| 7576 | |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7577 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 7578 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 7579 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 7580 | |
| 7581 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 7582 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7583 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7584 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 |
| 7585 | || instruction->GetResultType() == DataType::Type::kInt64); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7586 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7587 | locations->SetInAt(1, Location::Any()); |
| 7588 | locations->SetOut(Location::SameAsFirstInput()); |
| 7589 | } |
| 7590 | |
| 7591 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 7592 | HandleBitwiseOperation(instruction); |
| 7593 | } |
| 7594 | |
| 7595 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 7596 | HandleBitwiseOperation(instruction); |
| 7597 | } |
| 7598 | |
| 7599 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 7600 | HandleBitwiseOperation(instruction); |
| 7601 | } |
| 7602 | |
| 7603 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 7604 | LocationSummary* locations = instruction->GetLocations(); |
| 7605 | Location first = locations->InAt(0); |
| 7606 | Location second = locations->InAt(1); |
| 7607 | DCHECK(first.Equals(locations->Out())); |
| 7608 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7609 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7610 | if (second.IsRegister()) { |
| 7611 | if (instruction->IsAnd()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7612 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7613 | } else if (instruction->IsOr()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7614 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7615 | } else { |
| 7616 | DCHECK(instruction->IsXor()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7617 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7618 | } |
| 7619 | } else if (second.IsConstant()) { |
| 7620 | if (instruction->IsAnd()) { |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 7621 | __ andl(first.AsRegister<Register>(), |
| 7622 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7623 | } else if (instruction->IsOr()) { |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 7624 | __ orl(first.AsRegister<Register>(), |
| 7625 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7626 | } else { |
| 7627 | DCHECK(instruction->IsXor()); |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 7628 | __ xorl(first.AsRegister<Register>(), |
| 7629 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7630 | } |
| 7631 | } else { |
| 7632 | if (instruction->IsAnd()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7633 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7634 | } else if (instruction->IsOr()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7635 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7636 | } else { |
| 7637 | DCHECK(instruction->IsXor()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7638 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7639 | } |
| 7640 | } |
| 7641 | } else { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7642 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7643 | if (second.IsRegisterPair()) { |
| 7644 | if (instruction->IsAnd()) { |
| 7645 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 7646 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 7647 | } else if (instruction->IsOr()) { |
| 7648 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 7649 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 7650 | } else { |
| 7651 | DCHECK(instruction->IsXor()); |
| 7652 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 7653 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 7654 | } |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7655 | } else if (second.IsDoubleStackSlot()) { |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7656 | if (instruction->IsAnd()) { |
| 7657 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7658 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 7659 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7660 | } else if (instruction->IsOr()) { |
| 7661 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7662 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 7663 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7664 | } else { |
| 7665 | DCHECK(instruction->IsXor()); |
| 7666 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7667 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 7668 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7669 | } |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7670 | } else { |
| 7671 | DCHECK(second.IsConstant()) << second; |
| 7672 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7673 | int32_t low_value = Low32Bits(value); |
| 7674 | int32_t high_value = High32Bits(value); |
| 7675 | Immediate low(low_value); |
| 7676 | Immediate high(high_value); |
| 7677 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 7678 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7679 | if (instruction->IsAnd()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7680 | if (low_value == 0) { |
| 7681 | __ xorl(first_low, first_low); |
| 7682 | } else if (low_value != -1) { |
| 7683 | __ andl(first_low, low); |
| 7684 | } |
| 7685 | if (high_value == 0) { |
| 7686 | __ xorl(first_high, first_high); |
| 7687 | } else if (high_value != -1) { |
| 7688 | __ andl(first_high, high); |
| 7689 | } |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7690 | } else if (instruction->IsOr()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7691 | if (low_value != 0) { |
| 7692 | __ orl(first_low, low); |
| 7693 | } |
| 7694 | if (high_value != 0) { |
| 7695 | __ orl(first_high, high); |
| 7696 | } |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7697 | } else { |
| 7698 | DCHECK(instruction->IsXor()); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7699 | if (low_value != 0) { |
| 7700 | __ xorl(first_low, low); |
| 7701 | } |
| 7702 | if (high_value != 0) { |
| 7703 | __ xorl(first_high, high); |
| 7704 | } |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7705 | } |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7706 | } |
| 7707 | } |
| 7708 | } |
| 7709 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7710 | void InstructionCodeGeneratorX86::GenerateReferenceLoadOneRegister( |
| 7711 | HInstruction* instruction, |
| 7712 | Location out, |
| 7713 | uint32_t offset, |
| 7714 | Location maybe_temp, |
| 7715 | ReadBarrierOption read_barrier_option) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7716 | Register out_reg = out.AsRegister<Register>(); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7717 | if (read_barrier_option == kWithReadBarrier) { |
| 7718 | CHECK(kEmitCompilerReadBarrier); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7719 | if (kUseBakerReadBarrier) { |
| 7720 | // Load with fast path based Baker's read barrier. |
| 7721 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7722 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7723 | instruction, out, out_reg, offset, /* needs_null_check= */ false); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7724 | } else { |
| 7725 | // Load with slow path based read barrier. |
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7726 | // Save the value of `out` into `maybe_temp` before overwriting it |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7727 | // in the following move operation, as we will need it for the |
| 7728 | // read barrier below. |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7729 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7730 | __ movl(maybe_temp.AsRegister<Register>(), out_reg); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7731 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7732 | __ movl(out_reg, Address(out_reg, offset)); |
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7733 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7734 | } |
| 7735 | } else { |
| 7736 | // Plain load with no read barrier. |
| 7737 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7738 | __ movl(out_reg, Address(out_reg, offset)); |
| 7739 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7740 | } |
| 7741 | } |
| 7742 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7743 | void InstructionCodeGeneratorX86::GenerateReferenceLoadTwoRegisters( |
| 7744 | HInstruction* instruction, |
| 7745 | Location out, |
| 7746 | Location obj, |
| 7747 | uint32_t offset, |
| 7748 | ReadBarrierOption read_barrier_option) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7749 | Register out_reg = out.AsRegister<Register>(); |
| 7750 | Register obj_reg = obj.AsRegister<Register>(); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7751 | if (read_barrier_option == kWithReadBarrier) { |
| 7752 | CHECK(kEmitCompilerReadBarrier); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7753 | if (kUseBakerReadBarrier) { |
| 7754 | // Load with fast path based Baker's read barrier. |
| 7755 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7756 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7757 | instruction, out, obj_reg, offset, /* needs_null_check= */ false); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7758 | } else { |
| 7759 | // Load with slow path based read barrier. |
| 7760 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7761 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7762 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 7763 | } |
| 7764 | } else { |
| 7765 | // Plain load with no read barrier. |
| 7766 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7767 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7768 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7769 | } |
| 7770 | } |
| 7771 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7772 | void InstructionCodeGeneratorX86::GenerateGcRootFieldLoad( |
| 7773 | HInstruction* instruction, |
| 7774 | Location root, |
| 7775 | const Address& address, |
| 7776 | Label* fixup_label, |
| 7777 | ReadBarrierOption read_barrier_option) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7778 | Register root_reg = root.AsRegister<Register>(); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7779 | if (read_barrier_option == kWithReadBarrier) { |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7780 | DCHECK(kEmitCompilerReadBarrier); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7781 | if (kUseBakerReadBarrier) { |
| 7782 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 7783 | // Baker's read barrier are used: |
| 7784 | // |
| Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7785 | // root = obj.field; |
| 7786 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 7787 | // if (temp != null) { |
| 7788 | // root = temp(root) |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7789 | // } |
| 7790 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7791 | // /* GcRoot<mirror::Object> */ root = *address |
| 7792 | __ movl(root_reg, address); |
| 7793 | if (fixup_label != nullptr) { |
| 7794 | __ Bind(fixup_label); |
| 7795 | } |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7796 | static_assert( |
| 7797 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 7798 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 7799 | "have different sizes."); |
| 7800 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 7801 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 7802 | "have different sizes."); |
| 7803 | |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7804 | // Slow path marking the GC root `root`. |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7805 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathX86( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7806 | instruction, root, /* unpoison_ref_before_marking= */ false); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7807 | codegen_->AddSlowPath(slow_path); |
| 7808 | |
| Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7809 | // Test the entrypoint (`Thread::Current()->pReadBarrierMarkReg ## root.reg()`). |
| 7810 | const int32_t entry_point_offset = |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 7811 | Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(root.reg()); |
| Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7812 | __ fs()->cmpl(Address::Absolute(entry_point_offset), Immediate(0)); |
| 7813 | // The entrypoint is null when the GC is not marking. |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7814 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 7815 | __ Bind(slow_path->GetExitLabel()); |
| 7816 | } else { |
| 7817 | // GC root loaded through a slow path for read barriers other |
| 7818 | // than Baker's. |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7819 | // /* GcRoot<mirror::Object>* */ root = address |
| 7820 | __ leal(root_reg, address); |
| 7821 | if (fixup_label != nullptr) { |
| 7822 | __ Bind(fixup_label); |
| 7823 | } |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7824 | // /* mirror::Object* */ root = root->Read() |
| 7825 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 7826 | } |
| 7827 | } else { |
| 7828 | // Plain GC root load with no read barrier. |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7829 | // /* GcRoot<mirror::Object> */ root = *address |
| 7830 | __ movl(root_reg, address); |
| 7831 | if (fixup_label != nullptr) { |
| 7832 | __ Bind(fixup_label); |
| 7833 | } |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7834 | // Note that GC roots are not affected by heap poisoning, thus we |
| 7835 | // do not have to unpoison `root_reg` here. |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7836 | } |
| 7837 | } |
| 7838 | |
| 7839 | void CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7840 | Location ref, |
| 7841 | Register obj, |
| 7842 | uint32_t offset, |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7843 | bool needs_null_check) { |
| 7844 | DCHECK(kEmitCompilerReadBarrier); |
| 7845 | DCHECK(kUseBakerReadBarrier); |
| 7846 | |
| 7847 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7848 | Address src(obj, offset); |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7849 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7850 | } |
| 7851 | |
| 7852 | void CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7853 | Location ref, |
| 7854 | Register obj, |
| 7855 | uint32_t data_offset, |
| 7856 | Location index, |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7857 | bool needs_null_check) { |
| 7858 | DCHECK(kEmitCompilerReadBarrier); |
| 7859 | DCHECK(kUseBakerReadBarrier); |
| 7860 | |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 7861 | static_assert( |
| 7862 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 7863 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7864 | // /* HeapReference<Object> */ ref = |
| 7865 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7866 | Address src = CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset); |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7867 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7868 | } |
| 7869 | |
| 7870 | void CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7871 | Location ref, |
| 7872 | Register obj, |
| 7873 | const Address& src, |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7874 | bool needs_null_check, |
| 7875 | bool always_update_field, |
| 7876 | Register* temp) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7877 | DCHECK(kEmitCompilerReadBarrier); |
| 7878 | DCHECK(kUseBakerReadBarrier); |
| 7879 | |
| 7880 | // In slow path based read barriers, the read barrier call is |
| 7881 | // inserted after the original load. However, in fast path based |
| 7882 | // Baker's read barriers, we need to perform the load of |
| 7883 | // mirror::Object::monitor_ *before* the original reference load. |
| 7884 | // This load-load ordering is required by the read barrier. |
| 7885 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 7886 | // |
| 7887 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7888 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7889 | // HeapReference<Object> ref = *src; // Original reference load. |
| Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7890 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7891 | // if (is_gray) { |
| 7892 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 7893 | // } |
| 7894 | // |
| 7895 | // Note: the original implementation in ReadBarrier::Barrier is |
| 7896 | // slightly more complex as: |
| 7897 | // - it implements the load-load fence using a data dependency on |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7898 | // the high-bits of rb_state, which are expected to be all zeroes |
| 7899 | // (we use CodeGeneratorX86::GenerateMemoryBarrier instead here, |
| 7900 | // which is a no-op thanks to the x86 memory model); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7901 | // - it performs additional checks that we do not do here for |
| 7902 | // performance reasons. |
| 7903 | |
| 7904 | Register ref_reg = ref.AsRegister<Register>(); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7905 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 7906 | |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7907 | // 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] | 7908 | static_assert(ReadBarrier::NonGrayState() == 0, "Expecting non-gray to have value 0"); |
| Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7909 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7910 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 7911 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 7912 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 7913 | |
| Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7914 | // if (rb_state == ReadBarrier::GrayState()) |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7915 | // ref = ReadBarrier::Mark(ref); |
| 7916 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 7917 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7918 | if (needs_null_check) { |
| 7919 | MaybeRecordImplicitNullCheck(instruction); |
| 7920 | } |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7921 | |
| 7922 | // Load fence to prevent load-load reordering. |
| 7923 | // Note that this is a no-op, thanks to the x86 memory model. |
| 7924 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 7925 | |
| 7926 | // The actual reference load. |
| 7927 | // /* HeapReference<Object> */ ref = *src |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7928 | __ movl(ref_reg, src); // Flags are unaffected. |
| 7929 | |
| 7930 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 7931 | // Slow path marking the object `ref` when it is gray. |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7932 | SlowPathCode* slow_path; |
| 7933 | if (always_update_field) { |
| 7934 | DCHECK(temp != nullptr); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7935 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkAndUpdateFieldSlowPathX86( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7936 | instruction, ref, obj, src, /* unpoison_ref_before_marking= */ true, *temp); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7937 | } else { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7938 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkSlowPathX86( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7939 | instruction, ref, /* unpoison_ref_before_marking= */ true); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7940 | } |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7941 | AddSlowPath(slow_path); |
| 7942 | |
| 7943 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 7944 | __ j(kNotZero, slow_path->GetEntryLabel()); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7945 | |
| 7946 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7947 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7948 | |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7949 | __ Bind(slow_path->GetExitLabel()); |
| 7950 | } |
| 7951 | |
| 7952 | void CodeGeneratorX86::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7953 | Location out, |
| 7954 | Location ref, |
| 7955 | Location obj, |
| 7956 | uint32_t offset, |
| 7957 | Location index) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7958 | DCHECK(kEmitCompilerReadBarrier); |
| 7959 | |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7960 | // Insert a slow path based read barrier *after* the reference load. |
| 7961 | // |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7962 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7963 | // reference will be carried out by the runtime within the slow |
| 7964 | // path. |
| 7965 | // |
| 7966 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7967 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7968 | // not used by the artReadBarrierSlow entry point. |
| 7969 | // |
| 7970 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7971 | SlowPathCode* slow_path = new (GetScopedAllocator()) |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7972 | ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); |
| 7973 | AddSlowPath(slow_path); |
| 7974 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7975 | __ jmp(slow_path->GetEntryLabel()); |
| 7976 | __ Bind(slow_path->GetExitLabel()); |
| 7977 | } |
| 7978 | |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7979 | void CodeGeneratorX86::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 7980 | Location out, |
| 7981 | Location ref, |
| 7982 | Location obj, |
| 7983 | uint32_t offset, |
| 7984 | Location index) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7985 | if (kEmitCompilerReadBarrier) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7986 | // Baker's read barriers shall be handled by the fast path |
| 7987 | // (CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier). |
| 7988 | DCHECK(!kUseBakerReadBarrier); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7989 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7990 | // by the runtime within the slow path. |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7991 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7992 | } else if (kPoisonHeapReferences) { |
| 7993 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 7994 | } |
| 7995 | } |
| 7996 | |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7997 | void CodeGeneratorX86::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7998 | Location out, |
| 7999 | Location root) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8000 | DCHECK(kEmitCompilerReadBarrier); |
| 8001 | |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8002 | // Insert a slow path based read barrier *after* the GC root load. |
| 8003 | // |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8004 | // Note that GC roots are not affected by heap poisoning, so we do |
| 8005 | // not need to do anything special for this here. |
| 8006 | SlowPathCode* slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8007 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathX86(instruction, out, root); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8008 | AddSlowPath(slow_path); |
| 8009 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8010 | __ jmp(slow_path->GetEntryLabel()); |
| 8011 | __ Bind(slow_path->GetExitLabel()); |
| 8012 | } |
| 8013 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 8014 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8015 | // Nothing to do, this should be removed during prepare for register allocator. |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8016 | LOG(FATAL) << "Unreachable"; |
| 8017 | } |
| 8018 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 8019 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8020 | // Nothing to do, this should be removed during prepare for register allocator. |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8021 | LOG(FATAL) << "Unreachable"; |
| 8022 | } |
| 8023 | |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8024 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 8025 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 8026 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8027 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8028 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8029 | } |
| 8030 | |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8031 | void InstructionCodeGeneratorX86::GenPackedSwitchWithCompares(Register value_reg, |
| 8032 | int32_t lower_bound, |
| 8033 | uint32_t num_entries, |
| 8034 | HBasicBlock* switch_block, |
| 8035 | HBasicBlock* default_block) { |
| 8036 | // Figure out the correct compare values and jump conditions. |
| 8037 | // Handle the first compare/branch as a special case because it might |
| 8038 | // jump to the default case. |
| 8039 | DCHECK_GT(num_entries, 2u); |
| 8040 | Condition first_condition; |
| 8041 | uint32_t index; |
| 8042 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 8043 | if (lower_bound != 0) { |
| 8044 | first_condition = kLess; |
| 8045 | __ cmpl(value_reg, Immediate(lower_bound)); |
| 8046 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 8047 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8048 | |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8049 | index = 1; |
| 8050 | } else { |
| 8051 | // Handle all the compare/jumps below. |
| 8052 | first_condition = kBelow; |
| 8053 | index = 0; |
| 8054 | } |
| 8055 | |
| 8056 | // Handle the rest of the compare/jumps. |
| 8057 | for (; index + 1 < num_entries; index += 2) { |
| 8058 | int32_t compare_to_value = lower_bound + index + 1; |
| 8059 | __ cmpl(value_reg, Immediate(compare_to_value)); |
| 8060 | // Jump to successors[index] if value < case_value[index]. |
| 8061 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 8062 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 8063 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 8064 | } |
| 8065 | |
| 8066 | if (index != num_entries) { |
| 8067 | // There are an odd number of entries. Handle the last one. |
| 8068 | DCHECK_EQ(index + 1, num_entries); |
| 8069 | __ cmpl(value_reg, Immediate(lower_bound + index)); |
| 8070 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8071 | } |
| 8072 | |
| 8073 | // And the default for any other value. |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8074 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
| 8075 | __ jmp(codegen_->GetLabelOf(default_block)); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8076 | } |
| 8077 | } |
| 8078 | |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8079 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 8080 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 8081 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 8082 | LocationSummary* locations = switch_instr->GetLocations(); |
| 8083 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 8084 | |
| 8085 | GenPackedSwitchWithCompares(value_reg, |
| 8086 | lower_bound, |
| 8087 | num_entries, |
| 8088 | switch_instr->GetBlock(), |
| 8089 | switch_instr->GetDefaultBlock()); |
| 8090 | } |
| 8091 | |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8092 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 8093 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8094 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8095 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8096 | |
| 8097 | // Constant area pointer. |
| 8098 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8099 | |
| 8100 | // And the temporary we need. |
| 8101 | locations->AddTemp(Location::RequiresRegister()); |
| 8102 | } |
| 8103 | |
| 8104 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 8105 | int32_t lower_bound = switch_instr->GetStartValue(); |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8106 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8107 | LocationSummary* locations = switch_instr->GetLocations(); |
| 8108 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 8109 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 8110 | |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8111 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 8112 | GenPackedSwitchWithCompares(value_reg, |
| 8113 | lower_bound, |
| 8114 | num_entries, |
| 8115 | switch_instr->GetBlock(), |
| 8116 | default_block); |
| 8117 | return; |
| 8118 | } |
| 8119 | |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8120 | // Optimizing has a jump area. |
| 8121 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 8122 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 8123 | |
| 8124 | // Remove the bias, if needed. |
| 8125 | if (lower_bound != 0) { |
| 8126 | __ leal(temp_reg, Address(value_reg, -lower_bound)); |
| 8127 | value_reg = temp_reg; |
| 8128 | } |
| 8129 | |
| 8130 | // Is the value in range? |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8131 | DCHECK_GE(num_entries, 1u); |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8132 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 8133 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| 8134 | |
| 8135 | // We are in the range of the table. |
| 8136 | // Load (target-constant_area) from the jump table, indexing by the value. |
| 8137 | __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); |
| 8138 | |
| 8139 | // Compute the actual target address by adding in constant_area. |
| 8140 | __ addl(temp_reg, constant_area); |
| 8141 | |
| 8142 | // And jump. |
| 8143 | __ jmp(temp_reg); |
| 8144 | } |
| 8145 | |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8146 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 8147 | HX86ComputeBaseMethodAddress* insn) { |
| 8148 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8149 | new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8150 | locations->SetOut(Location::RequiresRegister()); |
| 8151 | } |
| 8152 | |
| 8153 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 8154 | HX86ComputeBaseMethodAddress* insn) { |
| 8155 | LocationSummary* locations = insn->GetLocations(); |
| 8156 | Register reg = locations->Out().AsRegister<Register>(); |
| 8157 | |
| 8158 | // Generate call to next instruction. |
| 8159 | Label next_instruction; |
| 8160 | __ call(&next_instruction); |
| 8161 | __ Bind(&next_instruction); |
| 8162 | |
| 8163 | // Remember this offset for later use with constant area. |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8164 | codegen_->AddMethodAddressOffset(insn, GetAssembler()->CodeSize()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8165 | |
| 8166 | // Grab the return address off the stack. |
| 8167 | __ popl(reg); |
| 8168 | } |
| 8169 | |
| 8170 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 8171 | HX86LoadFromConstantTable* insn) { |
| 8172 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8173 | new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8174 | |
| 8175 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8176 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 8177 | |
| 8178 | // 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] | 8179 | if (insn->IsEmittedAtUseSite()) { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8180 | return; |
| 8181 | } |
| 8182 | |
| 8183 | switch (insn->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8184 | case DataType::Type::kFloat32: |
| 8185 | case DataType::Type::kFloat64: |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8186 | locations->SetOut(Location::RequiresFpuRegister()); |
| 8187 | break; |
| 8188 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8189 | case DataType::Type::kInt32: |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8190 | locations->SetOut(Location::RequiresRegister()); |
| 8191 | break; |
| 8192 | |
| 8193 | default: |
| 8194 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 8195 | } |
| 8196 | } |
| 8197 | |
| 8198 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 8199 | if (insn->IsEmittedAtUseSite()) { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8200 | return; |
| 8201 | } |
| 8202 | |
| 8203 | LocationSummary* locations = insn->GetLocations(); |
| 8204 | Location out = locations->Out(); |
| 8205 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 8206 | HConstant *value = insn->GetConstant(); |
| 8207 | |
| 8208 | switch (insn->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8209 | case DataType::Type::kFloat32: |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8210 | __ movss(out.AsFpuRegister<XmmRegister>(), |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8211 | codegen_->LiteralFloatAddress( |
| 8212 | value->AsFloatConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8213 | break; |
| 8214 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8215 | case DataType::Type::kFloat64: |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8216 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8217 | codegen_->LiteralDoubleAddress( |
| 8218 | value->AsDoubleConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8219 | break; |
| 8220 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8221 | case DataType::Type::kInt32: |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8222 | __ movl(out.AsRegister<Register>(), |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8223 | codegen_->LiteralInt32Address( |
| 8224 | value->AsIntConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8225 | break; |
| 8226 | |
| 8227 | default: |
| 8228 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 8229 | } |
| 8230 | } |
| 8231 | |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8232 | /** |
| 8233 | * Class to handle late fixup of offsets into constant area. |
| 8234 | */ |
| Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 8235 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8236 | public: |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8237 | RIPFixup(CodeGeneratorX86& codegen, |
| 8238 | HX86ComputeBaseMethodAddress* base_method_address, |
| 8239 | size_t offset) |
| 8240 | : codegen_(&codegen), |
| 8241 | base_method_address_(base_method_address), |
| 8242 | offset_into_constant_area_(offset) {} |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8243 | |
| 8244 | protected: |
| 8245 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 8246 | |
| 8247 | CodeGeneratorX86* codegen_; |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8248 | HX86ComputeBaseMethodAddress* base_method_address_; |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8249 | |
| 8250 | private: |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8251 | void Process(const MemoryRegion& region, int pos) override { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8252 | // Patch the correct offset for the instruction. The place to patch is the |
| 8253 | // last 4 bytes of the instruction. |
| 8254 | // The value to patch is the distance from the offset in the constant area |
| 8255 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8256 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8257 | int32_t relative_position = |
| 8258 | constant_offset - codegen_->GetMethodAddressOffset(base_method_address_); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8259 | |
| 8260 | // Patch in the right value. |
| 8261 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 8262 | } |
| 8263 | |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8264 | // Location in constant area that the fixup refers to. |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8265 | int32_t offset_into_constant_area_; |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8266 | }; |
| 8267 | |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8268 | /** |
| 8269 | * Class to handle late fixup of offsets to a jump table that will be created in the |
| 8270 | * constant area. |
| 8271 | */ |
| 8272 | class JumpTableRIPFixup : public RIPFixup { |
| 8273 | public: |
| 8274 | JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8275 | : RIPFixup(codegen, switch_instr->GetBaseMethodAddress(), static_cast<size_t>(-1)), |
| 8276 | switch_instr_(switch_instr) {} |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8277 | |
| 8278 | void CreateJumpTable() { |
| 8279 | X86Assembler* assembler = codegen_->GetAssembler(); |
| 8280 | |
| 8281 | // Ensure that the reference to the jump table has the correct offset. |
| 8282 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 8283 | SetOffset(offset_in_constant_table); |
| 8284 | |
| 8285 | // The label values in the jump table are computed relative to the |
| 8286 | // instruction addressing the constant area. |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8287 | const int32_t relative_offset = codegen_->GetMethodAddressOffset(base_method_address_); |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8288 | |
| 8289 | // Populate the jump table with the correct values for the jump table. |
| 8290 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 8291 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 8292 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 8293 | // The value that we want is the target offset - the position of the table. |
| 8294 | for (int32_t i = 0; i < num_entries; i++) { |
| 8295 | HBasicBlock* b = successors[i]; |
| 8296 | Label* l = codegen_->GetLabelOf(b); |
| 8297 | DCHECK(l->IsBound()); |
| 8298 | int32_t offset_to_block = l->Position() - relative_offset; |
| 8299 | assembler->AppendInt32(offset_to_block); |
| 8300 | } |
| 8301 | } |
| 8302 | |
| 8303 | private: |
| 8304 | const HX86PackedSwitch* switch_instr_; |
| 8305 | }; |
| 8306 | |
| 8307 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 8308 | // Generate the constant area if needed. |
| 8309 | X86Assembler* assembler = GetAssembler(); |
| jaishank | 20d1c94 | 2019-03-08 15:08:17 +0530 | [diff] [blame] | 8310 | |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8311 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 8312 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 8313 | // byte values. |
| 8314 | assembler->Align(4, 0); |
| 8315 | constant_area_start_ = assembler->CodeSize(); |
| 8316 | |
| 8317 | // Populate any jump tables. |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 8318 | for (JumpTableRIPFixup* jump_table : fixups_to_jump_tables_) { |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8319 | jump_table->CreateJumpTable(); |
| 8320 | } |
| 8321 | |
| 8322 | // And now add the constant area to the generated code. |
| 8323 | assembler->AddConstantArea(); |
| 8324 | } |
| 8325 | |
| 8326 | // And finish up. |
| 8327 | CodeGenerator::Finalize(allocator); |
| 8328 | } |
| 8329 | |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8330 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, |
| 8331 | HX86ComputeBaseMethodAddress* method_base, |
| 8332 | Register reg) { |
| 8333 | AssemblerFixup* fixup = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8334 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddDouble(v)); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8335 | return Address(reg, kDummy32BitOffset, fixup); |
| 8336 | } |
| 8337 | |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8338 | Address CodeGeneratorX86::LiteralFloatAddress(float v, |
| 8339 | HX86ComputeBaseMethodAddress* method_base, |
| 8340 | Register reg) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8341 | AssemblerFixup* fixup = |
| 8342 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddFloat(v)); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8343 | return Address(reg, kDummy32BitOffset, fixup); |
| 8344 | } |
| 8345 | |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8346 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, |
| 8347 | HX86ComputeBaseMethodAddress* method_base, |
| 8348 | Register reg) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8349 | AssemblerFixup* fixup = |
| 8350 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddInt32(v)); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8351 | return Address(reg, kDummy32BitOffset, fixup); |
| 8352 | } |
| 8353 | |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8354 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, |
| 8355 | HX86ComputeBaseMethodAddress* method_base, |
| 8356 | Register reg) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8357 | AssemblerFixup* fixup = |
| 8358 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddInt64(v)); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8359 | return Address(reg, kDummy32BitOffset, fixup); |
| 8360 | } |
| 8361 | |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 8362 | void CodeGeneratorX86::Load32BitValue(Register dest, int32_t value) { |
| 8363 | if (value == 0) { |
| 8364 | __ xorl(dest, dest); |
| 8365 | } else { |
| 8366 | __ movl(dest, Immediate(value)); |
| 8367 | } |
| 8368 | } |
| 8369 | |
| 8370 | void CodeGeneratorX86::Compare32BitValue(Register dest, int32_t value) { |
| 8371 | if (value == 0) { |
| 8372 | __ testl(dest, dest); |
| 8373 | } else { |
| 8374 | __ cmpl(dest, Immediate(value)); |
| 8375 | } |
| 8376 | } |
| 8377 | |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8378 | void CodeGeneratorX86::GenerateIntCompare(Location lhs, Location rhs) { |
| 8379 | Register lhs_reg = lhs.AsRegister<Register>(); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8380 | GenerateIntCompare(lhs_reg, rhs); |
| 8381 | } |
| 8382 | |
| 8383 | void CodeGeneratorX86::GenerateIntCompare(Register lhs, Location rhs) { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8384 | if (rhs.IsConstant()) { |
| 8385 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8386 | Compare32BitValue(lhs, value); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8387 | } else if (rhs.IsStackSlot()) { |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8388 | __ cmpl(lhs, Address(ESP, rhs.GetStackIndex())); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8389 | } else { |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8390 | __ cmpl(lhs, rhs.AsRegister<Register>()); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8391 | } |
| 8392 | } |
| 8393 | |
| 8394 | Address CodeGeneratorX86::ArrayAddress(Register obj, |
| 8395 | Location index, |
| 8396 | ScaleFactor scale, |
| 8397 | uint32_t data_offset) { |
| 8398 | return index.IsConstant() ? |
| 8399 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) : |
| 8400 | Address(obj, index.AsRegister<Register>(), scale, data_offset); |
| 8401 | } |
| 8402 | |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8403 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, |
| 8404 | Register reg, |
| 8405 | Register value) { |
| 8406 | // Create a fixup to be used to create and address the jump table. |
| 8407 | JumpTableRIPFixup* table_fixup = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8408 | new (GetGraph()->GetAllocator()) JumpTableRIPFixup(*this, switch_instr); |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8409 | |
| 8410 | // We have to populate the jump tables. |
| 8411 | fixups_to_jump_tables_.push_back(table_fixup); |
| 8412 | |
| 8413 | // We want a scaled address, as we are extracting the correct offset from the table. |
| 8414 | return Address(reg, value, TIMES_4, kDummy32BitOffset, table_fixup); |
| 8415 | } |
| 8416 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8417 | // TODO: target as memory. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8418 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, DataType::Type type) { |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8419 | if (!target.IsValid()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8420 | DCHECK_EQ(type, DataType::Type::kVoid); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8421 | return; |
| 8422 | } |
| 8423 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8424 | DCHECK_NE(type, DataType::Type::kVoid); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8425 | |
| 8426 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 8427 | if (target.Equals(return_loc)) { |
| 8428 | return; |
| 8429 | } |
| 8430 | |
| 8431 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 8432 | // with the else branch. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8433 | if (type == DataType::Type::kInt64) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8434 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8435 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), DataType::Type::kInt32, nullptr); |
| 8436 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), DataType::Type::kInt32, nullptr); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8437 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 8438 | } else { |
| 8439 | // Let the parallel move resolver take care of all of this. |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8440 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8441 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 8442 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 8443 | } |
| 8444 | } |
| 8445 | |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8446 | void CodeGeneratorX86::PatchJitRootUse(uint8_t* code, |
| 8447 | const uint8_t* roots_data, |
| 8448 | const PatchInfo<Label>& info, |
| 8449 | uint64_t index_in_table) const { |
| 8450 | uint32_t code_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 8451 | uintptr_t address = |
| 8452 | 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] | 8453 | using unaligned_uint32_t __attribute__((__aligned__(1))) = uint32_t; |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8454 | reinterpret_cast<unaligned_uint32_t*>(code + code_offset)[0] = |
| 8455 | dchecked_integral_cast<uint32_t>(address); |
| 8456 | } |
| 8457 | |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 8458 | void CodeGeneratorX86::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 8459 | for (const PatchInfo<Label>& info : jit_string_patches_) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8460 | 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] | 8461 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 8462 | PatchJitRootUse(code, roots_data, info, index_in_table); |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8463 | } |
| 8464 | |
| 8465 | for (const PatchInfo<Label>& info : jit_class_patches_) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8466 | 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] | 8467 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 8468 | PatchJitRootUse(code, roots_data, info, index_in_table); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 8469 | } |
| 8470 | } |
| 8471 | |
| xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 8472 | void LocationsBuilderX86::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 8473 | ATTRIBUTE_UNUSED) { |
| 8474 | LOG(FATAL) << "Unreachable"; |
| 8475 | } |
| 8476 | |
| 8477 | void InstructionCodeGeneratorX86::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 8478 | ATTRIBUTE_UNUSED) { |
| 8479 | LOG(FATAL) << "Unreachable"; |
| 8480 | } |
| 8481 | |
| Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 8482 | bool LocationsBuilderX86::CpuHasAvxFeatureFlag() { |
| 8483 | return codegen_->GetInstructionSetFeatures().HasAVX(); |
| 8484 | } |
| 8485 | bool LocationsBuilderX86::CpuHasAvx2FeatureFlag() { |
| 8486 | return codegen_->GetInstructionSetFeatures().HasAVX2(); |
| 8487 | } |
| 8488 | bool InstructionCodeGeneratorX86::CpuHasAvxFeatureFlag() { |
| 8489 | return codegen_->GetInstructionSetFeatures().HasAVX(); |
| 8490 | } |
| 8491 | bool InstructionCodeGeneratorX86::CpuHasAvx2FeatureFlag() { |
| 8492 | return codegen_->GetInstructionSetFeatures().HasAVX2(); |
| 8493 | } |
| 8494 | |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 8495 | #undef __ |
| 8496 | |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 8497 | } // namespace x86 |
| 8498 | } // namespace art |