| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "code_generator_x86.h" |
| Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 18 | |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 19 | #include "art_method-inl.h" |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 20 | #include "class_table.h" |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 21 | #include "code_generator_utils.h" |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 22 | #include "compiled_method.h" |
| Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 23 | #include "entrypoints/quick/quick_entrypoints.h" |
| Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 24 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
| Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 25 | #include "gc/accounting/card_table.h" |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 26 | #include "gc/space/image_space.h" |
| Andreas Gampe | 09659c2 | 2017-09-18 18:23:32 -0700 | [diff] [blame] | 27 | #include "heap_poisoning.h" |
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 28 | #include "intrinsics.h" |
| 29 | #include "intrinsics_x86.h" |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 30 | #include "jit/profiling_info.h" |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 31 | #include "linker/linker_patch.h" |
| Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 32 | #include "lock_word.h" |
| Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 33 | #include "mirror/array-inl.h" |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 34 | #include "mirror/class-inl.h" |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 35 | #include "scoped_thread_state_change-inl.h" |
| Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 36 | #include "thread.h" |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 37 | #include "utils/assembler.h" |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 38 | #include "utils/stack_checks.h" |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 39 | #include "utils/x86/assembler_x86.h" |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 40 | #include "utils/x86/managed_register_x86.h" |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 41 | |
| Vladimir Marko | 0a51605 | 2019-10-14 13:00:44 +0000 | [diff] [blame] | 42 | namespace art { |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 43 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 44 | template<class MirrorType> |
| 45 | class GcRoot; |
| 46 | |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 47 | namespace x86 { |
| 48 | |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 49 | static constexpr int kCurrentMethodStackOffset = 0; |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 50 | static constexpr Register kMethodRegisterArgument = EAX; |
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 51 | static constexpr Register kCoreCalleeSaves[] = { EBP, ESI, EDI }; |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 52 | |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 53 | static constexpr int kC2ConditionMask = 0x400; |
| 54 | |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 55 | static constexpr int kFakeReturnRegister = Register(8); |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 56 | |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 57 | static constexpr int64_t kDoubleNaN = INT64_C(0x7FF8000000000000); |
| 58 | static constexpr int32_t kFloatNaN = INT32_C(0x7FC00000); |
| 59 | |
| Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 60 | static RegisterSet OneRegInReferenceOutSaveEverythingCallerSaves() { |
| 61 | InvokeRuntimeCallingConvention calling_convention; |
| 62 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 63 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 64 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 65 | // that the the kPrimNot result register is the same as the first argument register. |
| 66 | return caller_saves; |
| 67 | } |
| 68 | |
| Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 69 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 70 | #define __ down_cast<X86Assembler*>(codegen->GetAssembler())-> // NOLINT |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 71 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86PointerSize, x).Int32Value() |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 72 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 73 | class NullCheckSlowPathX86 : public SlowPathCode { |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 74 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 75 | explicit NullCheckSlowPathX86(HNullCheck* instruction) : SlowPathCode(instruction) {} |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 76 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 77 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 78 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 79 | __ Bind(GetEntryLabel()); |
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 80 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 81 | // Live registers will be restored in the catch block if caught. |
| 82 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 83 | } |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 84 | x86_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 85 | instruction_, |
| 86 | instruction_->GetDexPc(), |
| 87 | this); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 88 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 89 | } |
| 90 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 91 | bool IsFatal() const override { return true; } |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 92 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 93 | const char* GetDescription() const override { return "NullCheckSlowPathX86"; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 94 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 95 | private: |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 96 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86); |
| 97 | }; |
| 98 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 99 | class DivZeroCheckSlowPathX86 : public SlowPathCode { |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 100 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 101 | explicit DivZeroCheckSlowPathX86(HDivZeroCheck* instruction) : SlowPathCode(instruction) {} |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 102 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 103 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 104 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 105 | __ Bind(GetEntryLabel()); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 106 | x86_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 107 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 108 | } |
| 109 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 110 | bool IsFatal() const override { return true; } |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 111 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 112 | const char* GetDescription() const override { return "DivZeroCheckSlowPathX86"; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 113 | |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 114 | private: |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 115 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86); |
| 116 | }; |
| 117 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 118 | class DivRemMinusOneSlowPathX86 : public SlowPathCode { |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 119 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 120 | DivRemMinusOneSlowPathX86(HInstruction* instruction, Register reg, bool is_div) |
| 121 | : SlowPathCode(instruction), reg_(reg), is_div_(is_div) {} |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 122 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 123 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 124 | __ Bind(GetEntryLabel()); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 125 | if (is_div_) { |
| 126 | __ negl(reg_); |
| 127 | } else { |
| 128 | __ movl(reg_, Immediate(0)); |
| 129 | } |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 130 | __ jmp(GetExitLabel()); |
| 131 | } |
| 132 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 133 | const char* GetDescription() const override { return "DivRemMinusOneSlowPathX86"; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 134 | |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 135 | private: |
| 136 | Register reg_; |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 137 | bool is_div_; |
| 138 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 139 | }; |
| 140 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 141 | class BoundsCheckSlowPathX86 : public SlowPathCode { |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 142 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 143 | explicit BoundsCheckSlowPathX86(HBoundsCheck* instruction) : SlowPathCode(instruction) {} |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 144 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 145 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 146 | LocationSummary* locations = instruction_->GetLocations(); |
| Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 147 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 148 | __ Bind(GetEntryLabel()); |
| Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 149 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 150 | // move resolver. |
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 151 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 152 | // Live registers will be restored in the catch block if caught. |
| 153 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 154 | } |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 155 | |
| 156 | // Are we using an array length from memory? |
| 157 | HInstruction* array_length = instruction_->InputAt(1); |
| 158 | Location length_loc = locations->InAt(1); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 159 | InvokeRuntimeCallingConvention calling_convention; |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 160 | if (array_length->IsArrayLength() && array_length->IsEmittedAtUseSite()) { |
| 161 | // Load the array length into our temporary. |
| Nicolas Geoffray | 0aff3a8 | 2017-10-13 13:12:36 +0100 | [diff] [blame] | 162 | HArrayLength* length = array_length->AsArrayLength(); |
| 163 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(length); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 164 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 165 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
| 166 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(1)); |
| 167 | // Check for conflicts with index. |
| 168 | if (length_loc.Equals(locations->InAt(0))) { |
| 169 | // We know we aren't using parameter 2. |
| 170 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(2)); |
| 171 | } |
| 172 | __ movl(length_loc.AsRegister<Register>(), array_len); |
| Nicolas Geoffray | 0aff3a8 | 2017-10-13 13:12:36 +0100 | [diff] [blame] | 173 | if (mirror::kUseStringCompression && length->IsStringLength()) { |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 174 | __ shrl(length_loc.AsRegister<Register>(), Immediate(1)); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 175 | } |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 176 | } |
| Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 177 | x86_codegen->EmitParallelMoves( |
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 178 | locations->InAt(0), |
| Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 179 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 180 | DataType::Type::kInt32, |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 181 | length_loc, |
| Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 182 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 183 | DataType::Type::kInt32); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 184 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 185 | ? kQuickThrowStringBounds |
| 186 | : kQuickThrowArrayBounds; |
| 187 | x86_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 188 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 189 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 190 | } |
| 191 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 192 | bool IsFatal() const override { return true; } |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 193 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 194 | const char* GetDescription() const override { return "BoundsCheckSlowPathX86"; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 195 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 196 | private: |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 197 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86); |
| 198 | }; |
| 199 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 200 | class SuspendCheckSlowPathX86 : public SlowPathCode { |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 201 | public: |
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 202 | SuspendCheckSlowPathX86(HSuspendCheck* instruction, HBasicBlock* successor) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 203 | : SlowPathCode(instruction), successor_(successor) {} |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 204 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 205 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 206 | LocationSummary* locations = instruction_->GetLocations(); |
| Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 207 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 208 | __ Bind(GetEntryLabel()); |
| Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 209 | SaveLiveRegisters(codegen, locations); // Only saves full width XMM for SIMD. |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 210 | x86_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 211 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
| Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 212 | RestoreLiveRegisters(codegen, locations); // Only restores full width XMM for SIMD. |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 213 | if (successor_ == nullptr) { |
| 214 | __ jmp(GetReturnLabel()); |
| 215 | } else { |
| Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 216 | __ jmp(x86_codegen->GetLabelOf(successor_)); |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 217 | } |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 218 | } |
| 219 | |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 220 | Label* GetReturnLabel() { |
| 221 | DCHECK(successor_ == nullptr); |
| 222 | return &return_label_; |
| 223 | } |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 224 | |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 225 | HBasicBlock* GetSuccessor() const { |
| 226 | return successor_; |
| 227 | } |
| 228 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 229 | const char* GetDescription() const override { return "SuspendCheckSlowPathX86"; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 230 | |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 231 | private: |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 232 | HBasicBlock* const successor_; |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 233 | Label return_label_; |
| 234 | |
| 235 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86); |
| 236 | }; |
| 237 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 238 | class LoadStringSlowPathX86 : public SlowPathCode { |
| 239 | public: |
| 240 | explicit LoadStringSlowPathX86(HLoadString* instruction): SlowPathCode(instruction) {} |
| 241 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 242 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 243 | LocationSummary* locations = instruction_->GetLocations(); |
| 244 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 245 | |
| 246 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 247 | __ Bind(GetEntryLabel()); |
| 248 | SaveLiveRegisters(codegen, locations); |
| 249 | |
| 250 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 251 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 252 | __ movl(calling_convention.GetRegisterAt(0), Immediate(string_index.index_)); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 253 | x86_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 254 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 255 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 256 | RestoreLiveRegisters(codegen, locations); |
| 257 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 258 | __ jmp(GetExitLabel()); |
| 259 | } |
| 260 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 261 | const char* GetDescription() const override { return "LoadStringSlowPathX86"; } |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 262 | |
| 263 | private: |
| 264 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86); |
| 265 | }; |
| 266 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 267 | class LoadClassSlowPathX86 : public SlowPathCode { |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 268 | public: |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 269 | LoadClassSlowPathX86(HLoadClass* cls, HInstruction* at) |
| 270 | : SlowPathCode(at), cls_(cls) { |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 271 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 272 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 273 | } |
| 274 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 275 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 276 | LocationSummary* locations = instruction_->GetLocations(); |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 277 | Location out = locations->Out(); |
| 278 | const uint32_t dex_pc = instruction_->GetDexPc(); |
| 279 | bool must_resolve_type = instruction_->IsLoadClass() && cls_->MustResolveTypeOnSlowPath(); |
| 280 | bool must_do_clinit = instruction_->IsClinitCheck() || cls_->MustGenerateClinitCheck(); |
| 281 | |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 282 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 283 | __ Bind(GetEntryLabel()); |
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 284 | SaveLiveRegisters(codegen, locations); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 285 | |
| 286 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 287 | if (must_resolve_type) { |
| 288 | DCHECK(IsSameDexFile(cls_->GetDexFile(), x86_codegen->GetGraph()->GetDexFile())); |
| 289 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 290 | __ movl(calling_convention.GetRegisterAt(0), Immediate(type_index.index_)); |
| Vladimir Marko | 9d47925 | 2018-07-24 11:35:20 +0100 | [diff] [blame] | 291 | x86_codegen->InvokeRuntime(kQuickResolveType, instruction_, dex_pc, this); |
| 292 | CheckEntrypointTypes<kQuickResolveType, void*, uint32_t>(); |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 293 | // If we also must_do_clinit, the resolved type is now in the correct register. |
| 294 | } else { |
| 295 | DCHECK(must_do_clinit); |
| 296 | Location source = instruction_->IsLoadClass() ? out : locations->InAt(0); |
| 297 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), source); |
| 298 | } |
| 299 | if (must_do_clinit) { |
| 300 | x86_codegen->InvokeRuntime(kQuickInitializeStaticStorage, instruction_, dex_pc, this); |
| 301 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, mirror::Class*>(); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 302 | } |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 303 | |
| 304 | // Move the class to the desired location. |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 305 | if (out.IsValid()) { |
| 306 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 307 | x86_codegen->Move32(out, Location::RegisterLocation(EAX)); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 308 | } |
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 309 | RestoreLiveRegisters(codegen, locations); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 310 | __ jmp(GetExitLabel()); |
| 311 | } |
| 312 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 313 | const char* GetDescription() const override { return "LoadClassSlowPathX86"; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 314 | |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 315 | private: |
| 316 | // The class this slow path will load. |
| 317 | HLoadClass* const cls_; |
| 318 | |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 319 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86); |
| 320 | }; |
| 321 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 322 | class TypeCheckSlowPathX86 : public SlowPathCode { |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 323 | public: |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 324 | TypeCheckSlowPathX86(HInstruction* instruction, bool is_fatal) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 325 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 326 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 327 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 328 | LocationSummary* locations = instruction_->GetLocations(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 329 | DCHECK(instruction_->IsCheckCast() |
| 330 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 331 | |
| 332 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 333 | __ Bind(GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 334 | |
| Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 335 | if (kPoisonHeapReferences && |
| 336 | instruction_->IsCheckCast() && |
| 337 | instruction_->AsCheckCast()->GetTypeCheckKind() == TypeCheckKind::kInterfaceCheck) { |
| 338 | // First, unpoison the `cls` reference that was poisoned for direct memory comparison. |
| 339 | __ UnpoisonHeapReference(locations->InAt(1).AsRegister<Register>()); |
| 340 | } |
| 341 | |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 342 | if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 343 | SaveLiveRegisters(codegen, locations); |
| 344 | } |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 345 | |
| 346 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 347 | // move resolver. |
| 348 | InvokeRuntimeCallingConvention calling_convention; |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 349 | x86_codegen->EmitParallelMoves(locations->InAt(0), |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 350 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 351 | DataType::Type::kReference, |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 352 | locations->InAt(1), |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 353 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 354 | DataType::Type::kReference); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 355 | if (instruction_->IsInstanceOf()) { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 356 | x86_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 357 | instruction_, |
| 358 | instruction_->GetDexPc(), |
| 359 | this); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 360 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 361 | } else { |
| 362 | DCHECK(instruction_->IsCheckCast()); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 363 | x86_codegen->InvokeRuntime(kQuickCheckInstanceOf, |
| 364 | instruction_, |
| 365 | instruction_->GetDexPc(), |
| 366 | this); |
| 367 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 368 | } |
| 369 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 370 | if (!is_fatal_) { |
| 371 | if (instruction_->IsInstanceOf()) { |
| 372 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 373 | } |
| 374 | RestoreLiveRegisters(codegen, locations); |
| Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 375 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 376 | __ jmp(GetExitLabel()); |
| 377 | } |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 378 | } |
| 379 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 380 | const char* GetDescription() const override { return "TypeCheckSlowPathX86"; } |
| 381 | bool IsFatal() const override { return is_fatal_; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 382 | |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 383 | private: |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 384 | const bool is_fatal_; |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 385 | |
| 386 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86); |
| 387 | }; |
| 388 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 389 | class DeoptimizationSlowPathX86 : public SlowPathCode { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 390 | public: |
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 391 | explicit DeoptimizationSlowPathX86(HDeoptimize* instruction) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 392 | : SlowPathCode(instruction) {} |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 393 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 394 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 395 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 396 | __ Bind(GetEntryLabel()); |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 397 | LocationSummary* locations = instruction_->GetLocations(); |
| 398 | SaveLiveRegisters(codegen, locations); |
| 399 | InvokeRuntimeCallingConvention calling_convention; |
| 400 | x86_codegen->Load32BitValue( |
| 401 | calling_convention.GetRegisterAt(0), |
| 402 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 403 | x86_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 404 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 405 | } |
| 406 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 407 | const char* GetDescription() const override { return "DeoptimizationSlowPathX86"; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 408 | |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 409 | private: |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 410 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86); |
| 411 | }; |
| 412 | |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 413 | class ArraySetSlowPathX86 : public SlowPathCode { |
| 414 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 415 | explicit ArraySetSlowPathX86(HInstruction* instruction) : SlowPathCode(instruction) {} |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 416 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 417 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 418 | LocationSummary* locations = instruction_->GetLocations(); |
| 419 | __ Bind(GetEntryLabel()); |
| 420 | SaveLiveRegisters(codegen, locations); |
| 421 | |
| 422 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 423 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 424 | parallel_move.AddMove( |
| 425 | locations->InAt(0), |
| 426 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 427 | DataType::Type::kReference, |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 428 | nullptr); |
| 429 | parallel_move.AddMove( |
| 430 | locations->InAt(1), |
| 431 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 432 | DataType::Type::kInt32, |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 433 | nullptr); |
| 434 | parallel_move.AddMove( |
| 435 | locations->InAt(2), |
| 436 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 437 | DataType::Type::kReference, |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 438 | nullptr); |
| 439 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 440 | |
| 441 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 442 | x86_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 443 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 444 | RestoreLiveRegisters(codegen, locations); |
| 445 | __ jmp(GetExitLabel()); |
| 446 | } |
| 447 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 448 | const char* GetDescription() const override { return "ArraySetSlowPathX86"; } |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 449 | |
| 450 | private: |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 451 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86); |
| 452 | }; |
| 453 | |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 454 | // Slow path marking an object reference `ref` during a read |
| 455 | // barrier. The field `obj.field` in the object `obj` holding this |
| 456 | // reference does not get updated by this slow path after marking (see |
| 457 | // ReadBarrierMarkAndUpdateFieldSlowPathX86 below for that). |
| 458 | // |
| 459 | // This means that after the execution of this slow path, `ref` will |
| 460 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 461 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 462 | // probably still be a from-space reference (unless it gets updated by |
| 463 | // another thread, or if another thread installed another object |
| 464 | // reference (different from `ref`) in `obj.field`). |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 465 | class ReadBarrierMarkSlowPathX86 : public SlowPathCode { |
| 466 | public: |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 467 | ReadBarrierMarkSlowPathX86(HInstruction* instruction, |
| 468 | Location ref, |
| 469 | bool unpoison_ref_before_marking) |
| 470 | : SlowPathCode(instruction), |
| 471 | ref_(ref), |
| 472 | unpoison_ref_before_marking_(unpoison_ref_before_marking) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 473 | DCHECK(kEmitCompilerReadBarrier); |
| 474 | } |
| 475 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 476 | const char* GetDescription() const override { return "ReadBarrierMarkSlowPathX86"; } |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 477 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 478 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 479 | LocationSummary* locations = instruction_->GetLocations(); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 480 | Register ref_reg = ref_.AsRegister<Register>(); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 481 | DCHECK(locations->CanCall()); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 482 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 483 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 484 | instruction_->IsStaticFieldGet() || |
| 485 | instruction_->IsArrayGet() || |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 486 | instruction_->IsArraySet() || |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 487 | instruction_->IsLoadClass() || |
| 488 | instruction_->IsLoadString() || |
| 489 | instruction_->IsInstanceOf() || |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 490 | instruction_->IsCheckCast() || |
| Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 491 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 492 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 493 | << "Unexpected instruction in read barrier marking slow path: " |
| 494 | << instruction_->DebugName(); |
| 495 | |
| 496 | __ Bind(GetEntryLabel()); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 497 | if (unpoison_ref_before_marking_) { |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 498 | // Object* ref = ref_addr->AsMirrorPtr() |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 499 | __ MaybeUnpoisonHeapReference(ref_reg); |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 500 | } |
| Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 501 | // No need to save live registers; it's taken care of by the |
| 502 | // entrypoint. Also, there is no need to update the stack mask, |
| 503 | // as this runtime call will not trigger a garbage collection. |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 504 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 505 | DCHECK_NE(ref_reg, ESP); |
| 506 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 507 | // "Compact" slow path, saving two moves. |
| 508 | // |
| 509 | // Instead of using the standard runtime calling convention (input |
| 510 | // and output in EAX): |
| 511 | // |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 512 | // EAX <- ref |
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 513 | // EAX <- ReadBarrierMark(EAX) |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 514 | // ref <- EAX |
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 515 | // |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 516 | // we just use rX (the register containing `ref`) as input and output |
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 517 | // of a dedicated entrypoint: |
| 518 | // |
| 519 | // rX <- ReadBarrierMarkRegX(rX) |
| 520 | // |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 521 | int32_t entry_point_offset = Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(ref_reg); |
| Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 522 | // This runtime call does not require a stack map. |
| 523 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 524 | __ jmp(GetExitLabel()); |
| 525 | } |
| 526 | |
| 527 | private: |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 528 | // The location (register) of the marked object reference. |
| 529 | const Location ref_; |
| 530 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 531 | const bool unpoison_ref_before_marking_; |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 532 | |
| 533 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86); |
| 534 | }; |
| 535 | |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 536 | // Slow path marking an object reference `ref` during a read barrier, |
| 537 | // and if needed, atomically updating the field `obj.field` in the |
| 538 | // object `obj` holding this reference after marking (contrary to |
| 539 | // ReadBarrierMarkSlowPathX86 above, which never tries to update |
| 540 | // `obj.field`). |
| 541 | // |
| 542 | // This means that after the execution of this slow path, both `ref` |
| 543 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 544 | // hold the same to-space reference (unless another thread installed |
| 545 | // another object reference (different from `ref`) in `obj.field`). |
| 546 | class ReadBarrierMarkAndUpdateFieldSlowPathX86 : public SlowPathCode { |
| 547 | public: |
| 548 | ReadBarrierMarkAndUpdateFieldSlowPathX86(HInstruction* instruction, |
| 549 | Location ref, |
| 550 | Register obj, |
| 551 | const Address& field_addr, |
| 552 | bool unpoison_ref_before_marking, |
| 553 | Register temp) |
| 554 | : SlowPathCode(instruction), |
| 555 | ref_(ref), |
| 556 | obj_(obj), |
| 557 | field_addr_(field_addr), |
| 558 | unpoison_ref_before_marking_(unpoison_ref_before_marking), |
| 559 | temp_(temp) { |
| 560 | DCHECK(kEmitCompilerReadBarrier); |
| 561 | } |
| 562 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 563 | const char* GetDescription() const override { return "ReadBarrierMarkAndUpdateFieldSlowPathX86"; } |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 564 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 565 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 566 | LocationSummary* locations = instruction_->GetLocations(); |
| 567 | Register ref_reg = ref_.AsRegister<Register>(); |
| 568 | DCHECK(locations->CanCall()); |
| 569 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 570 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 571 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 572 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 573 | << instruction_->DebugName(); |
| 574 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 575 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 576 | |
| 577 | __ Bind(GetEntryLabel()); |
| 578 | if (unpoison_ref_before_marking_) { |
| 579 | // Object* ref = ref_addr->AsMirrorPtr() |
| 580 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 581 | } |
| 582 | |
| 583 | // Save the old (unpoisoned) reference. |
| 584 | __ movl(temp_, ref_reg); |
| 585 | |
| 586 | // No need to save live registers; it's taken care of by the |
| 587 | // entrypoint. Also, there is no need to update the stack mask, |
| 588 | // as this runtime call will not trigger a garbage collection. |
| 589 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 590 | DCHECK_NE(ref_reg, ESP); |
| 591 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
| 592 | // "Compact" slow path, saving two moves. |
| 593 | // |
| 594 | // Instead of using the standard runtime calling convention (input |
| 595 | // and output in EAX): |
| 596 | // |
| 597 | // EAX <- ref |
| 598 | // EAX <- ReadBarrierMark(EAX) |
| 599 | // ref <- EAX |
| 600 | // |
| 601 | // we just use rX (the register containing `ref`) as input and output |
| 602 | // of a dedicated entrypoint: |
| 603 | // |
| 604 | // rX <- ReadBarrierMarkRegX(rX) |
| 605 | // |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 606 | int32_t entry_point_offset = Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(ref_reg); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 607 | // This runtime call does not require a stack map. |
| 608 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 609 | |
| 610 | // If the new reference is different from the old reference, |
| 611 | // update the field in the holder (`*field_addr`). |
| 612 | // |
| 613 | // Note that this field could also hold a different object, if |
| 614 | // another thread had concurrently changed it. In that case, the |
| 615 | // LOCK CMPXCHGL instruction in the compare-and-set (CAS) |
| 616 | // operation below would abort the CAS, leaving the field as-is. |
| 617 | NearLabel done; |
| 618 | __ cmpl(temp_, ref_reg); |
| 619 | __ j(kEqual, &done); |
| 620 | |
| 621 | // Update the the holder's field atomically. This may fail if |
| 622 | // mutator updates before us, but it's OK. This is achieved |
| 623 | // using a strong compare-and-set (CAS) operation with relaxed |
| 624 | // memory synchronization ordering, where the expected value is |
| 625 | // the old reference and the desired value is the new reference. |
| 626 | // This operation is implemented with a 32-bit LOCK CMPXLCHG |
| 627 | // instruction, which requires the expected value (the old |
| 628 | // reference) to be in EAX. Save EAX beforehand, and move the |
| 629 | // expected value (stored in `temp_`) into EAX. |
| 630 | __ pushl(EAX); |
| 631 | __ movl(EAX, temp_); |
| 632 | |
| 633 | // Convenience aliases. |
| 634 | Register base = obj_; |
| 635 | Register expected = EAX; |
| 636 | Register value = ref_reg; |
| 637 | |
| 638 | bool base_equals_value = (base == value); |
| 639 | if (kPoisonHeapReferences) { |
| 640 | if (base_equals_value) { |
| 641 | // If `base` and `value` are the same register location, move |
| 642 | // `value` to a temporary register. This way, poisoning |
| 643 | // `value` won't invalidate `base`. |
| 644 | value = temp_; |
| 645 | __ movl(value, base); |
| 646 | } |
| 647 | |
| 648 | // Check that the register allocator did not assign the location |
| 649 | // of `expected` (EAX) to `value` nor to `base`, so that heap |
| 650 | // poisoning (when enabled) works as intended below. |
| 651 | // - If `value` were equal to `expected`, both references would |
| 652 | // be poisoned twice, meaning they would not be poisoned at |
| 653 | // all, as heap poisoning uses address negation. |
| 654 | // - If `base` were equal to `expected`, poisoning `expected` |
| 655 | // would invalidate `base`. |
| 656 | DCHECK_NE(value, expected); |
| 657 | DCHECK_NE(base, expected); |
| 658 | |
| 659 | __ PoisonHeapReference(expected); |
| 660 | __ PoisonHeapReference(value); |
| 661 | } |
| 662 | |
| 663 | __ LockCmpxchgl(field_addr_, value); |
| 664 | |
| 665 | // If heap poisoning is enabled, we need to unpoison the values |
| 666 | // that were poisoned earlier. |
| 667 | if (kPoisonHeapReferences) { |
| 668 | if (base_equals_value) { |
| 669 | // `value` has been moved to a temporary register, no need |
| 670 | // to unpoison it. |
| 671 | } else { |
| 672 | __ UnpoisonHeapReference(value); |
| 673 | } |
| 674 | // No need to unpoison `expected` (EAX), as it is be overwritten below. |
| 675 | } |
| 676 | |
| 677 | // Restore EAX. |
| 678 | __ popl(EAX); |
| 679 | |
| 680 | __ Bind(&done); |
| 681 | __ jmp(GetExitLabel()); |
| 682 | } |
| 683 | |
| 684 | private: |
| 685 | // The location (register) of the marked object reference. |
| 686 | const Location ref_; |
| 687 | // The register containing the object holding the marked object reference field. |
| 688 | const Register obj_; |
| 689 | // The address of the marked reference field. The base of this address must be `obj_`. |
| 690 | const Address field_addr_; |
| 691 | |
| 692 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 693 | const bool unpoison_ref_before_marking_; |
| 694 | |
| 695 | const Register temp_; |
| 696 | |
| 697 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathX86); |
| 698 | }; |
| 699 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 700 | // Slow path generating a read barrier for a heap reference. |
| 701 | class ReadBarrierForHeapReferenceSlowPathX86 : public SlowPathCode { |
| 702 | public: |
| 703 | ReadBarrierForHeapReferenceSlowPathX86(HInstruction* instruction, |
| 704 | Location out, |
| 705 | Location ref, |
| 706 | Location obj, |
| 707 | uint32_t offset, |
| 708 | Location index) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 709 | : SlowPathCode(instruction), |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 710 | out_(out), |
| 711 | ref_(ref), |
| 712 | obj_(obj), |
| 713 | offset_(offset), |
| 714 | index_(index) { |
| 715 | DCHECK(kEmitCompilerReadBarrier); |
| 716 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 717 | // has been overwritten by (or after) the heap object reference load |
| 718 | // to be instrumented, e.g.: |
| 719 | // |
| 720 | // __ movl(out, Address(out, offset)); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 721 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 722 | // |
| 723 | // In that case, we have lost the information about the original |
| 724 | // object, and the emitted read barrier cannot work properly. |
| 725 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 726 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 727 | } |
| 728 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 729 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 730 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 731 | LocationSummary* locations = instruction_->GetLocations(); |
| 732 | Register reg_out = out_.AsRegister<Register>(); |
| 733 | DCHECK(locations->CanCall()); |
| 734 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 735 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 736 | instruction_->IsStaticFieldGet() || |
| 737 | instruction_->IsArrayGet() || |
| 738 | instruction_->IsInstanceOf() || |
| 739 | instruction_->IsCheckCast() || |
| Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 740 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 741 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 742 | << instruction_->DebugName(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 743 | |
| 744 | __ Bind(GetEntryLabel()); |
| 745 | SaveLiveRegisters(codegen, locations); |
| 746 | |
| 747 | // We may have to change the index's value, but as `index_` is a |
| 748 | // constant member (like other "inputs" of this slow path), |
| 749 | // introduce a copy of it, `index`. |
| 750 | Location index = index_; |
| 751 | if (index_.IsValid()) { |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 752 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 753 | if (instruction_->IsArrayGet()) { |
| 754 | // Compute the actual memory offset and store it in `index`. |
| 755 | Register index_reg = index_.AsRegister<Register>(); |
| 756 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 757 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 758 | // We are about to change the value of `index_reg` (see the |
| 759 | // calls to art::x86::X86Assembler::shll and |
| 760 | // art::x86::X86Assembler::AddImmediate below), but it has |
| 761 | // not been saved by the previous call to |
| 762 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 763 | // callee-save register -- |
| 764 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 765 | // callee-save registers, as it has been designed with the |
| 766 | // assumption that callee-save registers are supposed to be |
| 767 | // handled by the called function. So, as a callee-save |
| 768 | // register, `index_reg` _would_ eventually be saved onto |
| 769 | // the stack, but it would be too late: we would have |
| 770 | // changed its value earlier. Therefore, we manually save |
| 771 | // it here into another freely available register, |
| 772 | // `free_reg`, chosen of course among the caller-save |
| 773 | // registers (as a callee-save `free_reg` register would |
| 774 | // exhibit the same problem). |
| 775 | // |
| 776 | // Note we could have requested a temporary register from |
| 777 | // the register allocator instead; but we prefer not to, as |
| 778 | // this is a slow path, and we know we can find a |
| 779 | // caller-save register that is available. |
| 780 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 781 | __ movl(free_reg, index_reg); |
| 782 | index_reg = free_reg; |
| 783 | index = Location::RegisterLocation(index_reg); |
| 784 | } else { |
| 785 | // The initial register stored in `index_` has already been |
| 786 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 787 | // (as it is not a callee-save register), so we can freely |
| 788 | // use it. |
| 789 | } |
| 790 | // Shifting the index value contained in `index_reg` by the scale |
| 791 | // factor (2) cannot overflow in practice, as the runtime is |
| 792 | // unable to allocate object arrays with a size larger than |
| 793 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 794 | __ shll(index_reg, Immediate(TIMES_4)); |
| 795 | static_assert( |
| 796 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 797 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 798 | __ AddImmediate(index_reg, Immediate(offset_)); |
| 799 | } else { |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 800 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 801 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 802 | // (as in the case of ArrayGet), as it is actually an offset |
| 803 | // to an object field within an object. |
| 804 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 805 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 806 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 807 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 808 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 809 | DCHECK_EQ(offset_, 0U); |
| 810 | DCHECK(index_.IsRegisterPair()); |
| 811 | // UnsafeGet's offset location is a register pair, the low |
| 812 | // part contains the correct offset. |
| 813 | index = index_.ToLow(); |
| 814 | } |
| 815 | } |
| 816 | |
| 817 | // We're moving two or three locations to locations that could |
| 818 | // overlap, so we need a parallel move resolver. |
| 819 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 820 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 821 | parallel_move.AddMove(ref_, |
| 822 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 823 | DataType::Type::kReference, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 824 | nullptr); |
| 825 | parallel_move.AddMove(obj_, |
| 826 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 827 | DataType::Type::kReference, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 828 | nullptr); |
| 829 | if (index.IsValid()) { |
| 830 | parallel_move.AddMove(index, |
| 831 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 832 | DataType::Type::kInt32, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 833 | nullptr); |
| 834 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 835 | } else { |
| 836 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 837 | __ movl(calling_convention.GetRegisterAt(2), Immediate(offset_)); |
| 838 | } |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 839 | x86_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 840 | CheckEntrypointTypes< |
| 841 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 842 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 843 | |
| 844 | RestoreLiveRegisters(codegen, locations); |
| 845 | __ jmp(GetExitLabel()); |
| 846 | } |
| 847 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 848 | const char* GetDescription() const override { return "ReadBarrierForHeapReferenceSlowPathX86"; } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 849 | |
| 850 | private: |
| 851 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 852 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 853 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 854 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 855 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 856 | return static_cast<Register>(i); |
| 857 | } |
| 858 | } |
| 859 | // We shall never fail to find a free caller-save register, as |
| 860 | // there are more than two core caller-save registers on x86 |
| 861 | // (meaning it is possible to find one which is different from |
| 862 | // `ref` and `obj`). |
| 863 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 864 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 865 | UNREACHABLE(); |
| 866 | } |
| 867 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 868 | const Location out_; |
| 869 | const Location ref_; |
| 870 | const Location obj_; |
| 871 | const uint32_t offset_; |
| 872 | // An additional location containing an index to an array. |
| 873 | // Only used for HArrayGet and the UnsafeGetObject & |
| 874 | // UnsafeGetObjectVolatile intrinsics. |
| 875 | const Location index_; |
| 876 | |
| 877 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86); |
| 878 | }; |
| 879 | |
| 880 | // Slow path generating a read barrier for a GC root. |
| 881 | class ReadBarrierForRootSlowPathX86 : public SlowPathCode { |
| 882 | public: |
| 883 | ReadBarrierForRootSlowPathX86(HInstruction* instruction, Location out, Location root) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 884 | : SlowPathCode(instruction), out_(out), root_(root) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 885 | DCHECK(kEmitCompilerReadBarrier); |
| 886 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 887 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 888 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 889 | LocationSummary* locations = instruction_->GetLocations(); |
| 890 | Register reg_out = out_.AsRegister<Register>(); |
| 891 | DCHECK(locations->CanCall()); |
| 892 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 893 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 894 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 895 | << instruction_->DebugName(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 896 | |
| 897 | __ Bind(GetEntryLabel()); |
| 898 | SaveLiveRegisters(codegen, locations); |
| 899 | |
| 900 | InvokeRuntimeCallingConvention calling_convention; |
| 901 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 902 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 903 | x86_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 904 | instruction_, |
| 905 | instruction_->GetDexPc(), |
| 906 | this); |
| 907 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 908 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 909 | |
| 910 | RestoreLiveRegisters(codegen, locations); |
| 911 | __ jmp(GetExitLabel()); |
| 912 | } |
| 913 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 914 | const char* GetDescription() const override { return "ReadBarrierForRootSlowPathX86"; } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 915 | |
| 916 | private: |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 917 | const Location out_; |
| 918 | const Location root_; |
| 919 | |
| 920 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86); |
| 921 | }; |
| 922 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 923 | #undef __ |
| Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 924 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 925 | #define __ down_cast<X86Assembler*>(GetAssembler())-> // NOLINT |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 926 | |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 927 | inline Condition X86Condition(IfCondition cond) { |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 928 | switch (cond) { |
| 929 | case kCondEQ: return kEqual; |
| 930 | case kCondNE: return kNotEqual; |
| 931 | case kCondLT: return kLess; |
| 932 | case kCondLE: return kLessEqual; |
| 933 | case kCondGT: return kGreater; |
| 934 | case kCondGE: return kGreaterEqual; |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 935 | case kCondB: return kBelow; |
| 936 | case kCondBE: return kBelowEqual; |
| 937 | case kCondA: return kAbove; |
| 938 | case kCondAE: return kAboveEqual; |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 939 | } |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 940 | LOG(FATAL) << "Unreachable"; |
| 941 | UNREACHABLE(); |
| 942 | } |
| 943 | |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 944 | // Maps signed condition to unsigned condition and FP condition to x86 name. |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 945 | inline Condition X86UnsignedOrFPCondition(IfCondition cond) { |
| 946 | switch (cond) { |
| 947 | case kCondEQ: return kEqual; |
| 948 | case kCondNE: return kNotEqual; |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 949 | // Signed to unsigned, and FP to x86 name. |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 950 | case kCondLT: return kBelow; |
| 951 | case kCondLE: return kBelowEqual; |
| 952 | case kCondGT: return kAbove; |
| 953 | case kCondGE: return kAboveEqual; |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 954 | // Unsigned remain unchanged. |
| 955 | case kCondB: return kBelow; |
| 956 | case kCondBE: return kBelowEqual; |
| 957 | case kCondA: return kAbove; |
| 958 | case kCondAE: return kAboveEqual; |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 959 | } |
| 960 | LOG(FATAL) << "Unreachable"; |
| 961 | UNREACHABLE(); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 962 | } |
| 963 | |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 964 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 965 | stream << Register(reg); |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 969 | stream << XmmRegister(reg); |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 970 | } |
| 971 | |
| Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 972 | const X86InstructionSetFeatures& CodeGeneratorX86::GetInstructionSetFeatures() const { |
| 973 | return *GetCompilerOptions().GetInstructionSetFeatures()->AsX86InstructionSetFeatures(); |
| 974 | } |
| 975 | |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 976 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 977 | __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); |
| 978 | return kX86WordSize; |
| Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 979 | } |
| 980 | |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 981 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 982 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); |
| 983 | return kX86WordSize; |
| Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 984 | } |
| 985 | |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 986 | size_t CodeGeneratorX86::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 987 | if (GetGraph()->HasSIMD()) { |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 988 | __ movups(Address(ESP, stack_index), XmmRegister(reg_id)); |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 989 | } else { |
| 990 | __ movsd(Address(ESP, stack_index), XmmRegister(reg_id)); |
| 991 | } |
| Artem Serov | 6a0b657 | 2019-07-26 20:38:37 +0100 | [diff] [blame] | 992 | return GetSlowPathFPWidth(); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | size_t CodeGeneratorX86::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 996 | if (GetGraph()->HasSIMD()) { |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 997 | __ movups(XmmRegister(reg_id), Address(ESP, stack_index)); |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 998 | } else { |
| 999 | __ movsd(XmmRegister(reg_id), Address(ESP, stack_index)); |
| 1000 | } |
| Artem Serov | 6a0b657 | 2019-07-26 20:38:37 +0100 | [diff] [blame] | 1001 | return GetSlowPathFPWidth(); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1002 | } |
| 1003 | |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1004 | void CodeGeneratorX86::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1005 | HInstruction* instruction, |
| 1006 | uint32_t dex_pc, |
| 1007 | SlowPathCode* slow_path) { |
| Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1008 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1009 | GenerateInvokeRuntime(GetThreadOffset<kX86PointerSize>(entrypoint).Int32Value()); |
| 1010 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1011 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1012 | } |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 1013 | } |
| 1014 | |
| Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1015 | void CodeGeneratorX86::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1016 | HInstruction* instruction, |
| 1017 | SlowPathCode* slow_path) { |
| 1018 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1019 | GenerateInvokeRuntime(entry_point_offset); |
| 1020 | } |
| 1021 | |
| 1022 | void CodeGeneratorX86::GenerateInvokeRuntime(int32_t entry_point_offset) { |
| Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1023 | __ fs()->call(Address::Absolute(entry_point_offset)); |
| 1024 | } |
| 1025 | |
| Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1026 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1027 | const CompilerOptions& compiler_options, |
| 1028 | OptimizingCompilerStats* stats) |
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1029 | : CodeGenerator(graph, |
| 1030 | kNumberOfCpuRegisters, |
| 1031 | kNumberOfXmmRegisters, |
| 1032 | kNumberOfRegisterPairs, |
| 1033 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1034 | arraysize(kCoreCalleeSaves)) |
| 1035 | | (1 << kFakeReturnRegister), |
| Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1036 | 0, |
| 1037 | compiler_options, |
| 1038 | stats), |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1039 | block_labels_(nullptr), |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1040 | location_builder_(graph, this), |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1041 | instruction_visitor_(graph, this), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1042 | move_resolver_(graph->GetAllocator(), this), |
| 1043 | assembler_(graph->GetAllocator()), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1044 | boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1045 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1046 | boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1047 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1048 | boot_image_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1049 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 1050 | boot_image_other_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1051 | jit_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1052 | jit_class_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1053 | constant_area_start_(-1), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1054 | fixups_to_jump_tables_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1055 | method_address_offset_(std::less<uint32_t>(), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1056 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1057 | // Use a fake return address register to mimic Quick. |
| 1058 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1059 | } |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1060 | |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1061 | void CodeGeneratorX86::SetupBlockedRegisters() const { |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1062 | // Stack register is always reserved. |
| Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1063 | blocked_core_registers_[ESP] = true; |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1064 | } |
| 1065 | |
| Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1066 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1067 | : InstructionCodeGenerator(graph, codegen), |
| Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1068 | assembler_(codegen->GetAssembler()), |
| 1069 | codegen_(codegen) {} |
| 1070 | |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1071 | static dwarf::Reg DWARFReg(Register reg) { |
| David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1072 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1073 | } |
| 1074 | |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1075 | void CodeGeneratorX86::MaybeIncrementHotness(bool is_frame_entry) { |
| 1076 | if (GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 1077 | Register reg = EAX; |
| 1078 | if (is_frame_entry) { |
| 1079 | reg = kMethodRegisterArgument; |
| 1080 | } else { |
| 1081 | __ pushl(EAX); |
| 1082 | __ movl(EAX, Address(ESP, kX86WordSize)); |
| 1083 | } |
| 1084 | NearLabel overflow; |
| 1085 | __ cmpw(Address(reg, ArtMethod::HotnessCountOffset().Int32Value()), |
| 1086 | Immediate(ArtMethod::MaxCounter())); |
| 1087 | __ j(kEqual, &overflow); |
| 1088 | __ addw(Address(reg, ArtMethod::HotnessCountOffset().Int32Value()), |
| 1089 | Immediate(1)); |
| 1090 | __ Bind(&overflow); |
| 1091 | if (!is_frame_entry) { |
| 1092 | __ popl(EAX); |
| 1093 | } |
| 1094 | } |
| 1095 | |
| 1096 | if (GetGraph()->IsCompilingBaseline() && !Runtime::Current()->IsAotCompiler()) { |
| 1097 | ScopedObjectAccess soa(Thread::Current()); |
| 1098 | ProfilingInfo* info = GetGraph()->GetArtMethod()->GetProfilingInfo(kRuntimePointerSize); |
| 1099 | uint32_t address = reinterpret_cast32<uint32_t>(info); |
| 1100 | NearLabel done; |
| 1101 | if (HasEmptyFrame()) { |
| 1102 | CHECK(is_frame_entry); |
| 1103 | // Alignment |
| 1104 | __ subl(ESP, Immediate(8)); |
| 1105 | __ cfi().AdjustCFAOffset(8); |
| 1106 | // We need a temporary. The stub also expects the method at bottom of stack. |
| 1107 | __ pushl(EAX); |
| 1108 | __ cfi().AdjustCFAOffset(4); |
| 1109 | __ movl(EAX, Immediate(address)); |
| 1110 | __ addw(Address(EAX, ProfilingInfo::BaselineHotnessCountOffset().Int32Value()), Immediate(1)); |
| 1111 | __ j(kCarryClear, &done); |
| 1112 | GenerateInvokeRuntime( |
| 1113 | GetThreadOffset<kX86PointerSize>(kQuickCompileOptimized).Int32Value()); |
| 1114 | __ Bind(&done); |
| 1115 | // We don't strictly require to restore EAX, but this makes the generated |
| 1116 | // code easier to reason about. |
| 1117 | __ popl(EAX); |
| 1118 | __ cfi().AdjustCFAOffset(-4); |
| 1119 | __ addl(ESP, Immediate(8)); |
| 1120 | __ cfi().AdjustCFAOffset(-8); |
| 1121 | } else { |
| 1122 | if (!RequiresCurrentMethod()) { |
| 1123 | CHECK(is_frame_entry); |
| 1124 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
| 1125 | } |
| 1126 | // We need a temporary. |
| 1127 | __ pushl(EAX); |
| 1128 | __ cfi().AdjustCFAOffset(4); |
| 1129 | __ movl(EAX, Immediate(address)); |
| 1130 | __ addw(Address(EAX, ProfilingInfo::BaselineHotnessCountOffset().Int32Value()), Immediate(1)); |
| 1131 | __ popl(EAX); // Put stack as expected before exiting or calling stub. |
| 1132 | __ cfi().AdjustCFAOffset(-4); |
| 1133 | __ j(kCarryClear, &done); |
| 1134 | GenerateInvokeRuntime( |
| 1135 | GetThreadOffset<kX86PointerSize>(kQuickCompileOptimized).Int32Value()); |
| 1136 | __ Bind(&done); |
| 1137 | } |
| 1138 | } |
| 1139 | } |
| 1140 | |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1141 | void CodeGeneratorX86::GenerateFrameEntry() { |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1142 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
| Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1143 | __ Bind(&frame_entry_label_); |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1144 | bool skip_overflow_check = |
| 1145 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1146 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
| Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 1147 | |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1148 | if (!skip_overflow_check) { |
| Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1149 | size_t reserved_bytes = GetStackOverflowReservedBytes(InstructionSet::kX86); |
| 1150 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(reserved_bytes))); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1151 | RecordPcInfo(nullptr, 0); |
| Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 1152 | } |
| 1153 | |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1154 | if (!HasEmptyFrame()) { |
| 1155 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 1156 | Register reg = kCoreCalleeSaves[i]; |
| 1157 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1158 | __ pushl(reg); |
| 1159 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 1160 | __ cfi().RelOffset(DWARFReg(reg), 0); |
| 1161 | } |
| 1162 | } |
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1163 | |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1164 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1165 | __ subl(ESP, Immediate(adjust)); |
| 1166 | __ cfi().AdjustCFAOffset(adjust); |
| 1167 | // Save the current method if we need it. Note that we do not |
| 1168 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1169 | // in the SSA graph. |
| 1170 | if (RequiresCurrentMethod()) { |
| 1171 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
| 1172 | } |
| 1173 | |
| 1174 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1175 | // Initialize should_deoptimize flag to 0. |
| 1176 | __ movl(Address(ESP, GetStackOffsetOfShouldDeoptimizeFlag()), Immediate(0)); |
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1177 | } |
| 1178 | } |
| 1179 | |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1180 | MaybeIncrementHotness(/* is_frame_entry= */ true); |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1181 | } |
| 1182 | |
| 1183 | void CodeGeneratorX86::GenerateFrameExit() { |
| David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1184 | __ cfi().RememberState(); |
| 1185 | if (!HasEmptyFrame()) { |
| 1186 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1187 | __ addl(ESP, Immediate(adjust)); |
| 1188 | __ cfi().AdjustCFAOffset(-adjust); |
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1189 | |
| David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1190 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1191 | Register reg = kCoreCalleeSaves[i]; |
| 1192 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1193 | __ popl(reg); |
| 1194 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 1195 | __ cfi().Restore(DWARFReg(reg)); |
| 1196 | } |
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1197 | } |
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1198 | } |
| David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1199 | __ ret(); |
| 1200 | __ cfi().RestoreState(); |
| 1201 | __ cfi().DefCFAOffset(GetFrameSize()); |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1202 | } |
| 1203 | |
| Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1204 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 1205 | __ Bind(GetLabelOf(block)); |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1206 | } |
| 1207 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1208 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(DataType::Type type) const { |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1209 | switch (type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1210 | case DataType::Type::kReference: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1211 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1212 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1213 | case DataType::Type::kInt8: |
| 1214 | case DataType::Type::kUint16: |
| 1215 | case DataType::Type::kInt16: |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1216 | case DataType::Type::kUint32: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1217 | case DataType::Type::kInt32: |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1218 | return Location::RegisterLocation(EAX); |
| 1219 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1220 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1221 | case DataType::Type::kInt64: |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1222 | return Location::RegisterPairLocation(EAX, EDX); |
| 1223 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1224 | case DataType::Type::kVoid: |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1225 | return Location::NoLocation(); |
| 1226 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1227 | case DataType::Type::kFloat64: |
| 1228 | case DataType::Type::kFloat32: |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1229 | return Location::FpuRegisterLocation(XMM0); |
| 1230 | } |
| Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1231 | |
| 1232 | UNREACHABLE(); |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1233 | } |
| 1234 | |
| 1235 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 1236 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1237 | } |
| 1238 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1239 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(DataType::Type type) { |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1240 | switch (type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1241 | case DataType::Type::kReference: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1242 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1243 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1244 | case DataType::Type::kInt8: |
| 1245 | case DataType::Type::kUint16: |
| 1246 | case DataType::Type::kInt16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1247 | case DataType::Type::kInt32: { |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1248 | uint32_t index = gp_index_++; |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1249 | stack_index_++; |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1250 | if (index < calling_convention.GetNumberOfRegisters()) { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1251 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1252 | } else { |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1253 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1254 | } |
| Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1255 | } |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1256 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1257 | case DataType::Type::kInt64: { |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1258 | uint32_t index = gp_index_; |
| 1259 | gp_index_ += 2; |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1260 | stack_index_ += 2; |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1261 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1262 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 1263 | calling_convention.GetRegisterPairAt(index)); |
| 1264 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1265 | } else { |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1266 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1267 | } |
| 1268 | } |
| 1269 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1270 | case DataType::Type::kFloat32: { |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1271 | uint32_t index = float_index_++; |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1272 | stack_index_++; |
| 1273 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1274 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1275 | } else { |
| 1276 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1277 | } |
| 1278 | } |
| 1279 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1280 | case DataType::Type::kFloat64: { |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1281 | uint32_t index = float_index_++; |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1282 | stack_index_ += 2; |
| 1283 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1284 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1285 | } else { |
| 1286 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1287 | } |
| 1288 | } |
| 1289 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1290 | case DataType::Type::kUint32: |
| 1291 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1292 | case DataType::Type::kVoid: |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1293 | LOG(FATAL) << "Unexpected parameter type " << type; |
| Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 1294 | UNREACHABLE(); |
| Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1295 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1296 | return Location::NoLocation(); |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1297 | } |
| Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1298 | |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1299 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 1300 | if (source.Equals(destination)) { |
| 1301 | return; |
| 1302 | } |
| 1303 | if (destination.IsRegister()) { |
| 1304 | if (source.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1305 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1306 | } else if (source.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1307 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1308 | } else { |
| 1309 | DCHECK(source.IsStackSlot()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1310 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1311 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1312 | } else if (destination.IsFpuRegister()) { |
| 1313 | if (source.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1314 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1315 | } else if (source.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1316 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1317 | } else { |
| 1318 | DCHECK(source.IsStackSlot()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1319 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1320 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1321 | } else { |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1322 | DCHECK(destination.IsStackSlot()) << destination; |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1323 | if (source.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1324 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1325 | } else if (source.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1326 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1327 | } else if (source.IsConstant()) { |
| 1328 | HConstant* constant = source.GetConstant(); |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1329 | int32_t value = GetInt32ValueOf(constant); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1330 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1331 | } else { |
| 1332 | DCHECK(source.IsStackSlot()); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1333 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 1334 | __ popl(Address(ESP, destination.GetStackIndex())); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1335 | } |
| 1336 | } |
| 1337 | } |
| 1338 | |
| 1339 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 1340 | if (source.Equals(destination)) { |
| 1341 | return; |
| 1342 | } |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1343 | if (destination.IsRegisterPair()) { |
| 1344 | if (source.IsRegisterPair()) { |
| Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1345 | EmitParallelMoves( |
| 1346 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1347 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1348 | DataType::Type::kInt32, |
| Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1349 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
| Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1350 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1351 | DataType::Type::kInt32); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1352 | } else if (source.IsFpuRegister()) { |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1353 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 1354 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 1355 | __ psrlq(src_reg, Immediate(32)); |
| 1356 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1357 | } else { |
| Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1358 | // No conflict possible, so just do the moves. |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1359 | DCHECK(source.IsDoubleStackSlot()); |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1360 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 1361 | __ movl(destination.AsRegisterPairHigh<Register>(), |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1362 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 1363 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1364 | } else if (destination.IsFpuRegister()) { |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1365 | if (source.IsFpuRegister()) { |
| 1366 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 1367 | } else if (source.IsDoubleStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1368 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1369 | } else if (source.IsRegisterPair()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1370 | size_t elem_size = DataType::Size(DataType::Type::kInt32); |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1371 | // Create stack space for 2 elements. |
| 1372 | __ subl(ESP, Immediate(2 * elem_size)); |
| 1373 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 1374 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 1375 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 1376 | // And remove the temporary stack space we allocated. |
| 1377 | __ addl(ESP, Immediate(2 * elem_size)); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1378 | } else { |
| 1379 | LOG(FATAL) << "Unimplemented"; |
| 1380 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1381 | } else { |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1382 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1383 | if (source.IsRegisterPair()) { |
| Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1384 | // No conflict possible, so just do the moves. |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1385 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1386 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1387 | source.AsRegisterPairHigh<Register>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1388 | } else if (source.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1389 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1390 | } else if (source.IsConstant()) { |
| 1391 | HConstant* constant = source.GetConstant(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1392 | DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant()); |
| 1393 | int64_t value = GetInt64ValueOf(constant); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1394 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1395 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
| 1396 | Immediate(High32Bits(value))); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1397 | } else { |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1398 | DCHECK(source.IsDoubleStackSlot()) << source; |
| Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1399 | EmitParallelMoves( |
| 1400 | Location::StackSlot(source.GetStackIndex()), |
| 1401 | Location::StackSlot(destination.GetStackIndex()), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1402 | DataType::Type::kInt32, |
| Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1403 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
| Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1404 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1405 | DataType::Type::kInt32); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1406 | } |
| 1407 | } |
| 1408 | } |
| 1409 | |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1410 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { |
| 1411 | DCHECK(location.IsRegister()); |
| 1412 | __ movl(location.AsRegister<Register>(), Immediate(value)); |
| 1413 | } |
| 1414 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1415 | void CodeGeneratorX86::MoveLocation(Location dst, Location src, DataType::Type dst_type) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1416 | HParallelMove move(GetGraph()->GetAllocator()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1417 | if (dst_type == DataType::Type::kInt64 && !src.IsConstant() && !src.IsFpuRegister()) { |
| 1418 | move.AddMove(src.ToLow(), dst.ToLow(), DataType::Type::kInt32, nullptr); |
| 1419 | move.AddMove(src.ToHigh(), dst.ToHigh(), DataType::Type::kInt32, nullptr); |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1420 | } else { |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1421 | move.AddMove(src, dst, dst_type, nullptr); |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1422 | } |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1423 | GetMoveResolver()->EmitNativeCode(&move); |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1424 | } |
| 1425 | |
| 1426 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1427 | if (location.IsRegister()) { |
| 1428 | locations->AddTemp(location); |
| 1429 | } else if (location.IsRegisterPair()) { |
| 1430 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1431 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1432 | } else { |
| 1433 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1434 | } |
| 1435 | } |
| 1436 | |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1437 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
| Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 1438 | if (successor->IsExitBlock()) { |
| 1439 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 1440 | return; // no code needed |
| 1441 | } |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1442 | |
| 1443 | HBasicBlock* block = got->GetBlock(); |
| 1444 | HInstruction* previous = got->GetPrevious(); |
| 1445 | |
| 1446 | HLoopInformation* info = block->GetLoopInformation(); |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1447 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1448 | codegen_->MaybeIncrementHotness(/* is_frame_entry= */ false); |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1449 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1450 | return; |
| 1451 | } |
| 1452 | |
| 1453 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1454 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1455 | } |
| 1456 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1457 | __ jmp(codegen_->GetLabelOf(successor)); |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1458 | } |
| 1459 | } |
| 1460 | |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1461 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 1462 | got->SetLocations(nullptr); |
| 1463 | } |
| 1464 | |
| 1465 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 1466 | HandleGoto(got, got->GetSuccessor()); |
| 1467 | } |
| 1468 | |
| 1469 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1470 | try_boundary->SetLocations(nullptr); |
| 1471 | } |
| 1472 | |
| 1473 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1474 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1475 | if (!successor->IsExitBlock()) { |
| 1476 | HandleGoto(try_boundary, successor); |
| 1477 | } |
| 1478 | } |
| 1479 | |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1480 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1481 | exit->SetLocations(nullptr); |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1482 | } |
| 1483 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1484 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1485 | } |
| 1486 | |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1487 | template<class LabelType> |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1488 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1489 | LabelType* true_label, |
| 1490 | LabelType* false_label) { |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1491 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1492 | __ j(kUnordered, true_label); |
| 1493 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1494 | __ j(kUnordered, false_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1495 | } |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1496 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1497 | } |
| 1498 | |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1499 | template<class LabelType> |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1500 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1501 | LabelType* true_label, |
| 1502 | LabelType* false_label) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1503 | LocationSummary* locations = cond->GetLocations(); |
| 1504 | Location left = locations->InAt(0); |
| 1505 | Location right = locations->InAt(1); |
| 1506 | IfCondition if_cond = cond->GetCondition(); |
| 1507 | |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1508 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1509 | Register left_low = left.AsRegisterPairLow<Register>(); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1510 | IfCondition true_high_cond = if_cond; |
| 1511 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1512 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); // unsigned on lower part |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1513 | |
| 1514 | // Set the conditions for the test, remembering that == needs to be |
| 1515 | // decided using the low words. |
| 1516 | switch (if_cond) { |
| 1517 | case kCondEQ: |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1518 | case kCondNE: |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1519 | // Nothing to do. |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1520 | break; |
| 1521 | case kCondLT: |
| 1522 | false_high_cond = kCondGT; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1523 | break; |
| 1524 | case kCondLE: |
| 1525 | true_high_cond = kCondLT; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1526 | break; |
| 1527 | case kCondGT: |
| 1528 | false_high_cond = kCondLT; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1529 | break; |
| 1530 | case kCondGE: |
| 1531 | true_high_cond = kCondGT; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1532 | break; |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1533 | case kCondB: |
| 1534 | false_high_cond = kCondA; |
| 1535 | break; |
| 1536 | case kCondBE: |
| 1537 | true_high_cond = kCondB; |
| 1538 | break; |
| 1539 | case kCondA: |
| 1540 | false_high_cond = kCondB; |
| 1541 | break; |
| 1542 | case kCondAE: |
| 1543 | true_high_cond = kCondA; |
| 1544 | break; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1545 | } |
| 1546 | |
| 1547 | if (right.IsConstant()) { |
| 1548 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1549 | int32_t val_high = High32Bits(value); |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1550 | int32_t val_low = Low32Bits(value); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1551 | |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1552 | codegen_->Compare32BitValue(left_high, val_high); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1553 | if (if_cond == kCondNE) { |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1554 | __ j(X86Condition(true_high_cond), true_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1555 | } else if (if_cond == kCondEQ) { |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1556 | __ j(X86Condition(false_high_cond), false_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1557 | } else { |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1558 | __ j(X86Condition(true_high_cond), true_label); |
| 1559 | __ j(X86Condition(false_high_cond), false_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1560 | } |
| 1561 | // Must be equal high, so compare the lows. |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1562 | codegen_->Compare32BitValue(left_low, val_low); |
| Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1563 | } else if (right.IsRegisterPair()) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1564 | Register right_high = right.AsRegisterPairHigh<Register>(); |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1565 | Register right_low = right.AsRegisterPairLow<Register>(); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1566 | |
| 1567 | __ cmpl(left_high, right_high); |
| 1568 | if (if_cond == kCondNE) { |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1569 | __ j(X86Condition(true_high_cond), true_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1570 | } else if (if_cond == kCondEQ) { |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1571 | __ j(X86Condition(false_high_cond), false_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1572 | } else { |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1573 | __ j(X86Condition(true_high_cond), true_label); |
| 1574 | __ j(X86Condition(false_high_cond), false_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1575 | } |
| 1576 | // Must be equal high, so compare the lows. |
| 1577 | __ cmpl(left_low, right_low); |
| Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1578 | } else { |
| 1579 | DCHECK(right.IsDoubleStackSlot()); |
| 1580 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
| 1581 | if (if_cond == kCondNE) { |
| 1582 | __ j(X86Condition(true_high_cond), true_label); |
| 1583 | } else if (if_cond == kCondEQ) { |
| 1584 | __ j(X86Condition(false_high_cond), false_label); |
| 1585 | } else { |
| 1586 | __ j(X86Condition(true_high_cond), true_label); |
| 1587 | __ j(X86Condition(false_high_cond), false_label); |
| 1588 | } |
| 1589 | // Must be equal high, so compare the lows. |
| 1590 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1591 | } |
| 1592 | // The last comparison might be unsigned. |
| 1593 | __ j(final_condition, true_label); |
| 1594 | } |
| 1595 | |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1596 | void InstructionCodeGeneratorX86::GenerateFPCompare(Location lhs, |
| 1597 | Location rhs, |
| 1598 | HInstruction* insn, |
| 1599 | bool is_double) { |
| 1600 | HX86LoadFromConstantTable* const_area = insn->InputAt(1)->AsX86LoadFromConstantTable(); |
| 1601 | if (is_double) { |
| 1602 | if (rhs.IsFpuRegister()) { |
| 1603 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1604 | } else if (const_area != nullptr) { |
| 1605 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1606 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), |
| 1607 | codegen_->LiteralDoubleAddress( |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1608 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 1609 | const_area->GetBaseMethodAddress(), |
| 1610 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1611 | } else { |
| 1612 | DCHECK(rhs.IsDoubleStackSlot()); |
| 1613 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1614 | } |
| 1615 | } else { |
| 1616 | if (rhs.IsFpuRegister()) { |
| 1617 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1618 | } else if (const_area != nullptr) { |
| 1619 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1620 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), |
| 1621 | codegen_->LiteralFloatAddress( |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1622 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 1623 | const_area->GetBaseMethodAddress(), |
| 1624 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1625 | } else { |
| 1626 | DCHECK(rhs.IsStackSlot()); |
| 1627 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1628 | } |
| 1629 | } |
| 1630 | } |
| 1631 | |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1632 | template<class LabelType> |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1633 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1634 | LabelType* true_target_in, |
| 1635 | LabelType* false_target_in) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1636 | // Generated branching requires both targets to be explicit. If either of the |
| 1637 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1638 | LabelType fallthrough_target; |
| 1639 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1640 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1641 | |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1642 | LocationSummary* locations = condition->GetLocations(); |
| 1643 | Location left = locations->InAt(0); |
| 1644 | Location right = locations->InAt(1); |
| 1645 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1646 | DataType::Type type = condition->InputAt(0)->GetType(); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1647 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1648 | case DataType::Type::kInt64: |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1649 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1650 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1651 | case DataType::Type::kFloat32: |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1652 | GenerateFPCompare(left, right, condition, false); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1653 | GenerateFPJumps(condition, true_target, false_target); |
| 1654 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1655 | case DataType::Type::kFloat64: |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1656 | GenerateFPCompare(left, right, condition, true); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1657 | GenerateFPJumps(condition, true_target, false_target); |
| 1658 | break; |
| 1659 | default: |
| 1660 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1661 | } |
| 1662 | |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1663 | if (false_target != &fallthrough_target) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1664 | __ jmp(false_target); |
| 1665 | } |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1666 | |
| 1667 | if (fallthrough_target.IsLinked()) { |
| 1668 | __ Bind(&fallthrough_target); |
| 1669 | } |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1670 | } |
| 1671 | |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1672 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1673 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1674 | // are set only strictly before `branch`. We can't use the eflags on long/FP |
| 1675 | // conditions if they are materialized due to the complex branching. |
| 1676 | return cond->IsCondition() && |
| 1677 | cond->GetNext() == branch && |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1678 | cond->InputAt(0)->GetType() != DataType::Type::kInt64 && |
| 1679 | !DataType::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1680 | } |
| 1681 | |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1682 | template<class LabelType> |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1683 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1684 | size_t condition_input_index, |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1685 | LabelType* true_target, |
| 1686 | LabelType* false_target) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1687 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1688 | |
| 1689 | if (true_target == nullptr && false_target == nullptr) { |
| 1690 | // Nothing to do. The code always falls through. |
| 1691 | return; |
| 1692 | } else if (cond->IsIntConstant()) { |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1693 | // Constant condition, statically compared against "true" (integer value 1). |
| 1694 | if (cond->AsIntConstant()->IsTrue()) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1695 | if (true_target != nullptr) { |
| 1696 | __ jmp(true_target); |
| Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1697 | } |
| Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1698 | } else { |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1699 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1700 | if (false_target != nullptr) { |
| 1701 | __ jmp(false_target); |
| 1702 | } |
| 1703 | } |
| 1704 | return; |
| 1705 | } |
| 1706 | |
| 1707 | // The following code generates these patterns: |
| 1708 | // (1) true_target == nullptr && false_target != nullptr |
| 1709 | // - opposite condition true => branch to false_target |
| 1710 | // (2) true_target != nullptr && false_target == nullptr |
| 1711 | // - condition true => branch to true_target |
| 1712 | // (3) true_target != nullptr && false_target != nullptr |
| 1713 | // - condition true => branch to true_target |
| 1714 | // - branch to false_target |
| 1715 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1716 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1717 | if (true_target == nullptr) { |
| 1718 | __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1719 | } else { |
| 1720 | __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); |
| 1721 | } |
| 1722 | } else { |
| 1723 | // Materialized condition, compare against 0. |
| 1724 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1725 | if (lhs.IsRegister()) { |
| 1726 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1727 | } else { |
| 1728 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1729 | } |
| 1730 | if (true_target == nullptr) { |
| 1731 | __ j(kEqual, false_target); |
| 1732 | } else { |
| 1733 | __ j(kNotEqual, true_target); |
| 1734 | } |
| Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1735 | } |
| 1736 | } else { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1737 | // Condition has not been materialized, use its inputs as the comparison and |
| 1738 | // its condition as the branch condition. |
| Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1739 | HCondition* condition = cond->AsCondition(); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1740 | |
| 1741 | // If this is a long or FP comparison that has been folded into |
| 1742 | // the HCondition, generate the comparison directly. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1743 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 1744 | if (type == DataType::Type::kInt64 || DataType::IsFloatingPointType(type)) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1745 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1746 | return; |
| 1747 | } |
| 1748 | |
| 1749 | Location lhs = condition->GetLocations()->InAt(0); |
| 1750 | Location rhs = condition->GetLocations()->InAt(1); |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1751 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition). |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1752 | codegen_->GenerateIntCompare(lhs, rhs); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1753 | if (true_target == nullptr) { |
| 1754 | __ j(X86Condition(condition->GetOppositeCondition()), false_target); |
| 1755 | } else { |
| Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1756 | __ j(X86Condition(condition->GetCondition()), true_target); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1757 | } |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1758 | } |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1759 | |
| 1760 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1761 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1762 | if (true_target != nullptr && false_target != nullptr) { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1763 | __ jmp(false_target); |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1764 | } |
| 1765 | } |
| 1766 | |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1767 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1768 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1769 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1770 | locations->SetInAt(0, Location::Any()); |
| 1771 | } |
| 1772 | } |
| 1773 | |
| 1774 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1775 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1776 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1777 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1778 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1779 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1780 | nullptr : codegen_->GetLabelOf(false_successor); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1781 | GenerateTestAndBranch(if_instr, /* condition_input_index= */ 0, true_target, false_target); |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1782 | } |
| 1783 | |
| 1784 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1785 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1786 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 1787 | InvokeRuntimeCallingConvention calling_convention; |
| 1788 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 1789 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1790 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1791 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1792 | locations->SetInAt(0, Location::Any()); |
| 1793 | } |
| 1794 | } |
| 1795 | |
| 1796 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1797 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86>(deoptimize); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1798 | GenerateTestAndBranch<Label>(deoptimize, |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1799 | /* condition_input_index= */ 0, |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1800 | slow_path->GetEntryLabel(), |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1801 | /* false_target= */ nullptr); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1802 | } |
| 1803 | |
| Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1804 | void LocationsBuilderX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1805 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
| Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1806 | LocationSummary(flag, LocationSummary::kNoCall); |
| 1807 | locations->SetOut(Location::RequiresRegister()); |
| 1808 | } |
| 1809 | |
| 1810 | void InstructionCodeGeneratorX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1811 | __ movl(flag->GetLocations()->Out().AsRegister<Register>(), |
| 1812 | Address(ESP, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1813 | } |
| 1814 | |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1815 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1816 | // There are no conditional move instructions for XMMs. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1817 | if (DataType::IsFloatingPointType(select->GetType())) { |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1818 | return false; |
| 1819 | } |
| 1820 | |
| 1821 | // A FP condition doesn't generate the single CC that we need. |
| 1822 | // In 32 bit mode, a long condition doesn't generate a single CC either. |
| 1823 | HInstruction* condition = select->GetCondition(); |
| 1824 | if (condition->IsCondition()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1825 | DataType::Type compare_type = condition->InputAt(0)->GetType(); |
| 1826 | if (compare_type == DataType::Type::kInt64 || |
| 1827 | DataType::IsFloatingPointType(compare_type)) { |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1828 | return false; |
| 1829 | } |
| 1830 | } |
| 1831 | |
| 1832 | // We can generate a CMOV for this Select. |
| 1833 | return true; |
| 1834 | } |
| 1835 | |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1836 | void LocationsBuilderX86::VisitSelect(HSelect* select) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1837 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1838 | if (DataType::IsFloatingPointType(select->GetType())) { |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1839 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1840 | locations->SetInAt(1, Location::Any()); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1841 | } else { |
| 1842 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1843 | if (SelectCanUseCMOV(select)) { |
| 1844 | if (select->InputAt(1)->IsConstant()) { |
| 1845 | // Cmov can't handle a constant value. |
| 1846 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1847 | } else { |
| 1848 | locations->SetInAt(1, Location::Any()); |
| 1849 | } |
| 1850 | } else { |
| 1851 | locations->SetInAt(1, Location::Any()); |
| 1852 | } |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1853 | } |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1854 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1855 | locations->SetInAt(2, Location::RequiresRegister()); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1856 | } |
| 1857 | locations->SetOut(Location::SameAsFirstInput()); |
| 1858 | } |
| 1859 | |
| 1860 | void InstructionCodeGeneratorX86::VisitSelect(HSelect* select) { |
| 1861 | LocationSummary* locations = select->GetLocations(); |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1862 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1863 | if (SelectCanUseCMOV(select)) { |
| 1864 | // If both the condition and the source types are integer, we can generate |
| 1865 | // a CMOV to implement Select. |
| 1866 | |
| 1867 | HInstruction* select_condition = select->GetCondition(); |
| 1868 | Condition cond = kNotEqual; |
| 1869 | |
| 1870 | // Figure out how to test the 'condition'. |
| 1871 | if (select_condition->IsCondition()) { |
| 1872 | HCondition* condition = select_condition->AsCondition(); |
| 1873 | if (!condition->IsEmittedAtUseSite()) { |
| 1874 | // This was a previously materialized condition. |
| 1875 | // Can we use the existing condition code? |
| 1876 | if (AreEflagsSetFrom(condition, select)) { |
| 1877 | // Materialization was the previous instruction. Condition codes are right. |
| 1878 | cond = X86Condition(condition->GetCondition()); |
| 1879 | } else { |
| 1880 | // No, we have to recreate the condition code. |
| 1881 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1882 | __ testl(cond_reg, cond_reg); |
| 1883 | } |
| 1884 | } else { |
| 1885 | // We can't handle FP or long here. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1886 | DCHECK_NE(condition->InputAt(0)->GetType(), DataType::Type::kInt64); |
| 1887 | DCHECK(!DataType::IsFloatingPointType(condition->InputAt(0)->GetType())); |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1888 | LocationSummary* cond_locations = condition->GetLocations(); |
| Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1889 | codegen_->GenerateIntCompare(cond_locations->InAt(0), cond_locations->InAt(1)); |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1890 | cond = X86Condition(condition->GetCondition()); |
| 1891 | } |
| 1892 | } else { |
| Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 1893 | // Must be a Boolean condition, which needs to be compared to 0. |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1894 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1895 | __ testl(cond_reg, cond_reg); |
| 1896 | } |
| 1897 | |
| 1898 | // If the condition is true, overwrite the output, which already contains false. |
| 1899 | Location false_loc = locations->InAt(0); |
| 1900 | Location true_loc = locations->InAt(1); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1901 | if (select->GetType() == DataType::Type::kInt64) { |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1902 | // 64 bit conditional move. |
| 1903 | Register false_high = false_loc.AsRegisterPairHigh<Register>(); |
| 1904 | Register false_low = false_loc.AsRegisterPairLow<Register>(); |
| 1905 | if (true_loc.IsRegisterPair()) { |
| 1906 | __ cmovl(cond, false_high, true_loc.AsRegisterPairHigh<Register>()); |
| 1907 | __ cmovl(cond, false_low, true_loc.AsRegisterPairLow<Register>()); |
| 1908 | } else { |
| 1909 | __ cmovl(cond, false_high, Address(ESP, true_loc.GetHighStackIndex(kX86WordSize))); |
| 1910 | __ cmovl(cond, false_low, Address(ESP, true_loc.GetStackIndex())); |
| 1911 | } |
| 1912 | } else { |
| 1913 | // 32 bit conditional move. |
| 1914 | Register false_reg = false_loc.AsRegister<Register>(); |
| 1915 | if (true_loc.IsRegister()) { |
| 1916 | __ cmovl(cond, false_reg, true_loc.AsRegister<Register>()); |
| 1917 | } else { |
| 1918 | __ cmovl(cond, false_reg, Address(ESP, true_loc.GetStackIndex())); |
| 1919 | } |
| 1920 | } |
| 1921 | } else { |
| 1922 | NearLabel false_target; |
| 1923 | GenerateTestAndBranch<NearLabel>( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1924 | select, /* condition_input_index= */ 2, /* true_target= */ nullptr, &false_target); |
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1925 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1926 | __ Bind(&false_target); |
| 1927 | } |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1928 | } |
| 1929 | |
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1930 | void LocationsBuilderX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1931 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1932 | } |
| 1933 | |
| David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1934 | void InstructionCodeGeneratorX86::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1935 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
| David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1936 | } |
| 1937 | |
| 1938 | void CodeGeneratorX86::GenerateNop() { |
| 1939 | __ nop(); |
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1940 | } |
| 1941 | |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1942 | void LocationsBuilderX86::HandleCondition(HCondition* cond) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1943 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1944 | new (GetGraph()->GetAllocator()) LocationSummary(cond, LocationSummary::kNoCall); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1945 | // Handle the long/FP comparisons made in instruction simplification. |
| 1946 | switch (cond->InputAt(0)->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1947 | case DataType::Type::kInt64: { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1948 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1949 | locations->SetInAt(1, Location::Any()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1950 | if (!cond->IsEmittedAtUseSite()) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1951 | locations->SetOut(Location::RequiresRegister()); |
| 1952 | } |
| 1953 | break; |
| 1954 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1955 | case DataType::Type::kFloat32: |
| 1956 | case DataType::Type::kFloat64: { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1957 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1958 | if (cond->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 1959 | DCHECK(cond->InputAt(1)->IsEmittedAtUseSite()); |
| 1960 | } else if (cond->InputAt(1)->IsConstant()) { |
| 1961 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1962 | } else { |
| 1963 | locations->SetInAt(1, Location::Any()); |
| 1964 | } |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1965 | if (!cond->IsEmittedAtUseSite()) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1966 | locations->SetOut(Location::RequiresRegister()); |
| 1967 | } |
| 1968 | break; |
| 1969 | } |
| 1970 | default: |
| 1971 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1972 | locations->SetInAt(1, Location::Any()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1973 | if (!cond->IsEmittedAtUseSite()) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1974 | // We need a byte register. |
| 1975 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1976 | } |
| 1977 | break; |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1978 | } |
| Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1979 | } |
| 1980 | |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1981 | void InstructionCodeGeneratorX86::HandleCondition(HCondition* cond) { |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1982 | if (cond->IsEmittedAtUseSite()) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1983 | return; |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1984 | } |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1985 | |
| 1986 | LocationSummary* locations = cond->GetLocations(); |
| 1987 | Location lhs = locations->InAt(0); |
| 1988 | Location rhs = locations->InAt(1); |
| 1989 | Register reg = locations->Out().AsRegister<Register>(); |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1990 | NearLabel true_label, false_label; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1991 | |
| 1992 | switch (cond->InputAt(0)->GetType()) { |
| 1993 | default: { |
| 1994 | // Integer case. |
| 1995 | |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 1996 | // Clear output register: setb only sets the low byte. |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1997 | __ xorl(reg, reg); |
| Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1998 | codegen_->GenerateIntCompare(lhs, rhs); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1999 | __ setb(X86Condition(cond->GetCondition()), reg); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2000 | return; |
| 2001 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2002 | case DataType::Type::kInt64: |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2003 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 2004 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2005 | case DataType::Type::kFloat32: |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2006 | GenerateFPCompare(lhs, rhs, cond, false); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2007 | GenerateFPJumps(cond, &true_label, &false_label); |
| 2008 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2009 | case DataType::Type::kFloat64: |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2010 | GenerateFPCompare(lhs, rhs, cond, true); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2011 | GenerateFPJumps(cond, &true_label, &false_label); |
| 2012 | break; |
| 2013 | } |
| 2014 | |
| 2015 | // Convert the jumps into the result. |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2016 | NearLabel done_label; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2017 | |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2018 | // False case: result = 0. |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2019 | __ Bind(&false_label); |
| 2020 | __ xorl(reg, reg); |
| 2021 | __ jmp(&done_label); |
| 2022 | |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2023 | // True case: result = 1. |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2024 | __ Bind(&true_label); |
| 2025 | __ movl(reg, Immediate(1)); |
| 2026 | __ Bind(&done_label); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2027 | } |
| 2028 | |
| 2029 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2030 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2031 | } |
| 2032 | |
| 2033 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2034 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2035 | } |
| 2036 | |
| 2037 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2038 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2039 | } |
| 2040 | |
| 2041 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2042 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2043 | } |
| 2044 | |
| 2045 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2046 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2047 | } |
| 2048 | |
| 2049 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2050 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2051 | } |
| 2052 | |
| 2053 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2054 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2055 | } |
| 2056 | |
| 2057 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2058 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2059 | } |
| 2060 | |
| 2061 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2062 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2063 | } |
| 2064 | |
| 2065 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2066 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2067 | } |
| 2068 | |
| 2069 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2070 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2071 | } |
| 2072 | |
| 2073 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2074 | HandleCondition(comp); |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2075 | } |
| 2076 | |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2077 | void LocationsBuilderX86::VisitBelow(HBelow* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2078 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2079 | } |
| 2080 | |
| 2081 | void InstructionCodeGeneratorX86::VisitBelow(HBelow* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2082 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2083 | } |
| 2084 | |
| 2085 | void LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2086 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2087 | } |
| 2088 | |
| 2089 | void InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2090 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2091 | } |
| 2092 | |
| 2093 | void LocationsBuilderX86::VisitAbove(HAbove* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2094 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2095 | } |
| 2096 | |
| 2097 | void InstructionCodeGeneratorX86::VisitAbove(HAbove* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2098 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2099 | } |
| 2100 | |
| 2101 | void LocationsBuilderX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2102 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2103 | } |
| 2104 | |
| 2105 | void InstructionCodeGeneratorX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2106 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2107 | } |
| 2108 | |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2109 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2110 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2111 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2112 | locations->SetOut(Location::ConstantLocation(constant)); |
| Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2113 | } |
| 2114 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2115 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2116 | // Will be generated at use site. |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2117 | } |
| 2118 | |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2119 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 2120 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2121 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2122 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2123 | } |
| 2124 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2125 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2126 | // Will be generated at use site. |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2127 | } |
| 2128 | |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2129 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2130 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2131 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2132 | locations->SetOut(Location::ConstantLocation(constant)); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2133 | } |
| 2134 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2135 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2136 | // Will be generated at use site. |
| 2137 | } |
| 2138 | |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2139 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 2140 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2141 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2142 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2143 | } |
| 2144 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2145 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2146 | // Will be generated at use site. |
| 2147 | } |
| 2148 | |
| 2149 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2150 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2151 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2152 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2153 | } |
| 2154 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2155 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2156 | // Will be generated at use site. |
| 2157 | } |
| 2158 | |
| Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2159 | void LocationsBuilderX86::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 2160 | constructor_fence->SetLocations(nullptr); |
| 2161 | } |
| 2162 | |
| 2163 | void InstructionCodeGeneratorX86::VisitConstructorFence( |
| 2164 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 2165 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 2166 | } |
| 2167 | |
| Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2168 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2169 | memory_barrier->SetLocations(nullptr); |
| 2170 | } |
| 2171 | |
| 2172 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 2173 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2174 | } |
| 2175 | |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2176 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2177 | ret->SetLocations(nullptr); |
| Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2178 | } |
| 2179 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2180 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2181 | codegen_->GenerateFrameExit(); |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2182 | } |
| 2183 | |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2184 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2185 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2186 | new (GetGraph()->GetAllocator()) LocationSummary(ret, LocationSummary::kNoCall); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2187 | switch (ret->InputAt(0)->GetType()) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2188 | case DataType::Type::kReference: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2189 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2190 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2191 | case DataType::Type::kInt8: |
| 2192 | case DataType::Type::kUint16: |
| 2193 | case DataType::Type::kInt16: |
| 2194 | case DataType::Type::kInt32: |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2195 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2196 | break; |
| 2197 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2198 | case DataType::Type::kInt64: |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2199 | locations->SetInAt( |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2200 | 0, Location::RegisterPairLocation(EAX, EDX)); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2201 | break; |
| 2202 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2203 | case DataType::Type::kFloat32: |
| 2204 | case DataType::Type::kFloat64: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2205 | locations->SetInAt( |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2206 | 0, Location::FpuRegisterLocation(XMM0)); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2207 | break; |
| 2208 | |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2209 | default: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2210 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2211 | } |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2212 | } |
| 2213 | |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2214 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2215 | if (kIsDebugBuild) { |
| 2216 | switch (ret->InputAt(0)->GetType()) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2217 | case DataType::Type::kReference: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2218 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2219 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2220 | case DataType::Type::kInt8: |
| 2221 | case DataType::Type::kUint16: |
| 2222 | case DataType::Type::kInt16: |
| 2223 | case DataType::Type::kInt32: |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2224 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2225 | break; |
| 2226 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2227 | case DataType::Type::kInt64: |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2228 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 2229 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2230 | break; |
| 2231 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2232 | case DataType::Type::kFloat32: |
| 2233 | case DataType::Type::kFloat64: |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2234 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2235 | break; |
| 2236 | |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2237 | default: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2238 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2239 | } |
| 2240 | } |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2241 | codegen_->GenerateFrameExit(); |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2242 | } |
| 2243 | |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2244 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2245 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2246 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2247 | // the method_idx. |
| 2248 | HandleInvoke(invoke); |
| 2249 | } |
| 2250 | |
| 2251 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2252 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2253 | } |
| 2254 | |
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2255 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2256 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2257 | // art::PrepareForRegisterAllocation. |
| 2258 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2259 | |
| Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2260 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2261 | if (intrinsic.TryDispatch(invoke)) { |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 2262 | if (invoke->GetLocations()->CanCall() && |
| 2263 | invoke->HasPcRelativeMethodLoadKind() && |
| 2264 | invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()).IsInvalid()) { |
| Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 2265 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2266 | } |
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2267 | return; |
| 2268 | } |
| 2269 | |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2270 | HandleInvoke(invoke); |
| Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2271 | |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2272 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 2273 | if (invoke->HasPcRelativeMethodLoadKind()) { |
| Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2274 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2275 | } |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2276 | } |
| 2277 | |
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2278 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 2279 | if (invoke->GetLocations()->Intrinsified()) { |
| 2280 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 2281 | intrinsic.Dispatch(invoke); |
| 2282 | return true; |
| 2283 | } |
| 2284 | return false; |
| 2285 | } |
| 2286 | |
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2287 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2288 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2289 | // art::PrepareForRegisterAllocation. |
| 2290 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2291 | |
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2292 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2293 | return; |
| Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2294 | } |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2295 | |
| Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2296 | LocationSummary* locations = invoke->GetLocations(); |
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2297 | codegen_->GenerateStaticOrDirectCall( |
| Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2298 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2299 | } |
| 2300 | |
| 2301 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 2302 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 2303 | if (intrinsic.TryDispatch(invoke)) { |
| 2304 | return; |
| 2305 | } |
| 2306 | |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2307 | HandleInvoke(invoke); |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2308 | if (codegen_->GetCompilerOptions().IsBaseline() && !Runtime::Current()->IsAotCompiler()) { |
| 2309 | // Add one temporary for inline cache update. |
| 2310 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(EBP)); |
| 2311 | } |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2312 | } |
| 2313 | |
| 2314 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2315 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2316 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2317 | } |
| 2318 | |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2319 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2320 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2321 | return; |
| 2322 | } |
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2323 | |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2324 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2325 | DCHECK(!codegen_->IsLeafMethod()); |
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2326 | } |
| 2327 | |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2328 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2329 | // This call to HandleInvoke allocates a temporary (core) register |
| 2330 | // which is also used to transfer the hidden argument from FP to |
| 2331 | // core register. |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2332 | HandleInvoke(invoke); |
| 2333 | // Add the hidden argument. |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2334 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2335 | |
| 2336 | if (codegen_->GetCompilerOptions().IsBaseline() && !Runtime::Current()->IsAotCompiler()) { |
| 2337 | // Add one temporary for inline cache update. |
| 2338 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(EBP)); |
| 2339 | } |
| 2340 | } |
| 2341 | |
| 2342 | void CodeGeneratorX86::MaybeGenerateInlineCacheCheck(HInstruction* instruction, Register klass) { |
| 2343 | DCHECK_EQ(EAX, klass); |
| Nicolas Geoffray | 17a39ba | 2019-11-27 20:57:48 +0000 | [diff] [blame] | 2344 | // We know the destination of an intrinsic, so no need to record inline |
| 2345 | // caches (also the intrinsic location builder doesn't request an additional |
| 2346 | // temporary). |
| 2347 | if (!instruction->GetLocations()->Intrinsified() && |
| 2348 | GetCompilerOptions().IsBaseline() && |
| 2349 | !Runtime::Current()->IsAotCompiler()) { |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2350 | DCHECK(!instruction->GetEnvironment()->IsFromInlinedInvoke()); |
| 2351 | ScopedObjectAccess soa(Thread::Current()); |
| 2352 | ProfilingInfo* info = GetGraph()->GetArtMethod()->GetProfilingInfo(kRuntimePointerSize); |
| 2353 | InlineCache* cache = info->GetInlineCache(instruction->GetDexPc()); |
| 2354 | uint32_t address = reinterpret_cast32<uint32_t>(cache); |
| 2355 | if (kIsDebugBuild) { |
| 2356 | uint32_t temp_index = instruction->GetLocations()->GetTempCount() - 1u; |
| 2357 | CHECK_EQ(EBP, instruction->GetLocations()->GetTemp(temp_index).AsRegister<Register>()); |
| 2358 | } |
| 2359 | Register temp = EBP; |
| 2360 | NearLabel done; |
| 2361 | __ movl(temp, Immediate(address)); |
| 2362 | // Fast path for a monomorphic cache. |
| 2363 | __ cmpl(klass, Address(temp, InlineCache::ClassesOffset().Int32Value())); |
| 2364 | __ j(kEqual, &done); |
| 2365 | GenerateInvokeRuntime(GetThreadOffset<kX86PointerSize>(kQuickUpdateInlineCache).Int32Value()); |
| 2366 | __ Bind(&done); |
| 2367 | } |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2368 | } |
| 2369 | |
| 2370 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2371 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2372 | LocationSummary* locations = invoke->GetLocations(); |
| 2373 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2374 | XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2375 | Location receiver = locations->InAt(0); |
| 2376 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2377 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2378 | // Set the hidden argument. This is safe to do this here, as XMM7 |
| 2379 | // won't be modified thereafter, before the `call` instruction. |
| 2380 | DCHECK_EQ(XMM7, hidden_reg); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2381 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2382 | __ movd(hidden_reg, temp); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2383 | |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2384 | if (receiver.IsStackSlot()) { |
| 2385 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2386 | // /* HeapReference<Class> */ temp = temp->klass_ |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2387 | __ movl(temp, Address(temp, class_offset)); |
| 2388 | } else { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2389 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2390 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2391 | } |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2392 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2393 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2394 | // emit a read barrier for the previous class reference load. |
| 2395 | // However this is not required in practice, as this is an |
| 2396 | // intermediate/temporary reference and because the current |
| 2397 | // concurrent copying collector keeps the from-space memory |
| 2398 | // intact/accessible until the end of the marking phase (the |
| 2399 | // concurrent copying collector may not in the future). |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2400 | __ MaybeUnpoisonHeapReference(temp); |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2401 | |
| 2402 | codegen_->MaybeGenerateInlineCacheCheck(invoke, temp); |
| 2403 | |
| Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2404 | // temp = temp->GetAddressOfIMT() |
| 2405 | __ movl(temp, |
| 2406 | Address(temp, mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2407 | // temp = temp->GetImtEntryAt(method_offset); |
| Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2408 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2409 | invoke->GetImtIndex(), kX86PointerSize)); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2410 | __ movl(temp, Address(temp, method_offset)); |
| 2411 | // call temp->GetEntryPoint(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2412 | __ call(Address(temp, |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2413 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2414 | |
| 2415 | DCHECK(!codegen_->IsLeafMethod()); |
| 2416 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2417 | } |
| 2418 | |
| Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2419 | void LocationsBuilderX86::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2420 | HandleInvoke(invoke); |
| 2421 | } |
| 2422 | |
| 2423 | void InstructionCodeGeneratorX86::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2424 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 2425 | } |
| 2426 | |
| Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 2427 | void LocationsBuilderX86::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 2428 | HandleInvoke(invoke); |
| 2429 | } |
| 2430 | |
| 2431 | void InstructionCodeGeneratorX86::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 2432 | codegen_->GenerateInvokeCustomCall(invoke); |
| 2433 | } |
| 2434 | |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2435 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 2436 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2437 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2438 | switch (neg->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2439 | case DataType::Type::kInt32: |
| 2440 | case DataType::Type::kInt64: |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2441 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2442 | locations->SetOut(Location::SameAsFirstInput()); |
| 2443 | break; |
| 2444 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2445 | case DataType::Type::kFloat32: |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2446 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2447 | locations->SetOut(Location::SameAsFirstInput()); |
| 2448 | locations->AddTemp(Location::RequiresRegister()); |
| 2449 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2450 | break; |
| 2451 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2452 | case DataType::Type::kFloat64: |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2453 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2454 | locations->SetOut(Location::SameAsFirstInput()); |
| 2455 | locations->AddTemp(Location::RequiresFpuRegister()); |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2456 | break; |
| 2457 | |
| 2458 | default: |
| 2459 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2460 | } |
| 2461 | } |
| 2462 | |
| 2463 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 2464 | LocationSummary* locations = neg->GetLocations(); |
| 2465 | Location out = locations->Out(); |
| 2466 | Location in = locations->InAt(0); |
| 2467 | switch (neg->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2468 | case DataType::Type::kInt32: |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2469 | DCHECK(in.IsRegister()); |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2470 | DCHECK(in.Equals(out)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2471 | __ negl(out.AsRegister<Register>()); |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2472 | break; |
| 2473 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2474 | case DataType::Type::kInt64: |
| Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2475 | DCHECK(in.IsRegisterPair()); |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2476 | DCHECK(in.Equals(out)); |
| Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2477 | __ negl(out.AsRegisterPairLow<Register>()); |
| 2478 | // Negation is similar to subtraction from zero. The least |
| 2479 | // significant byte triggers a borrow when it is different from |
| 2480 | // zero; to take it into account, add 1 to the most significant |
| 2481 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 2482 | // operation. |
| 2483 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2484 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 2485 | break; |
| 2486 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2487 | case DataType::Type::kFloat32: { |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2488 | DCHECK(in.Equals(out)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2489 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 2490 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2491 | // Implement float negation with an exclusive or with value |
| 2492 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2493 | // single-precision floating-point number). |
| 2494 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 2495 | __ movd(mask, constant); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2496 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2497 | break; |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2498 | } |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2499 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2500 | case DataType::Type::kFloat64: { |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2501 | DCHECK(in.Equals(out)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2502 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2503 | // Implement double negation with an exclusive or with value |
| 2504 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 2505 | // a double-precision floating-point number). |
| 2506 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2507 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2508 | break; |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2509 | } |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2510 | |
| 2511 | default: |
| 2512 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2513 | } |
| 2514 | } |
| 2515 | |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2516 | void LocationsBuilderX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2517 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2518 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2519 | DCHECK(DataType::IsFloatingPointType(neg->GetType())); |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2520 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2521 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2522 | locations->SetOut(Location::SameAsFirstInput()); |
| 2523 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2524 | } |
| 2525 | |
| 2526 | void InstructionCodeGeneratorX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2527 | LocationSummary* locations = neg->GetLocations(); |
| 2528 | Location out = locations->Out(); |
| 2529 | DCHECK(locations->InAt(0).Equals(out)); |
| 2530 | |
| 2531 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 2532 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2533 | if (neg->GetType() == DataType::Type::kFloat32) { |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 2534 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x80000000), |
| 2535 | neg->GetBaseMethodAddress(), |
| 2536 | constant_area)); |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2537 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| 2538 | } else { |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 2539 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000), |
| 2540 | neg->GetBaseMethodAddress(), |
| 2541 | constant_area)); |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2542 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| 2543 | } |
| 2544 | } |
| 2545 | |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2546 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2547 | DataType::Type result_type = conversion->GetResultType(); |
| 2548 | DataType::Type input_type = conversion->GetInputType(); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2549 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 2550 | << input_type << " -> " << result_type; |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2551 | |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2552 | // The float-to-long and double-to-long type conversions rely on a |
| 2553 | // call to the runtime. |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2554 | LocationSummary::CallKind call_kind = |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2555 | ((input_type == DataType::Type::kFloat32 || input_type == DataType::Type::kFloat64) |
| 2556 | && result_type == DataType::Type::kInt64) |
| Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2557 | ? LocationSummary::kCallOnMainOnly |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2558 | : LocationSummary::kNoCall; |
| 2559 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2560 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, call_kind); |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2561 | |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2562 | switch (result_type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2563 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2564 | case DataType::Type::kInt8: |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2565 | switch (input_type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2566 | case DataType::Type::kUint8: |
| 2567 | case DataType::Type::kInt8: |
| 2568 | case DataType::Type::kUint16: |
| 2569 | case DataType::Type::kInt16: |
| 2570 | case DataType::Type::kInt32: |
| 2571 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 2572 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2573 | // the validation of the linear scan implementation |
| 2574 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2575 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2576 | case DataType::Type::kInt64: { |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2577 | HInstruction* input = conversion->InputAt(0); |
| 2578 | Location input_location = input->IsConstant() |
| 2579 | ? Location::ConstantLocation(input->AsConstant()) |
| 2580 | : Location::RegisterPairLocation(EAX, EDX); |
| 2581 | locations->SetInAt(0, input_location); |
| 2582 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2583 | // the validation of the linear scan implementation |
| 2584 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2585 | break; |
| 2586 | } |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2587 | |
| 2588 | default: |
| 2589 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2590 | << " to " << result_type; |
| 2591 | } |
| 2592 | break; |
| 2593 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2594 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2595 | case DataType::Type::kInt16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2596 | DCHECK(DataType::IsIntegralType(input_type)) << input_type; |
| 2597 | locations->SetInAt(0, Location::Any()); |
| 2598 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2599 | break; |
| 2600 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2601 | case DataType::Type::kInt32: |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2602 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2603 | case DataType::Type::kInt64: |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2604 | locations->SetInAt(0, Location::Any()); |
| 2605 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2606 | break; |
| 2607 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2608 | case DataType::Type::kFloat32: |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2609 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2610 | locations->SetOut(Location::RequiresRegister()); |
| 2611 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2612 | break; |
| 2613 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2614 | case DataType::Type::kFloat64: |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2615 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2616 | locations->SetOut(Location::RequiresRegister()); |
| 2617 | locations->AddTemp(Location::RequiresFpuRegister()); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2618 | break; |
| 2619 | |
| 2620 | default: |
| 2621 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2622 | << " to " << result_type; |
| 2623 | } |
| 2624 | break; |
| 2625 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2626 | case DataType::Type::kInt64: |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2627 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2628 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2629 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2630 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2631 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2632 | case DataType::Type::kInt16: |
| 2633 | case DataType::Type::kInt32: |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2634 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 2635 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2636 | break; |
| 2637 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2638 | case DataType::Type::kFloat32: |
| 2639 | case DataType::Type::kFloat64: { |
| Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2640 | InvokeRuntimeCallingConvention calling_convention; |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2641 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 2642 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 2643 | |
| Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2644 | // The runtime helper puts the result in EAX, EDX. |
| 2645 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2646 | } |
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2647 | break; |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2648 | |
| 2649 | default: |
| 2650 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2651 | << " to " << result_type; |
| 2652 | } |
| 2653 | break; |
| 2654 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2655 | case DataType::Type::kFloat32: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2656 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2657 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2658 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2659 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2660 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2661 | case DataType::Type::kInt16: |
| 2662 | case DataType::Type::kInt32: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2663 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2664 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2665 | break; |
| 2666 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2667 | case DataType::Type::kInt64: |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2668 | locations->SetInAt(0, Location::Any()); |
| 2669 | locations->SetOut(Location::Any()); |
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2670 | break; |
| 2671 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2672 | case DataType::Type::kFloat64: |
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2673 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2674 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2675 | break; |
| 2676 | |
| 2677 | default: |
| 2678 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2679 | << " to " << result_type; |
| Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 2680 | } |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2681 | break; |
| 2682 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2683 | case DataType::Type::kFloat64: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2684 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2685 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2686 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2687 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2688 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2689 | case DataType::Type::kInt16: |
| 2690 | case DataType::Type::kInt32: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2691 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2692 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2693 | break; |
| 2694 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2695 | case DataType::Type::kInt64: |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2696 | locations->SetInAt(0, Location::Any()); |
| 2697 | locations->SetOut(Location::Any()); |
| Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2698 | break; |
| 2699 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2700 | case DataType::Type::kFloat32: |
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2701 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2702 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2703 | break; |
| 2704 | |
| 2705 | default: |
| 2706 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2707 | << " to " << result_type; |
| 2708 | } |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2709 | break; |
| 2710 | |
| 2711 | default: |
| 2712 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2713 | << " to " << result_type; |
| 2714 | } |
| 2715 | } |
| 2716 | |
| 2717 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 2718 | LocationSummary* locations = conversion->GetLocations(); |
| 2719 | Location out = locations->Out(); |
| 2720 | Location in = locations->InAt(0); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2721 | DataType::Type result_type = conversion->GetResultType(); |
| 2722 | DataType::Type input_type = conversion->GetInputType(); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2723 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 2724 | << input_type << " -> " << result_type; |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2725 | switch (result_type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2726 | case DataType::Type::kUint8: |
| 2727 | switch (input_type) { |
| 2728 | case DataType::Type::kInt8: |
| 2729 | case DataType::Type::kUint16: |
| 2730 | case DataType::Type::kInt16: |
| 2731 | case DataType::Type::kInt32: |
| 2732 | if (in.IsRegister()) { |
| 2733 | __ movzxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
| 2734 | } else { |
| 2735 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2736 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2737 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint8_t>(value))); |
| 2738 | } |
| 2739 | break; |
| 2740 | case DataType::Type::kInt64: |
| 2741 | if (in.IsRegisterPair()) { |
| 2742 | __ movzxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 2743 | } else { |
| 2744 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2745 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2746 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint8_t>(value))); |
| 2747 | } |
| 2748 | break; |
| 2749 | |
| 2750 | default: |
| 2751 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2752 | << " to " << result_type; |
| 2753 | } |
| 2754 | break; |
| 2755 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2756 | case DataType::Type::kInt8: |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2757 | switch (input_type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2758 | case DataType::Type::kUint8: |
| 2759 | case DataType::Type::kUint16: |
| 2760 | case DataType::Type::kInt16: |
| 2761 | case DataType::Type::kInt32: |
| 2762 | if (in.IsRegister()) { |
| 2763 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
| 2764 | } else { |
| 2765 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2766 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2767 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2768 | } |
| 2769 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2770 | case DataType::Type::kInt64: |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2771 | if (in.IsRegisterPair()) { |
| 2772 | __ movsxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 2773 | } else { |
| 2774 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2775 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2776 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2777 | } |
| 2778 | break; |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2779 | |
| 2780 | default: |
| 2781 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2782 | << " to " << result_type; |
| 2783 | } |
| 2784 | break; |
| 2785 | |
| 2786 | case DataType::Type::kUint16: |
| 2787 | switch (input_type) { |
| 2788 | case DataType::Type::kInt8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2789 | case DataType::Type::kInt16: |
| 2790 | case DataType::Type::kInt32: |
| Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2791 | if (in.IsRegister()) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2792 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
| 2793 | } else if (in.IsStackSlot()) { |
| 2794 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2795 | } else { |
| 2796 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2797 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2798 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
| 2799 | } |
| 2800 | break; |
| 2801 | case DataType::Type::kInt64: |
| 2802 | if (in.IsRegisterPair()) { |
| 2803 | __ movzxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2804 | } else if (in.IsDoubleStackSlot()) { |
| 2805 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2806 | } else { |
| 2807 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2808 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2809 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
| Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2810 | } |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2811 | break; |
| 2812 | |
| 2813 | default: |
| 2814 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2815 | << " to " << result_type; |
| 2816 | } |
| 2817 | break; |
| 2818 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2819 | case DataType::Type::kInt16: |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2820 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2821 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2822 | case DataType::Type::kInt32: |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2823 | if (in.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2824 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2825 | } else if (in.IsStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2826 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2827 | } else { |
| 2828 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2829 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2830 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2831 | } |
| 2832 | break; |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2833 | case DataType::Type::kInt64: |
| 2834 | if (in.IsRegisterPair()) { |
| 2835 | __ movsxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2836 | } else if (in.IsDoubleStackSlot()) { |
| 2837 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2838 | } else { |
| 2839 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2840 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2841 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
| 2842 | } |
| 2843 | break; |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2844 | |
| 2845 | default: |
| 2846 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2847 | << " to " << result_type; |
| 2848 | } |
| 2849 | break; |
| 2850 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2851 | case DataType::Type::kInt32: |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2852 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2853 | case DataType::Type::kInt64: |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2854 | if (in.IsRegisterPair()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2855 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2856 | } else if (in.IsDoubleStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2857 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2858 | } else { |
| 2859 | DCHECK(in.IsConstant()); |
| 2860 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2861 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2862 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2863 | } |
| 2864 | break; |
| 2865 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2866 | case DataType::Type::kFloat32: { |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2867 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2868 | Register output = out.AsRegister<Register>(); |
| 2869 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2870 | NearLabel done, nan; |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2871 | |
| 2872 | __ movl(output, Immediate(kPrimIntMax)); |
| 2873 | // temp = int-to-float(output) |
| 2874 | __ cvtsi2ss(temp, output); |
| 2875 | // if input >= temp goto done |
| 2876 | __ comiss(input, temp); |
| 2877 | __ j(kAboveEqual, &done); |
| 2878 | // if input == NaN goto nan |
| 2879 | __ j(kUnordered, &nan); |
| 2880 | // output = float-to-int-truncate(input) |
| 2881 | __ cvttss2si(output, input); |
| 2882 | __ jmp(&done); |
| 2883 | __ Bind(&nan); |
| 2884 | // output = 0 |
| 2885 | __ xorl(output, output); |
| 2886 | __ Bind(&done); |
| 2887 | break; |
| 2888 | } |
| 2889 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2890 | case DataType::Type::kFloat64: { |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2891 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2892 | Register output = out.AsRegister<Register>(); |
| 2893 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2894 | NearLabel done, nan; |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2895 | |
| 2896 | __ movl(output, Immediate(kPrimIntMax)); |
| 2897 | // temp = int-to-double(output) |
| 2898 | __ cvtsi2sd(temp, output); |
| 2899 | // if input >= temp goto done |
| 2900 | __ comisd(input, temp); |
| 2901 | __ j(kAboveEqual, &done); |
| 2902 | // if input == NaN goto nan |
| 2903 | __ j(kUnordered, &nan); |
| 2904 | // output = double-to-int-truncate(input) |
| 2905 | __ cvttsd2si(output, input); |
| 2906 | __ jmp(&done); |
| 2907 | __ Bind(&nan); |
| 2908 | // output = 0 |
| 2909 | __ xorl(output, output); |
| 2910 | __ Bind(&done); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2911 | break; |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2912 | } |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2913 | |
| 2914 | default: |
| 2915 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2916 | << " to " << result_type; |
| 2917 | } |
| 2918 | break; |
| 2919 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2920 | case DataType::Type::kInt64: |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2921 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2922 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2923 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2924 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2925 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2926 | case DataType::Type::kInt16: |
| 2927 | case DataType::Type::kInt32: |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2928 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2929 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2930 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2931 | __ cdq(); |
| 2932 | break; |
| 2933 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2934 | case DataType::Type::kFloat32: |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2935 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2936 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2937 | break; |
| 2938 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2939 | case DataType::Type::kFloat64: |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2940 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2941 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2942 | break; |
| 2943 | |
| 2944 | default: |
| 2945 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2946 | << " to " << result_type; |
| 2947 | } |
| 2948 | break; |
| 2949 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2950 | case DataType::Type::kFloat32: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2951 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2952 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2953 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2954 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2955 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2956 | case DataType::Type::kInt16: |
| 2957 | case DataType::Type::kInt32: |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2958 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2959 | break; |
| 2960 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2961 | case DataType::Type::kInt64: { |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2962 | size_t adjustment = 0; |
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2963 | |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2964 | // Create stack space for the call to |
| 2965 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2966 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2967 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2968 | adjustment = DataType::Size(DataType::Type::kInt64); |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2969 | __ subl(ESP, Immediate(adjustment)); |
| 2970 | } |
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2971 | |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2972 | // Load the value to the FP stack, using temporaries if needed. |
| 2973 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2974 | |
| 2975 | if (out.IsStackSlot()) { |
| 2976 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2977 | } else { |
| 2978 | __ fstps(Address(ESP, 0)); |
| 2979 | Location stack_temp = Location::StackSlot(0); |
| 2980 | codegen_->Move32(out, stack_temp); |
| 2981 | } |
| 2982 | |
| 2983 | // Remove the temporary stack space we allocated. |
| 2984 | if (adjustment != 0) { |
| 2985 | __ addl(ESP, Immediate(adjustment)); |
| 2986 | } |
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2987 | break; |
| 2988 | } |
| 2989 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2990 | case DataType::Type::kFloat64: |
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2991 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2992 | break; |
| 2993 | |
| 2994 | default: |
| 2995 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2996 | << " to " << result_type; |
| Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 2997 | } |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2998 | break; |
| 2999 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3000 | case DataType::Type::kFloat64: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3001 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3002 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3003 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3004 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3005 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3006 | case DataType::Type::kInt16: |
| 3007 | case DataType::Type::kInt32: |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3008 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3009 | break; |
| 3010 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3011 | case DataType::Type::kInt64: { |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3012 | size_t adjustment = 0; |
| Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3013 | |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3014 | // Create stack space for the call to |
| 3015 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 3016 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3017 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3018 | adjustment = DataType::Size(DataType::Type::kInt64); |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3019 | __ subl(ESP, Immediate(adjustment)); |
| 3020 | } |
| 3021 | |
| 3022 | // Load the value to the FP stack, using temporaries if needed. |
| 3023 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 3024 | |
| 3025 | if (out.IsDoubleStackSlot()) { |
| 3026 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 3027 | } else { |
| 3028 | __ fstpl(Address(ESP, 0)); |
| 3029 | Location stack_temp = Location::DoubleStackSlot(0); |
| 3030 | codegen_->Move64(out, stack_temp); |
| 3031 | } |
| 3032 | |
| 3033 | // Remove the temporary stack space we allocated. |
| 3034 | if (adjustment != 0) { |
| 3035 | __ addl(ESP, Immediate(adjustment)); |
| 3036 | } |
| Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3037 | break; |
| 3038 | } |
| 3039 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3040 | case DataType::Type::kFloat32: |
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3041 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3042 | break; |
| 3043 | |
| 3044 | default: |
| 3045 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3046 | << " to " << result_type; |
| Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3047 | } |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3048 | break; |
| 3049 | |
| 3050 | default: |
| 3051 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3052 | << " to " << result_type; |
| 3053 | } |
| 3054 | } |
| 3055 | |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3056 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3057 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3058 | new (GetGraph()->GetAllocator()) LocationSummary(add, LocationSummary::kNoCall); |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3059 | switch (add->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3060 | case DataType::Type::kInt32: { |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3061 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3062 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 3063 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3064 | break; |
| 3065 | } |
| 3066 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3067 | case DataType::Type::kInt64: { |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3068 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3069 | locations->SetInAt(1, Location::Any()); |
| 3070 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3071 | break; |
| 3072 | } |
| 3073 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3074 | case DataType::Type::kFloat32: |
| 3075 | case DataType::Type::kFloat64: { |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3076 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3077 | if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3078 | DCHECK(add->InputAt(1)->IsEmittedAtUseSite()); |
| Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3079 | } else if (add->InputAt(1)->IsConstant()) { |
| 3080 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3081 | } else { |
| 3082 | locations->SetInAt(1, Location::Any()); |
| 3083 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3084 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3085 | break; |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3086 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3087 | |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3088 | default: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3089 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 3090 | UNREACHABLE(); |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3091 | } |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3092 | } |
| 3093 | |
| 3094 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 3095 | LocationSummary* locations = add->GetLocations(); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3096 | Location first = locations->InAt(0); |
| 3097 | Location second = locations->InAt(1); |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3098 | Location out = locations->Out(); |
| 3099 | |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3100 | switch (add->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3101 | case DataType::Type::kInt32: { |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3102 | if (second.IsRegister()) { |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3103 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3104 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
| Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 3105 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 3106 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3107 | } else { |
| 3108 | __ leal(out.AsRegister<Register>(), Address( |
| 3109 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 3110 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3111 | } else if (second.IsConstant()) { |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3112 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3113 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3114 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 3115 | } else { |
| 3116 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 3117 | } |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3118 | } else { |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3119 | DCHECK(first.Equals(locations->Out())); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3120 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3121 | } |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3122 | break; |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3123 | } |
| 3124 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3125 | case DataType::Type::kInt64: { |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3126 | if (second.IsRegisterPair()) { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3127 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3128 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3129 | } else if (second.IsDoubleStackSlot()) { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3130 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 3131 | __ adcl(first.AsRegisterPairHigh<Register>(), |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3132 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3133 | } else { |
| 3134 | DCHECK(second.IsConstant()) << second; |
| 3135 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3136 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 3137 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3138 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3139 | break; |
| 3140 | } |
| 3141 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3142 | case DataType::Type::kFloat32: { |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3143 | if (second.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3144 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3145 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3146 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3147 | DCHECK(const_area->IsEmittedAtUseSite()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3148 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 3149 | codegen_->LiteralFloatAddress( |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3150 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3151 | const_area->GetBaseMethodAddress(), |
| 3152 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3153 | } else { |
| 3154 | DCHECK(second.IsStackSlot()); |
| 3155 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3156 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3157 | break; |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3158 | } |
| 3159 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3160 | case DataType::Type::kFloat64: { |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3161 | if (second.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3162 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3163 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3164 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3165 | DCHECK(const_area->IsEmittedAtUseSite()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3166 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 3167 | codegen_->LiteralDoubleAddress( |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3168 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3169 | const_area->GetBaseMethodAddress(), |
| 3170 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3171 | } else { |
| 3172 | DCHECK(second.IsDoubleStackSlot()); |
| 3173 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3174 | } |
| 3175 | break; |
| 3176 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3177 | |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3178 | default: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3179 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3180 | } |
| 3181 | } |
| 3182 | |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3183 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3184 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3185 | new (GetGraph()->GetAllocator()) LocationSummary(sub, LocationSummary::kNoCall); |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3186 | switch (sub->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3187 | case DataType::Type::kInt32: |
| 3188 | case DataType::Type::kInt64: { |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3189 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3190 | locations->SetInAt(1, Location::Any()); |
| 3191 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3192 | break; |
| 3193 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3194 | case DataType::Type::kFloat32: |
| 3195 | case DataType::Type::kFloat64: { |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3196 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3197 | if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3198 | DCHECK(sub->InputAt(1)->IsEmittedAtUseSite()); |
| Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3199 | } else if (sub->InputAt(1)->IsConstant()) { |
| 3200 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3201 | } else { |
| 3202 | locations->SetInAt(1, Location::Any()); |
| 3203 | } |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3204 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3205 | break; |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3206 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3207 | |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3208 | default: |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3209 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3210 | } |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3211 | } |
| 3212 | |
| 3213 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 3214 | LocationSummary* locations = sub->GetLocations(); |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3215 | Location first = locations->InAt(0); |
| 3216 | Location second = locations->InAt(1); |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3217 | DCHECK(first.Equals(locations->Out())); |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3218 | switch (sub->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3219 | case DataType::Type::kInt32: { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3220 | if (second.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3221 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3222 | } else if (second.IsConstant()) { |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3223 | __ subl(first.AsRegister<Register>(), |
| 3224 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3225 | } else { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3226 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3227 | } |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3228 | break; |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3229 | } |
| 3230 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3231 | case DataType::Type::kInt64: { |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3232 | if (second.IsRegisterPair()) { |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3233 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3234 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3235 | } else if (second.IsDoubleStackSlot()) { |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3236 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3237 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 3238 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3239 | } else { |
| 3240 | DCHECK(second.IsConstant()) << second; |
| 3241 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3242 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 3243 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3244 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3245 | break; |
| 3246 | } |
| 3247 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3248 | case DataType::Type::kFloat32: { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3249 | if (second.IsFpuRegister()) { |
| 3250 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3251 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3252 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3253 | DCHECK(const_area->IsEmittedAtUseSite()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3254 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3255 | codegen_->LiteralFloatAddress( |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3256 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3257 | const_area->GetBaseMethodAddress(), |
| 3258 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3259 | } else { |
| 3260 | DCHECK(second.IsStackSlot()); |
| 3261 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3262 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3263 | break; |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3264 | } |
| 3265 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3266 | case DataType::Type::kFloat64: { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3267 | if (second.IsFpuRegister()) { |
| 3268 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3269 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3270 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3271 | DCHECK(const_area->IsEmittedAtUseSite()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3272 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3273 | codegen_->LiteralDoubleAddress( |
| 3274 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3275 | const_area->GetBaseMethodAddress(), |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3276 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3277 | } else { |
| 3278 | DCHECK(second.IsDoubleStackSlot()); |
| 3279 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3280 | } |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3281 | break; |
| 3282 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3283 | |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3284 | default: |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3285 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3286 | } |
| 3287 | } |
| 3288 | |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3289 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 3290 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3291 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3292 | switch (mul->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3293 | case DataType::Type::kInt32: |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3294 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3295 | locations->SetInAt(1, Location::Any()); |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3296 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3297 | // Can use 3 operand multiply. |
| 3298 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3299 | } else { |
| 3300 | locations->SetOut(Location::SameAsFirstInput()); |
| 3301 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3302 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3303 | case DataType::Type::kInt64: { |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3304 | locations->SetInAt(0, Location::RequiresRegister()); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3305 | locations->SetInAt(1, Location::Any()); |
| 3306 | locations->SetOut(Location::SameAsFirstInput()); |
| 3307 | // Needed for imul on 32bits with 64bits output. |
| 3308 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 3309 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 3310 | break; |
| 3311 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3312 | case DataType::Type::kFloat32: |
| 3313 | case DataType::Type::kFloat64: { |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3314 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3315 | if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3316 | DCHECK(mul->InputAt(1)->IsEmittedAtUseSite()); |
| Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3317 | } else if (mul->InputAt(1)->IsConstant()) { |
| 3318 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3319 | } else { |
| 3320 | locations->SetInAt(1, Location::Any()); |
| 3321 | } |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3322 | locations->SetOut(Location::SameAsFirstInput()); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3323 | break; |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3324 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3325 | |
| 3326 | default: |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3327 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3328 | } |
| 3329 | } |
| 3330 | |
| 3331 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 3332 | LocationSummary* locations = mul->GetLocations(); |
| 3333 | Location first = locations->InAt(0); |
| 3334 | Location second = locations->InAt(1); |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3335 | Location out = locations->Out(); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3336 | |
| 3337 | switch (mul->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3338 | case DataType::Type::kInt32: |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3339 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3340 | // problems where the output may not be the same as the first operand. |
| 3341 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3342 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3343 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 3344 | } else if (second.IsRegister()) { |
| 3345 | DCHECK(first.Equals(out)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3346 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3347 | } else { |
| 3348 | DCHECK(second.IsStackSlot()); |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3349 | DCHECK(first.Equals(out)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3350 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3351 | } |
| 3352 | break; |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3353 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3354 | case DataType::Type::kInt64: { |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3355 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 3356 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3357 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 3358 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3359 | |
| 3360 | DCHECK_EQ(EAX, eax); |
| 3361 | DCHECK_EQ(EDX, edx); |
| 3362 | |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3363 | // input: in1 - 64 bits, in2 - 64 bits. |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3364 | // output: in1 |
| 3365 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3366 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3367 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3368 | if (second.IsConstant()) { |
| 3369 | DCHECK(second.GetConstant()->IsLongConstant()); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3370 | |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3371 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3372 | int32_t low_value = Low32Bits(value); |
| 3373 | int32_t high_value = High32Bits(value); |
| 3374 | Immediate low(low_value); |
| 3375 | Immediate high(high_value); |
| 3376 | |
| 3377 | __ movl(eax, high); |
| 3378 | // eax <- in1.lo * in2.hi |
| 3379 | __ imull(eax, in1_lo); |
| 3380 | // in1.hi <- in1.hi * in2.lo |
| 3381 | __ imull(in1_hi, low); |
| 3382 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3383 | __ addl(in1_hi, eax); |
| 3384 | // move in2_lo to eax to prepare for double precision |
| 3385 | __ movl(eax, low); |
| 3386 | // edx:eax <- in1.lo * in2.lo |
| 3387 | __ mull(in1_lo); |
| 3388 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3389 | __ addl(in1_hi, edx); |
| 3390 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3391 | __ movl(in1_lo, eax); |
| 3392 | } else if (second.IsRegisterPair()) { |
| 3393 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3394 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3395 | |
| 3396 | __ movl(eax, in2_hi); |
| 3397 | // eax <- in1.lo * in2.hi |
| 3398 | __ imull(eax, in1_lo); |
| 3399 | // in1.hi <- in1.hi * in2.lo |
| 3400 | __ imull(in1_hi, in2_lo); |
| 3401 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3402 | __ addl(in1_hi, eax); |
| 3403 | // move in1_lo to eax to prepare for double precision |
| 3404 | __ movl(eax, in1_lo); |
| 3405 | // edx:eax <- in1.lo * in2.lo |
| 3406 | __ mull(in2_lo); |
| 3407 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3408 | __ addl(in1_hi, edx); |
| 3409 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3410 | __ movl(in1_lo, eax); |
| 3411 | } else { |
| 3412 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 3413 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 3414 | Address in2_lo(ESP, second.GetStackIndex()); |
| 3415 | |
| 3416 | __ movl(eax, in2_hi); |
| 3417 | // eax <- in1.lo * in2.hi |
| 3418 | __ imull(eax, in1_lo); |
| 3419 | // in1.hi <- in1.hi * in2.lo |
| 3420 | __ imull(in1_hi, in2_lo); |
| 3421 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3422 | __ addl(in1_hi, eax); |
| 3423 | // move in1_lo to eax to prepare for double precision |
| 3424 | __ movl(eax, in1_lo); |
| 3425 | // edx:eax <- in1.lo * in2.lo |
| 3426 | __ mull(in2_lo); |
| 3427 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3428 | __ addl(in1_hi, edx); |
| 3429 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3430 | __ movl(in1_lo, eax); |
| 3431 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3432 | |
| 3433 | break; |
| 3434 | } |
| 3435 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3436 | case DataType::Type::kFloat32: { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3437 | DCHECK(first.Equals(locations->Out())); |
| 3438 | if (second.IsFpuRegister()) { |
| 3439 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3440 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3441 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3442 | DCHECK(const_area->IsEmittedAtUseSite()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3443 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3444 | codegen_->LiteralFloatAddress( |
| 3445 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3446 | const_area->GetBaseMethodAddress(), |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3447 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3448 | } else { |
| 3449 | DCHECK(second.IsStackSlot()); |
| 3450 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3451 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3452 | break; |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3453 | } |
| 3454 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3455 | case DataType::Type::kFloat64: { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3456 | DCHECK(first.Equals(locations->Out())); |
| 3457 | if (second.IsFpuRegister()) { |
| 3458 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3459 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3460 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3461 | DCHECK(const_area->IsEmittedAtUseSite()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3462 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3463 | codegen_->LiteralDoubleAddress( |
| 3464 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3465 | const_area->GetBaseMethodAddress(), |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3466 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3467 | } else { |
| 3468 | DCHECK(second.IsDoubleStackSlot()); |
| 3469 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3470 | } |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3471 | break; |
| 3472 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3473 | |
| 3474 | default: |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3475 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3476 | } |
| 3477 | } |
| 3478 | |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3479 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 3480 | uint32_t temp_offset, |
| 3481 | uint32_t stack_adjustment, |
| 3482 | bool is_fp, |
| 3483 | bool is_wide) { |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3484 | if (source.IsStackSlot()) { |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3485 | DCHECK(!is_wide); |
| 3486 | if (is_fp) { |
| 3487 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3488 | } else { |
| 3489 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3490 | } |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3491 | } else if (source.IsDoubleStackSlot()) { |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3492 | DCHECK(is_wide); |
| 3493 | if (is_fp) { |
| 3494 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3495 | } else { |
| 3496 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3497 | } |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3498 | } else { |
| 3499 | // 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] | 3500 | if (!is_wide) { |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3501 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3502 | codegen_->Move32(stack_temp, source); |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3503 | if (is_fp) { |
| 3504 | __ flds(Address(ESP, temp_offset)); |
| 3505 | } else { |
| 3506 | __ filds(Address(ESP, temp_offset)); |
| 3507 | } |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3508 | } else { |
| 3509 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3510 | codegen_->Move64(stack_temp, source); |
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3511 | if (is_fp) { |
| 3512 | __ fldl(Address(ESP, temp_offset)); |
| 3513 | } else { |
| 3514 | __ fildl(Address(ESP, temp_offset)); |
| 3515 | } |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3516 | } |
| 3517 | } |
| 3518 | } |
| 3519 | |
| 3520 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3521 | DataType::Type type = rem->GetResultType(); |
| 3522 | bool is_float = type == DataType::Type::kFloat32; |
| 3523 | size_t elem_size = DataType::Size(type); |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3524 | LocationSummary* locations = rem->GetLocations(); |
| 3525 | Location first = locations->InAt(0); |
| 3526 | Location second = locations->InAt(1); |
| 3527 | Location out = locations->Out(); |
| 3528 | |
| 3529 | // Create stack space for 2 elements. |
| 3530 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3531 | __ subl(ESP, Immediate(2 * elem_size)); |
| 3532 | |
| 3533 | // 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] | 3534 | const bool is_wide = !is_float; |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3535 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp= */ true, is_wide); |
| 3536 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp= */ true, is_wide); |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3537 | |
| 3538 | // Loop doing FPREM until we stabilize. |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3539 | NearLabel retry; |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3540 | __ Bind(&retry); |
| 3541 | __ fprem(); |
| 3542 | |
| 3543 | // Move FP status to AX. |
| 3544 | __ fstsw(); |
| 3545 | |
| 3546 | // And see if the argument reduction is complete. This is signaled by the |
| 3547 | // C2 FPU flag bit set to 0. |
| 3548 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 3549 | __ j(kNotEqual, &retry); |
| 3550 | |
| 3551 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3552 | // Store FP top of stack to real stack. |
| 3553 | if (is_float) { |
| 3554 | __ fsts(Address(ESP, 0)); |
| 3555 | } else { |
| 3556 | __ fstl(Address(ESP, 0)); |
| 3557 | } |
| 3558 | |
| 3559 | // Pop the 2 items from the FP stack. |
| 3560 | __ fucompp(); |
| 3561 | |
| 3562 | // Load the value from the stack into an XMM register. |
| 3563 | DCHECK(out.IsFpuRegister()) << out; |
| 3564 | if (is_float) { |
| 3565 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3566 | } else { |
| 3567 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3568 | } |
| 3569 | |
| 3570 | // And remove the temporary stack space we allocated. |
| 3571 | __ addl(ESP, Immediate(2 * elem_size)); |
| 3572 | } |
| 3573 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3574 | |
| 3575 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3576 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3577 | |
| 3578 | LocationSummary* locations = instruction->GetLocations(); |
| 3579 | DCHECK(locations->InAt(1).IsConstant()); |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3580 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3581 | |
| 3582 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3583 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3584 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3585 | |
| 3586 | DCHECK(imm == 1 || imm == -1); |
| 3587 | |
| 3588 | if (instruction->IsRem()) { |
| 3589 | __ xorl(out_register, out_register); |
| 3590 | } else { |
| 3591 | __ movl(out_register, input_register); |
| 3592 | if (imm == -1) { |
| 3593 | __ negl(out_register); |
| 3594 | } |
| 3595 | } |
| 3596 | } |
| 3597 | |
| Shalini Salomi Bodapati | a66784b | 2018-11-06 13:05:44 +0530 | [diff] [blame] | 3598 | void InstructionCodeGeneratorX86::RemByPowerOfTwo(HRem* instruction) { |
| 3599 | LocationSummary* locations = instruction->GetLocations(); |
| 3600 | Location second = locations->InAt(1); |
| 3601 | |
| 3602 | Register out = locations->Out().AsRegister<Register>(); |
| 3603 | Register numerator = locations->InAt(0).AsRegister<Register>(); |
| 3604 | |
| 3605 | int32_t imm = Int64FromConstant(second.GetConstant()); |
| 3606 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3607 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
| 3608 | |
| 3609 | Register tmp = locations->GetTemp(0).AsRegister<Register>(); |
| 3610 | NearLabel done; |
| 3611 | __ movl(out, numerator); |
| 3612 | __ andl(out, Immediate(abs_imm-1)); |
| 3613 | __ j(Condition::kZero, &done); |
| 3614 | __ leal(tmp, Address(out, static_cast<int32_t>(~(abs_imm-1)))); |
| 3615 | __ testl(numerator, numerator); |
| 3616 | __ cmovl(Condition::kLess, out, tmp); |
| 3617 | __ Bind(&done); |
| 3618 | } |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3619 | |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3620 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3621 | LocationSummary* locations = instruction->GetLocations(); |
| 3622 | |
| 3623 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3624 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3625 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3626 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3627 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3628 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3629 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 3630 | |
| Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3631 | __ leal(num, Address(input_register, abs_imm - 1)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3632 | __ testl(input_register, input_register); |
| 3633 | __ cmovl(kGreaterEqual, num, input_register); |
| 3634 | int shift = CTZ(imm); |
| 3635 | __ sarl(num, Immediate(shift)); |
| 3636 | |
| 3637 | if (imm < 0) { |
| 3638 | __ negl(num); |
| 3639 | } |
| 3640 | |
| 3641 | __ movl(out_register, num); |
| 3642 | } |
| 3643 | |
| 3644 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3645 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3646 | |
| 3647 | LocationSummary* locations = instruction->GetLocations(); |
| 3648 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 3649 | |
| 3650 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 3651 | Register out = locations->Out().AsRegister<Register>(); |
| 3652 | Register num; |
| 3653 | Register edx; |
| 3654 | |
| 3655 | if (instruction->IsDiv()) { |
| 3656 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 3657 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 3658 | } else { |
| 3659 | edx = locations->Out().AsRegister<Register>(); |
| 3660 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 3661 | } |
| 3662 | |
| 3663 | DCHECK_EQ(EAX, eax); |
| 3664 | DCHECK_EQ(EDX, edx); |
| 3665 | if (instruction->IsDiv()) { |
| 3666 | DCHECK_EQ(EAX, out); |
| 3667 | } else { |
| 3668 | DCHECK_EQ(EDX, out); |
| 3669 | } |
| 3670 | |
| 3671 | int64_t magic; |
| 3672 | int shift; |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3673 | CalculateMagicAndShiftForDivRem(imm, /* is_long= */ false, &magic, &shift); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3674 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3675 | // Save the numerator. |
| 3676 | __ movl(num, eax); |
| 3677 | |
| 3678 | // EAX = magic |
| 3679 | __ movl(eax, Immediate(magic)); |
| 3680 | |
| 3681 | // EDX:EAX = magic * numerator |
| 3682 | __ imull(num); |
| 3683 | |
| 3684 | if (imm > 0 && magic < 0) { |
| 3685 | // EDX += num |
| 3686 | __ addl(edx, num); |
| 3687 | } else if (imm < 0 && magic > 0) { |
| 3688 | __ subl(edx, num); |
| 3689 | } |
| 3690 | |
| 3691 | // Shift if needed. |
| 3692 | if (shift != 0) { |
| 3693 | __ sarl(edx, Immediate(shift)); |
| 3694 | } |
| 3695 | |
| 3696 | // EDX += 1 if EDX < 0 |
| 3697 | __ movl(eax, edx); |
| 3698 | __ shrl(edx, Immediate(31)); |
| 3699 | __ addl(edx, eax); |
| 3700 | |
| 3701 | if (instruction->IsRem()) { |
| 3702 | __ movl(eax, num); |
| 3703 | __ imull(edx, Immediate(imm)); |
| 3704 | __ subl(eax, edx); |
| 3705 | __ movl(edx, eax); |
| 3706 | } else { |
| 3707 | __ movl(eax, edx); |
| 3708 | } |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3709 | } |
| 3710 | |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3711 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3712 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3713 | |
| 3714 | LocationSummary* locations = instruction->GetLocations(); |
| 3715 | Location out = locations->Out(); |
| 3716 | Location first = locations->InAt(0); |
| 3717 | Location second = locations->InAt(1); |
| 3718 | bool is_div = instruction->IsDiv(); |
| 3719 | |
| 3720 | switch (instruction->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3721 | case DataType::Type::kInt32: { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3722 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 3723 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3724 | |
| Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3725 | if (second.IsConstant()) { |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3726 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3727 | |
| 3728 | if (imm == 0) { |
| 3729 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 3730 | } else if (imm == 1 || imm == -1) { |
| 3731 | DivRemOneOrMinusOne(instruction); |
| Shalini Salomi Bodapati | a66784b | 2018-11-06 13:05:44 +0530 | [diff] [blame] | 3732 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 3733 | if (is_div) { |
| 3734 | DivByPowerOfTwo(instruction->AsDiv()); |
| 3735 | } else { |
| 3736 | RemByPowerOfTwo(instruction->AsRem()); |
| 3737 | } |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3738 | } else { |
| 3739 | DCHECK(imm <= -2 || imm >= 2); |
| 3740 | GenerateDivRemWithAnyConstant(instruction); |
| 3741 | } |
| 3742 | } else { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3743 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) DivRemMinusOneSlowPathX86( |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3744 | instruction, out.AsRegister<Register>(), is_div); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3745 | codegen_->AddSlowPath(slow_path); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3746 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3747 | Register second_reg = second.AsRegister<Register>(); |
| 3748 | // 0x80000000/-1 triggers an arithmetic exception! |
| 3749 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 3750 | // it's safe to just use negl instead of more complex comparisons. |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3751 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3752 | __ cmpl(second_reg, Immediate(-1)); |
| 3753 | __ j(kEqual, slow_path->GetEntryLabel()); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3754 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3755 | // edx:eax <- sign-extended of eax |
| 3756 | __ cdq(); |
| 3757 | // eax = quotient, edx = remainder |
| 3758 | __ idivl(second_reg); |
| 3759 | __ Bind(slow_path->GetExitLabel()); |
| 3760 | } |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3761 | break; |
| 3762 | } |
| 3763 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3764 | case DataType::Type::kInt64: { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3765 | InvokeRuntimeCallingConvention calling_convention; |
| 3766 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3767 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3768 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3769 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3770 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 3771 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 3772 | |
| 3773 | if (is_div) { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3774 | codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3775 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3776 | } else { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3777 | codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3778 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3779 | } |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3780 | break; |
| 3781 | } |
| 3782 | |
| 3783 | default: |
| 3784 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 3785 | } |
| 3786 | } |
| 3787 | |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3788 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3789 | LocationSummary::CallKind call_kind = (div->GetResultType() == DataType::Type::kInt64) |
| Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3790 | ? LocationSummary::kCallOnMainOnly |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3791 | : LocationSummary::kNoCall; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3792 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(div, call_kind); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3793 | |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3794 | switch (div->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3795 | case DataType::Type::kInt32: { |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3796 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3797 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3798 | locations->SetOut(Location::SameAsFirstInput()); |
| 3799 | // Intel uses edx:eax as the dividend. |
| 3800 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3801 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3802 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 3803 | // output and request another temp. |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3804 | if (div->InputAt(1)->IsIntConstant()) { |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3805 | locations->AddTemp(Location::RequiresRegister()); |
| 3806 | } |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3807 | break; |
| 3808 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3809 | case DataType::Type::kInt64: { |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3810 | InvokeRuntimeCallingConvention calling_convention; |
| 3811 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3812 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3813 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3814 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3815 | // Runtime helper puts the result in EAX, EDX. |
| 3816 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3817 | break; |
| 3818 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3819 | case DataType::Type::kFloat32: |
| 3820 | case DataType::Type::kFloat64: { |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3821 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3822 | if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3823 | DCHECK(div->InputAt(1)->IsEmittedAtUseSite()); |
| Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3824 | } else if (div->InputAt(1)->IsConstant()) { |
| 3825 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3826 | } else { |
| 3827 | locations->SetInAt(1, Location::Any()); |
| 3828 | } |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3829 | locations->SetOut(Location::SameAsFirstInput()); |
| 3830 | break; |
| 3831 | } |
| 3832 | |
| 3833 | default: |
| 3834 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3835 | } |
| 3836 | } |
| 3837 | |
| 3838 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 3839 | LocationSummary* locations = div->GetLocations(); |
| 3840 | Location first = locations->InAt(0); |
| 3841 | Location second = locations->InAt(1); |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3842 | |
| 3843 | switch (div->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3844 | case DataType::Type::kInt32: |
| 3845 | case DataType::Type::kInt64: { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3846 | GenerateDivRemIntegral(div); |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3847 | break; |
| 3848 | } |
| 3849 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3850 | case DataType::Type::kFloat32: { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3851 | if (second.IsFpuRegister()) { |
| 3852 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3853 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3854 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3855 | DCHECK(const_area->IsEmittedAtUseSite()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3856 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3857 | codegen_->LiteralFloatAddress( |
| 3858 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3859 | const_area->GetBaseMethodAddress(), |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3860 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3861 | } else { |
| 3862 | DCHECK(second.IsStackSlot()); |
| 3863 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3864 | } |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3865 | break; |
| 3866 | } |
| 3867 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3868 | case DataType::Type::kFloat64: { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3869 | if (second.IsFpuRegister()) { |
| 3870 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3871 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3872 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3873 | DCHECK(const_area->IsEmittedAtUseSite()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3874 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3875 | codegen_->LiteralDoubleAddress( |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3876 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3877 | const_area->GetBaseMethodAddress(), |
| 3878 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3879 | } else { |
| 3880 | DCHECK(second.IsDoubleStackSlot()); |
| 3881 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3882 | } |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3883 | break; |
| 3884 | } |
| 3885 | |
| 3886 | default: |
| 3887 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3888 | } |
| 3889 | } |
| 3890 | |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3891 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3892 | DataType::Type type = rem->GetResultType(); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3893 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3894 | LocationSummary::CallKind call_kind = (rem->GetResultType() == DataType::Type::kInt64) |
| Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3895 | ? LocationSummary::kCallOnMainOnly |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3896 | : LocationSummary::kNoCall; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3897 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3898 | |
| Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3899 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3900 | case DataType::Type::kInt32: { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3901 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3902 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3903 | locations->SetOut(Location::RegisterLocation(EDX)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3904 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3905 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 3906 | // output and request another temp. |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3907 | if (rem->InputAt(1)->IsIntConstant()) { |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3908 | locations->AddTemp(Location::RequiresRegister()); |
| 3909 | } |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3910 | break; |
| 3911 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3912 | case DataType::Type::kInt64: { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3913 | InvokeRuntimeCallingConvention calling_convention; |
| 3914 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3915 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3916 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3917 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3918 | // Runtime helper puts the result in EAX, EDX. |
| 3919 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3920 | break; |
| 3921 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3922 | case DataType::Type::kFloat64: |
| 3923 | case DataType::Type::kFloat32: { |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3924 | locations->SetInAt(0, Location::Any()); |
| 3925 | locations->SetInAt(1, Location::Any()); |
| 3926 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3927 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3928 | break; |
| 3929 | } |
| 3930 | |
| 3931 | default: |
| Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3932 | LOG(FATAL) << "Unexpected rem type " << type; |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3933 | } |
| 3934 | } |
| 3935 | |
| 3936 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3937 | DataType::Type type = rem->GetResultType(); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3938 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3939 | case DataType::Type::kInt32: |
| 3940 | case DataType::Type::kInt64: { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3941 | GenerateDivRemIntegral(rem); |
| 3942 | break; |
| 3943 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3944 | case DataType::Type::kFloat32: |
| 3945 | case DataType::Type::kFloat64: { |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3946 | GenerateRemFP(rem); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3947 | break; |
| 3948 | } |
| 3949 | default: |
| 3950 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3951 | } |
| 3952 | } |
| 3953 | |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 3954 | static void CreateMinMaxLocations(ArenaAllocator* allocator, HBinaryOperation* minmax) { |
| 3955 | LocationSummary* locations = new (allocator) LocationSummary(minmax); |
| 3956 | switch (minmax->GetResultType()) { |
| 3957 | case DataType::Type::kInt32: |
| 3958 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3959 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3960 | locations->SetOut(Location::SameAsFirstInput()); |
| 3961 | break; |
| 3962 | case DataType::Type::kInt64: |
| 3963 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3964 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3965 | locations->SetOut(Location::SameAsFirstInput()); |
| 3966 | // Register to use to perform a long subtract to set cc. |
| 3967 | locations->AddTemp(Location::RequiresRegister()); |
| 3968 | break; |
| 3969 | case DataType::Type::kFloat32: |
| 3970 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3971 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3972 | locations->SetOut(Location::SameAsFirstInput()); |
| 3973 | locations->AddTemp(Location::RequiresRegister()); |
| 3974 | break; |
| 3975 | case DataType::Type::kFloat64: |
| 3976 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3977 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3978 | locations->SetOut(Location::SameAsFirstInput()); |
| 3979 | break; |
| 3980 | default: |
| 3981 | LOG(FATAL) << "Unexpected type for HMinMax " << minmax->GetResultType(); |
| 3982 | } |
| 3983 | } |
| 3984 | |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 3985 | void InstructionCodeGeneratorX86::GenerateMinMaxInt(LocationSummary* locations, |
| 3986 | bool is_min, |
| 3987 | DataType::Type type) { |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 3988 | Location op1_loc = locations->InAt(0); |
| 3989 | Location op2_loc = locations->InAt(1); |
| 3990 | |
| 3991 | // Shortcut for same input locations. |
| 3992 | if (op1_loc.Equals(op2_loc)) { |
| 3993 | // Can return immediately, as op1_loc == out_loc. |
| 3994 | // Note: if we ever support separate registers, e.g., output into memory, we need to check for |
| 3995 | // a copy here. |
| 3996 | DCHECK(locations->Out().Equals(op1_loc)); |
| 3997 | return; |
| 3998 | } |
| 3999 | |
| 4000 | if (type == DataType::Type::kInt64) { |
| 4001 | // Need to perform a subtract to get the sign right. |
| 4002 | // op1 is already in the same location as the output. |
| 4003 | Location output = locations->Out(); |
| 4004 | Register output_lo = output.AsRegisterPairLow<Register>(); |
| 4005 | Register output_hi = output.AsRegisterPairHigh<Register>(); |
| 4006 | |
| 4007 | Register op2_lo = op2_loc.AsRegisterPairLow<Register>(); |
| 4008 | Register op2_hi = op2_loc.AsRegisterPairHigh<Register>(); |
| 4009 | |
| 4010 | // The comparison is performed by subtracting the second operand from |
| 4011 | // the first operand and then setting the status flags in the same |
| 4012 | // manner as the SUB instruction." |
| 4013 | __ cmpl(output_lo, op2_lo); |
| 4014 | |
| 4015 | // Now use a temp and the borrow to finish the subtraction of op2_hi. |
| 4016 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4017 | __ movl(temp, output_hi); |
| 4018 | __ sbbl(temp, op2_hi); |
| 4019 | |
| 4020 | // Now the condition code is correct. |
| 4021 | Condition cond = is_min ? Condition::kGreaterEqual : Condition::kLess; |
| 4022 | __ cmovl(cond, output_lo, op2_lo); |
| 4023 | __ cmovl(cond, output_hi, op2_hi); |
| 4024 | } else { |
| 4025 | DCHECK_EQ(type, DataType::Type::kInt32); |
| 4026 | Register out = locations->Out().AsRegister<Register>(); |
| 4027 | Register op2 = op2_loc.AsRegister<Register>(); |
| 4028 | |
| 4029 | // (out := op1) |
| 4030 | // out <=? op2 |
| 4031 | // if out is min jmp done |
| 4032 | // out := op2 |
| 4033 | // done: |
| 4034 | |
| 4035 | __ cmpl(out, op2); |
| 4036 | Condition cond = is_min ? Condition::kGreater : Condition::kLess; |
| 4037 | __ cmovl(cond, out, op2); |
| 4038 | } |
| 4039 | } |
| 4040 | |
| 4041 | void InstructionCodeGeneratorX86::GenerateMinMaxFP(LocationSummary* locations, |
| 4042 | bool is_min, |
| 4043 | DataType::Type type) { |
| 4044 | Location op1_loc = locations->InAt(0); |
| 4045 | Location op2_loc = locations->InAt(1); |
| 4046 | Location out_loc = locations->Out(); |
| 4047 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
| 4048 | |
| 4049 | // Shortcut for same input locations. |
| 4050 | if (op1_loc.Equals(op2_loc)) { |
| 4051 | DCHECK(out_loc.Equals(op1_loc)); |
| 4052 | return; |
| 4053 | } |
| 4054 | |
| 4055 | // (out := op1) |
| 4056 | // out <=? op2 |
| 4057 | // if Nan jmp Nan_label |
| 4058 | // if out is min jmp done |
| 4059 | // if op2 is min jmp op2_label |
| 4060 | // handle -0/+0 |
| 4061 | // jmp done |
| 4062 | // Nan_label: |
| 4063 | // out := NaN |
| 4064 | // op2_label: |
| 4065 | // out := op2 |
| 4066 | // done: |
| 4067 | // |
| 4068 | // This removes one jmp, but needs to copy one input (op1) to out. |
| 4069 | // |
| 4070 | // TODO: This is straight from Quick (except literal pool). Make NaN an out-of-line slowpath? |
| 4071 | |
| 4072 | XmmRegister op2 = op2_loc.AsFpuRegister<XmmRegister>(); |
| 4073 | |
| 4074 | NearLabel nan, done, op2_label; |
| 4075 | if (type == DataType::Type::kFloat64) { |
| 4076 | __ ucomisd(out, op2); |
| 4077 | } else { |
| 4078 | DCHECK_EQ(type, DataType::Type::kFloat32); |
| 4079 | __ ucomiss(out, op2); |
| 4080 | } |
| 4081 | |
| 4082 | __ j(Condition::kParityEven, &nan); |
| 4083 | |
| 4084 | __ j(is_min ? Condition::kAbove : Condition::kBelow, &op2_label); |
| 4085 | __ j(is_min ? Condition::kBelow : Condition::kAbove, &done); |
| 4086 | |
| 4087 | // Handle 0.0/-0.0. |
| 4088 | if (is_min) { |
| 4089 | if (type == DataType::Type::kFloat64) { |
| 4090 | __ orpd(out, op2); |
| 4091 | } else { |
| 4092 | __ orps(out, op2); |
| 4093 | } |
| 4094 | } else { |
| 4095 | if (type == DataType::Type::kFloat64) { |
| 4096 | __ andpd(out, op2); |
| 4097 | } else { |
| 4098 | __ andps(out, op2); |
| 4099 | } |
| 4100 | } |
| 4101 | __ jmp(&done); |
| 4102 | |
| 4103 | // NaN handling. |
| 4104 | __ Bind(&nan); |
| 4105 | if (type == DataType::Type::kFloat64) { |
| 4106 | // TODO: Use a constant from the constant table (requires extra input). |
| 4107 | __ LoadLongConstant(out, kDoubleNaN); |
| 4108 | } else { |
| 4109 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 4110 | __ movl(constant, Immediate(kFloatNaN)); |
| 4111 | __ movd(out, constant); |
| 4112 | } |
| 4113 | __ jmp(&done); |
| 4114 | |
| 4115 | // out := op2; |
| 4116 | __ Bind(&op2_label); |
| 4117 | if (type == DataType::Type::kFloat64) { |
| 4118 | __ movsd(out, op2); |
| 4119 | } else { |
| 4120 | __ movss(out, op2); |
| 4121 | } |
| 4122 | |
| 4123 | // Done. |
| 4124 | __ Bind(&done); |
| 4125 | } |
| 4126 | |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4127 | void InstructionCodeGeneratorX86::GenerateMinMax(HBinaryOperation* minmax, bool is_min) { |
| 4128 | DataType::Type type = minmax->GetResultType(); |
| 4129 | switch (type) { |
| 4130 | case DataType::Type::kInt32: |
| 4131 | case DataType::Type::kInt64: |
| 4132 | GenerateMinMaxInt(minmax->GetLocations(), is_min, type); |
| 4133 | break; |
| 4134 | case DataType::Type::kFloat32: |
| 4135 | case DataType::Type::kFloat64: |
| 4136 | GenerateMinMaxFP(minmax->GetLocations(), is_min, type); |
| 4137 | break; |
| 4138 | default: |
| 4139 | LOG(FATAL) << "Unexpected type for HMinMax " << type; |
| 4140 | } |
| 4141 | } |
| 4142 | |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4143 | void LocationsBuilderX86::VisitMin(HMin* min) { |
| 4144 | CreateMinMaxLocations(GetGraph()->GetAllocator(), min); |
| 4145 | } |
| 4146 | |
| 4147 | void InstructionCodeGeneratorX86::VisitMin(HMin* min) { |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4148 | GenerateMinMax(min, /*is_min*/ true); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4149 | } |
| 4150 | |
| 4151 | void LocationsBuilderX86::VisitMax(HMax* max) { |
| 4152 | CreateMinMaxLocations(GetGraph()->GetAllocator(), max); |
| 4153 | } |
| 4154 | |
| 4155 | void InstructionCodeGeneratorX86::VisitMax(HMax* max) { |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4156 | GenerateMinMax(max, /*is_min*/ false); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4157 | } |
| 4158 | |
| Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 4159 | void LocationsBuilderX86::VisitAbs(HAbs* abs) { |
| 4160 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 4161 | switch (abs->GetResultType()) { |
| 4162 | case DataType::Type::kInt32: |
| 4163 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 4164 | locations->SetOut(Location::SameAsFirstInput()); |
| 4165 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 4166 | break; |
| 4167 | case DataType::Type::kInt64: |
| 4168 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4169 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4170 | locations->AddTemp(Location::RequiresRegister()); |
| 4171 | break; |
| 4172 | case DataType::Type::kFloat32: |
| 4173 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4174 | locations->SetOut(Location::SameAsFirstInput()); |
| 4175 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4176 | locations->AddTemp(Location::RequiresRegister()); |
| 4177 | break; |
| 4178 | case DataType::Type::kFloat64: |
| 4179 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4180 | locations->SetOut(Location::SameAsFirstInput()); |
| 4181 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4182 | break; |
| 4183 | default: |
| 4184 | LOG(FATAL) << "Unexpected type for HAbs " << abs->GetResultType(); |
| 4185 | } |
| 4186 | } |
| 4187 | |
| 4188 | void InstructionCodeGeneratorX86::VisitAbs(HAbs* abs) { |
| 4189 | LocationSummary* locations = abs->GetLocations(); |
| 4190 | switch (abs->GetResultType()) { |
| 4191 | case DataType::Type::kInt32: { |
| 4192 | Register out = locations->Out().AsRegister<Register>(); |
| 4193 | DCHECK_EQ(out, EAX); |
| 4194 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4195 | DCHECK_EQ(temp, EDX); |
| 4196 | // Sign extend EAX into EDX. |
| 4197 | __ cdq(); |
| 4198 | // XOR EAX with sign. |
| 4199 | __ xorl(EAX, EDX); |
| 4200 | // Subtract out sign to correct. |
| 4201 | __ subl(EAX, EDX); |
| 4202 | // The result is in EAX. |
| 4203 | break; |
| 4204 | } |
| 4205 | case DataType::Type::kInt64: { |
| 4206 | Location input = locations->InAt(0); |
| 4207 | Register input_lo = input.AsRegisterPairLow<Register>(); |
| 4208 | Register input_hi = input.AsRegisterPairHigh<Register>(); |
| 4209 | Location output = locations->Out(); |
| 4210 | Register output_lo = output.AsRegisterPairLow<Register>(); |
| 4211 | Register output_hi = output.AsRegisterPairHigh<Register>(); |
| 4212 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4213 | // Compute the sign into the temporary. |
| 4214 | __ movl(temp, input_hi); |
| 4215 | __ sarl(temp, Immediate(31)); |
| 4216 | // Store the sign into the output. |
| 4217 | __ movl(output_lo, temp); |
| 4218 | __ movl(output_hi, temp); |
| 4219 | // XOR the input to the output. |
| 4220 | __ xorl(output_lo, input_lo); |
| 4221 | __ xorl(output_hi, input_hi); |
| 4222 | // Subtract the sign. |
| 4223 | __ subl(output_lo, temp); |
| 4224 | __ sbbl(output_hi, temp); |
| 4225 | break; |
| 4226 | } |
| 4227 | case DataType::Type::kFloat32: { |
| 4228 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4229 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4230 | Register constant = locations->GetTemp(1).AsRegister<Register>(); |
| 4231 | __ movl(constant, Immediate(INT32_C(0x7FFFFFFF))); |
| 4232 | __ movd(temp, constant); |
| 4233 | __ andps(out, temp); |
| 4234 | break; |
| 4235 | } |
| 4236 | case DataType::Type::kFloat64: { |
| 4237 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4238 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4239 | // TODO: Use a constant from the constant table (requires extra input). |
| 4240 | __ LoadLongConstant(temp, INT64_C(0x7FFFFFFFFFFFFFFF)); |
| 4241 | __ andpd(out, temp); |
| 4242 | break; |
| 4243 | } |
| 4244 | default: |
| 4245 | LOG(FATAL) << "Unexpected type for HAbs " << abs->GetResultType(); |
| 4246 | } |
| 4247 | } |
| 4248 | |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4249 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4250 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4251 | switch (instruction->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4252 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4253 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4254 | case DataType::Type::kInt8: |
| 4255 | case DataType::Type::kUint16: |
| 4256 | case DataType::Type::kInt16: |
| 4257 | case DataType::Type::kInt32: { |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4258 | locations->SetInAt(0, Location::Any()); |
| 4259 | break; |
| 4260 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4261 | case DataType::Type::kInt64: { |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4262 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 4263 | if (!instruction->IsConstant()) { |
| 4264 | locations->AddTemp(Location::RequiresRegister()); |
| 4265 | } |
| 4266 | break; |
| 4267 | } |
| 4268 | default: |
| 4269 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 4270 | } |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4271 | } |
| 4272 | |
| 4273 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4274 | SlowPathCode* slow_path = |
| 4275 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathX86(instruction); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4276 | codegen_->AddSlowPath(slow_path); |
| 4277 | |
| 4278 | LocationSummary* locations = instruction->GetLocations(); |
| 4279 | Location value = locations->InAt(0); |
| 4280 | |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4281 | switch (instruction->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4282 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4283 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4284 | case DataType::Type::kInt8: |
| 4285 | case DataType::Type::kUint16: |
| 4286 | case DataType::Type::kInt16: |
| 4287 | case DataType::Type::kInt32: { |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4288 | if (value.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4289 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4290 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4291 | } else if (value.IsStackSlot()) { |
| 4292 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 4293 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4294 | } else { |
| 4295 | DCHECK(value.IsConstant()) << value; |
| 4296 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4297 | __ jmp(slow_path->GetEntryLabel()); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4298 | } |
| 4299 | } |
| 4300 | break; |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4301 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4302 | case DataType::Type::kInt64: { |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4303 | if (value.IsRegisterPair()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4304 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4305 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 4306 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 4307 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4308 | } else { |
| 4309 | DCHECK(value.IsConstant()) << value; |
| 4310 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 4311 | __ jmp(slow_path->GetEntryLabel()); |
| 4312 | } |
| 4313 | } |
| 4314 | break; |
| 4315 | } |
| 4316 | default: |
| 4317 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4318 | } |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4319 | } |
| 4320 | |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4321 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 4322 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4323 | |
| 4324 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4325 | new (GetGraph()->GetAllocator()) LocationSummary(op, LocationSummary::kNoCall); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4326 | |
| 4327 | switch (op->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4328 | case DataType::Type::kInt32: |
| 4329 | case DataType::Type::kInt64: { |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4330 | // Can't have Location::Any() and output SameAsFirstInput() |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4331 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4332 | // The shift count needs to be in CL or a constant. |
| 4333 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4334 | locations->SetOut(Location::SameAsFirstInput()); |
| 4335 | break; |
| 4336 | } |
| 4337 | default: |
| 4338 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 4339 | } |
| 4340 | } |
| 4341 | |
| 4342 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 4343 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4344 | |
| 4345 | LocationSummary* locations = op->GetLocations(); |
| 4346 | Location first = locations->InAt(0); |
| 4347 | Location second = locations->InAt(1); |
| 4348 | DCHECK(first.Equals(locations->Out())); |
| 4349 | |
| 4350 | switch (op->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4351 | case DataType::Type::kInt32: { |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4352 | DCHECK(first.IsRegister()); |
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4353 | Register first_reg = first.AsRegister<Register>(); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4354 | if (second.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4355 | Register second_reg = second.AsRegister<Register>(); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4356 | DCHECK_EQ(ECX, second_reg); |
| 4357 | if (op->IsShl()) { |
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4358 | __ shll(first_reg, second_reg); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4359 | } else if (op->IsShr()) { |
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4360 | __ sarl(first_reg, second_reg); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4361 | } else { |
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4362 | __ shrl(first_reg, second_reg); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4363 | } |
| 4364 | } else { |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4365 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance; |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4366 | if (shift == 0) { |
| 4367 | return; |
| 4368 | } |
| 4369 | Immediate imm(shift); |
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4370 | if (op->IsShl()) { |
| 4371 | __ shll(first_reg, imm); |
| 4372 | } else if (op->IsShr()) { |
| 4373 | __ sarl(first_reg, imm); |
| 4374 | } else { |
| 4375 | __ shrl(first_reg, imm); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4376 | } |
| 4377 | } |
| 4378 | break; |
| 4379 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4380 | case DataType::Type::kInt64: { |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4381 | if (second.IsRegister()) { |
| 4382 | Register second_reg = second.AsRegister<Register>(); |
| 4383 | DCHECK_EQ(ECX, second_reg); |
| 4384 | if (op->IsShl()) { |
| 4385 | GenerateShlLong(first, second_reg); |
| 4386 | } else if (op->IsShr()) { |
| 4387 | GenerateShrLong(first, second_reg); |
| 4388 | } else { |
| 4389 | GenerateUShrLong(first, second_reg); |
| 4390 | } |
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4391 | } else { |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4392 | // Shift by a constant. |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4393 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4394 | // Nothing to do if the shift is 0, as the input is already the output. |
| 4395 | if (shift != 0) { |
| 4396 | if (op->IsShl()) { |
| 4397 | GenerateShlLong(first, shift); |
| 4398 | } else if (op->IsShr()) { |
| 4399 | GenerateShrLong(first, shift); |
| 4400 | } else { |
| 4401 | GenerateUShrLong(first, shift); |
| 4402 | } |
| 4403 | } |
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4404 | } |
| 4405 | break; |
| 4406 | } |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4407 | default: |
| 4408 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 4409 | } |
| 4410 | } |
| 4411 | |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4412 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 4413 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4414 | Register high = loc.AsRegisterPairHigh<Register>(); |
| Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 4415 | if (shift == 1) { |
| 4416 | // This is just an addition. |
| 4417 | __ addl(low, low); |
| 4418 | __ adcl(high, high); |
| 4419 | } else if (shift == 32) { |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4420 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 4421 | codegen_->EmitParallelMoves( |
| 4422 | loc.ToLow(), |
| 4423 | loc.ToHigh(), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4424 | DataType::Type::kInt32, |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4425 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 4426 | loc.ToLow(), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4427 | DataType::Type::kInt32); |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4428 | } else if (shift > 32) { |
| 4429 | // Low part becomes 0. High part is low part << (shift-32). |
| 4430 | __ movl(high, low); |
| 4431 | __ shll(high, Immediate(shift - 32)); |
| 4432 | __ xorl(low, low); |
| 4433 | } else { |
| 4434 | // Between 1 and 31. |
| 4435 | __ shld(high, low, Immediate(shift)); |
| 4436 | __ shll(low, Immediate(shift)); |
| 4437 | } |
| 4438 | } |
| 4439 | |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4440 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4441 | NearLabel done; |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4442 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 4443 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 4444 | __ testl(shifter, Immediate(32)); |
| 4445 | __ j(kEqual, &done); |
| 4446 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 4447 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 4448 | __ Bind(&done); |
| 4449 | } |
| 4450 | |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4451 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 4452 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4453 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 4454 | if (shift == 32) { |
| 4455 | // Need to copy the sign. |
| 4456 | DCHECK_NE(low, high); |
| 4457 | __ movl(low, high); |
| 4458 | __ sarl(high, Immediate(31)); |
| 4459 | } else if (shift > 32) { |
| 4460 | DCHECK_NE(low, high); |
| 4461 | // High part becomes sign. Low part is shifted by shift - 32. |
| 4462 | __ movl(low, high); |
| 4463 | __ sarl(high, Immediate(31)); |
| 4464 | __ sarl(low, Immediate(shift - 32)); |
| 4465 | } else { |
| 4466 | // Between 1 and 31. |
| 4467 | __ shrd(low, high, Immediate(shift)); |
| 4468 | __ sarl(high, Immediate(shift)); |
| 4469 | } |
| 4470 | } |
| 4471 | |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4472 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4473 | NearLabel done; |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4474 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4475 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4476 | __ testl(shifter, Immediate(32)); |
| 4477 | __ j(kEqual, &done); |
| 4478 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4479 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 4480 | __ Bind(&done); |
| 4481 | } |
| 4482 | |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4483 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 4484 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4485 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 4486 | if (shift == 32) { |
| 4487 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 4488 | codegen_->EmitParallelMoves( |
| 4489 | loc.ToHigh(), |
| 4490 | loc.ToLow(), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4491 | DataType::Type::kInt32, |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4492 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 4493 | loc.ToHigh(), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4494 | DataType::Type::kInt32); |
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4495 | } else if (shift > 32) { |
| 4496 | // Low part is high >> (shift - 32). High part becomes 0. |
| 4497 | __ movl(low, high); |
| 4498 | __ shrl(low, Immediate(shift - 32)); |
| 4499 | __ xorl(high, high); |
| 4500 | } else { |
| 4501 | // Between 1 and 31. |
| 4502 | __ shrd(low, high, Immediate(shift)); |
| 4503 | __ shrl(high, Immediate(shift)); |
| 4504 | } |
| 4505 | } |
| 4506 | |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4507 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4508 | NearLabel done; |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4509 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4510 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4511 | __ testl(shifter, Immediate(32)); |
| 4512 | __ j(kEqual, &done); |
| 4513 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4514 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 4515 | __ Bind(&done); |
| 4516 | } |
| 4517 | |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4518 | void LocationsBuilderX86::VisitRor(HRor* ror) { |
| 4519 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4520 | new (GetGraph()->GetAllocator()) LocationSummary(ror, LocationSummary::kNoCall); |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4521 | |
| 4522 | switch (ror->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4523 | case DataType::Type::kInt64: |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4524 | // Add the temporary needed. |
| 4525 | locations->AddTemp(Location::RequiresRegister()); |
| 4526 | FALLTHROUGH_INTENDED; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4527 | case DataType::Type::kInt32: |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4528 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4529 | // The shift count needs to be in CL (unless it is a constant). |
| 4530 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); |
| 4531 | locations->SetOut(Location::SameAsFirstInput()); |
| 4532 | break; |
| 4533 | default: |
| 4534 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4535 | UNREACHABLE(); |
| 4536 | } |
| 4537 | } |
| 4538 | |
| 4539 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { |
| 4540 | LocationSummary* locations = ror->GetLocations(); |
| 4541 | Location first = locations->InAt(0); |
| 4542 | Location second = locations->InAt(1); |
| 4543 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4544 | if (ror->GetResultType() == DataType::Type::kInt32) { |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4545 | Register first_reg = first.AsRegister<Register>(); |
| 4546 | if (second.IsRegister()) { |
| 4547 | Register second_reg = second.AsRegister<Register>(); |
| 4548 | __ rorl(first_reg, second_reg); |
| 4549 | } else { |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4550 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4551 | __ rorl(first_reg, imm); |
| 4552 | } |
| 4553 | return; |
| 4554 | } |
| 4555 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4556 | DCHECK_EQ(ror->GetResultType(), DataType::Type::kInt64); |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4557 | Register first_reg_lo = first.AsRegisterPairLow<Register>(); |
| 4558 | Register first_reg_hi = first.AsRegisterPairHigh<Register>(); |
| 4559 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 4560 | if (second.IsRegister()) { |
| 4561 | Register second_reg = second.AsRegister<Register>(); |
| 4562 | DCHECK_EQ(second_reg, ECX); |
| 4563 | __ movl(temp_reg, first_reg_hi); |
| 4564 | __ shrd(first_reg_hi, first_reg_lo, second_reg); |
| 4565 | __ shrd(first_reg_lo, temp_reg, second_reg); |
| 4566 | __ movl(temp_reg, first_reg_hi); |
| 4567 | __ testl(second_reg, Immediate(32)); |
| 4568 | __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); |
| 4569 | __ cmovl(kNotEqual, first_reg_lo, temp_reg); |
| 4570 | } else { |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4571 | int32_t shift_amt = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4572 | if (shift_amt == 0) { |
| 4573 | // Already fine. |
| 4574 | return; |
| 4575 | } |
| 4576 | if (shift_amt == 32) { |
| 4577 | // Just swap. |
| 4578 | __ movl(temp_reg, first_reg_lo); |
| 4579 | __ movl(first_reg_lo, first_reg_hi); |
| 4580 | __ movl(first_reg_hi, temp_reg); |
| 4581 | return; |
| 4582 | } |
| 4583 | |
| 4584 | Immediate imm(shift_amt); |
| 4585 | // Save the constents of the low value. |
| 4586 | __ movl(temp_reg, first_reg_lo); |
| 4587 | |
| 4588 | // Shift right into low, feeding bits from high. |
| 4589 | __ shrd(first_reg_lo, first_reg_hi, imm); |
| 4590 | |
| 4591 | // Shift right into high, feeding bits from the original low. |
| 4592 | __ shrd(first_reg_hi, temp_reg, imm); |
| 4593 | |
| 4594 | // Swap if needed. |
| 4595 | if (shift_amt > 32) { |
| 4596 | __ movl(temp_reg, first_reg_lo); |
| 4597 | __ movl(first_reg_lo, first_reg_hi); |
| 4598 | __ movl(first_reg_hi, temp_reg); |
| 4599 | } |
| 4600 | } |
| 4601 | } |
| 4602 | |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4603 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 4604 | HandleShift(shl); |
| 4605 | } |
| 4606 | |
| 4607 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 4608 | HandleShift(shl); |
| 4609 | } |
| 4610 | |
| 4611 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 4612 | HandleShift(shr); |
| 4613 | } |
| 4614 | |
| 4615 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 4616 | HandleShift(shr); |
| 4617 | } |
| 4618 | |
| 4619 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 4620 | HandleShift(ushr); |
| 4621 | } |
| 4622 | |
| 4623 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 4624 | HandleShift(ushr); |
| 4625 | } |
| 4626 | |
| Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4627 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4628 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4629 | instruction, LocationSummary::kCallOnMainOnly); |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4630 | locations->SetOut(Location::RegisterLocation(EAX)); |
| Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 4631 | InvokeRuntimeCallingConvention calling_convention; |
| 4632 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4633 | } |
| 4634 | |
| 4635 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
| Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 4636 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
| 4637 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| 4638 | DCHECK(!codegen_->IsLeafMethod()); |
| Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4639 | } |
| 4640 | |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4641 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4642 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4643 | instruction, LocationSummary::kCallOnMainOnly); |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4644 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 4645 | InvokeRuntimeCallingConvention calling_convention; |
| Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4646 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4647 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4648 | } |
| 4649 | |
| 4650 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
| Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 4651 | // Note: if heap poisoning is enabled, the entry point takes care of poisoning the reference. |
| 4652 | QuickEntrypointEnum entrypoint = CodeGenerator::GetArrayAllocationEntrypoint(instruction); |
| Nicolas Geoffray | d095844 | 2017-01-30 14:57:16 +0000 | [diff] [blame] | 4653 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
| Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4654 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4655 | DCHECK(!codegen_->IsLeafMethod()); |
| 4656 | } |
| 4657 | |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4658 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4659 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4660 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4661 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4662 | if (location.IsStackSlot()) { |
| 4663 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4664 | } else if (location.IsDoubleStackSlot()) { |
| 4665 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4666 | } |
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4667 | locations->SetOut(location); |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4668 | } |
| 4669 | |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4670 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 4671 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 4672 | } |
| 4673 | |
| 4674 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4675 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4676 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4677 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4678 | } |
| 4679 | |
| 4680 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4681 | } |
| 4682 | |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4683 | void LocationsBuilderX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4684 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4685 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4686 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4687 | locations->SetOut(Location::RequiresRegister()); |
| 4688 | } |
| 4689 | |
| 4690 | void InstructionCodeGeneratorX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4691 | LocationSummary* locations = instruction->GetLocations(); |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4692 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4693 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4694 | instruction->GetIndex(), kX86PointerSize).SizeValue(); |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4695 | __ movl(locations->Out().AsRegister<Register>(), |
| 4696 | Address(locations->InAt(0).AsRegister<Register>(), method_offset)); |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4697 | } else { |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4698 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4699 | instruction->GetIndex(), kX86PointerSize)); |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4700 | __ movl(locations->Out().AsRegister<Register>(), |
| 4701 | Address(locations->InAt(0).AsRegister<Register>(), |
| 4702 | mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
| 4703 | // temp = temp->GetImtEntryAt(method_offset); |
| 4704 | __ movl(locations->Out().AsRegister<Register>(), |
| 4705 | Address(locations->Out().AsRegister<Register>(), method_offset)); |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4706 | } |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4707 | } |
| 4708 | |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4709 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4710 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4711 | new (GetGraph()->GetAllocator()) LocationSummary(not_, LocationSummary::kNoCall); |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4712 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4713 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4714 | } |
| 4715 | |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4716 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 4717 | LocationSummary* locations = not_->GetLocations(); |
| Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4718 | Location in = locations->InAt(0); |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4719 | Location out = locations->Out(); |
| Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4720 | DCHECK(in.Equals(out)); |
| Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4721 | switch (not_->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4722 | case DataType::Type::kInt32: |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4723 | __ notl(out.AsRegister<Register>()); |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4724 | break; |
| 4725 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4726 | case DataType::Type::kInt64: |
| Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4727 | __ notl(out.AsRegisterPairLow<Register>()); |
| 4728 | __ notl(out.AsRegisterPairHigh<Register>()); |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4729 | break; |
| 4730 | |
| 4731 | default: |
| 4732 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4733 | } |
| Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4734 | } |
| 4735 | |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4736 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4737 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4738 | new (GetGraph()->GetAllocator()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4739 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4740 | locations->SetOut(Location::SameAsFirstInput()); |
| 4741 | } |
| 4742 | |
| 4743 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4744 | LocationSummary* locations = bool_not->GetLocations(); |
| 4745 | Location in = locations->InAt(0); |
| 4746 | Location out = locations->Out(); |
| 4747 | DCHECK(in.Equals(out)); |
| 4748 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 4749 | } |
| 4750 | |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4751 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4752 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4753 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4754 | switch (compare->InputAt(0)->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4755 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4756 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4757 | case DataType::Type::kInt8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4758 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4759 | case DataType::Type::kInt16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4760 | case DataType::Type::kInt32: |
| 4761 | case DataType::Type::kInt64: { |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4762 | locations->SetInAt(0, Location::RequiresRegister()); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4763 | locations->SetInAt(1, Location::Any()); |
| 4764 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4765 | break; |
| 4766 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4767 | case DataType::Type::kFloat32: |
| 4768 | case DataType::Type::kFloat64: { |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4769 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4770 | if (compare->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4771 | DCHECK(compare->InputAt(1)->IsEmittedAtUseSite()); |
| 4772 | } else if (compare->InputAt(1)->IsConstant()) { |
| 4773 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4774 | } else { |
| 4775 | locations->SetInAt(1, Location::Any()); |
| 4776 | } |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4777 | locations->SetOut(Location::RequiresRegister()); |
| 4778 | break; |
| 4779 | } |
| 4780 | default: |
| 4781 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4782 | } |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4783 | } |
| 4784 | |
| 4785 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4786 | LocationSummary* locations = compare->GetLocations(); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4787 | Register out = locations->Out().AsRegister<Register>(); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4788 | Location left = locations->InAt(0); |
| 4789 | Location right = locations->InAt(1); |
| 4790 | |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4791 | NearLabel less, greater, done; |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4792 | Condition less_cond = kLess; |
| 4793 | |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4794 | switch (compare->InputAt(0)->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4795 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4796 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4797 | case DataType::Type::kInt8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4798 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4799 | case DataType::Type::kInt16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4800 | case DataType::Type::kInt32: { |
| Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 4801 | codegen_->GenerateIntCompare(left, right); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4802 | break; |
| 4803 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4804 | case DataType::Type::kInt64: { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4805 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 4806 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 4807 | int32_t val_low = 0; |
| 4808 | int32_t val_high = 0; |
| 4809 | bool right_is_const = false; |
| 4810 | |
| 4811 | if (right.IsConstant()) { |
| 4812 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 4813 | right_is_const = true; |
| 4814 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 4815 | val_low = Low32Bits(val); |
| 4816 | val_high = High32Bits(val); |
| 4817 | } |
| 4818 | |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4819 | if (right.IsRegisterPair()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4820 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4821 | } else if (right.IsDoubleStackSlot()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4822 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4823 | } else { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4824 | DCHECK(right_is_const) << right; |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4825 | codegen_->Compare32BitValue(left_high, val_high); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4826 | } |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4827 | __ j(kLess, &less); // Signed compare. |
| 4828 | __ j(kGreater, &greater); // Signed compare. |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4829 | if (right.IsRegisterPair()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4830 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4831 | } else if (right.IsDoubleStackSlot()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4832 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4833 | } else { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4834 | DCHECK(right_is_const) << right; |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4835 | codegen_->Compare32BitValue(left_low, val_low); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4836 | } |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4837 | less_cond = kBelow; // for CF (unsigned). |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4838 | break; |
| 4839 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4840 | case DataType::Type::kFloat32: { |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4841 | GenerateFPCompare(left, right, compare, false); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4842 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4843 | less_cond = kBelow; // for CF (floats). |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4844 | break; |
| 4845 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4846 | case DataType::Type::kFloat64: { |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4847 | GenerateFPCompare(left, right, compare, true); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4848 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4849 | less_cond = kBelow; // for CF (floats). |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4850 | break; |
| 4851 | } |
| 4852 | default: |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4853 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4854 | } |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4855 | |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4856 | __ movl(out, Immediate(0)); |
| 4857 | __ j(kEqual, &done); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4858 | __ j(less_cond, &less); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4859 | |
| 4860 | __ Bind(&greater); |
| 4861 | __ movl(out, Immediate(1)); |
| 4862 | __ jmp(&done); |
| 4863 | |
| 4864 | __ Bind(&less); |
| 4865 | __ movl(out, Immediate(-1)); |
| 4866 | |
| 4867 | __ Bind(&done); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4868 | } |
| 4869 | |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4870 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4871 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4872 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4873 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
| Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4874 | locations->SetInAt(i, Location::Any()); |
| 4875 | } |
| 4876 | locations->SetOut(Location::Any()); |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4877 | } |
| 4878 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4879 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4880 | LOG(FATAL) << "Unreachable"; |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4881 | } |
| 4882 | |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4883 | void CodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4884 | /* |
| 4885 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 4886 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 4887 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4888 | */ |
| 4889 | switch (kind) { |
| 4890 | case MemBarrierKind::kAnyAny: { |
| Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4891 | MemoryFence(); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4892 | break; |
| 4893 | } |
| 4894 | case MemBarrierKind::kAnyStore: |
| 4895 | case MemBarrierKind::kLoadAny: |
| 4896 | case MemBarrierKind::kStoreStore: { |
| 4897 | // nop |
| 4898 | break; |
| 4899 | } |
| Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4900 | case MemBarrierKind::kNTStoreStore: |
| 4901 | // Non-Temporal Store/Store needs an explicit fence. |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4902 | MemoryFence(/* non-temporal= */ true); |
| Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4903 | break; |
| Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4904 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4905 | } |
| 4906 | |
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4907 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( |
| 4908 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| Nicolas Geoffray | bdb2ecc | 2018-09-18 14:33:55 +0100 | [diff] [blame] | 4909 | ArtMethod* method ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4910 | return desired_dispatch_info; |
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4911 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4912 | |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4913 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 4914 | Register temp) { |
| 4915 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4916 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4917 | if (!invoke->GetLocations()->Intrinsified()) { |
| 4918 | return location.AsRegister<Register>(); |
| 4919 | } |
| 4920 | // For intrinsics we allow any location, so it may be on the stack. |
| 4921 | if (!location.IsRegister()) { |
| 4922 | __ movl(temp, Address(ESP, location.GetStackIndex())); |
| 4923 | return temp; |
| 4924 | } |
| 4925 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 4926 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 4927 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 4928 | // simple and more robust approach rather that trying to determine if that's the case. |
| 4929 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| Vladimir Marko | 4ee8e29 | 2017-06-02 15:39:30 +0000 | [diff] [blame] | 4930 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 4931 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 4932 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 4933 | __ movl(temp, Address(ESP, stack_offset)); |
| 4934 | return temp; |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4935 | } |
| 4936 | return location.AsRegister<Register>(); |
| 4937 | } |
| 4938 | |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4939 | void CodeGeneratorX86::GenerateStaticOrDirectCall( |
| 4940 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4941 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4942 | switch (invoke->GetMethodLoadKind()) { |
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4943 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4944 | // temp = thread->string_init_entrypoint |
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4945 | uint32_t offset = |
| 4946 | GetThreadOffset<kX86PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 4947 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(offset)); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4948 | break; |
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4949 | } |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4950 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
| Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4951 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4952 | break; |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4953 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 4954 | DCHECK(GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4955 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4956 | temp.AsRegister<Register>()); |
| 4957 | __ leal(temp.AsRegister<Register>(), Address(base_reg, CodeGeneratorX86::kDummy32BitOffset)); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4958 | RecordBootImageMethodPatch(invoke); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4959 | break; |
| 4960 | } |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4961 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageRelRo: { |
| 4962 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4963 | temp.AsRegister<Register>()); |
| 4964 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
| 4965 | RecordBootImageRelRoPatch( |
| 4966 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(), |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4967 | GetBootImageOffset(invoke)); |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4968 | break; |
| 4969 | } |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4970 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4971 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4972 | temp.AsRegister<Register>()); |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4973 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4974 | RecordMethodBssEntryPatch(invoke); |
| Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 4975 | // No need for memory fence, thanks to the x86 memory model. |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4976 | break; |
| 4977 | } |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4978 | case HInvokeStaticOrDirect::MethodLoadKind::kJitDirectAddress: |
| 4979 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 4980 | break; |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4981 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 4982 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 4983 | return; // No code pointer retrieval; the runtime performs the call directly. |
| Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4984 | } |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4985 | } |
| 4986 | |
| 4987 | switch (invoke->GetCodePtrLocation()) { |
| 4988 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 4989 | __ call(GetFrameEntryLabel()); |
| 4990 | break; |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4991 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4992 | // (callee_method + offset_of_quick_compiled_code)() |
| 4993 | __ call(Address(callee_method.AsRegister<Register>(), |
| 4994 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4995 | kX86PointerSize).Int32Value())); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4996 | break; |
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4997 | } |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4998 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4999 | |
| 5000 | DCHECK(!IsLeafMethod()); |
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 5001 | } |
| 5002 | |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5003 | void CodeGeneratorX86::GenerateVirtualCall( |
| 5004 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5005 | Register temp = temp_in.AsRegister<Register>(); |
| 5006 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 5007 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
| Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 5008 | |
| 5009 | // Use the calling convention instead of the location of the receiver, as |
| 5010 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 5011 | // slow path, the arguments have been moved to the right place, so here we are |
| 5012 | // guaranteed that the receiver is the first register of the calling convention. |
| 5013 | InvokeDexCallingConvention calling_convention; |
| 5014 | Register receiver = calling_convention.GetRegisterAt(0); |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5015 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5016 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 5017 | __ movl(temp, Address(receiver, class_offset)); |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5018 | MaybeRecordImplicitNullCheck(invoke); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5019 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 5020 | // emit a read barrier for the previous class reference load. |
| 5021 | // However this is not required in practice, as this is an |
| 5022 | // intermediate/temporary reference and because the current |
| 5023 | // concurrent copying collector keeps the from-space memory |
| 5024 | // intact/accessible until the end of the marking phase (the |
| 5025 | // concurrent copying collector may not in the future). |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5026 | __ MaybeUnpoisonHeapReference(temp); |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 5027 | |
| 5028 | MaybeGenerateInlineCacheCheck(invoke, temp); |
| 5029 | |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5030 | // temp = temp->GetMethodAt(method_offset); |
| 5031 | __ movl(temp, Address(temp, method_offset)); |
| 5032 | // call temp->GetEntryPoint(); |
| 5033 | __ call(Address( |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5034 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5035 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5036 | } |
| 5037 | |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5038 | void CodeGeneratorX86::RecordBootImageIntrinsicPatch(HX86ComputeBaseMethodAddress* method_address, |
| 5039 | uint32_t intrinsic_data) { |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5040 | boot_image_other_patches_.emplace_back( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5041 | method_address, /* target_dex_file= */ nullptr, intrinsic_data); |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5042 | __ Bind(&boot_image_other_patches_.back().label); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5043 | } |
| 5044 | |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 5045 | void CodeGeneratorX86::RecordBootImageRelRoPatch(HX86ComputeBaseMethodAddress* method_address, |
| 5046 | uint32_t boot_image_offset) { |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5047 | boot_image_other_patches_.emplace_back( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5048 | method_address, /* target_dex_file= */ nullptr, boot_image_offset); |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5049 | __ Bind(&boot_image_other_patches_.back().label); |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 5050 | } |
| 5051 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5052 | void CodeGeneratorX86::RecordBootImageMethodPatch(HInvokeStaticOrDirect* invoke) { |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5053 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5054 | HX86ComputeBaseMethodAddress* method_address = |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5055 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5056 | boot_image_method_patches_.emplace_back( |
| 5057 | method_address, invoke->GetTargetMethod().dex_file, invoke->GetTargetMethod().index); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5058 | __ Bind(&boot_image_method_patches_.back().label); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5059 | } |
| 5060 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5061 | void CodeGeneratorX86::RecordMethodBssEntryPatch(HInvokeStaticOrDirect* invoke) { |
| 5062 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 5063 | HX86ComputeBaseMethodAddress* method_address = |
| 5064 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5065 | // 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] | 5066 | method_bss_entry_patches_.emplace_back( |
| 5067 | method_address, &GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()); |
| 5068 | __ Bind(&method_bss_entry_patches_.back().label); |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5069 | } |
| 5070 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5071 | void CodeGeneratorX86::RecordBootImageTypePatch(HLoadClass* load_class) { |
| 5072 | HX86ComputeBaseMethodAddress* method_address = |
| 5073 | load_class->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 5074 | boot_image_type_patches_.emplace_back( |
| 5075 | method_address, &load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5076 | __ Bind(&boot_image_type_patches_.back().label); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5077 | } |
| 5078 | |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5079 | Label* CodeGeneratorX86::NewTypeBssEntryPatch(HLoadClass* load_class) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5080 | HX86ComputeBaseMethodAddress* method_address = |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 5081 | load_class->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 5082 | type_bss_entry_patches_.emplace_back( |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5083 | method_address, &load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5084 | return &type_bss_entry_patches_.back().label; |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5085 | } |
| 5086 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5087 | void CodeGeneratorX86::RecordBootImageStringPatch(HLoadString* load_string) { |
| 5088 | HX86ComputeBaseMethodAddress* method_address = |
| 5089 | load_string->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 5090 | boot_image_string_patches_.emplace_back( |
| 5091 | method_address, &load_string->GetDexFile(), load_string->GetStringIndex().index_); |
| 5092 | __ Bind(&boot_image_string_patches_.back().label); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5093 | } |
| 5094 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5095 | Label* CodeGeneratorX86::NewStringBssEntryPatch(HLoadString* load_string) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5096 | HX86ComputeBaseMethodAddress* method_address = |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 5097 | load_string->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5098 | string_bss_entry_patches_.emplace_back( |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5099 | method_address, &load_string->GetDexFile(), load_string->GetStringIndex().index_); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5100 | return &string_bss_entry_patches_.back().label; |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5101 | } |
| 5102 | |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5103 | void CodeGeneratorX86::LoadBootImageAddress(Register reg, |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5104 | uint32_t boot_image_reference, |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5105 | HInvokeStaticOrDirect* invoke) { |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5106 | if (GetCompilerOptions().IsBootImage()) { |
| 5107 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 5108 | HX86ComputeBaseMethodAddress* method_address = |
| 5109 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
| 5110 | DCHECK(method_address != nullptr); |
| 5111 | Register method_address_reg = |
| 5112 | invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()).AsRegister<Register>(); |
| 5113 | __ leal(reg, Address(method_address_reg, CodeGeneratorX86::kDummy32BitOffset)); |
| 5114 | RecordBootImageIntrinsicPatch(method_address, boot_image_reference); |
| Vladimir Marko | a2da9b9 | 2018-10-10 14:21:55 +0100 | [diff] [blame] | 5115 | } else if (GetCompilerOptions().GetCompilePic()) { |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5116 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 5117 | HX86ComputeBaseMethodAddress* method_address = |
| 5118 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
| 5119 | DCHECK(method_address != nullptr); |
| 5120 | Register method_address_reg = |
| 5121 | invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()).AsRegister<Register>(); |
| 5122 | __ movl(reg, Address(method_address_reg, CodeGeneratorX86::kDummy32BitOffset)); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5123 | RecordBootImageRelRoPatch(method_address, boot_image_reference); |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5124 | } else { |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5125 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5126 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 5127 | DCHECK(!heap->GetBootImageSpaces().empty()); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5128 | const uint8_t* address = heap->GetBootImageSpaces()[0]->Begin() + boot_image_reference; |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5129 | __ movl(reg, Immediate(dchecked_integral_cast<uint32_t>(reinterpret_cast<uintptr_t>(address)))); |
| 5130 | } |
| 5131 | } |
| 5132 | |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5133 | void CodeGeneratorX86::AllocateInstanceForIntrinsic(HInvokeStaticOrDirect* invoke, |
| 5134 | uint32_t boot_image_offset) { |
| 5135 | DCHECK(invoke->IsStatic()); |
| 5136 | InvokeRuntimeCallingConvention calling_convention; |
| 5137 | Register argument = calling_convention.GetRegisterAt(0); |
| 5138 | if (GetCompilerOptions().IsBootImage()) { |
| 5139 | DCHECK_EQ(boot_image_offset, IntrinsicVisitor::IntegerValueOfInfo::kInvalidReference); |
| 5140 | // Load the class the same way as for HLoadClass::LoadKind::kBootImageLinkTimePcRelative. |
| 5141 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 5142 | HX86ComputeBaseMethodAddress* method_address = |
| 5143 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
| 5144 | DCHECK(method_address != nullptr); |
| 5145 | Register method_address_reg = |
| 5146 | invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()).AsRegister<Register>(); |
| 5147 | __ leal(argument, Address(method_address_reg, CodeGeneratorX86::kDummy32BitOffset)); |
| 5148 | MethodReference target_method = invoke->GetTargetMethod(); |
| 5149 | dex::TypeIndex type_idx = target_method.dex_file->GetMethodId(target_method.index).class_idx_; |
| 5150 | boot_image_type_patches_.emplace_back(method_address, target_method.dex_file, type_idx.index_); |
| 5151 | __ Bind(&boot_image_type_patches_.back().label); |
| 5152 | } else { |
| 5153 | LoadBootImageAddress(argument, boot_image_offset, invoke); |
| 5154 | } |
| 5155 | InvokeRuntime(kQuickAllocObjectInitialized, invoke, invoke->GetDexPc()); |
| 5156 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| 5157 | } |
| 5158 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5159 | // The label points to the end of the "movl" or another instruction but the literal offset |
| 5160 | // for method patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 5161 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
| 5162 | |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5163 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5164 | inline void CodeGeneratorX86::EmitPcRelativeLinkerPatches( |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 5165 | const ArenaDeque<X86PcRelativePatchInfo>& infos, |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5166 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 5167 | for (const X86PcRelativePatchInfo& info : infos) { |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5168 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5169 | linker_patches->push_back(Factory(literal_offset, |
| 5170 | info.target_dex_file, |
| 5171 | GetMethodAddressOffset(info.method_address), |
| 5172 | info.offset_or_index)); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5173 | } |
| 5174 | } |
| 5175 | |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5176 | template <linker::LinkerPatch (*Factory)(size_t, uint32_t, uint32_t)> |
| 5177 | linker::LinkerPatch NoDexFileAdapter(size_t literal_offset, |
| 5178 | const DexFile* target_dex_file, |
| 5179 | uint32_t pc_insn_offset, |
| 5180 | uint32_t boot_image_offset) { |
| 5181 | DCHECK(target_dex_file == nullptr); // Unused for these patches, should be null. |
| 5182 | return Factory(literal_offset, pc_insn_offset, boot_image_offset); |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 5183 | } |
| 5184 | |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5185 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5186 | DCHECK(linker_patches->empty()); |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 5187 | size_t size = |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5188 | boot_image_method_patches_.size() + |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5189 | method_bss_entry_patches_.size() + |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5190 | boot_image_type_patches_.size() + |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5191 | type_bss_entry_patches_.size() + |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5192 | boot_image_string_patches_.size() + |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5193 | string_bss_entry_patches_.size() + |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5194 | boot_image_other_patches_.size(); |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 5195 | linker_patches->reserve(size); |
| Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 5196 | if (GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()) { |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5197 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
| 5198 | boot_image_method_patches_, linker_patches); |
| 5199 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
| 5200 | boot_image_type_patches_, linker_patches); |
| 5201 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5202 | boot_image_string_patches_, linker_patches); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5203 | } else { |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5204 | DCHECK(boot_image_method_patches_.empty()); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5205 | DCHECK(boot_image_type_patches_.empty()); |
| 5206 | DCHECK(boot_image_string_patches_.empty()); |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5207 | } |
| 5208 | if (GetCompilerOptions().IsBootImage()) { |
| 5209 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::IntrinsicReferencePatch>>( |
| 5210 | boot_image_other_patches_, linker_patches); |
| 5211 | } else { |
| 5212 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::DataBimgRelRoPatch>>( |
| 5213 | boot_image_other_patches_, linker_patches); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5214 | } |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5215 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 5216 | method_bss_entry_patches_, linker_patches); |
| 5217 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 5218 | type_bss_entry_patches_, linker_patches); |
| 5219 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 5220 | string_bss_entry_patches_, linker_patches); |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5221 | DCHECK_EQ(size, linker_patches->size()); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5222 | } |
| 5223 | |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5224 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 5225 | Register card, |
| 5226 | Register object, |
| 5227 | Register value, |
| 5228 | bool value_can_be_null) { |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 5229 | NearLabel is_null; |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5230 | if (value_can_be_null) { |
| 5231 | __ testl(value, value); |
| 5232 | __ j(kEqual, &is_null); |
| 5233 | } |
| Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5234 | // Load the address of the card table into `card`. |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5235 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86PointerSize>().Int32Value())); |
| Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5236 | // Calculate the offset (in the card table) of the card corresponding to |
| 5237 | // `object`. |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5238 | __ movl(temp, object); |
| 5239 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
| Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5240 | // Write the `art::gc::accounting::CardTable::kCardDirty` value into the |
| 5241 | // `object`'s card. |
| 5242 | // |
| 5243 | // Register `card` contains the address of the card table. Note that the card |
| 5244 | // table's base is biased during its creation so that it always starts at an |
| 5245 | // address whose least-significant byte is equal to `kCardDirty` (see |
| 5246 | // art::gc::accounting::CardTable::Create). Therefore the MOVB instruction |
| 5247 | // below writes the `kCardDirty` (byte) value into the `object`'s card |
| 5248 | // (located at `card + object >> kCardShift`). |
| 5249 | // |
| 5250 | // This dual use of the value in register `card` (1. to calculate the location |
| 5251 | // of the card to mark; and 2. to load the `kCardDirty` value) saves a load |
| 5252 | // (no need to explicitly load `kCardDirty` as an immediate value). |
| Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 5253 | __ movb(Address(temp, card, TIMES_1, 0), |
| 5254 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5255 | if (value_can_be_null) { |
| 5256 | __ Bind(&is_null); |
| 5257 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5258 | } |
| 5259 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5260 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 5261 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5262 | |
| 5263 | bool object_field_get_with_read_barrier = |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5264 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5265 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5266 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 5267 | kEmitCompilerReadBarrier |
| 5268 | ? LocationSummary::kCallOnSlowPath |
| 5269 | : LocationSummary::kNoCall); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5270 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5271 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5272 | } |
| Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5273 | locations->SetInAt(0, Location::RequiresRegister()); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5274 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5275 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5276 | locations->SetOut(Location::RequiresFpuRegister()); |
| 5277 | } else { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5278 | // The output overlaps in case of long: we don't want the low move |
| 5279 | // to overwrite the object's location. Likewise, in the case of |
| 5280 | // an object field get with read barriers enabled, we do not want |
| 5281 | // the move to overwrite the object's location, as we need it to emit |
| 5282 | // the read barrier. |
| 5283 | locations->SetOut( |
| 5284 | Location::RequiresRegister(), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5285 | (object_field_get_with_read_barrier || instruction->GetType() == DataType::Type::kInt64) ? |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5286 | Location::kOutputOverlap : |
| 5287 | Location::kNoOutputOverlap); |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5288 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5289 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5290 | if (field_info.IsVolatile() && (field_info.GetFieldType() == DataType::Type::kInt64)) { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5291 | // Long values can be loaded atomically into an XMM using movsd. |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5292 | // So we use an XMM register as a temp to achieve atomicity (first |
| 5293 | // load the temp into the XMM and then copy the XMM into the |
| 5294 | // output, 32 bits at a time). |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5295 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 5296 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5297 | } |
| 5298 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5299 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 5300 | const FieldInfo& field_info) { |
| 5301 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5302 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5303 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5304 | Location base_loc = locations->InAt(0); |
| 5305 | Register base = base_loc.AsRegister<Register>(); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5306 | Location out = locations->Out(); |
| 5307 | bool is_volatile = field_info.IsVolatile(); |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5308 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 5309 | DataType::Type load_type = instruction->GetType(); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5310 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5311 | |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5312 | switch (load_type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5313 | case DataType::Type::kBool: |
| 5314 | case DataType::Type::kUint8: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5315 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5316 | break; |
| 5317 | } |
| 5318 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5319 | case DataType::Type::kInt8: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5320 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5321 | break; |
| 5322 | } |
| 5323 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5324 | case DataType::Type::kUint16: { |
| 5325 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5326 | break; |
| 5327 | } |
| 5328 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5329 | case DataType::Type::kInt16: { |
| 5330 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5331 | break; |
| 5332 | } |
| 5333 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5334 | case DataType::Type::kInt32: |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5335 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5336 | break; |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5337 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5338 | case DataType::Type::kReference: { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5339 | // /* HeapReference<Object> */ out = *(base + offset) |
| 5340 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5341 | // Note that a potential implicit null check is handled in this |
| 5342 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 5343 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5344 | instruction, out, base, offset, /* needs_null_check= */ true); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5345 | if (is_volatile) { |
| 5346 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5347 | } |
| 5348 | } else { |
| 5349 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| 5350 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5351 | if (is_volatile) { |
| 5352 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5353 | } |
| 5354 | // If read barriers are enabled, emit read barriers other than |
| 5355 | // Baker's using a slow path (and also unpoison the loaded |
| 5356 | // reference, if heap poisoning is enabled). |
| 5357 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 5358 | } |
| 5359 | break; |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5360 | } |
| 5361 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5362 | case DataType::Type::kInt64: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5363 | if (is_volatile) { |
| 5364 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 5365 | __ movsd(temp, Address(base, offset)); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5366 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5367 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 5368 | __ psrlq(temp, Immediate(32)); |
| 5369 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 5370 | } else { |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5371 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5372 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5373 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5374 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 5375 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5376 | break; |
| 5377 | } |
| 5378 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5379 | case DataType::Type::kFloat32: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5380 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5381 | break; |
| 5382 | } |
| 5383 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5384 | case DataType::Type::kFloat64: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5385 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5386 | break; |
| 5387 | } |
| 5388 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5389 | case DataType::Type::kUint32: |
| 5390 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5391 | case DataType::Type::kVoid: |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5392 | LOG(FATAL) << "Unreachable type " << load_type; |
| Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5393 | UNREACHABLE(); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5394 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5395 | |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5396 | if (load_type == DataType::Type::kReference || load_type == DataType::Type::kInt64) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5397 | // Potential implicit null checks, in the case of reference or |
| 5398 | // long fields, are handled in the previous switch statement. |
| 5399 | } else { |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5400 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5401 | } |
| 5402 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5403 | if (is_volatile) { |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5404 | if (load_type == DataType::Type::kReference) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5405 | // Memory barriers, in the case of references, are also handled |
| 5406 | // in the previous switch statement. |
| 5407 | } else { |
| 5408 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5409 | } |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5410 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5411 | } |
| 5412 | |
| 5413 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 5414 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5415 | |
| 5416 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5417 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5418 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5419 | bool is_volatile = field_info.IsVolatile(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5420 | DataType::Type field_type = field_info.GetFieldType(); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5421 | bool is_byte_type = DataType::Size(field_type) == 1u; |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5422 | |
| 5423 | // The register allocator does not support multiple |
| 5424 | // inputs that die at entry with one in a specific register. |
| 5425 | if (is_byte_type) { |
| 5426 | // Ensure the value is in a byte register. |
| 5427 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5428 | } else if (DataType::IsFloatingPointType(field_type)) { |
| 5429 | if (is_volatile && field_type == DataType::Type::kFloat64) { |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5430 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 5431 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 5432 | } else { |
| 5433 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 5434 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5435 | } else if (is_volatile && field_type == DataType::Type::kInt64) { |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5436 | // 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] | 5437 | locations->SetInAt(1, Location::RequiresRegister()); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5438 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5439 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 5440 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 5441 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 5442 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 5443 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 5444 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 5445 | locations->AddTemp(Location::RequiresFpuRegister()); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5446 | } else { |
| 5447 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5448 | |
| 5449 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 5450 | // Temporary registers for the write barrier. |
| 5451 | locations->AddTemp(Location::RequiresRegister()); // May be used for reference poisoning too. |
| 5452 | // Ensure the card is in a byte register. |
| 5453 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 5454 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5455 | } |
| 5456 | } |
| 5457 | |
| 5458 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5459 | const FieldInfo& field_info, |
| 5460 | bool value_can_be_null) { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5461 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5462 | |
| 5463 | LocationSummary* locations = instruction->GetLocations(); |
| 5464 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 5465 | Location value = locations->InAt(1); |
| 5466 | bool is_volatile = field_info.IsVolatile(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5467 | DataType::Type field_type = field_info.GetFieldType(); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5468 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5469 | bool needs_write_barrier = |
| 5470 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5471 | |
| 5472 | if (is_volatile) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5473 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5474 | } |
| 5475 | |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5476 | bool maybe_record_implicit_null_check_done = false; |
| 5477 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5478 | switch (field_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5479 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5480 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5481 | case DataType::Type::kInt8: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5482 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 5483 | break; |
| 5484 | } |
| 5485 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5486 | case DataType::Type::kUint16: |
| 5487 | case DataType::Type::kInt16: { |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5488 | if (value.IsConstant()) { |
| Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5489 | __ movw(Address(base, offset), |
| 5490 | Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5491 | } else { |
| 5492 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 5493 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5494 | break; |
| 5495 | } |
| 5496 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5497 | case DataType::Type::kInt32: |
| 5498 | case DataType::Type::kReference: { |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5499 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 5500 | // Note that in the case where `value` is a null reference, |
| 5501 | // we do not enter this block, as the reference does not |
| 5502 | // need poisoning. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5503 | DCHECK_EQ(field_type, DataType::Type::kReference); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5504 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5505 | __ movl(temp, value.AsRegister<Register>()); |
| 5506 | __ PoisonHeapReference(temp); |
| 5507 | __ movl(Address(base, offset), temp); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5508 | } else if (value.IsConstant()) { |
| 5509 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5510 | __ movl(Address(base, offset), Immediate(v)); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5511 | } else { |
| Nicolas Geoffray | 0397163 | 2016-03-17 10:44:24 +0000 | [diff] [blame] | 5512 | DCHECK(value.IsRegister()) << value; |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5513 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 5514 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5515 | break; |
| 5516 | } |
| 5517 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5518 | case DataType::Type::kInt64: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5519 | if (is_volatile) { |
| 5520 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 5521 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 5522 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 5523 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 5524 | __ punpckldq(temp1, temp2); |
| 5525 | __ movsd(Address(base, offset), temp1); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5526 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5527 | } else if (value.IsConstant()) { |
| 5528 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 5529 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 5530 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5531 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5532 | } else { |
| 5533 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5534 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5535 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 5536 | } |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5537 | maybe_record_implicit_null_check_done = true; |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5538 | break; |
| 5539 | } |
| 5540 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5541 | case DataType::Type::kFloat32: { |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5542 | if (value.IsConstant()) { |
| 5543 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5544 | __ movl(Address(base, offset), Immediate(v)); |
| 5545 | } else { |
| 5546 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 5547 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5548 | break; |
| 5549 | } |
| 5550 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5551 | case DataType::Type::kFloat64: { |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5552 | if (value.IsConstant()) { |
| 5553 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 5554 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 5555 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5556 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
| 5557 | maybe_record_implicit_null_check_done = true; |
| 5558 | } else { |
| 5559 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 5560 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5561 | break; |
| 5562 | } |
| 5563 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5564 | case DataType::Type::kUint32: |
| 5565 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5566 | case DataType::Type::kVoid: |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5567 | LOG(FATAL) << "Unreachable type " << field_type; |
| 5568 | UNREACHABLE(); |
| 5569 | } |
| 5570 | |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5571 | if (!maybe_record_implicit_null_check_done) { |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5572 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5573 | } |
| 5574 | |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5575 | if (needs_write_barrier) { |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5576 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5577 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5578 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5579 | } |
| 5580 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5581 | if (is_volatile) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5582 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5583 | } |
| 5584 | } |
| 5585 | |
| 5586 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5587 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5588 | } |
| 5589 | |
| 5590 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5591 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5592 | } |
| 5593 | |
| 5594 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 5595 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5596 | } |
| 5597 | |
| 5598 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5599 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5600 | } |
| 5601 | |
| 5602 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5603 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5604 | } |
| 5605 | |
| 5606 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5607 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5608 | } |
| 5609 | |
| 5610 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5611 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5612 | } |
| 5613 | |
| 5614 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5615 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5616 | } |
| 5617 | |
| Vladimir Marko | 552a134 | 2017-10-31 10:56:47 +0000 | [diff] [blame] | 5618 | void LocationsBuilderX86::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 5619 | codegen_->CreateStringBuilderAppendLocations(instruction, Location::RegisterLocation(EAX)); |
| 5620 | } |
| 5621 | |
| 5622 | void InstructionCodeGeneratorX86::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 5623 | __ movl(EAX, Immediate(instruction->GetFormat()->GetValue())); |
| 5624 | codegen_->InvokeRuntime(kQuickStringBuilderAppend, instruction, instruction->GetDexPc()); |
| 5625 | } |
| 5626 | |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5627 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 5628 | HUnresolvedInstanceFieldGet* instruction) { |
| 5629 | FieldAccessCallingConventionX86 calling_convention; |
| 5630 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5631 | instruction, instruction->GetFieldType(), calling_convention); |
| 5632 | } |
| 5633 | |
| 5634 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 5635 | HUnresolvedInstanceFieldGet* instruction) { |
| 5636 | FieldAccessCallingConventionX86 calling_convention; |
| 5637 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5638 | instruction->GetFieldType(), |
| 5639 | instruction->GetFieldIndex(), |
| 5640 | instruction->GetDexPc(), |
| 5641 | calling_convention); |
| 5642 | } |
| 5643 | |
| 5644 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 5645 | HUnresolvedInstanceFieldSet* instruction) { |
| 5646 | FieldAccessCallingConventionX86 calling_convention; |
| 5647 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5648 | instruction, instruction->GetFieldType(), calling_convention); |
| 5649 | } |
| 5650 | |
| 5651 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 5652 | HUnresolvedInstanceFieldSet* instruction) { |
| 5653 | FieldAccessCallingConventionX86 calling_convention; |
| 5654 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5655 | instruction->GetFieldType(), |
| 5656 | instruction->GetFieldIndex(), |
| 5657 | instruction->GetDexPc(), |
| 5658 | calling_convention); |
| 5659 | } |
| 5660 | |
| 5661 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 5662 | HUnresolvedStaticFieldGet* instruction) { |
| 5663 | FieldAccessCallingConventionX86 calling_convention; |
| 5664 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5665 | instruction, instruction->GetFieldType(), calling_convention); |
| 5666 | } |
| 5667 | |
| 5668 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 5669 | HUnresolvedStaticFieldGet* instruction) { |
| 5670 | FieldAccessCallingConventionX86 calling_convention; |
| 5671 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5672 | instruction->GetFieldType(), |
| 5673 | instruction->GetFieldIndex(), |
| 5674 | instruction->GetDexPc(), |
| 5675 | calling_convention); |
| 5676 | } |
| 5677 | |
| 5678 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 5679 | HUnresolvedStaticFieldSet* instruction) { |
| 5680 | FieldAccessCallingConventionX86 calling_convention; |
| 5681 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5682 | instruction, instruction->GetFieldType(), calling_convention); |
| 5683 | } |
| 5684 | |
| 5685 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 5686 | HUnresolvedStaticFieldSet* instruction) { |
| 5687 | FieldAccessCallingConventionX86 calling_convention; |
| 5688 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5689 | instruction->GetFieldType(), |
| 5690 | instruction->GetFieldIndex(), |
| 5691 | instruction->GetDexPc(), |
| 5692 | calling_convention); |
| 5693 | } |
| 5694 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5695 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5696 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5697 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 5698 | ? Location::RequiresRegister() |
| 5699 | : Location::Any(); |
| 5700 | locations->SetInAt(0, loc); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5701 | } |
| 5702 | |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5703 | void CodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5704 | if (CanMoveNullCheckToUser(instruction)) { |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5705 | return; |
| 5706 | } |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5707 | LocationSummary* locations = instruction->GetLocations(); |
| 5708 | Location obj = locations->InAt(0); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5709 | |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5710 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5711 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5712 | } |
| 5713 | |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5714 | void CodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5715 | SlowPathCode* slow_path = new (GetScopedAllocator()) NullCheckSlowPathX86(instruction); |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5716 | AddSlowPath(slow_path); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5717 | |
| 5718 | LocationSummary* locations = instruction->GetLocations(); |
| 5719 | Location obj = locations->InAt(0); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5720 | |
| 5721 | if (obj.IsRegister()) { |
| Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 5722 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5723 | } else if (obj.IsStackSlot()) { |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5724 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5725 | } else { |
| 5726 | DCHECK(obj.IsConstant()) << obj; |
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5727 | DCHECK(obj.GetConstant()->IsNullConstant()); |
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5728 | __ jmp(slow_path->GetEntryLabel()); |
| 5729 | return; |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5730 | } |
| 5731 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5732 | } |
| 5733 | |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5734 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5735 | codegen_->GenerateNullCheck(instruction); |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5736 | } |
| 5737 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5738 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5739 | bool object_array_get_with_read_barrier = |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5740 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5741 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5742 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 5743 | object_array_get_with_read_barrier |
| 5744 | ? LocationSummary::kCallOnSlowPath |
| 5745 | : LocationSummary::kNoCall); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5746 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5747 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5748 | } |
| Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5749 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5750 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5751 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5752 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5753 | } else { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5754 | // The output overlaps in case of long: we don't want the low move |
| 5755 | // to overwrite the array's location. Likewise, in the case of an |
| 5756 | // object array get with read barriers enabled, we do not want the |
| 5757 | // move to overwrite the array's location, as we need it to emit |
| 5758 | // the read barrier. |
| 5759 | locations->SetOut( |
| 5760 | Location::RequiresRegister(), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5761 | (instruction->GetType() == DataType::Type::kInt64 || object_array_get_with_read_barrier) |
| 5762 | ? Location::kOutputOverlap |
| 5763 | : Location::kNoOutputOverlap); |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5764 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5765 | } |
| 5766 | |
| 5767 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 5768 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5769 | Location obj_loc = locations->InAt(0); |
| 5770 | Register obj = obj_loc.AsRegister<Register>(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5771 | Location index = locations->InAt(1); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5772 | Location out_loc = locations->Out(); |
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5773 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5774 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5775 | DataType::Type type = instruction->GetType(); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5776 | switch (type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5777 | case DataType::Type::kBool: |
| 5778 | case DataType::Type::kUint8: { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5779 | Register out = out_loc.AsRegister<Register>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5780 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5781 | break; |
| 5782 | } |
| 5783 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5784 | case DataType::Type::kInt8: { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5785 | Register out = out_loc.AsRegister<Register>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5786 | __ movsxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5787 | break; |
| 5788 | } |
| 5789 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5790 | case DataType::Type::kUint16: { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5791 | Register out = out_loc.AsRegister<Register>(); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5792 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5793 | // Branch cases into compressed and uncompressed for each index's type. |
| 5794 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 5795 | NearLabel done, not_compressed; |
| Vladimir Marko | 3c89d42 | 2017-02-17 11:30:23 +0000 | [diff] [blame] | 5796 | __ testb(Address(obj, count_offset), Immediate(1)); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5797 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5798 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 5799 | "Expecting 0=compressed, 1=uncompressed"); |
| 5800 | __ j(kNotZero, ¬_compressed); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5801 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| 5802 | __ jmp(&done); |
| 5803 | __ Bind(¬_compressed); |
| 5804 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5805 | __ Bind(&done); |
| 5806 | } else { |
| 5807 | // Common case for charAt of array of char or when string compression's |
| 5808 | // feature is turned off. |
| 5809 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5810 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5811 | break; |
| 5812 | } |
| 5813 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5814 | case DataType::Type::kInt16: { |
| 5815 | Register out = out_loc.AsRegister<Register>(); |
| 5816 | __ movsxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5817 | break; |
| 5818 | } |
| 5819 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5820 | case DataType::Type::kInt32: { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5821 | Register out = out_loc.AsRegister<Register>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5822 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5823 | break; |
| 5824 | } |
| 5825 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5826 | case DataType::Type::kReference: { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5827 | static_assert( |
| 5828 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5829 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5830 | // /* HeapReference<Object> */ out = |
| 5831 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5832 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5833 | // Note that a potential implicit null check is handled in this |
| 5834 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 5835 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5836 | instruction, out_loc, obj, data_offset, index, /* needs_null_check= */ true); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5837 | } else { |
| 5838 | Register out = out_loc.AsRegister<Register>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5839 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| 5840 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5841 | // If read barriers are enabled, emit read barriers other than |
| 5842 | // Baker's using a slow path (and also unpoison the loaded |
| 5843 | // reference, if heap poisoning is enabled). |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5844 | if (index.IsConstant()) { |
| 5845 | uint32_t offset = |
| 5846 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5847 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5848 | } else { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5849 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5850 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5851 | } |
| 5852 | } |
| 5853 | break; |
| 5854 | } |
| 5855 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5856 | case DataType::Type::kInt64: { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5857 | DCHECK_NE(obj, out_loc.AsRegisterPairLow<Register>()); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5858 | __ movl(out_loc.AsRegisterPairLow<Register>(), |
| 5859 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
| 5860 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5861 | __ movl(out_loc.AsRegisterPairHigh<Register>(), |
| 5862 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset + kX86WordSize)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5863 | break; |
| 5864 | } |
| 5865 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5866 | case DataType::Type::kFloat32: { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5867 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5868 | __ movss(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5869 | break; |
| 5870 | } |
| 5871 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5872 | case DataType::Type::kFloat64: { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5873 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5874 | __ movsd(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5875 | break; |
| 5876 | } |
| 5877 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5878 | case DataType::Type::kUint32: |
| 5879 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5880 | case DataType::Type::kVoid: |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5881 | LOG(FATAL) << "Unreachable type " << type; |
| Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5882 | UNREACHABLE(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5883 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5884 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5885 | if (type == DataType::Type::kReference || type == DataType::Type::kInt64) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5886 | // Potential implicit null checks, in the case of reference or |
| 5887 | // long arrays, are handled in the previous switch statement. |
| 5888 | } else { |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5889 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5890 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5891 | } |
| 5892 | |
| 5893 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5894 | DataType::Type value_type = instruction->GetComponentType(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5895 | |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5896 | bool needs_write_barrier = |
| 5897 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5898 | bool needs_type_check = instruction->NeedsTypeCheck(); |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5899 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5900 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5901 | instruction, |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5902 | needs_type_check ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5903 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5904 | bool is_byte_type = DataType::Size(value_type) == 1u; |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5905 | // We need the inputs to be different than the output in case of long operation. |
| 5906 | // In case of a byte operation, the register allocator does not support multiple |
| 5907 | // inputs that die at entry with one in a specific register. |
| 5908 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5909 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5910 | if (is_byte_type) { |
| 5911 | // Ensure the value is in a byte register. |
| 5912 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5913 | } else if (DataType::IsFloatingPointType(value_type)) { |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5914 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5915 | } else { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5916 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 5917 | } |
| 5918 | if (needs_write_barrier) { |
| 5919 | // Temporary registers for the write barrier. |
| 5920 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 5921 | // Ensure the card is in a byte register. |
| Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5922 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5923 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5924 | } |
| 5925 | |
| 5926 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 5927 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5928 | Location array_loc = locations->InAt(0); |
| 5929 | Register array = array_loc.AsRegister<Register>(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5930 | Location index = locations->InAt(1); |
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5931 | Location value = locations->InAt(2); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5932 | DataType::Type value_type = instruction->GetComponentType(); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5933 | bool needs_type_check = instruction->NeedsTypeCheck(); |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5934 | bool needs_write_barrier = |
| 5935 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5936 | |
| 5937 | switch (value_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5938 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5939 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5940 | case DataType::Type::kInt8: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5941 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5942 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_1, offset); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5943 | if (value.IsRegister()) { |
| 5944 | __ movb(address, value.AsRegister<ByteRegister>()); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5945 | } else { |
| Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5946 | __ movb(address, Immediate(CodeGenerator::GetInt8ValueOf(value.GetConstant()))); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5947 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5948 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5949 | break; |
| 5950 | } |
| 5951 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5952 | case DataType::Type::kUint16: |
| 5953 | case DataType::Type::kInt16: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5954 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5955 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_2, offset); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5956 | if (value.IsRegister()) { |
| 5957 | __ movw(address, value.AsRegister<Register>()); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5958 | } else { |
| Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5959 | __ movw(address, Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5960 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5961 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5962 | break; |
| 5963 | } |
| 5964 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5965 | case DataType::Type::kReference: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5966 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5967 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5968 | |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5969 | if (!value.IsRegister()) { |
| 5970 | // Just setting null. |
| 5971 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5972 | DCHECK(value.IsConstant()) << value; |
| 5973 | __ movl(address, Immediate(0)); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5974 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5975 | DCHECK(!needs_write_barrier); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5976 | DCHECK(!needs_type_check); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5977 | break; |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5978 | } |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5979 | |
| 5980 | DCHECK(needs_write_barrier); |
| 5981 | Register register_value = value.AsRegister<Register>(); |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5982 | Location temp_loc = locations->GetTemp(0); |
| 5983 | Register temp = temp_loc.AsRegister<Register>(); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5984 | |
| 5985 | bool can_value_be_null = instruction->GetValueCanBeNull(); |
| 5986 | NearLabel do_store; |
| 5987 | if (can_value_be_null) { |
| 5988 | __ testl(register_value, register_value); |
| 5989 | __ j(kEqual, &do_store); |
| 5990 | } |
| 5991 | |
| 5992 | SlowPathCode* slow_path = nullptr; |
| 5993 | if (needs_type_check) { |
| Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 5994 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathX86(instruction); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5995 | codegen_->AddSlowPath(slow_path); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5996 | |
| 5997 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5998 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5999 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6000 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6001 | // Note that when Baker read barriers are enabled, the type |
| 6002 | // checks are performed without read barriers. This is fine, |
| 6003 | // even in the case where a class object is in the from-space |
| 6004 | // after the flip, as a comparison involving such a type would |
| 6005 | // not produce a false positive; it may of course produce a |
| 6006 | // false negative, in which case we would take the ArraySet |
| 6007 | // slow path. |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6008 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6009 | // /* HeapReference<Class> */ temp = array->klass_ |
| 6010 | __ movl(temp, Address(array, class_offset)); |
| 6011 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6012 | __ MaybeUnpoisonHeapReference(temp); |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6013 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6014 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 6015 | __ movl(temp, Address(temp, component_offset)); |
| 6016 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 6017 | // nor the object reference in `register_value->klass`, as |
| 6018 | // we are comparing two poisoned references. |
| 6019 | __ cmpl(temp, Address(register_value, class_offset)); |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6020 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6021 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6022 | NearLabel do_put; |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6023 | __ j(kEqual, &do_put); |
| 6024 | // If heap poisoning is enabled, the `temp` reference has |
| 6025 | // not been unpoisoned yet; unpoison it now. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6026 | __ MaybeUnpoisonHeapReference(temp); |
| 6027 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6028 | // If heap poisoning is enabled, no need to unpoison the |
| 6029 | // heap reference loaded below, as it is only used for a |
| 6030 | // comparison with null. |
| 6031 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 6032 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6033 | __ Bind(&do_put); |
| 6034 | } else { |
| 6035 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6036 | } |
| Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6037 | } |
| 6038 | |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6039 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 6040 | codegen_->MarkGCCard( |
| 6041 | temp, card, array, value.AsRegister<Register>(), /* value_can_be_null= */ false); |
| 6042 | |
| 6043 | if (can_value_be_null) { |
| 6044 | DCHECK(do_store.IsLinked()); |
| 6045 | __ Bind(&do_store); |
| 6046 | } |
| 6047 | |
| 6048 | Register source = register_value; |
| Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6049 | if (kPoisonHeapReferences) { |
| 6050 | __ movl(temp, register_value); |
| 6051 | __ PoisonHeapReference(temp); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6052 | source = temp; |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6053 | } |
| 6054 | |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6055 | __ movl(address, source); |
| 6056 | |
| 6057 | if (can_value_be_null || !needs_type_check) { |
| 6058 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6059 | } |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6060 | |
| Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6061 | if (slow_path != nullptr) { |
| 6062 | __ Bind(slow_path->GetExitLabel()); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6063 | } |
| 6064 | |
| 6065 | break; |
| 6066 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6067 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6068 | case DataType::Type::kInt32: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6069 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6070 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6071 | if (value.IsRegister()) { |
| 6072 | __ movl(address, value.AsRegister<Register>()); |
| 6073 | } else { |
| 6074 | DCHECK(value.IsConstant()) << value; |
| 6075 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 6076 | __ movl(address, Immediate(v)); |
| 6077 | } |
| 6078 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6079 | break; |
| 6080 | } |
| 6081 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6082 | case DataType::Type::kInt64: { |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6083 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6084 | if (value.IsRegisterPair()) { |
| 6085 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 6086 | value.AsRegisterPairLow<Register>()); |
| 6087 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6088 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 6089 | value.AsRegisterPairHigh<Register>()); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6090 | } else { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6091 | DCHECK(value.IsConstant()); |
| 6092 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
| 6093 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 6094 | Immediate(Low32Bits(val))); |
| 6095 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6096 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 6097 | Immediate(High32Bits(val))); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6098 | } |
| 6099 | break; |
| 6100 | } |
| 6101 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6102 | case DataType::Type::kFloat32: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6103 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6104 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6105 | if (value.IsFpuRegister()) { |
| 6106 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 6107 | } else { |
| 6108 | DCHECK(value.IsConstant()); |
| 6109 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 6110 | __ movl(address, Immediate(v)); |
| 6111 | } |
| 6112 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6113 | break; |
| 6114 | } |
| 6115 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6116 | case DataType::Type::kFloat64: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6117 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6118 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6119 | if (value.IsFpuRegister()) { |
| 6120 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 6121 | } else { |
| 6122 | DCHECK(value.IsConstant()); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6123 | Address address_hi = |
| 6124 | CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset + kX86WordSize); |
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6125 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 6126 | __ movl(address, Immediate(Low32Bits(v))); |
| 6127 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6128 | __ movl(address_hi, Immediate(High32Bits(v))); |
| 6129 | } |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6130 | break; |
| 6131 | } |
| 6132 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 6133 | case DataType::Type::kUint32: |
| 6134 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6135 | case DataType::Type::kVoid: |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6136 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 6137 | UNREACHABLE(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6138 | } |
| 6139 | } |
| 6140 | |
| 6141 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6142 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 6143 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6144 | if (!instruction->IsEmittedAtUseSite()) { |
| 6145 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6146 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6147 | } |
| 6148 | |
| 6149 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6150 | if (instruction->IsEmittedAtUseSite()) { |
| 6151 | return; |
| 6152 | } |
| 6153 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6154 | LocationSummary* locations = instruction->GetLocations(); |
| Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 6155 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6156 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 6157 | Register out = locations->Out().AsRegister<Register>(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6158 | __ movl(out, Address(obj, offset)); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6159 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6160 | // Mask out most significant bit in case the array is String's array of char. |
| 6161 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6162 | __ shrl(out, Immediate(1)); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6163 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6164 | } |
| 6165 | |
| 6166 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6167 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6168 | InvokeRuntimeCallingConvention calling_convention; |
| 6169 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6170 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 6171 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 6172 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6173 | HInstruction* length = instruction->InputAt(1); |
| 6174 | if (!length->IsEmittedAtUseSite()) { |
| 6175 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 6176 | } |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6177 | // Need register to see array's length. |
| 6178 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 6179 | locations->AddTemp(Location::RequiresRegister()); |
| 6180 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6181 | } |
| 6182 | |
| 6183 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6184 | const bool is_string_compressed_char_at = |
| 6185 | mirror::kUseStringCompression && instruction->IsStringCharAt(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6186 | LocationSummary* locations = instruction->GetLocations(); |
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 6187 | Location index_loc = locations->InAt(0); |
| 6188 | Location length_loc = locations->InAt(1); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6189 | SlowPathCode* slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6190 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathX86(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6191 | |
| Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 6192 | if (length_loc.IsConstant()) { |
| 6193 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 6194 | if (index_loc.IsConstant()) { |
| 6195 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 6196 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 6197 | if (index < 0 || index >= length) { |
| 6198 | codegen_->AddSlowPath(slow_path); |
| 6199 | __ jmp(slow_path->GetEntryLabel()); |
| 6200 | } else { |
| 6201 | // Some optimization after BCE may have generated this, and we should not |
| 6202 | // generate a bounds check if it is a valid range. |
| 6203 | } |
| 6204 | return; |
| 6205 | } |
| 6206 | |
| 6207 | // We have to reverse the jump condition because the length is the constant. |
| 6208 | Register index_reg = index_loc.AsRegister<Register>(); |
| 6209 | __ cmpl(index_reg, Immediate(length)); |
| 6210 | codegen_->AddSlowPath(slow_path); |
| 6211 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 6212 | } else { |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6213 | HInstruction* array_length = instruction->InputAt(1); |
| 6214 | if (array_length->IsEmittedAtUseSite()) { |
| 6215 | // Address the length field in the array. |
| 6216 | DCHECK(array_length->IsArrayLength()); |
| 6217 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 6218 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 6219 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6220 | if (is_string_compressed_char_at) { |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6221 | // TODO: if index_loc.IsConstant(), compare twice the index (to compensate for |
| 6222 | // the string compression flag) with the in-memory length and avoid the temporary. |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6223 | Register length_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 6224 | __ movl(length_reg, array_len); |
| 6225 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6226 | __ shrl(length_reg, Immediate(1)); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6227 | codegen_->GenerateIntCompare(length_reg, index_loc); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6228 | } else { |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6229 | // Checking bounds for general case: |
| 6230 | // Array of char or string's array with feature compression off. |
| 6231 | if (index_loc.IsConstant()) { |
| 6232 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 6233 | __ cmpl(array_len, Immediate(value)); |
| 6234 | } else { |
| 6235 | __ cmpl(array_len, index_loc.AsRegister<Register>()); |
| 6236 | } |
| 6237 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6238 | } |
| Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 6239 | } else { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6240 | codegen_->GenerateIntCompare(length_loc, index_loc); |
| Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 6241 | } |
| 6242 | codegen_->AddSlowPath(slow_path); |
| 6243 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 6244 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6245 | } |
| 6246 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6247 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6248 | LOG(FATAL) << "Unreachable"; |
| Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6249 | } |
| 6250 | |
| 6251 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
| Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 6252 | if (instruction->GetNext()->IsSuspendCheck() && |
| 6253 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 6254 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 6255 | // The back edge will generate the suspend check. |
| 6256 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 6257 | } |
| 6258 | |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6259 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 6260 | } |
| 6261 | |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6262 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6263 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6264 | instruction, LocationSummary::kCallOnSlowPath); |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 6265 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 6266 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 6267 | // registers in full width (since the runtime only saves/restores lower part). |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6268 | locations->SetCustomSlowPathCallerSaves( |
| 6269 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6270 | } |
| 6271 | |
| 6272 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6273 | HBasicBlock* block = instruction->GetBlock(); |
| 6274 | if (block->GetLoopInformation() != nullptr) { |
| 6275 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 6276 | // The back edge will generate the suspend check. |
| 6277 | return; |
| 6278 | } |
| 6279 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 6280 | // The goto will generate the suspend check. |
| 6281 | return; |
| 6282 | } |
| 6283 | GenerateSuspendCheck(instruction, nullptr); |
| 6284 | } |
| 6285 | |
| 6286 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 6287 | HBasicBlock* successor) { |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6288 | SuspendCheckSlowPathX86* slow_path = |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6289 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 6290 | if (slow_path == nullptr) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6291 | slow_path = |
| 6292 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathX86(instruction, successor); |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6293 | instruction->SetSlowPath(slow_path); |
| 6294 | codegen_->AddSlowPath(slow_path); |
| 6295 | if (successor != nullptr) { |
| 6296 | DCHECK(successor->IsLoopHeader()); |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6297 | } |
| 6298 | } else { |
| 6299 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 6300 | } |
| 6301 | |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6302 | __ fs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86PointerSize>().Int32Value()), |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6303 | Immediate(0)); |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6304 | if (successor == nullptr) { |
| 6305 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6306 | __ Bind(slow_path->GetReturnLabel()); |
| 6307 | } else { |
| 6308 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 6309 | __ jmp(slow_path->GetEntryLabel()); |
| 6310 | } |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6311 | } |
| 6312 | |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6313 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 6314 | return codegen_->GetAssembler(); |
| 6315 | } |
| 6316 | |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6317 | void ParallelMoveResolverX86::MoveMemoryToMemory(int dst, int src, int number_of_words) { |
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6318 | ScratchRegisterScope ensure_scratch( |
| 6319 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 6320 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 6321 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6322 | |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6323 | // Now that temp register is available (possibly spilled), move blocks of memory. |
| 6324 | for (int i = 0; i < number_of_words; i++) { |
| 6325 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 6326 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 6327 | stack_offset += kX86WordSize; |
| 6328 | } |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6329 | } |
| 6330 | |
| 6331 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6332 | MoveOperands* move = moves_[index]; |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6333 | Location source = move->GetSource(); |
| 6334 | Location destination = move->GetDestination(); |
| 6335 | |
| 6336 | if (source.IsRegister()) { |
| 6337 | if (destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6338 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6339 | } else if (destination.IsFpuRegister()) { |
| 6340 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6341 | } else { |
| 6342 | DCHECK(destination.IsStackSlot()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6343 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6344 | } |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6345 | } else if (source.IsRegisterPair()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6346 | size_t elem_size = DataType::Size(DataType::Type::kInt32); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6347 | // Create stack space for 2 elements. |
| 6348 | __ subl(ESP, Immediate(2 * elem_size)); |
| 6349 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 6350 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 6351 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 6352 | // And remove the temporary stack space we allocated. |
| 6353 | __ addl(ESP, Immediate(2 * elem_size)); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6354 | } else if (source.IsFpuRegister()) { |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6355 | if (destination.IsRegister()) { |
| 6356 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
| 6357 | } else if (destination.IsFpuRegister()) { |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6358 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6359 | } else if (destination.IsRegisterPair()) { |
| 6360 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 6361 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 6362 | __ psrlq(src_reg, Immediate(32)); |
| 6363 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6364 | } else if (destination.IsStackSlot()) { |
| 6365 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6366 | } else if (destination.IsDoubleStackSlot()) { |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6367 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6368 | } else { |
| 6369 | DCHECK(destination.IsSIMDStackSlot()); |
| 6370 | __ movups(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6371 | } |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6372 | } else if (source.IsStackSlot()) { |
| 6373 | if (destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6374 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6375 | } else if (destination.IsFpuRegister()) { |
| 6376 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6377 | } else { |
| 6378 | DCHECK(destination.IsStackSlot()); |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6379 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 1); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6380 | } |
| 6381 | } else if (source.IsDoubleStackSlot()) { |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6382 | if (destination.IsRegisterPair()) { |
| 6383 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 6384 | __ movl(destination.AsRegisterPairHigh<Register>(), |
| 6385 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 6386 | } else if (destination.IsFpuRegister()) { |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6387 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 6388 | } else { |
| 6389 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6390 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 2); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6391 | } |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6392 | } else if (source.IsSIMDStackSlot()) { |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6393 | if (destination.IsFpuRegister()) { |
| 6394 | __ movups(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 6395 | } else { |
| 6396 | DCHECK(destination.IsSIMDStackSlot()); |
| 6397 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 4); |
| 6398 | } |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 6399 | } else if (source.IsConstant()) { |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6400 | HConstant* constant = source.GetConstant(); |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 6401 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 6402 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6403 | if (destination.IsRegister()) { |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 6404 | if (value == 0) { |
| 6405 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 6406 | } else { |
| 6407 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 6408 | } |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6409 | } else { |
| 6410 | DCHECK(destination.IsStackSlot()) << destination; |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 6411 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6412 | } |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6413 | } else if (constant->IsFloatConstant()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6414 | float fp_value = constant->AsFloatConstant()->GetValue(); |
| Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 6415 | int32_t value = bit_cast<int32_t, float>(fp_value); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6416 | Immediate imm(value); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6417 | if (destination.IsFpuRegister()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6418 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 6419 | if (value == 0) { |
| 6420 | // Easy handling of 0.0. |
| 6421 | __ xorps(dest, dest); |
| 6422 | } else { |
| 6423 | ScratchRegisterScope ensure_scratch( |
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6424 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 6425 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 6426 | __ movl(temp, Immediate(value)); |
| 6427 | __ movd(dest, temp); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6428 | } |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6429 | } else { |
| 6430 | DCHECK(destination.IsStackSlot()) << destination; |
| 6431 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 6432 | } |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6433 | } else if (constant->IsLongConstant()) { |
| 6434 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 6435 | int32_t low_value = Low32Bits(value); |
| 6436 | int32_t high_value = High32Bits(value); |
| 6437 | Immediate low(low_value); |
| 6438 | Immediate high(high_value); |
| 6439 | if (destination.IsDoubleStackSlot()) { |
| 6440 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 6441 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 6442 | } else { |
| 6443 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 6444 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 6445 | } |
| 6446 | } else { |
| 6447 | DCHECK(constant->IsDoubleConstant()); |
| 6448 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
| Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 6449 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6450 | int32_t low_value = Low32Bits(value); |
| 6451 | int32_t high_value = High32Bits(value); |
| 6452 | Immediate low(low_value); |
| 6453 | Immediate high(high_value); |
| 6454 | if (destination.IsFpuRegister()) { |
| 6455 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 6456 | if (value == 0) { |
| 6457 | // Easy handling of 0.0. |
| 6458 | __ xorpd(dest, dest); |
| 6459 | } else { |
| 6460 | __ pushl(high); |
| 6461 | __ pushl(low); |
| 6462 | __ movsd(dest, Address(ESP, 0)); |
| 6463 | __ addl(ESP, Immediate(8)); |
| 6464 | } |
| 6465 | } else { |
| 6466 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6467 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 6468 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 6469 | } |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 6470 | } |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6471 | } else { |
| Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 6472 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6473 | } |
| 6474 | } |
| 6475 | |
| Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 6476 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6477 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 6478 | ScratchRegisterScope ensure_scratch( |
| 6479 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 6480 | |
| 6481 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 6482 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 6483 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 6484 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6485 | } |
| 6486 | |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6487 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6488 | ScratchRegisterScope ensure_scratch( |
| 6489 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 6490 | |
| 6491 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 6492 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 6493 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 6494 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 6495 | __ movd(reg, temp_reg); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6496 | } |
| 6497 | |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6498 | void ParallelMoveResolverX86::Exchange128(XmmRegister reg, int mem) { |
| 6499 | size_t extra_slot = 4 * kX86WordSize; |
| 6500 | __ subl(ESP, Immediate(extra_slot)); |
| 6501 | __ movups(Address(ESP, 0), XmmRegister(reg)); |
| 6502 | ExchangeMemory(0, mem + extra_slot, 4); |
| 6503 | __ movups(XmmRegister(reg), Address(ESP, 0)); |
| 6504 | __ addl(ESP, Immediate(extra_slot)); |
| 6505 | } |
| 6506 | |
| 6507 | void ParallelMoveResolverX86::ExchangeMemory(int mem1, int mem2, int number_of_words) { |
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6508 | ScratchRegisterScope ensure_scratch1( |
| 6509 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6510 | |
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6511 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 6512 | ScratchRegisterScope ensure_scratch2( |
| 6513 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6514 | |
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6515 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 6516 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6517 | |
| 6518 | // Now that temp registers are available (possibly spilled), exchange blocks of memory. |
| 6519 | for (int i = 0; i < number_of_words; i++) { |
| 6520 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 6521 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 6522 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 6523 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
| 6524 | stack_offset += kX86WordSize; |
| 6525 | } |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6526 | } |
| 6527 | |
| 6528 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6529 | MoveOperands* move = moves_[index]; |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6530 | Location source = move->GetSource(); |
| 6531 | Location destination = move->GetDestination(); |
| 6532 | |
| 6533 | if (source.IsRegister() && destination.IsRegister()) { |
| Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 6534 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 6535 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 6536 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 6537 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 6538 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6539 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6540 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6541 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6542 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6543 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6544 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 1); |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6545 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 6546 | // Use XOR Swap algorithm to avoid a temporary. |
| 6547 | DCHECK_NE(source.reg(), destination.reg()); |
| 6548 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 6549 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 6550 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 6551 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 6552 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 6553 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 6554 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6555 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 6556 | // Take advantage of the 16 bytes in the XMM register. |
| 6557 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 6558 | Address stack(ESP, destination.GetStackIndex()); |
| 6559 | // Load the double into the high doubleword. |
| 6560 | __ movhpd(reg, stack); |
| 6561 | |
| 6562 | // Store the low double into the destination. |
| 6563 | __ movsd(stack, reg); |
| 6564 | |
| 6565 | // Move the high double to the low double. |
| 6566 | __ psrldq(reg, Immediate(8)); |
| 6567 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 6568 | // Take advantage of the 16 bytes in the XMM register. |
| 6569 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 6570 | Address stack(ESP, source.GetStackIndex()); |
| 6571 | // Load the double into the high doubleword. |
| 6572 | __ movhpd(reg, stack); |
| 6573 | |
| 6574 | // Store the low double into the destination. |
| 6575 | __ movsd(stack, reg); |
| 6576 | |
| 6577 | // Move the high double to the low double. |
| 6578 | __ psrldq(reg, Immediate(8)); |
| 6579 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6580 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 2); |
| 6581 | } else if (source.IsSIMDStackSlot() && destination.IsSIMDStackSlot()) { |
| 6582 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 4); |
| 6583 | } else if (source.IsFpuRegister() && destination.IsSIMDStackSlot()) { |
| 6584 | Exchange128(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 6585 | } else if (destination.IsFpuRegister() && source.IsSIMDStackSlot()) { |
| 6586 | Exchange128(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6587 | } else { |
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6588 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6589 | } |
| 6590 | } |
| 6591 | |
| 6592 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 6593 | __ pushl(static_cast<Register>(reg)); |
| 6594 | } |
| 6595 | |
| 6596 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 6597 | __ popl(static_cast<Register>(reg)); |
| Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6598 | } |
| 6599 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6600 | HLoadClass::LoadKind CodeGeneratorX86::GetSupportedLoadClassKind( |
| 6601 | HLoadClass::LoadKind desired_class_load_kind) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6602 | switch (desired_class_load_kind) { |
| Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6603 | case HLoadClass::LoadKind::kInvalid: |
| 6604 | LOG(FATAL) << "UNREACHABLE"; |
| 6605 | UNREACHABLE(); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6606 | case HLoadClass::LoadKind::kReferrersClass: |
| 6607 | break; |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6608 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6609 | case HLoadClass::LoadKind::kBootImageRelRo: |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6610 | case HLoadClass::LoadKind::kBssEntry: |
| Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6611 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6612 | break; |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6613 | case HLoadClass::LoadKind::kJitBootImageAddress: |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6614 | case HLoadClass::LoadKind::kJitTableAddress: |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6615 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6616 | break; |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6617 | case HLoadClass::LoadKind::kRuntimeCall: |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6618 | break; |
| 6619 | } |
| 6620 | return desired_class_load_kind; |
| 6621 | } |
| 6622 | |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6623 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6624 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6625 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6626 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6627 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6628 | cls, |
| 6629 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6630 | Location::RegisterLocation(EAX)); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6631 | DCHECK_EQ(calling_convention.GetRegisterAt(0), EAX); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6632 | return; |
| 6633 | } |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6634 | DCHECK(!cls->NeedsAccessCheck()); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6635 | |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6636 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 6637 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6638 | ? LocationSummary::kCallOnSlowPath |
| 6639 | : LocationSummary::kNoCall; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6640 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6641 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6642 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6643 | } |
| 6644 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6645 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6646 | load_kind == HLoadClass::LoadKind::kBootImageLinkTimePcRelative || |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6647 | load_kind == HLoadClass::LoadKind::kBootImageRelRo || |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6648 | load_kind == HLoadClass::LoadKind::kBssEntry) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6649 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6650 | } |
| 6651 | locations->SetOut(Location::RequiresRegister()); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6652 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 6653 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 6654 | // Rely on the type resolution and/or initialization to save everything. |
| Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 6655 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6656 | } else { |
| 6657 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6658 | } |
| 6659 | } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6660 | } |
| 6661 | |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6662 | Label* CodeGeneratorX86::NewJitRootClassPatch(const DexFile& dex_file, |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6663 | dex::TypeIndex type_index, |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6664 | Handle<mirror::Class> handle) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6665 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6666 | // Add a patch entry and return the label. |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6667 | jit_class_patches_.emplace_back(&dex_file, type_index.index_); |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6668 | PatchInfo<Label>* info = &jit_class_patches_.back(); |
| 6669 | return &info->label; |
| 6670 | } |
| 6671 | |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6672 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6673 | // move. |
| 6674 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6675 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6676 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6677 | codegen_->GenerateLoadClassRuntimeCall(cls); |
| Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6678 | return; |
| 6679 | } |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6680 | DCHECK(!cls->NeedsAccessCheck()); |
| Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6681 | |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6682 | LocationSummary* locations = cls->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6683 | Location out_loc = locations->Out(); |
| 6684 | Register out = out_loc.AsRegister<Register>(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6685 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6686 | bool generate_null_check = false; |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6687 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 6688 | ? kWithoutReadBarrier |
| 6689 | : kCompilerReadBarrierOption; |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6690 | switch (load_kind) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6691 | case HLoadClass::LoadKind::kReferrersClass: { |
| 6692 | DCHECK(!cls->CanCallRuntime()); |
| 6693 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 6694 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6695 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 6696 | GenerateGcRootFieldLoad( |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6697 | cls, |
| 6698 | out_loc, |
| 6699 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6700 | /* fixup_label= */ nullptr, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6701 | read_barrier_option); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6702 | break; |
| 6703 | } |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6704 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
| Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 6705 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 6706 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6707 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6708 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6709 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6710 | codegen_->RecordBootImageTypePatch(cls); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6711 | break; |
| 6712 | } |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6713 | case HLoadClass::LoadKind::kBootImageRelRo: { |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6714 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 6715 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6716 | __ movl(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6717 | codegen_->RecordBootImageRelRoPatch(cls->InputAt(0)->AsX86ComputeBaseMethodAddress(), |
| 6718 | codegen_->GetBootImageOffset(cls)); |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6719 | break; |
| 6720 | } |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6721 | case HLoadClass::LoadKind::kBssEntry: { |
| 6722 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6723 | Address address(method_address, CodeGeneratorX86::kDummy32BitOffset); |
| 6724 | Label* fixup_label = codegen_->NewTypeBssEntryPatch(cls); |
| 6725 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
| Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 6726 | // No need for memory fence, thanks to the x86 memory model. |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6727 | generate_null_check = true; |
| 6728 | break; |
| 6729 | } |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6730 | case HLoadClass::LoadKind::kJitBootImageAddress: { |
| 6731 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 6732 | uint32_t address = reinterpret_cast32<uint32_t>(cls->GetClass().Get()); |
| 6733 | DCHECK_NE(address, 0u); |
| 6734 | __ movl(out, Immediate(address)); |
| 6735 | break; |
| 6736 | } |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6737 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 6738 | Address address = Address::Absolute(CodeGeneratorX86::kDummy32BitOffset); |
| 6739 | Label* fixup_label = codegen_->NewJitRootClassPatch( |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6740 | cls->GetDexFile(), cls->GetTypeIndex(), cls->GetClass()); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6741 | // /* GcRoot<mirror::Class> */ out = *address |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6742 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6743 | break; |
| 6744 | } |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6745 | case HLoadClass::LoadKind::kRuntimeCall: |
| Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6746 | case HLoadClass::LoadKind::kInvalid: |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6747 | LOG(FATAL) << "UNREACHABLE"; |
| 6748 | UNREACHABLE(); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6749 | } |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6750 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6751 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6752 | DCHECK(cls->CanCallRuntime()); |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 6753 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86(cls, cls); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6754 | codegen_->AddSlowPath(slow_path); |
| Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6755 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6756 | if (generate_null_check) { |
| 6757 | __ testl(out, out); |
| 6758 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6759 | } |
| Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6760 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6761 | if (cls->MustGenerateClinitCheck()) { |
| 6762 | GenerateClassInitializationCheck(slow_path, out); |
| 6763 | } else { |
| 6764 | __ Bind(slow_path->GetExitLabel()); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6765 | } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6766 | } |
| 6767 | } |
| 6768 | |
| Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 6769 | void LocationsBuilderX86::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 6770 | InvokeRuntimeCallingConvention calling_convention; |
| 6771 | Location location = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 6772 | CodeGenerator::CreateLoadMethodHandleRuntimeCallLocationSummary(load, location, location); |
| 6773 | } |
| 6774 | |
| 6775 | void InstructionCodeGeneratorX86::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 6776 | codegen_->GenerateLoadMethodHandleRuntimeCall(load); |
| 6777 | } |
| 6778 | |
| Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6779 | void LocationsBuilderX86::VisitLoadMethodType(HLoadMethodType* load) { |
| 6780 | InvokeRuntimeCallingConvention calling_convention; |
| 6781 | Location location = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 6782 | CodeGenerator::CreateLoadMethodTypeRuntimeCallLocationSummary(load, location, location); |
| 6783 | } |
| 6784 | |
| 6785 | void InstructionCodeGeneratorX86::VisitLoadMethodType(HLoadMethodType* load) { |
| 6786 | codegen_->GenerateLoadMethodTypeRuntimeCall(load); |
| 6787 | } |
| 6788 | |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6789 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 6790 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6791 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6792 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6793 | if (check->HasUses()) { |
| 6794 | locations->SetOut(Location::SameAsFirstInput()); |
| 6795 | } |
| Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 6796 | // Rely on the type initialization to save everything we need. |
| 6797 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6798 | } |
| 6799 | |
| 6800 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6801 | // We assume the class to not be null. |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 6802 | SlowPathCode* slow_path = |
| 6803 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86(check->GetLoadClass(), check); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6804 | codegen_->AddSlowPath(slow_path); |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6805 | GenerateClassInitializationCheck(slow_path, |
| 6806 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6807 | } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6808 | |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6809 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6810 | SlowPathCode* slow_path, Register class_reg) { |
| Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 6811 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
| 6812 | const size_t status_byte_offset = |
| 6813 | mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte); |
| Vladimir Marko | bf12191 | 2019-06-04 13:49:05 +0100 | [diff] [blame] | 6814 | constexpr uint32_t shifted_visibly_initialized_value = |
| 6815 | enum_cast<uint32_t>(ClassStatus::kVisiblyInitialized) << (status_lsb_position % kBitsPerByte); |
| Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 6816 | |
| Vladimir Marko | bf12191 | 2019-06-04 13:49:05 +0100 | [diff] [blame] | 6817 | __ cmpb(Address(class_reg, status_byte_offset), Immediate(shifted_visibly_initialized_value)); |
| Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 6818 | __ j(kBelow, slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6819 | __ Bind(slow_path->GetExitLabel()); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6820 | } |
| 6821 | |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6822 | void InstructionCodeGeneratorX86::GenerateBitstringTypeCheckCompare(HTypeCheckInstruction* check, |
| 6823 | Register temp) { |
| 6824 | uint32_t path_to_root = check->GetBitstringPathToRoot(); |
| 6825 | uint32_t mask = check->GetBitstringMask(); |
| 6826 | DCHECK(IsPowerOfTwo(mask + 1)); |
| 6827 | size_t mask_bits = WhichPowerOf2(mask + 1); |
| 6828 | |
| 6829 | if (mask_bits == 16u) { |
| 6830 | // Compare the bitstring in memory. |
| 6831 | __ cmpw(Address(temp, mirror::Class::StatusOffset()), Immediate(path_to_root)); |
| 6832 | } else { |
| 6833 | // /* uint32_t */ temp = temp->status_ |
| 6834 | __ movl(temp, Address(temp, mirror::Class::StatusOffset())); |
| 6835 | // Compare the bitstring bits using SUB. |
| 6836 | __ subl(temp, Immediate(path_to_root)); |
| 6837 | // Shift out bits that do not contribute to the comparison. |
| 6838 | __ shll(temp, Immediate(32u - mask_bits)); |
| 6839 | } |
| 6840 | } |
| 6841 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6842 | HLoadString::LoadKind CodeGeneratorX86::GetSupportedLoadStringKind( |
| 6843 | HLoadString::LoadKind desired_string_load_kind) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6844 | switch (desired_string_load_kind) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6845 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6846 | case HLoadString::LoadKind::kBootImageRelRo: |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6847 | case HLoadString::LoadKind::kBssEntry: |
| Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6848 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6849 | break; |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6850 | case HLoadString::LoadKind::kJitBootImageAddress: |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6851 | case HLoadString::LoadKind::kJitTableAddress: |
| 6852 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6853 | break; |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6854 | case HLoadString::LoadKind::kRuntimeCall: |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6855 | break; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6856 | } |
| 6857 | return desired_string_load_kind; |
| 6858 | } |
| 6859 | |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6860 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6861 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6862 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6863 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6864 | if (load_kind == HLoadString::LoadKind::kBootImageLinkTimePcRelative || |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6865 | load_kind == HLoadString::LoadKind::kBootImageRelRo || |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6866 | load_kind == HLoadString::LoadKind::kBssEntry) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6867 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6868 | } |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6869 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
| Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6870 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 6871 | } else { |
| 6872 | locations->SetOut(Location::RequiresRegister()); |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6873 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 6874 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6875 | // Rely on the pResolveString to save everything. |
| Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 6876 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6877 | } else { |
| 6878 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6879 | } |
| 6880 | } |
| Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6881 | } |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6882 | } |
| 6883 | |
| Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6884 | Label* CodeGeneratorX86::NewJitRootStringPatch(const DexFile& dex_file, |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6885 | dex::StringIndex string_index, |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6886 | Handle<mirror::String> handle) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6887 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6888 | // Add a patch entry and return the label. |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6889 | jit_string_patches_.emplace_back(&dex_file, string_index.index_); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6890 | PatchInfo<Label>* info = &jit_string_patches_.back(); |
| 6891 | return &info->label; |
| 6892 | } |
| 6893 | |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6894 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6895 | // move. |
| 6896 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
| Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6897 | LocationSummary* locations = load->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6898 | Location out_loc = locations->Out(); |
| 6899 | Register out = out_loc.AsRegister<Register>(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6900 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6901 | switch (load->GetLoadKind()) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6902 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 6903 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 6904 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6905 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6906 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6907 | codegen_->RecordBootImageStringPatch(load); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6908 | return; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6909 | } |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6910 | case HLoadString::LoadKind::kBootImageRelRo: { |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6911 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 6912 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6913 | __ movl(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6914 | codegen_->RecordBootImageRelRoPatch(load->InputAt(0)->AsX86ComputeBaseMethodAddress(), |
| 6915 | codegen_->GetBootImageOffset(load)); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6916 | return; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6917 | } |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6918 | case HLoadString::LoadKind::kBssEntry: { |
| 6919 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6920 | Address address = Address(method_address, CodeGeneratorX86::kDummy32BitOffset); |
| 6921 | Label* fixup_label = codegen_->NewStringBssEntryPatch(load); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6922 | // /* GcRoot<mirror::String> */ out = *address /* PC-relative */ |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6923 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
| Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 6924 | // No need for memory fence, thanks to the x86 memory model. |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6925 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadStringSlowPathX86(load); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6926 | codegen_->AddSlowPath(slow_path); |
| 6927 | __ testl(out, out); |
| 6928 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6929 | __ Bind(slow_path->GetExitLabel()); |
| 6930 | return; |
| 6931 | } |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6932 | case HLoadString::LoadKind::kJitBootImageAddress: { |
| 6933 | uint32_t address = reinterpret_cast32<uint32_t>(load->GetString().Get()); |
| 6934 | DCHECK_NE(address, 0u); |
| 6935 | __ movl(out, Immediate(address)); |
| 6936 | return; |
| 6937 | } |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6938 | case HLoadString::LoadKind::kJitTableAddress: { |
| 6939 | Address address = Address::Absolute(CodeGeneratorX86::kDummy32BitOffset); |
| 6940 | Label* fixup_label = codegen_->NewJitRootStringPatch( |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6941 | load->GetDexFile(), load->GetStringIndex(), load->GetString()); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6942 | // /* GcRoot<mirror::String> */ out = *address |
| 6943 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
| 6944 | return; |
| 6945 | } |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6946 | default: |
| Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6947 | break; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6948 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6949 | |
| Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6950 | // 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] | 6951 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6952 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
| Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6953 | __ movl(calling_convention.GetRegisterAt(0), Immediate(load->GetStringIndex().index_)); |
| Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6954 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 6955 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6956 | } |
| 6957 | |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6958 | static Address GetExceptionTlsAddress() { |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6959 | return Address::Absolute(Thread::ExceptionOffset<kX86PointerSize>().Int32Value()); |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6960 | } |
| 6961 | |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6962 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 6963 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6964 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6965 | locations->SetOut(Location::RequiresRegister()); |
| 6966 | } |
| 6967 | |
| 6968 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6969 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 6970 | } |
| 6971 | |
| 6972 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6973 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6974 | } |
| 6975 | |
| 6976 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6977 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6978 | } |
| 6979 | |
| 6980 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6981 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6982 | instruction, LocationSummary::kCallOnMainOnly); |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6983 | InvokeRuntimeCallingConvention calling_convention; |
| 6984 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6985 | } |
| 6986 | |
| 6987 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6988 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6989 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6990 | } |
| 6991 | |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6992 | // Temp is used for read barrier. |
| 6993 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 6994 | if (kEmitCompilerReadBarrier && |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6995 | !kUseBakerReadBarrier && |
| 6996 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6997 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6998 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 6999 | return 1; |
| 7000 | } |
| 7001 | return 0; |
| 7002 | } |
| 7003 | |
| Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 7004 | // Interface case has 2 temps, one for holding the number of interfaces, one for the current |
| 7005 | // interface pointer, the current interface is compared in memory. |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7006 | // The other checks have one temp for loading the object's class. |
| 7007 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 7008 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7009 | return 2; |
| 7010 | } |
| 7011 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7012 | } |
| 7013 | |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7014 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7015 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7016 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7017 | bool baker_read_barrier_slow_path = false; |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7018 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7019 | case TypeCheckKind::kExactCheck: |
| 7020 | case TypeCheckKind::kAbstractClassCheck: |
| 7021 | case TypeCheckKind::kClassHierarchyCheck: |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7022 | case TypeCheckKind::kArrayObjectCheck: { |
| 7023 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 7024 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 7025 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7026 | break; |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7027 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7028 | case TypeCheckKind::kArrayCheck: |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7029 | case TypeCheckKind::kUnresolvedCheck: |
| 7030 | case TypeCheckKind::kInterfaceCheck: |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7031 | call_kind = LocationSummary::kCallOnSlowPath; |
| 7032 | break; |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7033 | case TypeCheckKind::kBitstringCheck: |
| 7034 | break; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7035 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7036 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7037 | LocationSummary* locations = |
| 7038 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7039 | if (baker_read_barrier_slow_path) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 7040 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7041 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7042 | locations->SetInAt(0, Location::RequiresRegister()); |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7043 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 7044 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 7045 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 7046 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 7047 | } else { |
| 7048 | locations->SetInAt(1, Location::Any()); |
| 7049 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7050 | // Note that TypeCheckSlowPathX86 uses this "out" register too. |
| 7051 | locations->SetOut(Location::RequiresRegister()); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7052 | // When read barriers are enabled, we need a temporary register for some cases. |
| 7053 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7054 | } |
| 7055 | |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7056 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7057 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7058 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7059 | Location obj_loc = locations->InAt(0); |
| 7060 | Register obj = obj_loc.AsRegister<Register>(); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7061 | Location cls = locations->InAt(1); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7062 | Location out_loc = locations->Out(); |
| 7063 | Register out = out_loc.AsRegister<Register>(); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7064 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 7065 | DCHECK_LE(num_temps, 1u); |
| 7066 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7067 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7068 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7069 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7070 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7071 | SlowPathCode* slow_path = nullptr; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7072 | NearLabel done, zero; |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7073 | |
| 7074 | // Return 0 if `obj` is null. |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7075 | // Avoid null check if we know obj is not null. |
| 7076 | if (instruction->MustDoNullCheck()) { |
| 7077 | __ testl(obj, obj); |
| 7078 | __ j(kEqual, &zero); |
| 7079 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7080 | |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7081 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7082 | case TypeCheckKind::kExactCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7083 | ReadBarrierOption read_barrier_option = |
| 7084 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7085 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7086 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7087 | out_loc, |
| 7088 | obj_loc, |
| 7089 | class_offset, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7090 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7091 | if (cls.IsRegister()) { |
| 7092 | __ cmpl(out, cls.AsRegister<Register>()); |
| 7093 | } else { |
| 7094 | DCHECK(cls.IsStackSlot()) << cls; |
| 7095 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 7096 | } |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7097 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7098 | // Classes must be equal for the instanceof to succeed. |
| 7099 | __ j(kNotEqual, &zero); |
| 7100 | __ movl(out, Immediate(1)); |
| 7101 | __ jmp(&done); |
| 7102 | break; |
| 7103 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7104 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7105 | case TypeCheckKind::kAbstractClassCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7106 | ReadBarrierOption read_barrier_option = |
| 7107 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7108 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7109 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7110 | out_loc, |
| 7111 | obj_loc, |
| 7112 | class_offset, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7113 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7114 | // If the class is abstract, we eagerly fetch the super class of the |
| 7115 | // object to avoid doing a comparison we know will fail. |
| 7116 | NearLabel loop; |
| 7117 | __ Bind(&loop); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7118 | // /* HeapReference<Class> */ out = out->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7119 | GenerateReferenceLoadOneRegister(instruction, |
| 7120 | out_loc, |
| 7121 | super_offset, |
| 7122 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7123 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7124 | __ testl(out, out); |
| 7125 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7126 | __ j(kEqual, &done); |
| 7127 | if (cls.IsRegister()) { |
| 7128 | __ cmpl(out, cls.AsRegister<Register>()); |
| 7129 | } else { |
| 7130 | DCHECK(cls.IsStackSlot()) << cls; |
| 7131 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 7132 | } |
| 7133 | __ j(kNotEqual, &loop); |
| 7134 | __ movl(out, Immediate(1)); |
| 7135 | if (zero.IsLinked()) { |
| 7136 | __ jmp(&done); |
| 7137 | } |
| 7138 | break; |
| 7139 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7140 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7141 | case TypeCheckKind::kClassHierarchyCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7142 | ReadBarrierOption read_barrier_option = |
| 7143 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7144 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7145 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7146 | out_loc, |
| 7147 | obj_loc, |
| 7148 | class_offset, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7149 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7150 | // Walk over the class hierarchy to find a match. |
| 7151 | NearLabel loop, success; |
| 7152 | __ Bind(&loop); |
| 7153 | if (cls.IsRegister()) { |
| 7154 | __ cmpl(out, cls.AsRegister<Register>()); |
| 7155 | } else { |
| 7156 | DCHECK(cls.IsStackSlot()) << cls; |
| 7157 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 7158 | } |
| 7159 | __ j(kEqual, &success); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7160 | // /* HeapReference<Class> */ out = out->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7161 | GenerateReferenceLoadOneRegister(instruction, |
| 7162 | out_loc, |
| 7163 | super_offset, |
| 7164 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7165 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7166 | __ testl(out, out); |
| 7167 | __ j(kNotEqual, &loop); |
| 7168 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7169 | __ jmp(&done); |
| 7170 | __ Bind(&success); |
| 7171 | __ movl(out, Immediate(1)); |
| 7172 | if (zero.IsLinked()) { |
| 7173 | __ jmp(&done); |
| 7174 | } |
| 7175 | break; |
| 7176 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7177 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7178 | case TypeCheckKind::kArrayObjectCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7179 | ReadBarrierOption read_barrier_option = |
| 7180 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7181 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7182 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7183 | out_loc, |
| 7184 | obj_loc, |
| 7185 | class_offset, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7186 | read_barrier_option); |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7187 | // Do an exact check. |
| 7188 | NearLabel exact_check; |
| 7189 | if (cls.IsRegister()) { |
| 7190 | __ cmpl(out, cls.AsRegister<Register>()); |
| 7191 | } else { |
| 7192 | DCHECK(cls.IsStackSlot()) << cls; |
| 7193 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 7194 | } |
| 7195 | __ j(kEqual, &exact_check); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7196 | // 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] | 7197 | // /* HeapReference<Class> */ out = out->component_type_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7198 | GenerateReferenceLoadOneRegister(instruction, |
| 7199 | out_loc, |
| 7200 | component_offset, |
| 7201 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7202 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7203 | __ testl(out, out); |
| 7204 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7205 | __ j(kEqual, &done); |
| 7206 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 7207 | __ j(kNotEqual, &zero); |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7208 | __ Bind(&exact_check); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7209 | __ movl(out, Immediate(1)); |
| 7210 | __ jmp(&done); |
| 7211 | break; |
| 7212 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7213 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7214 | case TypeCheckKind::kArrayCheck: { |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7215 | // No read barrier since the slow path will retry upon failure. |
| 7216 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7217 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7218 | out_loc, |
| 7219 | obj_loc, |
| 7220 | class_offset, |
| 7221 | kWithoutReadBarrier); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7222 | if (cls.IsRegister()) { |
| 7223 | __ cmpl(out, cls.AsRegister<Register>()); |
| 7224 | } else { |
| 7225 | DCHECK(cls.IsStackSlot()) << cls; |
| 7226 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 7227 | } |
| 7228 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7229 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7230 | instruction, /* is_fatal= */ false); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7231 | codegen_->AddSlowPath(slow_path); |
| 7232 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 7233 | __ movl(out, Immediate(1)); |
| 7234 | if (zero.IsLinked()) { |
| 7235 | __ jmp(&done); |
| 7236 | } |
| 7237 | break; |
| 7238 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7239 | |
| Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 7240 | case TypeCheckKind::kUnresolvedCheck: |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7241 | case TypeCheckKind::kInterfaceCheck: { |
| 7242 | // 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] | 7243 | // into the slow path for the unresolved and interface check |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7244 | // cases. |
| 7245 | // |
| 7246 | // We cannot directly call the InstanceofNonTrivial runtime |
| 7247 | // entry point without resorting to a type checking slow path |
| 7248 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 7249 | // require to assign fixed registers for the inputs of this |
| 7250 | // HInstanceOf instruction (following the runtime calling |
| 7251 | // convention), which might be cluttered by the potential first |
| 7252 | // read barrier emission at the beginning of this method. |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7253 | // |
| 7254 | // TODO: Introduce a new runtime entry point taking the object |
| 7255 | // to test (instead of its class) as argument, and let it deal |
| 7256 | // with the read barrier issues. This will let us refactor this |
| 7257 | // case of the `switch` code as it was previously (with a direct |
| 7258 | // call to the runtime not using a type checking slow path). |
| 7259 | // This should also be beneficial for the other cases above. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7260 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7261 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7262 | instruction, /* is_fatal= */ false); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7263 | codegen_->AddSlowPath(slow_path); |
| 7264 | __ jmp(slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7265 | if (zero.IsLinked()) { |
| 7266 | __ jmp(&done); |
| 7267 | } |
| 7268 | break; |
| 7269 | } |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7270 | |
| 7271 | case TypeCheckKind::kBitstringCheck: { |
| 7272 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7273 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7274 | out_loc, |
| 7275 | obj_loc, |
| 7276 | class_offset, |
| 7277 | kWithoutReadBarrier); |
| 7278 | |
| 7279 | GenerateBitstringTypeCheckCompare(instruction, out); |
| 7280 | __ j(kNotEqual, &zero); |
| 7281 | __ movl(out, Immediate(1)); |
| 7282 | __ jmp(&done); |
| 7283 | break; |
| 7284 | } |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7285 | } |
| 7286 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7287 | if (zero.IsLinked()) { |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7288 | __ Bind(&zero); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7289 | __ xorl(out, out); |
| 7290 | } |
| 7291 | |
| 7292 | if (done.IsLinked()) { |
| 7293 | __ Bind(&done); |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7294 | } |
| 7295 | |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7296 | if (slow_path != nullptr) { |
| 7297 | __ Bind(slow_path->GetExitLabel()); |
| 7298 | } |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7299 | } |
| 7300 | |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7301 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7302 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7303 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7304 | LocationSummary* locations = |
| 7305 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7306 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7307 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 7308 | // Require a register for the interface check since there is a loop that compares the class to |
| 7309 | // a memory address. |
| 7310 | locations->SetInAt(1, Location::RequiresRegister()); |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7311 | } else if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 7312 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 7313 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 7314 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7315 | } else { |
| 7316 | locations->SetInAt(1, Location::Any()); |
| 7317 | } |
| Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 7318 | // 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] | 7319 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
| 7320 | } |
| 7321 | |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7322 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7323 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7324 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7325 | Location obj_loc = locations->InAt(0); |
| 7326 | Register obj = obj_loc.AsRegister<Register>(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7327 | Location cls = locations->InAt(1); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7328 | Location temp_loc = locations->GetTemp(0); |
| 7329 | Register temp = temp_loc.AsRegister<Register>(); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7330 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 7331 | DCHECK_GE(num_temps, 1u); |
| 7332 | DCHECK_LE(num_temps, 2u); |
| 7333 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 7334 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7335 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7336 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7337 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 7338 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 7339 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 7340 | const uint32_t object_array_data_offset = |
| 7341 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7342 | |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7343 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7344 | SlowPathCode* type_check_slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7345 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
| 7346 | instruction, is_type_check_slow_path_fatal); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7347 | codegen_->AddSlowPath(type_check_slow_path); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7348 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7349 | NearLabel done; |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7350 | // Avoid null check if we know obj is not null. |
| 7351 | if (instruction->MustDoNullCheck()) { |
| 7352 | __ testl(obj, obj); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7353 | __ j(kEqual, &done); |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7354 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7355 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7356 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7357 | case TypeCheckKind::kExactCheck: |
| 7358 | case TypeCheckKind::kArrayCheck: { |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7359 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7360 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7361 | temp_loc, |
| 7362 | obj_loc, |
| 7363 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7364 | kWithoutReadBarrier); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7365 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7366 | if (cls.IsRegister()) { |
| 7367 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 7368 | } else { |
| 7369 | DCHECK(cls.IsStackSlot()) << cls; |
| 7370 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 7371 | } |
| 7372 | // Jump to slow path for throwing the exception or doing a |
| 7373 | // more involved array check. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7374 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7375 | break; |
| 7376 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7377 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7378 | case TypeCheckKind::kAbstractClassCheck: { |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7379 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7380 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7381 | temp_loc, |
| 7382 | obj_loc, |
| 7383 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7384 | kWithoutReadBarrier); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7385 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7386 | // If the class is abstract, we eagerly fetch the super class of the |
| 7387 | // object to avoid doing a comparison we know will fail. |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7388 | NearLabel loop; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7389 | __ Bind(&loop); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7390 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7391 | GenerateReferenceLoadOneRegister(instruction, |
| 7392 | temp_loc, |
| 7393 | super_offset, |
| 7394 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7395 | kWithoutReadBarrier); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7396 | |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7397 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 7398 | // exception. |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7399 | __ testl(temp, temp); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7400 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7401 | |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7402 | // Otherwise, compare the classes |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7403 | if (cls.IsRegister()) { |
| 7404 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 7405 | } else { |
| 7406 | DCHECK(cls.IsStackSlot()) << cls; |
| 7407 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 7408 | } |
| 7409 | __ j(kNotEqual, &loop); |
| 7410 | break; |
| 7411 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7412 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7413 | case TypeCheckKind::kClassHierarchyCheck: { |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7414 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7415 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7416 | temp_loc, |
| 7417 | obj_loc, |
| 7418 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7419 | kWithoutReadBarrier); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7420 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7421 | // Walk over the class hierarchy to find a match. |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7422 | NearLabel loop; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7423 | __ Bind(&loop); |
| 7424 | if (cls.IsRegister()) { |
| 7425 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 7426 | } else { |
| 7427 | DCHECK(cls.IsStackSlot()) << cls; |
| 7428 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 7429 | } |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7430 | __ j(kEqual, &done); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7431 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7432 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7433 | GenerateReferenceLoadOneRegister(instruction, |
| 7434 | temp_loc, |
| 7435 | super_offset, |
| 7436 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7437 | kWithoutReadBarrier); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7438 | |
| 7439 | // If the class reference currently in `temp` is not null, jump |
| 7440 | // back at the beginning of the loop. |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7441 | __ testl(temp, temp); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7442 | __ j(kNotZero, &loop); |
| 7443 | // Otherwise, jump to the slow path to throw the exception.; |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7444 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7445 | break; |
| 7446 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7447 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7448 | case TypeCheckKind::kArrayObjectCheck: { |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7449 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7450 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7451 | temp_loc, |
| 7452 | obj_loc, |
| 7453 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7454 | kWithoutReadBarrier); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7455 | |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7456 | // Do an exact check. |
| 7457 | if (cls.IsRegister()) { |
| 7458 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 7459 | } else { |
| 7460 | DCHECK(cls.IsStackSlot()) << cls; |
| 7461 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 7462 | } |
| 7463 | __ j(kEqual, &done); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7464 | |
| 7465 | // 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] | 7466 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7467 | GenerateReferenceLoadOneRegister(instruction, |
| 7468 | temp_loc, |
| 7469 | component_offset, |
| 7470 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7471 | kWithoutReadBarrier); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7472 | |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7473 | // If the component type is null (i.e. the object not an array), jump to the slow path to |
| 7474 | // throw the exception. Otherwise proceed with the check. |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7475 | __ testl(temp, temp); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7476 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7477 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7478 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7479 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7480 | break; |
| 7481 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7482 | |
| Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 7483 | case TypeCheckKind::kUnresolvedCheck: |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7484 | // 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] | 7485 | // We cannot directly call the CheckCast runtime entry point |
| 7486 | // without resorting to a type checking slow path here (i.e. by |
| 7487 | // calling InvokeRuntime directly), as it would require to |
| 7488 | // assign fixed registers for the inputs of this HInstanceOf |
| 7489 | // instruction (following the runtime calling convention), which |
| 7490 | // might be cluttered by the potential first read barrier |
| 7491 | // emission at the beginning of this method. |
| 7492 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7493 | break; |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7494 | |
| 7495 | case TypeCheckKind::kInterfaceCheck: { |
| Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 7496 | // Fast path for the interface check. Try to avoid read barriers to improve the fast path. |
| 7497 | // We can not get false positives by doing this. |
| 7498 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7499 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7500 | temp_loc, |
| 7501 | obj_loc, |
| 7502 | class_offset, |
| 7503 | kWithoutReadBarrier); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7504 | |
| Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 7505 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 7506 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7507 | temp_loc, |
| 7508 | temp_loc, |
| 7509 | iftable_offset, |
| 7510 | kWithoutReadBarrier); |
| 7511 | // Iftable is never null. |
| 7512 | __ movl(maybe_temp2_loc.AsRegister<Register>(), Address(temp, array_length_offset)); |
| 7513 | // Maybe poison the `cls` for direct comparison with memory. |
| 7514 | __ MaybePoisonHeapReference(cls.AsRegister<Register>()); |
| 7515 | // Loop through the iftable and check if any class matches. |
| 7516 | NearLabel start_loop; |
| 7517 | __ Bind(&start_loop); |
| 7518 | // Need to subtract first to handle the empty array case. |
| 7519 | __ subl(maybe_temp2_loc.AsRegister<Register>(), Immediate(2)); |
| 7520 | __ j(kNegative, type_check_slow_path->GetEntryLabel()); |
| 7521 | // Go to next interface if the classes do not match. |
| 7522 | __ cmpl(cls.AsRegister<Register>(), |
| 7523 | CodeGeneratorX86::ArrayAddress(temp, |
| 7524 | maybe_temp2_loc, |
| 7525 | TIMES_4, |
| 7526 | object_array_data_offset)); |
| 7527 | __ j(kNotEqual, &start_loop); |
| 7528 | // If `cls` was poisoned above, unpoison it. |
| 7529 | __ MaybeUnpoisonHeapReference(cls.AsRegister<Register>()); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7530 | break; |
| 7531 | } |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7532 | |
| 7533 | case TypeCheckKind::kBitstringCheck: { |
| 7534 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7535 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7536 | temp_loc, |
| 7537 | obj_loc, |
| 7538 | class_offset, |
| 7539 | kWithoutReadBarrier); |
| 7540 | |
| 7541 | GenerateBitstringTypeCheckCompare(instruction, temp); |
| 7542 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
| 7543 | break; |
| 7544 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7545 | } |
| 7546 | __ Bind(&done); |
| 7547 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7548 | __ Bind(type_check_slow_path->GetExitLabel()); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7549 | } |
| 7550 | |
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7551 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7552 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 7553 | instruction, LocationSummary::kCallOnMainOnly); |
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7554 | InvokeRuntimeCallingConvention calling_convention; |
| 7555 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 7556 | } |
| 7557 | |
| 7558 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 7559 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject |
| 7560 | : kQuickUnlockObject, |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 7561 | instruction, |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 7562 | instruction->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7563 | if (instruction->IsEnter()) { |
| 7564 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 7565 | } else { |
| 7566 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 7567 | } |
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7568 | } |
| 7569 | |
| Shalini Salomi Bodapati | dd121f6 | 2018-10-26 15:03:53 +0530 | [diff] [blame] | 7570 | void LocationsBuilderX86::VisitX86AndNot(HX86AndNot* instruction) { |
| 7571 | DCHECK(codegen_->GetInstructionSetFeatures().HasAVX2()); |
| 7572 | DCHECK(DataType::IsIntOrLongType(instruction->GetType())) << instruction->GetType(); |
| 7573 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| 7574 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7575 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7576 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7577 | } |
| 7578 | |
| 7579 | void InstructionCodeGeneratorX86::VisitX86AndNot(HX86AndNot* instruction) { |
| 7580 | LocationSummary* locations = instruction->GetLocations(); |
| 7581 | Location first = locations->InAt(0); |
| 7582 | Location second = locations->InAt(1); |
| 7583 | Location dest = locations->Out(); |
| 7584 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
| 7585 | __ andn(dest.AsRegister<Register>(), |
| 7586 | first.AsRegister<Register>(), |
| 7587 | second.AsRegister<Register>()); |
| 7588 | } else { |
| 7589 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
| 7590 | __ andn(dest.AsRegisterPairLow<Register>(), |
| 7591 | first.AsRegisterPairLow<Register>(), |
| 7592 | second.AsRegisterPairLow<Register>()); |
| 7593 | __ andn(dest.AsRegisterPairHigh<Register>(), |
| 7594 | first.AsRegisterPairHigh<Register>(), |
| 7595 | second.AsRegisterPairHigh<Register>()); |
| 7596 | } |
| 7597 | } |
| 7598 | |
| 7599 | void LocationsBuilderX86::VisitX86MaskOrResetLeastSetBit(HX86MaskOrResetLeastSetBit* instruction) { |
| 7600 | DCHECK(codegen_->GetInstructionSetFeatures().HasAVX2()); |
| 7601 | DCHECK(instruction->GetType() == DataType::Type::kInt32) << instruction->GetType(); |
| 7602 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| 7603 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7604 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7605 | } |
| 7606 | |
| 7607 | void InstructionCodeGeneratorX86::VisitX86MaskOrResetLeastSetBit( |
| 7608 | HX86MaskOrResetLeastSetBit* instruction) { |
| 7609 | LocationSummary* locations = instruction->GetLocations(); |
| 7610 | Location src = locations->InAt(0); |
| 7611 | Location dest = locations->Out(); |
| 7612 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
| 7613 | switch (instruction->GetOpKind()) { |
| 7614 | case HInstruction::kAnd: |
| 7615 | __ blsr(dest.AsRegister<Register>(), src.AsRegister<Register>()); |
| 7616 | break; |
| 7617 | case HInstruction::kXor: |
| 7618 | __ blsmsk(dest.AsRegister<Register>(), src.AsRegister<Register>()); |
| 7619 | break; |
| 7620 | default: |
| 7621 | LOG(FATAL) << "Unreachable"; |
| 7622 | } |
| 7623 | } |
| 7624 | |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7625 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 7626 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 7627 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 7628 | |
| 7629 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 7630 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7631 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7632 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 |
| 7633 | || instruction->GetResultType() == DataType::Type::kInt64); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7634 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7635 | locations->SetInAt(1, Location::Any()); |
| 7636 | locations->SetOut(Location::SameAsFirstInput()); |
| 7637 | } |
| 7638 | |
| 7639 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 7640 | HandleBitwiseOperation(instruction); |
| 7641 | } |
| 7642 | |
| 7643 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 7644 | HandleBitwiseOperation(instruction); |
| 7645 | } |
| 7646 | |
| 7647 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 7648 | HandleBitwiseOperation(instruction); |
| 7649 | } |
| 7650 | |
| 7651 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 7652 | LocationSummary* locations = instruction->GetLocations(); |
| 7653 | Location first = locations->InAt(0); |
| 7654 | Location second = locations->InAt(1); |
| 7655 | DCHECK(first.Equals(locations->Out())); |
| 7656 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7657 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7658 | if (second.IsRegister()) { |
| 7659 | if (instruction->IsAnd()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7660 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7661 | } else if (instruction->IsOr()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7662 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7663 | } else { |
| 7664 | DCHECK(instruction->IsXor()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7665 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7666 | } |
| 7667 | } else if (second.IsConstant()) { |
| 7668 | if (instruction->IsAnd()) { |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 7669 | __ andl(first.AsRegister<Register>(), |
| 7670 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7671 | } else if (instruction->IsOr()) { |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 7672 | __ orl(first.AsRegister<Register>(), |
| 7673 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7674 | } else { |
| 7675 | DCHECK(instruction->IsXor()); |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 7676 | __ xorl(first.AsRegister<Register>(), |
| 7677 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7678 | } |
| 7679 | } else { |
| 7680 | if (instruction->IsAnd()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7681 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7682 | } else if (instruction->IsOr()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7683 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7684 | } else { |
| 7685 | DCHECK(instruction->IsXor()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7686 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7687 | } |
| 7688 | } |
| 7689 | } else { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7690 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7691 | if (second.IsRegisterPair()) { |
| 7692 | if (instruction->IsAnd()) { |
| 7693 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 7694 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 7695 | } else if (instruction->IsOr()) { |
| 7696 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 7697 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 7698 | } else { |
| 7699 | DCHECK(instruction->IsXor()); |
| 7700 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 7701 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 7702 | } |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7703 | } else if (second.IsDoubleStackSlot()) { |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7704 | if (instruction->IsAnd()) { |
| 7705 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7706 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 7707 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7708 | } else if (instruction->IsOr()) { |
| 7709 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7710 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 7711 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7712 | } else { |
| 7713 | DCHECK(instruction->IsXor()); |
| 7714 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7715 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 7716 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7717 | } |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7718 | } else { |
| 7719 | DCHECK(second.IsConstant()) << second; |
| 7720 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7721 | int32_t low_value = Low32Bits(value); |
| 7722 | int32_t high_value = High32Bits(value); |
| 7723 | Immediate low(low_value); |
| 7724 | Immediate high(high_value); |
| 7725 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 7726 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7727 | if (instruction->IsAnd()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7728 | if (low_value == 0) { |
| 7729 | __ xorl(first_low, first_low); |
| 7730 | } else if (low_value != -1) { |
| 7731 | __ andl(first_low, low); |
| 7732 | } |
| 7733 | if (high_value == 0) { |
| 7734 | __ xorl(first_high, first_high); |
| 7735 | } else if (high_value != -1) { |
| 7736 | __ andl(first_high, high); |
| 7737 | } |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7738 | } else if (instruction->IsOr()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7739 | if (low_value != 0) { |
| 7740 | __ orl(first_low, low); |
| 7741 | } |
| 7742 | if (high_value != 0) { |
| 7743 | __ orl(first_high, high); |
| 7744 | } |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7745 | } else { |
| 7746 | DCHECK(instruction->IsXor()); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7747 | if (low_value != 0) { |
| 7748 | __ xorl(first_low, low); |
| 7749 | } |
| 7750 | if (high_value != 0) { |
| 7751 | __ xorl(first_high, high); |
| 7752 | } |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7753 | } |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7754 | } |
| 7755 | } |
| 7756 | } |
| 7757 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7758 | void InstructionCodeGeneratorX86::GenerateReferenceLoadOneRegister( |
| 7759 | HInstruction* instruction, |
| 7760 | Location out, |
| 7761 | uint32_t offset, |
| 7762 | Location maybe_temp, |
| 7763 | ReadBarrierOption read_barrier_option) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7764 | Register out_reg = out.AsRegister<Register>(); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7765 | if (read_barrier_option == kWithReadBarrier) { |
| 7766 | CHECK(kEmitCompilerReadBarrier); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7767 | if (kUseBakerReadBarrier) { |
| 7768 | // Load with fast path based Baker's read barrier. |
| 7769 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7770 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7771 | instruction, out, out_reg, offset, /* needs_null_check= */ false); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7772 | } else { |
| 7773 | // Load with slow path based read barrier. |
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7774 | // Save the value of `out` into `maybe_temp` before overwriting it |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7775 | // in the following move operation, as we will need it for the |
| 7776 | // read barrier below. |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7777 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7778 | __ movl(maybe_temp.AsRegister<Register>(), out_reg); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7779 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7780 | __ movl(out_reg, Address(out_reg, offset)); |
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7781 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7782 | } |
| 7783 | } else { |
| 7784 | // Plain load with no read barrier. |
| 7785 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7786 | __ movl(out_reg, Address(out_reg, offset)); |
| 7787 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7788 | } |
| 7789 | } |
| 7790 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7791 | void InstructionCodeGeneratorX86::GenerateReferenceLoadTwoRegisters( |
| 7792 | HInstruction* instruction, |
| 7793 | Location out, |
| 7794 | Location obj, |
| 7795 | uint32_t offset, |
| 7796 | ReadBarrierOption read_barrier_option) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7797 | Register out_reg = out.AsRegister<Register>(); |
| 7798 | Register obj_reg = obj.AsRegister<Register>(); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7799 | if (read_barrier_option == kWithReadBarrier) { |
| 7800 | CHECK(kEmitCompilerReadBarrier); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7801 | if (kUseBakerReadBarrier) { |
| 7802 | // Load with fast path based Baker's read barrier. |
| 7803 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7804 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7805 | instruction, out, obj_reg, offset, /* needs_null_check= */ false); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7806 | } else { |
| 7807 | // Load with slow path based read barrier. |
| 7808 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7809 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7810 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 7811 | } |
| 7812 | } else { |
| 7813 | // Plain load with no read barrier. |
| 7814 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7815 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7816 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7817 | } |
| 7818 | } |
| 7819 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7820 | void InstructionCodeGeneratorX86::GenerateGcRootFieldLoad( |
| 7821 | HInstruction* instruction, |
| 7822 | Location root, |
| 7823 | const Address& address, |
| 7824 | Label* fixup_label, |
| 7825 | ReadBarrierOption read_barrier_option) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7826 | Register root_reg = root.AsRegister<Register>(); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7827 | if (read_barrier_option == kWithReadBarrier) { |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7828 | DCHECK(kEmitCompilerReadBarrier); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7829 | if (kUseBakerReadBarrier) { |
| 7830 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 7831 | // Baker's read barrier are used: |
| 7832 | // |
| Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7833 | // root = obj.field; |
| 7834 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 7835 | // if (temp != null) { |
| 7836 | // root = temp(root) |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7837 | // } |
| 7838 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7839 | // /* GcRoot<mirror::Object> */ root = *address |
| 7840 | __ movl(root_reg, address); |
| 7841 | if (fixup_label != nullptr) { |
| 7842 | __ Bind(fixup_label); |
| 7843 | } |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7844 | static_assert( |
| 7845 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 7846 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 7847 | "have different sizes."); |
| 7848 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 7849 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 7850 | "have different sizes."); |
| 7851 | |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7852 | // Slow path marking the GC root `root`. |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7853 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathX86( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7854 | instruction, root, /* unpoison_ref_before_marking= */ false); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7855 | codegen_->AddSlowPath(slow_path); |
| 7856 | |
| Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7857 | // Test the entrypoint (`Thread::Current()->pReadBarrierMarkReg ## root.reg()`). |
| 7858 | const int32_t entry_point_offset = |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 7859 | Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(root.reg()); |
| Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7860 | __ fs()->cmpl(Address::Absolute(entry_point_offset), Immediate(0)); |
| 7861 | // The entrypoint is null when the GC is not marking. |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7862 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 7863 | __ Bind(slow_path->GetExitLabel()); |
| 7864 | } else { |
| 7865 | // GC root loaded through a slow path for read barriers other |
| 7866 | // than Baker's. |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7867 | // /* GcRoot<mirror::Object>* */ root = address |
| 7868 | __ leal(root_reg, address); |
| 7869 | if (fixup_label != nullptr) { |
| 7870 | __ Bind(fixup_label); |
| 7871 | } |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7872 | // /* mirror::Object* */ root = root->Read() |
| 7873 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 7874 | } |
| 7875 | } else { |
| 7876 | // Plain GC root load with no read barrier. |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7877 | // /* GcRoot<mirror::Object> */ root = *address |
| 7878 | __ movl(root_reg, address); |
| 7879 | if (fixup_label != nullptr) { |
| 7880 | __ Bind(fixup_label); |
| 7881 | } |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7882 | // Note that GC roots are not affected by heap poisoning, thus we |
| 7883 | // do not have to unpoison `root_reg` here. |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7884 | } |
| 7885 | } |
| 7886 | |
| 7887 | void CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7888 | Location ref, |
| 7889 | Register obj, |
| 7890 | uint32_t offset, |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7891 | bool needs_null_check) { |
| 7892 | DCHECK(kEmitCompilerReadBarrier); |
| 7893 | DCHECK(kUseBakerReadBarrier); |
| 7894 | |
| 7895 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7896 | Address src(obj, offset); |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7897 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7898 | } |
| 7899 | |
| 7900 | void CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7901 | Location ref, |
| 7902 | Register obj, |
| 7903 | uint32_t data_offset, |
| 7904 | Location index, |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7905 | bool needs_null_check) { |
| 7906 | DCHECK(kEmitCompilerReadBarrier); |
| 7907 | DCHECK(kUseBakerReadBarrier); |
| 7908 | |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 7909 | static_assert( |
| 7910 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 7911 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7912 | // /* HeapReference<Object> */ ref = |
| 7913 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7914 | Address src = CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset); |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7915 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7916 | } |
| 7917 | |
| 7918 | void CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7919 | Location ref, |
| 7920 | Register obj, |
| 7921 | const Address& src, |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7922 | bool needs_null_check, |
| 7923 | bool always_update_field, |
| 7924 | Register* temp) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7925 | DCHECK(kEmitCompilerReadBarrier); |
| 7926 | DCHECK(kUseBakerReadBarrier); |
| 7927 | |
| 7928 | // In slow path based read barriers, the read barrier call is |
| 7929 | // inserted after the original load. However, in fast path based |
| 7930 | // Baker's read barriers, we need to perform the load of |
| 7931 | // mirror::Object::monitor_ *before* the original reference load. |
| 7932 | // This load-load ordering is required by the read barrier. |
| 7933 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 7934 | // |
| 7935 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7936 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7937 | // HeapReference<Object> ref = *src; // Original reference load. |
| Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7938 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7939 | // if (is_gray) { |
| 7940 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 7941 | // } |
| 7942 | // |
| 7943 | // Note: the original implementation in ReadBarrier::Barrier is |
| 7944 | // slightly more complex as: |
| 7945 | // - it implements the load-load fence using a data dependency on |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7946 | // the high-bits of rb_state, which are expected to be all zeroes |
| 7947 | // (we use CodeGeneratorX86::GenerateMemoryBarrier instead here, |
| 7948 | // which is a no-op thanks to the x86 memory model); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7949 | // - it performs additional checks that we do not do here for |
| 7950 | // performance reasons. |
| 7951 | |
| 7952 | Register ref_reg = ref.AsRegister<Register>(); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7953 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 7954 | |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7955 | // 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] | 7956 | static_assert(ReadBarrier::NonGrayState() == 0, "Expecting non-gray to have value 0"); |
| Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7957 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7958 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 7959 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 7960 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 7961 | |
| Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7962 | // if (rb_state == ReadBarrier::GrayState()) |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7963 | // ref = ReadBarrier::Mark(ref); |
| 7964 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 7965 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7966 | if (needs_null_check) { |
| 7967 | MaybeRecordImplicitNullCheck(instruction); |
| 7968 | } |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7969 | |
| 7970 | // Load fence to prevent load-load reordering. |
| 7971 | // Note that this is a no-op, thanks to the x86 memory model. |
| 7972 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 7973 | |
| 7974 | // The actual reference load. |
| 7975 | // /* HeapReference<Object> */ ref = *src |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7976 | __ movl(ref_reg, src); // Flags are unaffected. |
| 7977 | |
| 7978 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 7979 | // Slow path marking the object `ref` when it is gray. |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7980 | SlowPathCode* slow_path; |
| 7981 | if (always_update_field) { |
| 7982 | DCHECK(temp != nullptr); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7983 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkAndUpdateFieldSlowPathX86( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7984 | instruction, ref, obj, src, /* unpoison_ref_before_marking= */ true, *temp); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7985 | } else { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7986 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkSlowPathX86( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7987 | instruction, ref, /* unpoison_ref_before_marking= */ true); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7988 | } |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7989 | AddSlowPath(slow_path); |
| 7990 | |
| 7991 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 7992 | __ j(kNotZero, slow_path->GetEntryLabel()); |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7993 | |
| 7994 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7995 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7996 | |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7997 | __ Bind(slow_path->GetExitLabel()); |
| 7998 | } |
| 7999 | |
| 8000 | void CodeGeneratorX86::GenerateReadBarrierSlow(HInstruction* instruction, |
| 8001 | Location out, |
| 8002 | Location ref, |
| 8003 | Location obj, |
| 8004 | uint32_t offset, |
| 8005 | Location index) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8006 | DCHECK(kEmitCompilerReadBarrier); |
| 8007 | |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8008 | // Insert a slow path based read barrier *after* the reference load. |
| 8009 | // |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8010 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 8011 | // reference will be carried out by the runtime within the slow |
| 8012 | // path. |
| 8013 | // |
| 8014 | // Note that `ref` currently does not get unpoisoned (when heap |
| 8015 | // poisoning is enabled), which is alright as the `ref` argument is |
| 8016 | // not used by the artReadBarrierSlow entry point. |
| 8017 | // |
| 8018 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8019 | SlowPathCode* slow_path = new (GetScopedAllocator()) |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8020 | ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); |
| 8021 | AddSlowPath(slow_path); |
| 8022 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8023 | __ jmp(slow_path->GetEntryLabel()); |
| 8024 | __ Bind(slow_path->GetExitLabel()); |
| 8025 | } |
| 8026 | |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8027 | void CodeGeneratorX86::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 8028 | Location out, |
| 8029 | Location ref, |
| 8030 | Location obj, |
| 8031 | uint32_t offset, |
| 8032 | Location index) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8033 | if (kEmitCompilerReadBarrier) { |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8034 | // Baker's read barriers shall be handled by the fast path |
| 8035 | // (CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier). |
| 8036 | DCHECK(!kUseBakerReadBarrier); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8037 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 8038 | // by the runtime within the slow path. |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8039 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8040 | } else if (kPoisonHeapReferences) { |
| 8041 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 8042 | } |
| 8043 | } |
| 8044 | |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8045 | void CodeGeneratorX86::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 8046 | Location out, |
| 8047 | Location root) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8048 | DCHECK(kEmitCompilerReadBarrier); |
| 8049 | |
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8050 | // Insert a slow path based read barrier *after* the GC root load. |
| 8051 | // |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8052 | // Note that GC roots are not affected by heap poisoning, so we do |
| 8053 | // not need to do anything special for this here. |
| 8054 | SlowPathCode* slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8055 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathX86(instruction, out, root); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8056 | AddSlowPath(slow_path); |
| 8057 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8058 | __ jmp(slow_path->GetEntryLabel()); |
| 8059 | __ Bind(slow_path->GetExitLabel()); |
| 8060 | } |
| 8061 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 8062 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8063 | // Nothing to do, this should be removed during prepare for register allocator. |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8064 | LOG(FATAL) << "Unreachable"; |
| 8065 | } |
| 8066 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 8067 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8068 | // Nothing to do, this should be removed during prepare for register allocator. |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8069 | LOG(FATAL) << "Unreachable"; |
| 8070 | } |
| 8071 | |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8072 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 8073 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 8074 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8075 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8076 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8077 | } |
| 8078 | |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8079 | void InstructionCodeGeneratorX86::GenPackedSwitchWithCompares(Register value_reg, |
| 8080 | int32_t lower_bound, |
| 8081 | uint32_t num_entries, |
| 8082 | HBasicBlock* switch_block, |
| 8083 | HBasicBlock* default_block) { |
| 8084 | // Figure out the correct compare values and jump conditions. |
| 8085 | // Handle the first compare/branch as a special case because it might |
| 8086 | // jump to the default case. |
| 8087 | DCHECK_GT(num_entries, 2u); |
| 8088 | Condition first_condition; |
| 8089 | uint32_t index; |
| 8090 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 8091 | if (lower_bound != 0) { |
| 8092 | first_condition = kLess; |
| 8093 | __ cmpl(value_reg, Immediate(lower_bound)); |
| 8094 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 8095 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8096 | |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8097 | index = 1; |
| 8098 | } else { |
| 8099 | // Handle all the compare/jumps below. |
| 8100 | first_condition = kBelow; |
| 8101 | index = 0; |
| 8102 | } |
| 8103 | |
| 8104 | // Handle the rest of the compare/jumps. |
| 8105 | for (; index + 1 < num_entries; index += 2) { |
| 8106 | int32_t compare_to_value = lower_bound + index + 1; |
| 8107 | __ cmpl(value_reg, Immediate(compare_to_value)); |
| 8108 | // Jump to successors[index] if value < case_value[index]. |
| 8109 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 8110 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 8111 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 8112 | } |
| 8113 | |
| 8114 | if (index != num_entries) { |
| 8115 | // There are an odd number of entries. Handle the last one. |
| 8116 | DCHECK_EQ(index + 1, num_entries); |
| 8117 | __ cmpl(value_reg, Immediate(lower_bound + index)); |
| 8118 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8119 | } |
| 8120 | |
| 8121 | // And the default for any other value. |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8122 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
| 8123 | __ jmp(codegen_->GetLabelOf(default_block)); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8124 | } |
| 8125 | } |
| 8126 | |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8127 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 8128 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 8129 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 8130 | LocationSummary* locations = switch_instr->GetLocations(); |
| 8131 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 8132 | |
| 8133 | GenPackedSwitchWithCompares(value_reg, |
| 8134 | lower_bound, |
| 8135 | num_entries, |
| 8136 | switch_instr->GetBlock(), |
| 8137 | switch_instr->GetDefaultBlock()); |
| 8138 | } |
| 8139 | |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8140 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 8141 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8142 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8143 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8144 | |
| 8145 | // Constant area pointer. |
| 8146 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8147 | |
| 8148 | // And the temporary we need. |
| 8149 | locations->AddTemp(Location::RequiresRegister()); |
| 8150 | } |
| 8151 | |
| 8152 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 8153 | int32_t lower_bound = switch_instr->GetStartValue(); |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8154 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8155 | LocationSummary* locations = switch_instr->GetLocations(); |
| 8156 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 8157 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 8158 | |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8159 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 8160 | GenPackedSwitchWithCompares(value_reg, |
| 8161 | lower_bound, |
| 8162 | num_entries, |
| 8163 | switch_instr->GetBlock(), |
| 8164 | default_block); |
| 8165 | return; |
| 8166 | } |
| 8167 | |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8168 | // Optimizing has a jump area. |
| 8169 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 8170 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 8171 | |
| 8172 | // Remove the bias, if needed. |
| 8173 | if (lower_bound != 0) { |
| 8174 | __ leal(temp_reg, Address(value_reg, -lower_bound)); |
| 8175 | value_reg = temp_reg; |
| 8176 | } |
| 8177 | |
| 8178 | // Is the value in range? |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8179 | DCHECK_GE(num_entries, 1u); |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8180 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 8181 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| 8182 | |
| 8183 | // We are in the range of the table. |
| 8184 | // Load (target-constant_area) from the jump table, indexing by the value. |
| 8185 | __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); |
| 8186 | |
| 8187 | // Compute the actual target address by adding in constant_area. |
| 8188 | __ addl(temp_reg, constant_area); |
| 8189 | |
| 8190 | // And jump. |
| 8191 | __ jmp(temp_reg); |
| 8192 | } |
| 8193 | |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8194 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 8195 | HX86ComputeBaseMethodAddress* insn) { |
| 8196 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8197 | new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8198 | locations->SetOut(Location::RequiresRegister()); |
| 8199 | } |
| 8200 | |
| 8201 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 8202 | HX86ComputeBaseMethodAddress* insn) { |
| 8203 | LocationSummary* locations = insn->GetLocations(); |
| 8204 | Register reg = locations->Out().AsRegister<Register>(); |
| 8205 | |
| 8206 | // Generate call to next instruction. |
| 8207 | Label next_instruction; |
| 8208 | __ call(&next_instruction); |
| 8209 | __ Bind(&next_instruction); |
| 8210 | |
| 8211 | // Remember this offset for later use with constant area. |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8212 | codegen_->AddMethodAddressOffset(insn, GetAssembler()->CodeSize()); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8213 | |
| 8214 | // Grab the return address off the stack. |
| 8215 | __ popl(reg); |
| 8216 | } |
| 8217 | |
| 8218 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 8219 | HX86LoadFromConstantTable* insn) { |
| 8220 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8221 | new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8222 | |
| 8223 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8224 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 8225 | |
| 8226 | // 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] | 8227 | if (insn->IsEmittedAtUseSite()) { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8228 | return; |
| 8229 | } |
| 8230 | |
| 8231 | switch (insn->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8232 | case DataType::Type::kFloat32: |
| 8233 | case DataType::Type::kFloat64: |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8234 | locations->SetOut(Location::RequiresFpuRegister()); |
| 8235 | break; |
| 8236 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8237 | case DataType::Type::kInt32: |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8238 | locations->SetOut(Location::RequiresRegister()); |
| 8239 | break; |
| 8240 | |
| 8241 | default: |
| 8242 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 8243 | } |
| 8244 | } |
| 8245 | |
| 8246 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 8247 | if (insn->IsEmittedAtUseSite()) { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8248 | return; |
| 8249 | } |
| 8250 | |
| 8251 | LocationSummary* locations = insn->GetLocations(); |
| 8252 | Location out = locations->Out(); |
| 8253 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 8254 | HConstant *value = insn->GetConstant(); |
| 8255 | |
| 8256 | switch (insn->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8257 | case DataType::Type::kFloat32: |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8258 | __ movss(out.AsFpuRegister<XmmRegister>(), |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8259 | codegen_->LiteralFloatAddress( |
| 8260 | value->AsFloatConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8261 | break; |
| 8262 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8263 | case DataType::Type::kFloat64: |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8264 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8265 | codegen_->LiteralDoubleAddress( |
| 8266 | value->AsDoubleConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8267 | break; |
| 8268 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8269 | case DataType::Type::kInt32: |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8270 | __ movl(out.AsRegister<Register>(), |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8271 | codegen_->LiteralInt32Address( |
| 8272 | value->AsIntConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8273 | break; |
| 8274 | |
| 8275 | default: |
| 8276 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 8277 | } |
| 8278 | } |
| 8279 | |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8280 | /** |
| 8281 | * Class to handle late fixup of offsets into constant area. |
| 8282 | */ |
| Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 8283 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8284 | public: |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8285 | RIPFixup(CodeGeneratorX86& codegen, |
| 8286 | HX86ComputeBaseMethodAddress* base_method_address, |
| 8287 | size_t offset) |
| 8288 | : codegen_(&codegen), |
| 8289 | base_method_address_(base_method_address), |
| 8290 | offset_into_constant_area_(offset) {} |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8291 | |
| 8292 | protected: |
| 8293 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 8294 | |
| 8295 | CodeGeneratorX86* codegen_; |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8296 | HX86ComputeBaseMethodAddress* base_method_address_; |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8297 | |
| 8298 | private: |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8299 | void Process(const MemoryRegion& region, int pos) override { |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8300 | // Patch the correct offset for the instruction. The place to patch is the |
| 8301 | // last 4 bytes of the instruction. |
| 8302 | // The value to patch is the distance from the offset in the constant area |
| 8303 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8304 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8305 | int32_t relative_position = |
| 8306 | constant_offset - codegen_->GetMethodAddressOffset(base_method_address_); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8307 | |
| 8308 | // Patch in the right value. |
| 8309 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 8310 | } |
| 8311 | |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8312 | // Location in constant area that the fixup refers to. |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8313 | int32_t offset_into_constant_area_; |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8314 | }; |
| 8315 | |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8316 | /** |
| 8317 | * Class to handle late fixup of offsets to a jump table that will be created in the |
| 8318 | * constant area. |
| 8319 | */ |
| 8320 | class JumpTableRIPFixup : public RIPFixup { |
| 8321 | public: |
| 8322 | JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8323 | : RIPFixup(codegen, switch_instr->GetBaseMethodAddress(), static_cast<size_t>(-1)), |
| 8324 | switch_instr_(switch_instr) {} |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8325 | |
| 8326 | void CreateJumpTable() { |
| 8327 | X86Assembler* assembler = codegen_->GetAssembler(); |
| 8328 | |
| 8329 | // Ensure that the reference to the jump table has the correct offset. |
| 8330 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 8331 | SetOffset(offset_in_constant_table); |
| 8332 | |
| 8333 | // The label values in the jump table are computed relative to the |
| 8334 | // instruction addressing the constant area. |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8335 | const int32_t relative_offset = codegen_->GetMethodAddressOffset(base_method_address_); |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8336 | |
| 8337 | // Populate the jump table with the correct values for the jump table. |
| 8338 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 8339 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 8340 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 8341 | // The value that we want is the target offset - the position of the table. |
| 8342 | for (int32_t i = 0; i < num_entries; i++) { |
| 8343 | HBasicBlock* b = successors[i]; |
| 8344 | Label* l = codegen_->GetLabelOf(b); |
| 8345 | DCHECK(l->IsBound()); |
| 8346 | int32_t offset_to_block = l->Position() - relative_offset; |
| 8347 | assembler->AppendInt32(offset_to_block); |
| 8348 | } |
| 8349 | } |
| 8350 | |
| 8351 | private: |
| 8352 | const HX86PackedSwitch* switch_instr_; |
| 8353 | }; |
| 8354 | |
| 8355 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 8356 | // Generate the constant area if needed. |
| 8357 | X86Assembler* assembler = GetAssembler(); |
| jaishank | 20d1c94 | 2019-03-08 15:08:17 +0530 | [diff] [blame] | 8358 | |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8359 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 8360 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 8361 | // byte values. |
| 8362 | assembler->Align(4, 0); |
| 8363 | constant_area_start_ = assembler->CodeSize(); |
| 8364 | |
| 8365 | // Populate any jump tables. |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 8366 | for (JumpTableRIPFixup* jump_table : fixups_to_jump_tables_) { |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8367 | jump_table->CreateJumpTable(); |
| 8368 | } |
| 8369 | |
| 8370 | // And now add the constant area to the generated code. |
| 8371 | assembler->AddConstantArea(); |
| 8372 | } |
| 8373 | |
| 8374 | // And finish up. |
| 8375 | CodeGenerator::Finalize(allocator); |
| 8376 | } |
| 8377 | |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8378 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, |
| 8379 | HX86ComputeBaseMethodAddress* method_base, |
| 8380 | Register reg) { |
| 8381 | AssemblerFixup* fixup = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8382 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddDouble(v)); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8383 | return Address(reg, kDummy32BitOffset, fixup); |
| 8384 | } |
| 8385 | |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8386 | Address CodeGeneratorX86::LiteralFloatAddress(float v, |
| 8387 | HX86ComputeBaseMethodAddress* method_base, |
| 8388 | Register reg) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8389 | AssemblerFixup* fixup = |
| 8390 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddFloat(v)); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8391 | return Address(reg, kDummy32BitOffset, fixup); |
| 8392 | } |
| 8393 | |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8394 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, |
| 8395 | HX86ComputeBaseMethodAddress* method_base, |
| 8396 | Register reg) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8397 | AssemblerFixup* fixup = |
| 8398 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddInt32(v)); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8399 | return Address(reg, kDummy32BitOffset, fixup); |
| 8400 | } |
| 8401 | |
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8402 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, |
| 8403 | HX86ComputeBaseMethodAddress* method_base, |
| 8404 | Register reg) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8405 | AssemblerFixup* fixup = |
| 8406 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddInt64(v)); |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8407 | return Address(reg, kDummy32BitOffset, fixup); |
| 8408 | } |
| 8409 | |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 8410 | void CodeGeneratorX86::Load32BitValue(Register dest, int32_t value) { |
| 8411 | if (value == 0) { |
| 8412 | __ xorl(dest, dest); |
| 8413 | } else { |
| 8414 | __ movl(dest, Immediate(value)); |
| 8415 | } |
| 8416 | } |
| 8417 | |
| 8418 | void CodeGeneratorX86::Compare32BitValue(Register dest, int32_t value) { |
| 8419 | if (value == 0) { |
| 8420 | __ testl(dest, dest); |
| 8421 | } else { |
| 8422 | __ cmpl(dest, Immediate(value)); |
| 8423 | } |
| 8424 | } |
| 8425 | |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8426 | void CodeGeneratorX86::GenerateIntCompare(Location lhs, Location rhs) { |
| 8427 | Register lhs_reg = lhs.AsRegister<Register>(); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8428 | GenerateIntCompare(lhs_reg, rhs); |
| 8429 | } |
| 8430 | |
| 8431 | void CodeGeneratorX86::GenerateIntCompare(Register lhs, Location rhs) { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8432 | if (rhs.IsConstant()) { |
| 8433 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8434 | Compare32BitValue(lhs, value); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8435 | } else if (rhs.IsStackSlot()) { |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8436 | __ cmpl(lhs, Address(ESP, rhs.GetStackIndex())); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8437 | } else { |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8438 | __ cmpl(lhs, rhs.AsRegister<Register>()); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8439 | } |
| 8440 | } |
| 8441 | |
| 8442 | Address CodeGeneratorX86::ArrayAddress(Register obj, |
| 8443 | Location index, |
| 8444 | ScaleFactor scale, |
| 8445 | uint32_t data_offset) { |
| 8446 | return index.IsConstant() ? |
| 8447 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) : |
| 8448 | Address(obj, index.AsRegister<Register>(), scale, data_offset); |
| 8449 | } |
| 8450 | |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8451 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, |
| 8452 | Register reg, |
| 8453 | Register value) { |
| 8454 | // Create a fixup to be used to create and address the jump table. |
| 8455 | JumpTableRIPFixup* table_fixup = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8456 | new (GetGraph()->GetAllocator()) JumpTableRIPFixup(*this, switch_instr); |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8457 | |
| 8458 | // We have to populate the jump tables. |
| 8459 | fixups_to_jump_tables_.push_back(table_fixup); |
| 8460 | |
| 8461 | // We want a scaled address, as we are extracting the correct offset from the table. |
| 8462 | return Address(reg, value, TIMES_4, kDummy32BitOffset, table_fixup); |
| 8463 | } |
| 8464 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8465 | // TODO: target as memory. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8466 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, DataType::Type type) { |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8467 | if (!target.IsValid()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8468 | DCHECK_EQ(type, DataType::Type::kVoid); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8469 | return; |
| 8470 | } |
| 8471 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8472 | DCHECK_NE(type, DataType::Type::kVoid); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8473 | |
| 8474 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 8475 | if (target.Equals(return_loc)) { |
| 8476 | return; |
| 8477 | } |
| 8478 | |
| 8479 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 8480 | // with the else branch. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8481 | if (type == DataType::Type::kInt64) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8482 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8483 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), DataType::Type::kInt32, nullptr); |
| 8484 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), DataType::Type::kInt32, nullptr); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8485 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 8486 | } else { |
| 8487 | // Let the parallel move resolver take care of all of this. |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8488 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8489 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 8490 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 8491 | } |
| 8492 | } |
| 8493 | |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8494 | void CodeGeneratorX86::PatchJitRootUse(uint8_t* code, |
| 8495 | const uint8_t* roots_data, |
| 8496 | const PatchInfo<Label>& info, |
| 8497 | uint64_t index_in_table) const { |
| 8498 | uint32_t code_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 8499 | uintptr_t address = |
| 8500 | 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] | 8501 | using unaligned_uint32_t __attribute__((__aligned__(1))) = uint32_t; |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8502 | reinterpret_cast<unaligned_uint32_t*>(code + code_offset)[0] = |
| 8503 | dchecked_integral_cast<uint32_t>(address); |
| 8504 | } |
| 8505 | |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 8506 | void CodeGeneratorX86::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 8507 | for (const PatchInfo<Label>& info : jit_string_patches_) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8508 | 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] | 8509 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 8510 | PatchJitRootUse(code, roots_data, info, index_in_table); |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8511 | } |
| 8512 | |
| 8513 | for (const PatchInfo<Label>& info : jit_class_patches_) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8514 | 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] | 8515 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 8516 | PatchJitRootUse(code, roots_data, info, index_in_table); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 8517 | } |
| 8518 | } |
| 8519 | |
| xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 8520 | void LocationsBuilderX86::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 8521 | ATTRIBUTE_UNUSED) { |
| 8522 | LOG(FATAL) << "Unreachable"; |
| 8523 | } |
| 8524 | |
| 8525 | void InstructionCodeGeneratorX86::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 8526 | ATTRIBUTE_UNUSED) { |
| 8527 | LOG(FATAL) << "Unreachable"; |
| 8528 | } |
| 8529 | |
| Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 8530 | bool LocationsBuilderX86::CpuHasAvxFeatureFlag() { |
| 8531 | return codegen_->GetInstructionSetFeatures().HasAVX(); |
| 8532 | } |
| 8533 | bool LocationsBuilderX86::CpuHasAvx2FeatureFlag() { |
| 8534 | return codegen_->GetInstructionSetFeatures().HasAVX2(); |
| 8535 | } |
| 8536 | bool InstructionCodeGeneratorX86::CpuHasAvxFeatureFlag() { |
| 8537 | return codegen_->GetInstructionSetFeatures().HasAVX(); |
| 8538 | } |
| 8539 | bool InstructionCodeGeneratorX86::CpuHasAvx2FeatureFlag() { |
| 8540 | return codegen_->GetInstructionSetFeatures().HasAVX2(); |
| 8541 | } |
| 8542 | |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 8543 | #undef __ |
| 8544 | |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 8545 | } // namespace x86 |
| 8546 | } // namespace art |