Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "code_generator_x86.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 18 | |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 19 | #include "arch/x86/jni_frame_x86.h" |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 20 | #include "art_method-inl.h" |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 21 | #include "class_table.h" |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 22 | #include "code_generator_utils.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 23 | #include "compiled_method.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 24 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 25 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 26 | #include "gc/accounting/card_table.h" |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 27 | #include "gc/space/image_space.h" |
Andreas Gampe | 09659c2 | 2017-09-18 18:23:32 -0700 | [diff] [blame] | 28 | #include "heap_poisoning.h" |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 29 | #include "intrinsics.h" |
| 30 | #include "intrinsics_x86.h" |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 31 | #include "jit/profiling_info.h" |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 32 | #include "linker/linker_patch.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 33 | #include "lock_word.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 34 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 35 | #include "mirror/class-inl.h" |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 36 | #include "scoped_thread_state_change-inl.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 37 | #include "thread.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 38 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 39 | #include "utils/stack_checks.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 40 | #include "utils/x86/assembler_x86.h" |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 41 | #include "utils/x86/managed_register_x86.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 42 | |
Vladimir Marko | 0a51605 | 2019-10-14 13:00:44 +0000 | [diff] [blame] | 43 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 44 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 45 | template<class MirrorType> |
| 46 | class GcRoot; |
| 47 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 48 | namespace x86 { |
| 49 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 50 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 51 | static constexpr Register kMethodRegisterArgument = EAX; |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 52 | static constexpr Register kCoreCalleeSaves[] = { EBP, ESI, EDI }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 53 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 54 | static constexpr int kC2ConditionMask = 0x400; |
| 55 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 56 | static constexpr int kFakeReturnRegister = Register(8); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 57 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 58 | static constexpr int64_t kDoubleNaN = INT64_C(0x7FF8000000000000); |
| 59 | static constexpr int32_t kFloatNaN = INT32_C(0x7FC00000); |
| 60 | |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 61 | static RegisterSet OneRegInReferenceOutSaveEverythingCallerSaves() { |
| 62 | InvokeRuntimeCallingConvention calling_convention; |
| 63 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 64 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 65 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 66 | // that the the kPrimNot result register is the same as the first argument register. |
| 67 | return caller_saves; |
| 68 | } |
| 69 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 70 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 71 | #define __ down_cast<X86Assembler*>(codegen->GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 72 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86PointerSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 73 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 74 | class NullCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 75 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 76 | explicit NullCheckSlowPathX86(HNullCheck* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 77 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 78 | void EmitNativeCode(CodeGenerator* codegen) override { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 79 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 80 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 81 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 82 | // Live registers will be restored in the catch block if caught. |
| 83 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 84 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 85 | x86_codegen->InvokeRuntime(kQuickThrowNullPointer, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 86 | instruction_, |
| 87 | instruction_->GetDexPc(), |
| 88 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 89 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 90 | } |
| 91 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 92 | bool IsFatal() const override { return true; } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 93 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 94 | const char* GetDescription() const override { return "NullCheckSlowPathX86"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 95 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 96 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 97 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86); |
| 98 | }; |
| 99 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 100 | class DivZeroCheckSlowPathX86 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 101 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 102 | explicit DivZeroCheckSlowPathX86(HDivZeroCheck* instruction) : SlowPathCode(instruction) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 103 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 104 | void EmitNativeCode(CodeGenerator* codegen) override { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 105 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 106 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 107 | x86_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 108 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 109 | } |
| 110 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 111 | bool IsFatal() const override { return true; } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 112 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 113 | const char* GetDescription() const override { return "DivZeroCheckSlowPathX86"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 114 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 115 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 116 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86); |
| 117 | }; |
| 118 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 119 | class DivRemMinusOneSlowPathX86 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 120 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 121 | DivRemMinusOneSlowPathX86(HInstruction* instruction, Register reg, bool is_div) |
| 122 | : SlowPathCode(instruction), reg_(reg), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 123 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 124 | void EmitNativeCode(CodeGenerator* codegen) override { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 125 | __ Bind(GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 126 | if (is_div_) { |
| 127 | __ negl(reg_); |
| 128 | } else { |
| 129 | __ movl(reg_, Immediate(0)); |
| 130 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 131 | __ jmp(GetExitLabel()); |
| 132 | } |
| 133 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 134 | const char* GetDescription() const override { return "DivRemMinusOneSlowPathX86"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 135 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 136 | private: |
| 137 | Register reg_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 138 | bool is_div_; |
| 139 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 140 | }; |
| 141 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 142 | class BoundsCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 143 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 144 | explicit BoundsCheckSlowPathX86(HBoundsCheck* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 145 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 146 | void EmitNativeCode(CodeGenerator* codegen) override { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 147 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 148 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 149 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 150 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 151 | // move resolver. |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 152 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 153 | // Live registers will be restored in the catch block if caught. |
| 154 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 155 | } |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 156 | |
| 157 | // Are we using an array length from memory? |
| 158 | HInstruction* array_length = instruction_->InputAt(1); |
| 159 | Location length_loc = locations->InAt(1); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 160 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 161 | if (array_length->IsArrayLength() && array_length->IsEmittedAtUseSite()) { |
| 162 | // Load the array length into our temporary. |
Nicolas Geoffray | 0aff3a8 | 2017-10-13 13:12:36 +0100 | [diff] [blame] | 163 | HArrayLength* length = array_length->AsArrayLength(); |
| 164 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(length); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 165 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 166 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
| 167 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(1)); |
| 168 | // Check for conflicts with index. |
| 169 | if (length_loc.Equals(locations->InAt(0))) { |
| 170 | // We know we aren't using parameter 2. |
| 171 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(2)); |
| 172 | } |
| 173 | __ movl(length_loc.AsRegister<Register>(), array_len); |
Nicolas Geoffray | 0aff3a8 | 2017-10-13 13:12:36 +0100 | [diff] [blame] | 174 | if (mirror::kUseStringCompression && length->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 175 | __ shrl(length_loc.AsRegister<Register>(), Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 176 | } |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 177 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 178 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 179 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 180 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 181 | DataType::Type::kInt32, |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 182 | length_loc, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 183 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 184 | DataType::Type::kInt32); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 185 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 186 | ? kQuickThrowStringBounds |
| 187 | : kQuickThrowArrayBounds; |
| 188 | x86_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 189 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 190 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 191 | } |
| 192 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 193 | bool IsFatal() const override { return true; } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 194 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 195 | const char* GetDescription() const override { return "BoundsCheckSlowPathX86"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 196 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 197 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 198 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86); |
| 199 | }; |
| 200 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 201 | class SuspendCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 202 | public: |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 203 | SuspendCheckSlowPathX86(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 204 | : SlowPathCode(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 205 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 206 | void EmitNativeCode(CodeGenerator* codegen) override { |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 207 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 208 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 209 | __ Bind(GetEntryLabel()); |
Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 210 | SaveLiveRegisters(codegen, locations); // Only saves full width XMM for SIMD. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 211 | x86_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 212 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 213 | RestoreLiveRegisters(codegen, locations); // Only restores full width XMM for SIMD. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 214 | if (successor_ == nullptr) { |
| 215 | __ jmp(GetReturnLabel()); |
| 216 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 217 | __ jmp(x86_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 218 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 219 | } |
| 220 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 221 | Label* GetReturnLabel() { |
| 222 | DCHECK(successor_ == nullptr); |
| 223 | return &return_label_; |
| 224 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 225 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 226 | HBasicBlock* GetSuccessor() const { |
| 227 | return successor_; |
| 228 | } |
| 229 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 230 | const char* GetDescription() const override { return "SuspendCheckSlowPathX86"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 231 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 232 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 233 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 234 | Label return_label_; |
| 235 | |
| 236 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86); |
| 237 | }; |
| 238 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 239 | class LoadStringSlowPathX86 : public SlowPathCode { |
| 240 | public: |
| 241 | explicit LoadStringSlowPathX86(HLoadString* instruction): SlowPathCode(instruction) {} |
| 242 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 243 | void EmitNativeCode(CodeGenerator* codegen) override { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 244 | LocationSummary* locations = instruction_->GetLocations(); |
| 245 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 246 | |
| 247 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 248 | __ Bind(GetEntryLabel()); |
| 249 | SaveLiveRegisters(codegen, locations); |
| 250 | |
| 251 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 252 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 253 | __ movl(calling_convention.GetRegisterAt(0), Immediate(string_index.index_)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 254 | x86_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 255 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 256 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 257 | RestoreLiveRegisters(codegen, locations); |
| 258 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 259 | __ jmp(GetExitLabel()); |
| 260 | } |
| 261 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 262 | const char* GetDescription() const override { return "LoadStringSlowPathX86"; } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 263 | |
| 264 | private: |
| 265 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86); |
| 266 | }; |
| 267 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 268 | class LoadClassSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 269 | public: |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 270 | LoadClassSlowPathX86(HLoadClass* cls, HInstruction* at) |
| 271 | : SlowPathCode(at), cls_(cls) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 272 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 273 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 274 | } |
| 275 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 276 | void EmitNativeCode(CodeGenerator* codegen) override { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 277 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 278 | Location out = locations->Out(); |
| 279 | const uint32_t dex_pc = instruction_->GetDexPc(); |
| 280 | bool must_resolve_type = instruction_->IsLoadClass() && cls_->MustResolveTypeOnSlowPath(); |
| 281 | bool must_do_clinit = instruction_->IsClinitCheck() || cls_->MustGenerateClinitCheck(); |
| 282 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 283 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 284 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 285 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 286 | |
| 287 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 288 | if (must_resolve_type) { |
| 289 | DCHECK(IsSameDexFile(cls_->GetDexFile(), x86_codegen->GetGraph()->GetDexFile())); |
| 290 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 291 | __ movl(calling_convention.GetRegisterAt(0), Immediate(type_index.index_)); |
Vladimir Marko | 9d47925 | 2018-07-24 11:35:20 +0100 | [diff] [blame] | 292 | x86_codegen->InvokeRuntime(kQuickResolveType, instruction_, dex_pc, this); |
| 293 | CheckEntrypointTypes<kQuickResolveType, void*, uint32_t>(); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 294 | // If we also must_do_clinit, the resolved type is now in the correct register. |
| 295 | } else { |
| 296 | DCHECK(must_do_clinit); |
| 297 | Location source = instruction_->IsLoadClass() ? out : locations->InAt(0); |
| 298 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), source); |
| 299 | } |
| 300 | if (must_do_clinit) { |
| 301 | x86_codegen->InvokeRuntime(kQuickInitializeStaticStorage, instruction_, dex_pc, this); |
| 302 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, mirror::Class*>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 303 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 304 | |
| 305 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 306 | if (out.IsValid()) { |
| 307 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 308 | x86_codegen->Move32(out, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 309 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 310 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 311 | __ jmp(GetExitLabel()); |
| 312 | } |
| 313 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 314 | const char* GetDescription() const override { return "LoadClassSlowPathX86"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 315 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 316 | private: |
| 317 | // The class this slow path will load. |
| 318 | HLoadClass* const cls_; |
| 319 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 320 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86); |
| 321 | }; |
| 322 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 323 | class TypeCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 324 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 325 | TypeCheckSlowPathX86(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 326 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 327 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 328 | void EmitNativeCode(CodeGenerator* codegen) override { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 329 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 330 | DCHECK(instruction_->IsCheckCast() |
| 331 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 332 | |
| 333 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 334 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 335 | |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 336 | if (kPoisonHeapReferences && |
| 337 | instruction_->IsCheckCast() && |
| 338 | instruction_->AsCheckCast()->GetTypeCheckKind() == TypeCheckKind::kInterfaceCheck) { |
| 339 | // First, unpoison the `cls` reference that was poisoned for direct memory comparison. |
| 340 | __ UnpoisonHeapReference(locations->InAt(1).AsRegister<Register>()); |
| 341 | } |
| 342 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 343 | if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 344 | SaveLiveRegisters(codegen, locations); |
| 345 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 346 | |
| 347 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 348 | // move resolver. |
| 349 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 350 | x86_codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 351 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 352 | DataType::Type::kReference, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 353 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 354 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 355 | DataType::Type::kReference); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 356 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 357 | x86_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 358 | instruction_, |
| 359 | instruction_->GetDexPc(), |
| 360 | this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 361 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 362 | } else { |
| 363 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 364 | x86_codegen->InvokeRuntime(kQuickCheckInstanceOf, |
| 365 | instruction_, |
| 366 | instruction_->GetDexPc(), |
| 367 | this); |
| 368 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 369 | } |
| 370 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 371 | if (!is_fatal_) { |
| 372 | if (instruction_->IsInstanceOf()) { |
| 373 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 374 | } |
| 375 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 376 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 377 | __ jmp(GetExitLabel()); |
| 378 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 379 | } |
| 380 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 381 | const char* GetDescription() const override { return "TypeCheckSlowPathX86"; } |
| 382 | bool IsFatal() const override { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 383 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 384 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 385 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 386 | |
| 387 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86); |
| 388 | }; |
| 389 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 390 | class DeoptimizationSlowPathX86 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 391 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 392 | explicit DeoptimizationSlowPathX86(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 393 | : SlowPathCode(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 394 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 395 | void EmitNativeCode(CodeGenerator* codegen) override { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 396 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 397 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 398 | LocationSummary* locations = instruction_->GetLocations(); |
| 399 | SaveLiveRegisters(codegen, locations); |
| 400 | InvokeRuntimeCallingConvention calling_convention; |
| 401 | x86_codegen->Load32BitValue( |
| 402 | calling_convention.GetRegisterAt(0), |
| 403 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 404 | x86_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 405 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 406 | } |
| 407 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 408 | const char* GetDescription() const override { return "DeoptimizationSlowPathX86"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 409 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 410 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 411 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86); |
| 412 | }; |
| 413 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 414 | class ArraySetSlowPathX86 : public SlowPathCode { |
| 415 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 416 | explicit ArraySetSlowPathX86(HInstruction* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 417 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 418 | void EmitNativeCode(CodeGenerator* codegen) override { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 419 | LocationSummary* locations = instruction_->GetLocations(); |
| 420 | __ Bind(GetEntryLabel()); |
| 421 | SaveLiveRegisters(codegen, locations); |
| 422 | |
| 423 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 424 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 425 | parallel_move.AddMove( |
| 426 | locations->InAt(0), |
| 427 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 428 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 429 | nullptr); |
| 430 | parallel_move.AddMove( |
| 431 | locations->InAt(1), |
| 432 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 433 | DataType::Type::kInt32, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 434 | nullptr); |
| 435 | parallel_move.AddMove( |
| 436 | locations->InAt(2), |
| 437 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 438 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 439 | nullptr); |
| 440 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 441 | |
| 442 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 443 | x86_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 444 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 445 | RestoreLiveRegisters(codegen, locations); |
| 446 | __ jmp(GetExitLabel()); |
| 447 | } |
| 448 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 449 | const char* GetDescription() const override { return "ArraySetSlowPathX86"; } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 450 | |
| 451 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 452 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86); |
| 453 | }; |
| 454 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 455 | // Slow path marking an object reference `ref` during a read |
| 456 | // barrier. The field `obj.field` in the object `obj` holding this |
| 457 | // reference does not get updated by this slow path after marking (see |
| 458 | // ReadBarrierMarkAndUpdateFieldSlowPathX86 below for that). |
| 459 | // |
| 460 | // This means that after the execution of this slow path, `ref` will |
| 461 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 462 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 463 | // probably still be a from-space reference (unless it gets updated by |
| 464 | // another thread, or if another thread installed another object |
| 465 | // reference (different from `ref`) in `obj.field`). |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 466 | class ReadBarrierMarkSlowPathX86 : public SlowPathCode { |
| 467 | public: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 468 | ReadBarrierMarkSlowPathX86(HInstruction* instruction, |
| 469 | Location ref, |
| 470 | bool unpoison_ref_before_marking) |
| 471 | : SlowPathCode(instruction), |
| 472 | ref_(ref), |
| 473 | unpoison_ref_before_marking_(unpoison_ref_before_marking) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 474 | DCHECK(kEmitCompilerReadBarrier); |
| 475 | } |
| 476 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 477 | const char* GetDescription() const override { return "ReadBarrierMarkSlowPathX86"; } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 478 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 479 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 480 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 481 | Register ref_reg = ref_.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 482 | DCHECK(locations->CanCall()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 483 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 484 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 485 | instruction_->IsStaticFieldGet() || |
| 486 | instruction_->IsArrayGet() || |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 487 | instruction_->IsArraySet() || |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 488 | instruction_->IsLoadClass() || |
| 489 | instruction_->IsLoadString() || |
| 490 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 491 | instruction_->IsCheckCast() || |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 492 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 493 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 494 | << "Unexpected instruction in read barrier marking slow path: " |
| 495 | << instruction_->DebugName(); |
| 496 | |
| 497 | __ Bind(GetEntryLabel()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 498 | if (unpoison_ref_before_marking_) { |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 499 | // Object* ref = ref_addr->AsMirrorPtr() |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 500 | __ MaybeUnpoisonHeapReference(ref_reg); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 501 | } |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 502 | // No need to save live registers; it's taken care of by the |
| 503 | // entrypoint. Also, there is no need to update the stack mask, |
| 504 | // as this runtime call will not trigger a garbage collection. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 505 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 506 | DCHECK_NE(ref_reg, ESP); |
| 507 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 508 | // "Compact" slow path, saving two moves. |
| 509 | // |
| 510 | // Instead of using the standard runtime calling convention (input |
| 511 | // and output in EAX): |
| 512 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 513 | // EAX <- ref |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 514 | // EAX <- ReadBarrierMark(EAX) |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 515 | // ref <- EAX |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 516 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 517 | // we just use rX (the register containing `ref`) as input and output |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 518 | // of a dedicated entrypoint: |
| 519 | // |
| 520 | // rX <- ReadBarrierMarkRegX(rX) |
| 521 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 522 | int32_t entry_point_offset = Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(ref_reg); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 523 | // This runtime call does not require a stack map. |
| 524 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 525 | __ jmp(GetExitLabel()); |
| 526 | } |
| 527 | |
| 528 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 529 | // The location (register) of the marked object reference. |
| 530 | const Location ref_; |
| 531 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 532 | const bool unpoison_ref_before_marking_; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 533 | |
| 534 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86); |
| 535 | }; |
| 536 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 537 | // Slow path marking an object reference `ref` during a read barrier, |
| 538 | // and if needed, atomically updating the field `obj.field` in the |
| 539 | // object `obj` holding this reference after marking (contrary to |
| 540 | // ReadBarrierMarkSlowPathX86 above, which never tries to update |
| 541 | // `obj.field`). |
| 542 | // |
| 543 | // This means that after the execution of this slow path, both `ref` |
| 544 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 545 | // hold the same to-space reference (unless another thread installed |
| 546 | // another object reference (different from `ref`) in `obj.field`). |
| 547 | class ReadBarrierMarkAndUpdateFieldSlowPathX86 : public SlowPathCode { |
| 548 | public: |
| 549 | ReadBarrierMarkAndUpdateFieldSlowPathX86(HInstruction* instruction, |
| 550 | Location ref, |
| 551 | Register obj, |
| 552 | const Address& field_addr, |
| 553 | bool unpoison_ref_before_marking, |
| 554 | Register temp) |
| 555 | : SlowPathCode(instruction), |
| 556 | ref_(ref), |
| 557 | obj_(obj), |
| 558 | field_addr_(field_addr), |
| 559 | unpoison_ref_before_marking_(unpoison_ref_before_marking), |
| 560 | temp_(temp) { |
| 561 | DCHECK(kEmitCompilerReadBarrier); |
| 562 | } |
| 563 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 564 | const char* GetDescription() const override { return "ReadBarrierMarkAndUpdateFieldSlowPathX86"; } |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 565 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 566 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 567 | LocationSummary* locations = instruction_->GetLocations(); |
| 568 | Register ref_reg = ref_.AsRegister<Register>(); |
| 569 | DCHECK(locations->CanCall()); |
| 570 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 571 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 572 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 573 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 574 | << instruction_->DebugName(); |
| 575 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 576 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 577 | |
| 578 | __ Bind(GetEntryLabel()); |
| 579 | if (unpoison_ref_before_marking_) { |
| 580 | // Object* ref = ref_addr->AsMirrorPtr() |
| 581 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 582 | } |
| 583 | |
| 584 | // Save the old (unpoisoned) reference. |
| 585 | __ movl(temp_, ref_reg); |
| 586 | |
| 587 | // No need to save live registers; it's taken care of by the |
| 588 | // entrypoint. Also, there is no need to update the stack mask, |
| 589 | // as this runtime call will not trigger a garbage collection. |
| 590 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 591 | DCHECK_NE(ref_reg, ESP); |
| 592 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
| 593 | // "Compact" slow path, saving two moves. |
| 594 | // |
| 595 | // Instead of using the standard runtime calling convention (input |
| 596 | // and output in EAX): |
| 597 | // |
| 598 | // EAX <- ref |
| 599 | // EAX <- ReadBarrierMark(EAX) |
| 600 | // ref <- EAX |
| 601 | // |
| 602 | // we just use rX (the register containing `ref`) as input and output |
| 603 | // of a dedicated entrypoint: |
| 604 | // |
| 605 | // rX <- ReadBarrierMarkRegX(rX) |
| 606 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 607 | int32_t entry_point_offset = Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(ref_reg); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 608 | // This runtime call does not require a stack map. |
| 609 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 610 | |
| 611 | // If the new reference is different from the old reference, |
| 612 | // update the field in the holder (`*field_addr`). |
| 613 | // |
| 614 | // Note that this field could also hold a different object, if |
| 615 | // another thread had concurrently changed it. In that case, the |
| 616 | // LOCK CMPXCHGL instruction in the compare-and-set (CAS) |
| 617 | // operation below would abort the CAS, leaving the field as-is. |
| 618 | NearLabel done; |
| 619 | __ cmpl(temp_, ref_reg); |
| 620 | __ j(kEqual, &done); |
| 621 | |
| 622 | // Update the the holder's field atomically. This may fail if |
| 623 | // mutator updates before us, but it's OK. This is achieved |
| 624 | // using a strong compare-and-set (CAS) operation with relaxed |
| 625 | // memory synchronization ordering, where the expected value is |
| 626 | // the old reference and the desired value is the new reference. |
| 627 | // This operation is implemented with a 32-bit LOCK CMPXLCHG |
| 628 | // instruction, which requires the expected value (the old |
| 629 | // reference) to be in EAX. Save EAX beforehand, and move the |
| 630 | // expected value (stored in `temp_`) into EAX. |
| 631 | __ pushl(EAX); |
| 632 | __ movl(EAX, temp_); |
| 633 | |
| 634 | // Convenience aliases. |
| 635 | Register base = obj_; |
| 636 | Register expected = EAX; |
| 637 | Register value = ref_reg; |
| 638 | |
| 639 | bool base_equals_value = (base == value); |
| 640 | if (kPoisonHeapReferences) { |
| 641 | if (base_equals_value) { |
| 642 | // If `base` and `value` are the same register location, move |
| 643 | // `value` to a temporary register. This way, poisoning |
| 644 | // `value` won't invalidate `base`. |
| 645 | value = temp_; |
| 646 | __ movl(value, base); |
| 647 | } |
| 648 | |
| 649 | // Check that the register allocator did not assign the location |
| 650 | // of `expected` (EAX) to `value` nor to `base`, so that heap |
| 651 | // poisoning (when enabled) works as intended below. |
| 652 | // - If `value` were equal to `expected`, both references would |
| 653 | // be poisoned twice, meaning they would not be poisoned at |
| 654 | // all, as heap poisoning uses address negation. |
| 655 | // - If `base` were equal to `expected`, poisoning `expected` |
| 656 | // would invalidate `base`. |
| 657 | DCHECK_NE(value, expected); |
| 658 | DCHECK_NE(base, expected); |
| 659 | |
| 660 | __ PoisonHeapReference(expected); |
| 661 | __ PoisonHeapReference(value); |
| 662 | } |
| 663 | |
| 664 | __ LockCmpxchgl(field_addr_, value); |
| 665 | |
| 666 | // If heap poisoning is enabled, we need to unpoison the values |
| 667 | // that were poisoned earlier. |
| 668 | if (kPoisonHeapReferences) { |
| 669 | if (base_equals_value) { |
| 670 | // `value` has been moved to a temporary register, no need |
| 671 | // to unpoison it. |
| 672 | } else { |
| 673 | __ UnpoisonHeapReference(value); |
| 674 | } |
| 675 | // No need to unpoison `expected` (EAX), as it is be overwritten below. |
| 676 | } |
| 677 | |
| 678 | // Restore EAX. |
| 679 | __ popl(EAX); |
| 680 | |
| 681 | __ Bind(&done); |
| 682 | __ jmp(GetExitLabel()); |
| 683 | } |
| 684 | |
| 685 | private: |
| 686 | // The location (register) of the marked object reference. |
| 687 | const Location ref_; |
| 688 | // The register containing the object holding the marked object reference field. |
| 689 | const Register obj_; |
| 690 | // The address of the marked reference field. The base of this address must be `obj_`. |
| 691 | const Address field_addr_; |
| 692 | |
| 693 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 694 | const bool unpoison_ref_before_marking_; |
| 695 | |
| 696 | const Register temp_; |
| 697 | |
| 698 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathX86); |
| 699 | }; |
| 700 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 701 | // Slow path generating a read barrier for a heap reference. |
| 702 | class ReadBarrierForHeapReferenceSlowPathX86 : public SlowPathCode { |
| 703 | public: |
| 704 | ReadBarrierForHeapReferenceSlowPathX86(HInstruction* instruction, |
| 705 | Location out, |
| 706 | Location ref, |
| 707 | Location obj, |
| 708 | uint32_t offset, |
| 709 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 710 | : SlowPathCode(instruction), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 711 | out_(out), |
| 712 | ref_(ref), |
| 713 | obj_(obj), |
| 714 | offset_(offset), |
| 715 | index_(index) { |
| 716 | DCHECK(kEmitCompilerReadBarrier); |
| 717 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 718 | // has been overwritten by (or after) the heap object reference load |
| 719 | // to be instrumented, e.g.: |
| 720 | // |
| 721 | // __ movl(out, Address(out, offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 722 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 723 | // |
| 724 | // In that case, we have lost the information about the original |
| 725 | // object, and the emitted read barrier cannot work properly. |
| 726 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 727 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 728 | } |
| 729 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 730 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 731 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 732 | LocationSummary* locations = instruction_->GetLocations(); |
| 733 | Register reg_out = out_.AsRegister<Register>(); |
| 734 | DCHECK(locations->CanCall()); |
| 735 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 736 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 737 | instruction_->IsStaticFieldGet() || |
| 738 | instruction_->IsArrayGet() || |
| 739 | instruction_->IsInstanceOf() || |
| 740 | instruction_->IsCheckCast() || |
Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 741 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 742 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 743 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 744 | |
| 745 | __ Bind(GetEntryLabel()); |
| 746 | SaveLiveRegisters(codegen, locations); |
| 747 | |
| 748 | // We may have to change the index's value, but as `index_` is a |
| 749 | // constant member (like other "inputs" of this slow path), |
| 750 | // introduce a copy of it, `index`. |
| 751 | Location index = index_; |
| 752 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 753 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 754 | if (instruction_->IsArrayGet()) { |
| 755 | // Compute the actual memory offset and store it in `index`. |
| 756 | Register index_reg = index_.AsRegister<Register>(); |
| 757 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 758 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 759 | // We are about to change the value of `index_reg` (see the |
| 760 | // calls to art::x86::X86Assembler::shll and |
| 761 | // art::x86::X86Assembler::AddImmediate below), but it has |
| 762 | // not been saved by the previous call to |
| 763 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 764 | // callee-save register -- |
| 765 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 766 | // callee-save registers, as it has been designed with the |
| 767 | // assumption that callee-save registers are supposed to be |
| 768 | // handled by the called function. So, as a callee-save |
| 769 | // register, `index_reg` _would_ eventually be saved onto |
| 770 | // the stack, but it would be too late: we would have |
| 771 | // changed its value earlier. Therefore, we manually save |
| 772 | // it here into another freely available register, |
| 773 | // `free_reg`, chosen of course among the caller-save |
| 774 | // registers (as a callee-save `free_reg` register would |
| 775 | // exhibit the same problem). |
| 776 | // |
| 777 | // Note we could have requested a temporary register from |
| 778 | // the register allocator instead; but we prefer not to, as |
| 779 | // this is a slow path, and we know we can find a |
| 780 | // caller-save register that is available. |
| 781 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 782 | __ movl(free_reg, index_reg); |
| 783 | index_reg = free_reg; |
| 784 | index = Location::RegisterLocation(index_reg); |
| 785 | } else { |
| 786 | // The initial register stored in `index_` has already been |
| 787 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 788 | // (as it is not a callee-save register), so we can freely |
| 789 | // use it. |
| 790 | } |
| 791 | // Shifting the index value contained in `index_reg` by the scale |
| 792 | // factor (2) cannot overflow in practice, as the runtime is |
| 793 | // unable to allocate object arrays with a size larger than |
| 794 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 795 | __ shll(index_reg, Immediate(TIMES_4)); |
| 796 | static_assert( |
| 797 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 798 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 799 | __ AddImmediate(index_reg, Immediate(offset_)); |
| 800 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 801 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 802 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 803 | // (as in the case of ArrayGet), as it is actually an offset |
| 804 | // to an object field within an object. |
| 805 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 806 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 807 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 808 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 809 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 810 | DCHECK_EQ(offset_, 0U); |
| 811 | DCHECK(index_.IsRegisterPair()); |
| 812 | // UnsafeGet's offset location is a register pair, the low |
| 813 | // part contains the correct offset. |
| 814 | index = index_.ToLow(); |
| 815 | } |
| 816 | } |
| 817 | |
| 818 | // We're moving two or three locations to locations that could |
| 819 | // overlap, so we need a parallel move resolver. |
| 820 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 821 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 822 | parallel_move.AddMove(ref_, |
| 823 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 824 | DataType::Type::kReference, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 825 | nullptr); |
| 826 | parallel_move.AddMove(obj_, |
| 827 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 828 | DataType::Type::kReference, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 829 | nullptr); |
| 830 | if (index.IsValid()) { |
| 831 | parallel_move.AddMove(index, |
| 832 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 833 | DataType::Type::kInt32, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 834 | nullptr); |
| 835 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 836 | } else { |
| 837 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 838 | __ movl(calling_convention.GetRegisterAt(2), Immediate(offset_)); |
| 839 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 840 | x86_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 841 | CheckEntrypointTypes< |
| 842 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 843 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 844 | |
| 845 | RestoreLiveRegisters(codegen, locations); |
| 846 | __ jmp(GetExitLabel()); |
| 847 | } |
| 848 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 849 | const char* GetDescription() const override { return "ReadBarrierForHeapReferenceSlowPathX86"; } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 850 | |
| 851 | private: |
| 852 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 853 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 854 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 855 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 856 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 857 | return static_cast<Register>(i); |
| 858 | } |
| 859 | } |
| 860 | // We shall never fail to find a free caller-save register, as |
| 861 | // there are more than two core caller-save registers on x86 |
| 862 | // (meaning it is possible to find one which is different from |
| 863 | // `ref` and `obj`). |
| 864 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 865 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 866 | UNREACHABLE(); |
| 867 | } |
| 868 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 869 | const Location out_; |
| 870 | const Location ref_; |
| 871 | const Location obj_; |
| 872 | const uint32_t offset_; |
| 873 | // An additional location containing an index to an array. |
| 874 | // Only used for HArrayGet and the UnsafeGetObject & |
| 875 | // UnsafeGetObjectVolatile intrinsics. |
| 876 | const Location index_; |
| 877 | |
| 878 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86); |
| 879 | }; |
| 880 | |
| 881 | // Slow path generating a read barrier for a GC root. |
| 882 | class ReadBarrierForRootSlowPathX86 : public SlowPathCode { |
| 883 | public: |
| 884 | ReadBarrierForRootSlowPathX86(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 885 | : SlowPathCode(instruction), out_(out), root_(root) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 886 | DCHECK(kEmitCompilerReadBarrier); |
| 887 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 888 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 889 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 890 | LocationSummary* locations = instruction_->GetLocations(); |
| 891 | Register reg_out = out_.AsRegister<Register>(); |
| 892 | DCHECK(locations->CanCall()); |
| 893 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 894 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 895 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 896 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 897 | |
| 898 | __ Bind(GetEntryLabel()); |
| 899 | SaveLiveRegisters(codegen, locations); |
| 900 | |
| 901 | InvokeRuntimeCallingConvention calling_convention; |
| 902 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 903 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 904 | x86_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 905 | instruction_, |
| 906 | instruction_->GetDexPc(), |
| 907 | this); |
| 908 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 909 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 910 | |
| 911 | RestoreLiveRegisters(codegen, locations); |
| 912 | __ jmp(GetExitLabel()); |
| 913 | } |
| 914 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 915 | const char* GetDescription() const override { return "ReadBarrierForRootSlowPathX86"; } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 916 | |
| 917 | private: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 918 | const Location out_; |
| 919 | const Location root_; |
| 920 | |
| 921 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86); |
| 922 | }; |
| 923 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 924 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 925 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 926 | #define __ down_cast<X86Assembler*>(GetAssembler())-> // NOLINT |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 927 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 928 | inline Condition X86Condition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 929 | switch (cond) { |
| 930 | case kCondEQ: return kEqual; |
| 931 | case kCondNE: return kNotEqual; |
| 932 | case kCondLT: return kLess; |
| 933 | case kCondLE: return kLessEqual; |
| 934 | case kCondGT: return kGreater; |
| 935 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 936 | case kCondB: return kBelow; |
| 937 | case kCondBE: return kBelowEqual; |
| 938 | case kCondA: return kAbove; |
| 939 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 940 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 941 | LOG(FATAL) << "Unreachable"; |
| 942 | UNREACHABLE(); |
| 943 | } |
| 944 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 945 | // Maps signed condition to unsigned condition and FP condition to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 946 | inline Condition X86UnsignedOrFPCondition(IfCondition cond) { |
| 947 | switch (cond) { |
| 948 | case kCondEQ: return kEqual; |
| 949 | case kCondNE: return kNotEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 950 | // Signed to unsigned, and FP to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 951 | case kCondLT: return kBelow; |
| 952 | case kCondLE: return kBelowEqual; |
| 953 | case kCondGT: return kAbove; |
| 954 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 955 | // Unsigned remain unchanged. |
| 956 | case kCondB: return kBelow; |
| 957 | case kCondBE: return kBelowEqual; |
| 958 | case kCondA: return kAbove; |
| 959 | case kCondAE: return kAboveEqual; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 960 | } |
| 961 | LOG(FATAL) << "Unreachable"; |
| 962 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 963 | } |
| 964 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 965 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 966 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 967 | } |
| 968 | |
| 969 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 970 | stream << XmmRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 971 | } |
| 972 | |
Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 973 | const X86InstructionSetFeatures& CodeGeneratorX86::GetInstructionSetFeatures() const { |
| 974 | return *GetCompilerOptions().GetInstructionSetFeatures()->AsX86InstructionSetFeatures(); |
| 975 | } |
| 976 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 977 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 978 | __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); |
| 979 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 980 | } |
| 981 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 982 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 983 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); |
| 984 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 985 | } |
| 986 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 987 | size_t CodeGeneratorX86::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 988 | if (GetGraph()->HasSIMD()) { |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 989 | __ movups(Address(ESP, stack_index), XmmRegister(reg_id)); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 990 | } else { |
| 991 | __ movsd(Address(ESP, stack_index), XmmRegister(reg_id)); |
| 992 | } |
Artem Serov | 6a0b657 | 2019-07-26 20:38:37 +0100 | [diff] [blame] | 993 | return GetSlowPathFPWidth(); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | size_t CodeGeneratorX86::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 997 | if (GetGraph()->HasSIMD()) { |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 998 | __ movups(XmmRegister(reg_id), Address(ESP, stack_index)); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 999 | } else { |
| 1000 | __ movsd(XmmRegister(reg_id), Address(ESP, stack_index)); |
| 1001 | } |
Artem Serov | 6a0b657 | 2019-07-26 20:38:37 +0100 | [diff] [blame] | 1002 | return GetSlowPathFPWidth(); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1003 | } |
| 1004 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1005 | void CodeGeneratorX86::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1006 | HInstruction* instruction, |
| 1007 | uint32_t dex_pc, |
| 1008 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1009 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1010 | GenerateInvokeRuntime(GetThreadOffset<kX86PointerSize>(entrypoint).Int32Value()); |
| 1011 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1012 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1013 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 1014 | } |
| 1015 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1016 | void CodeGeneratorX86::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1017 | HInstruction* instruction, |
| 1018 | SlowPathCode* slow_path) { |
| 1019 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1020 | GenerateInvokeRuntime(entry_point_offset); |
| 1021 | } |
| 1022 | |
| 1023 | void CodeGeneratorX86::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1024 | __ fs()->call(Address::Absolute(entry_point_offset)); |
| 1025 | } |
| 1026 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1027 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1028 | const CompilerOptions& compiler_options, |
| 1029 | OptimizingCompilerStats* stats) |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1030 | : CodeGenerator(graph, |
| 1031 | kNumberOfCpuRegisters, |
| 1032 | kNumberOfXmmRegisters, |
| 1033 | kNumberOfRegisterPairs, |
| 1034 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1035 | arraysize(kCoreCalleeSaves)) |
| 1036 | | (1 << kFakeReturnRegister), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1037 | 0, |
| 1038 | compiler_options, |
| 1039 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1040 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1041 | location_builder_(graph, this), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1042 | instruction_visitor_(graph, this), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1043 | move_resolver_(graph->GetAllocator(), this), |
| 1044 | assembler_(graph->GetAllocator()), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1045 | boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1046 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1047 | boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1048 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1049 | boot_image_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1050 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 1051 | boot_image_other_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1052 | jit_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1053 | jit_class_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1054 | constant_area_start_(-1), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1055 | fixups_to_jump_tables_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1056 | method_address_offset_(std::less<uint32_t>(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1057 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1058 | // Use a fake return address register to mimic Quick. |
| 1059 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1060 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1061 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1062 | void CodeGeneratorX86::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1063 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1064 | blocked_core_registers_[ESP] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1065 | } |
| 1066 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1067 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1068 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1069 | assembler_(codegen->GetAssembler()), |
| 1070 | codegen_(codegen) {} |
| 1071 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1072 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1073 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1074 | } |
| 1075 | |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1076 | void CodeGeneratorX86::MaybeIncrementHotness(bool is_frame_entry) { |
| 1077 | if (GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 1078 | Register reg = EAX; |
| 1079 | if (is_frame_entry) { |
| 1080 | reg = kMethodRegisterArgument; |
| 1081 | } else { |
| 1082 | __ pushl(EAX); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1083 | __ cfi().AdjustCFAOffset(4); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1084 | __ movl(EAX, Address(ESP, kX86WordSize)); |
| 1085 | } |
| 1086 | NearLabel overflow; |
| 1087 | __ cmpw(Address(reg, ArtMethod::HotnessCountOffset().Int32Value()), |
| 1088 | Immediate(ArtMethod::MaxCounter())); |
| 1089 | __ j(kEqual, &overflow); |
| 1090 | __ addw(Address(reg, ArtMethod::HotnessCountOffset().Int32Value()), |
| 1091 | Immediate(1)); |
| 1092 | __ Bind(&overflow); |
| 1093 | if (!is_frame_entry) { |
| 1094 | __ popl(EAX); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1095 | __ cfi().AdjustCFAOffset(-4); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1096 | } |
| 1097 | } |
| 1098 | |
| 1099 | if (GetGraph()->IsCompilingBaseline() && !Runtime::Current()->IsAotCompiler()) { |
| 1100 | ScopedObjectAccess soa(Thread::Current()); |
| 1101 | ProfilingInfo* info = GetGraph()->GetArtMethod()->GetProfilingInfo(kRuntimePointerSize); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1102 | if (info != nullptr) { |
| 1103 | uint32_t address = reinterpret_cast32<uint32_t>(info); |
| 1104 | NearLabel done; |
| 1105 | if (HasEmptyFrame()) { |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1106 | CHECK(is_frame_entry); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1107 | // Alignment |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1108 | IncreaseFrame(8); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1109 | // We need a temporary. The stub also expects the method at bottom of stack. |
| 1110 | __ pushl(EAX); |
| 1111 | __ cfi().AdjustCFAOffset(4); |
| 1112 | __ movl(EAX, Immediate(address)); |
| 1113 | __ addw(Address(EAX, ProfilingInfo::BaselineHotnessCountOffset().Int32Value()), |
| 1114 | Immediate(1)); |
| 1115 | __ j(kCarryClear, &done); |
| 1116 | GenerateInvokeRuntime( |
| 1117 | GetThreadOffset<kX86PointerSize>(kQuickCompileOptimized).Int32Value()); |
| 1118 | __ Bind(&done); |
| 1119 | // We don't strictly require to restore EAX, but this makes the generated |
| 1120 | // code easier to reason about. |
| 1121 | __ popl(EAX); |
| 1122 | __ cfi().AdjustCFAOffset(-4); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1123 | DecreaseFrame(8); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1124 | } else { |
| 1125 | if (!RequiresCurrentMethod()) { |
| 1126 | CHECK(is_frame_entry); |
| 1127 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
| 1128 | } |
| 1129 | // We need a temporary. |
| 1130 | __ pushl(EAX); |
| 1131 | __ cfi().AdjustCFAOffset(4); |
| 1132 | __ movl(EAX, Immediate(address)); |
| 1133 | __ addw(Address(EAX, ProfilingInfo::BaselineHotnessCountOffset().Int32Value()), |
| 1134 | Immediate(1)); |
| 1135 | __ popl(EAX); // Put stack as expected before exiting or calling stub. |
| 1136 | __ cfi().AdjustCFAOffset(-4); |
| 1137 | __ j(kCarryClear, &done); |
| 1138 | GenerateInvokeRuntime( |
| 1139 | GetThreadOffset<kX86PointerSize>(kQuickCompileOptimized).Int32Value()); |
| 1140 | __ Bind(&done); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1141 | } |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1142 | } |
| 1143 | } |
| 1144 | } |
| 1145 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1146 | void CodeGeneratorX86::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1147 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1148 | __ Bind(&frame_entry_label_); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1149 | bool skip_overflow_check = |
| 1150 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1151 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 1152 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1153 | if (!skip_overflow_check) { |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1154 | size_t reserved_bytes = GetStackOverflowReservedBytes(InstructionSet::kX86); |
| 1155 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(reserved_bytes))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1156 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 1157 | } |
| 1158 | |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1159 | if (!HasEmptyFrame()) { |
| 1160 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 1161 | Register reg = kCoreCalleeSaves[i]; |
| 1162 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1163 | __ pushl(reg); |
| 1164 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 1165 | __ cfi().RelOffset(DWARFReg(reg), 0); |
| 1166 | } |
| 1167 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1168 | |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1169 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1170 | IncreaseFrame(adjust); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1171 | // Save the current method if we need it. Note that we do not |
| 1172 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1173 | // in the SSA graph. |
| 1174 | if (RequiresCurrentMethod()) { |
| 1175 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
| 1176 | } |
| 1177 | |
| 1178 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1179 | // Initialize should_deoptimize flag to 0. |
| 1180 | __ movl(Address(ESP, GetStackOffsetOfShouldDeoptimizeFlag()), Immediate(0)); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1181 | } |
| 1182 | } |
| 1183 | |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1184 | MaybeIncrementHotness(/* is_frame_entry= */ true); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1185 | } |
| 1186 | |
| 1187 | void CodeGeneratorX86::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1188 | __ cfi().RememberState(); |
| 1189 | if (!HasEmptyFrame()) { |
| 1190 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1191 | DecreaseFrame(adjust); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1192 | |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1193 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1194 | Register reg = kCoreCalleeSaves[i]; |
| 1195 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1196 | __ popl(reg); |
| 1197 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 1198 | __ cfi().Restore(DWARFReg(reg)); |
| 1199 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1200 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1201 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1202 | __ ret(); |
| 1203 | __ cfi().RestoreState(); |
| 1204 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1205 | } |
| 1206 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1207 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 1208 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1209 | } |
| 1210 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1211 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(DataType::Type type) const { |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1212 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1213 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1214 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1215 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1216 | case DataType::Type::kInt8: |
| 1217 | case DataType::Type::kUint16: |
| 1218 | case DataType::Type::kInt16: |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1219 | case DataType::Type::kUint32: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1220 | case DataType::Type::kInt32: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1221 | return Location::RegisterLocation(EAX); |
| 1222 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1223 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1224 | case DataType::Type::kInt64: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1225 | return Location::RegisterPairLocation(EAX, EDX); |
| 1226 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1227 | case DataType::Type::kVoid: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1228 | return Location::NoLocation(); |
| 1229 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1230 | case DataType::Type::kFloat64: |
| 1231 | case DataType::Type::kFloat32: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1232 | return Location::FpuRegisterLocation(XMM0); |
| 1233 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1234 | |
| 1235 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1236 | } |
| 1237 | |
| 1238 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 1239 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1240 | } |
| 1241 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1242 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(DataType::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1243 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1244 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1245 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1246 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1247 | case DataType::Type::kInt8: |
| 1248 | case DataType::Type::kUint16: |
| 1249 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1250 | case DataType::Type::kInt32: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1251 | uint32_t index = gp_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1252 | stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1253 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1254 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1255 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1256 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1257 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1258 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1259 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1260 | case DataType::Type::kInt64: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1261 | uint32_t index = gp_index_; |
| 1262 | gp_index_ += 2; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1263 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1264 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1265 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 1266 | calling_convention.GetRegisterPairAt(index)); |
| 1267 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1268 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1269 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1270 | } |
| 1271 | } |
| 1272 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1273 | case DataType::Type::kFloat32: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1274 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1275 | stack_index_++; |
| 1276 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1277 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1278 | } else { |
| 1279 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1280 | } |
| 1281 | } |
| 1282 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1283 | case DataType::Type::kFloat64: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1284 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1285 | stack_index_ += 2; |
| 1286 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1287 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1288 | } else { |
| 1289 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1290 | } |
| 1291 | } |
| 1292 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1293 | case DataType::Type::kUint32: |
| 1294 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1295 | case DataType::Type::kVoid: |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1296 | LOG(FATAL) << "Unexpected parameter type " << type; |
Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 1297 | UNREACHABLE(); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1298 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1299 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1300 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1301 | |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 1302 | Location CriticalNativeCallingConventionVisitorX86::GetNextLocation(DataType::Type type) { |
| 1303 | DCHECK_NE(type, DataType::Type::kReference); |
| 1304 | |
| 1305 | Location location; |
| 1306 | if (DataType::Is64BitType(type)) { |
| 1307 | location = Location::DoubleStackSlot(stack_offset_); |
| 1308 | stack_offset_ += 2 * kFramePointerSize; |
| 1309 | } else { |
| 1310 | location = Location::StackSlot(stack_offset_); |
| 1311 | stack_offset_ += kFramePointerSize; |
| 1312 | } |
| 1313 | if (for_register_allocation_) { |
| 1314 | location = Location::Any(); |
| 1315 | } |
| 1316 | return location; |
| 1317 | } |
| 1318 | |
| 1319 | Location CriticalNativeCallingConventionVisitorX86::GetReturnLocation(DataType::Type type) const { |
| 1320 | // We perform conversion to the managed ABI return register after the call if needed. |
| 1321 | InvokeDexCallingConventionVisitorX86 dex_calling_convention; |
| 1322 | return dex_calling_convention.GetReturnLocation(type); |
| 1323 | } |
| 1324 | |
| 1325 | Location CriticalNativeCallingConventionVisitorX86::GetMethodLocation() const { |
| 1326 | // Pass the method in the hidden argument EAX. |
| 1327 | return Location::RegisterLocation(EAX); |
| 1328 | } |
| 1329 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1330 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 1331 | if (source.Equals(destination)) { |
| 1332 | return; |
| 1333 | } |
| 1334 | if (destination.IsRegister()) { |
| 1335 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1336 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1337 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1338 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1339 | } else { |
| 1340 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1341 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1342 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1343 | } else if (destination.IsFpuRegister()) { |
| 1344 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1345 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1346 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1347 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1348 | } else { |
| 1349 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1350 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1351 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1352 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1353 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1354 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1355 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1356 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1357 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1358 | } else if (source.IsConstant()) { |
| 1359 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1360 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1361 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1362 | } else { |
| 1363 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1364 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 1365 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1366 | } |
| 1367 | } |
| 1368 | } |
| 1369 | |
| 1370 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 1371 | if (source.Equals(destination)) { |
| 1372 | return; |
| 1373 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1374 | if (destination.IsRegisterPair()) { |
| 1375 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1376 | EmitParallelMoves( |
| 1377 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1378 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1379 | DataType::Type::kInt32, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1380 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1381 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1382 | DataType::Type::kInt32); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1383 | } else if (source.IsFpuRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1384 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 1385 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 1386 | __ psrlq(src_reg, Immediate(32)); |
| 1387 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1388 | } else { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1389 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1390 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1391 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 1392 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1393 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 1394 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1395 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1396 | if (source.IsFpuRegister()) { |
| 1397 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 1398 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1399 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1400 | } else if (source.IsRegisterPair()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1401 | size_t elem_size = DataType::Size(DataType::Type::kInt32); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1402 | // Push the 2 source registers to the stack. |
| 1403 | __ pushl(source.AsRegisterPairHigh<Register>()); |
| 1404 | __ cfi().AdjustCFAOffset(elem_size); |
| 1405 | __ pushl(source.AsRegisterPairLow<Register>()); |
| 1406 | __ cfi().AdjustCFAOffset(elem_size); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1407 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 1408 | // And remove the temporary stack space we allocated. |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1409 | DecreaseFrame(2 * elem_size); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1410 | } else { |
| 1411 | LOG(FATAL) << "Unimplemented"; |
| 1412 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1413 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1414 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1415 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1416 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1417 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1418 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1419 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1420 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1421 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1422 | } else if (source.IsConstant()) { |
| 1423 | HConstant* constant = source.GetConstant(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1424 | DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant()); |
| 1425 | int64_t value = GetInt64ValueOf(constant); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1426 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1427 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
| 1428 | Immediate(High32Bits(value))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1429 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1430 | DCHECK(source.IsDoubleStackSlot()) << source; |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1431 | EmitParallelMoves( |
| 1432 | Location::StackSlot(source.GetStackIndex()), |
| 1433 | Location::StackSlot(destination.GetStackIndex()), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1434 | DataType::Type::kInt32, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1435 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1436 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1437 | DataType::Type::kInt32); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1438 | } |
| 1439 | } |
| 1440 | } |
| 1441 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1442 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { |
| 1443 | DCHECK(location.IsRegister()); |
| 1444 | __ movl(location.AsRegister<Register>(), Immediate(value)); |
| 1445 | } |
| 1446 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1447 | void CodeGeneratorX86::MoveLocation(Location dst, Location src, DataType::Type dst_type) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1448 | HParallelMove move(GetGraph()->GetAllocator()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1449 | if (dst_type == DataType::Type::kInt64 && !src.IsConstant() && !src.IsFpuRegister()) { |
| 1450 | move.AddMove(src.ToLow(), dst.ToLow(), DataType::Type::kInt32, nullptr); |
| 1451 | move.AddMove(src.ToHigh(), dst.ToHigh(), DataType::Type::kInt32, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1452 | } else { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1453 | move.AddMove(src, dst, dst_type, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1454 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1455 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1456 | } |
| 1457 | |
| 1458 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1459 | if (location.IsRegister()) { |
| 1460 | locations->AddTemp(location); |
| 1461 | } else if (location.IsRegisterPair()) { |
| 1462 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1463 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1464 | } else { |
| 1465 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1466 | } |
| 1467 | } |
| 1468 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1469 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 1470 | if (successor->IsExitBlock()) { |
| 1471 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 1472 | return; // no code needed |
| 1473 | } |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1474 | |
| 1475 | HBasicBlock* block = got->GetBlock(); |
| 1476 | HInstruction* previous = got->GetPrevious(); |
| 1477 | |
| 1478 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1479 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1480 | codegen_->MaybeIncrementHotness(/* is_frame_entry= */ false); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1481 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1482 | return; |
| 1483 | } |
| 1484 | |
| 1485 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1486 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1487 | } |
| 1488 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1489 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1490 | } |
| 1491 | } |
| 1492 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1493 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 1494 | got->SetLocations(nullptr); |
| 1495 | } |
| 1496 | |
| 1497 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 1498 | HandleGoto(got, got->GetSuccessor()); |
| 1499 | } |
| 1500 | |
| 1501 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1502 | try_boundary->SetLocations(nullptr); |
| 1503 | } |
| 1504 | |
| 1505 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1506 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1507 | if (!successor->IsExitBlock()) { |
| 1508 | HandleGoto(try_boundary, successor); |
| 1509 | } |
| 1510 | } |
| 1511 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1512 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1513 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1514 | } |
| 1515 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1516 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1517 | } |
| 1518 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1519 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1520 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1521 | LabelType* true_label, |
| 1522 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1523 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1524 | __ j(kUnordered, true_label); |
| 1525 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1526 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1527 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1528 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1529 | } |
| 1530 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1531 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1532 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1533 | LabelType* true_label, |
| 1534 | LabelType* false_label) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1535 | LocationSummary* locations = cond->GetLocations(); |
| 1536 | Location left = locations->InAt(0); |
| 1537 | Location right = locations->InAt(1); |
| 1538 | IfCondition if_cond = cond->GetCondition(); |
| 1539 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1540 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1541 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1542 | IfCondition true_high_cond = if_cond; |
| 1543 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1544 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); // unsigned on lower part |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1545 | |
| 1546 | // Set the conditions for the test, remembering that == needs to be |
| 1547 | // decided using the low words. |
| 1548 | switch (if_cond) { |
| 1549 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1550 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1551 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1552 | break; |
| 1553 | case kCondLT: |
| 1554 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1555 | break; |
| 1556 | case kCondLE: |
| 1557 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1558 | break; |
| 1559 | case kCondGT: |
| 1560 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1561 | break; |
| 1562 | case kCondGE: |
| 1563 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1564 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1565 | case kCondB: |
| 1566 | false_high_cond = kCondA; |
| 1567 | break; |
| 1568 | case kCondBE: |
| 1569 | true_high_cond = kCondB; |
| 1570 | break; |
| 1571 | case kCondA: |
| 1572 | false_high_cond = kCondB; |
| 1573 | break; |
| 1574 | case kCondAE: |
| 1575 | true_high_cond = kCondA; |
| 1576 | break; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1577 | } |
| 1578 | |
| 1579 | if (right.IsConstant()) { |
| 1580 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1581 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1582 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1583 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1584 | codegen_->Compare32BitValue(left_high, val_high); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1585 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1586 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1587 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1588 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1589 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1590 | __ j(X86Condition(true_high_cond), true_label); |
| 1591 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1592 | } |
| 1593 | // Must be equal high, so compare the lows. |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1594 | codegen_->Compare32BitValue(left_low, val_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1595 | } else if (right.IsRegisterPair()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1596 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1597 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1598 | |
| 1599 | __ cmpl(left_high, right_high); |
| 1600 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1601 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1602 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1603 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1604 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1605 | __ j(X86Condition(true_high_cond), true_label); |
| 1606 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1607 | } |
| 1608 | // Must be equal high, so compare the lows. |
| 1609 | __ cmpl(left_low, right_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1610 | } else { |
| 1611 | DCHECK(right.IsDoubleStackSlot()); |
| 1612 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
| 1613 | if (if_cond == kCondNE) { |
| 1614 | __ j(X86Condition(true_high_cond), true_label); |
| 1615 | } else if (if_cond == kCondEQ) { |
| 1616 | __ j(X86Condition(false_high_cond), false_label); |
| 1617 | } else { |
| 1618 | __ j(X86Condition(true_high_cond), true_label); |
| 1619 | __ j(X86Condition(false_high_cond), false_label); |
| 1620 | } |
| 1621 | // Must be equal high, so compare the lows. |
| 1622 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1623 | } |
| 1624 | // The last comparison might be unsigned. |
| 1625 | __ j(final_condition, true_label); |
| 1626 | } |
| 1627 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1628 | void InstructionCodeGeneratorX86::GenerateFPCompare(Location lhs, |
| 1629 | Location rhs, |
| 1630 | HInstruction* insn, |
| 1631 | bool is_double) { |
| 1632 | HX86LoadFromConstantTable* const_area = insn->InputAt(1)->AsX86LoadFromConstantTable(); |
| 1633 | if (is_double) { |
| 1634 | if (rhs.IsFpuRegister()) { |
| 1635 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1636 | } else if (const_area != nullptr) { |
| 1637 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1638 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), |
| 1639 | codegen_->LiteralDoubleAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1640 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 1641 | const_area->GetBaseMethodAddress(), |
| 1642 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1643 | } else { |
| 1644 | DCHECK(rhs.IsDoubleStackSlot()); |
| 1645 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1646 | } |
| 1647 | } else { |
| 1648 | if (rhs.IsFpuRegister()) { |
| 1649 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1650 | } else if (const_area != nullptr) { |
| 1651 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1652 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), |
| 1653 | codegen_->LiteralFloatAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1654 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 1655 | const_area->GetBaseMethodAddress(), |
| 1656 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1657 | } else { |
| 1658 | DCHECK(rhs.IsStackSlot()); |
| 1659 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1660 | } |
| 1661 | } |
| 1662 | } |
| 1663 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1664 | template<class LabelType> |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1665 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1666 | LabelType* true_target_in, |
| 1667 | LabelType* false_target_in) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1668 | // Generated branching requires both targets to be explicit. If either of the |
| 1669 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1670 | LabelType fallthrough_target; |
| 1671 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1672 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1673 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1674 | LocationSummary* locations = condition->GetLocations(); |
| 1675 | Location left = locations->InAt(0); |
| 1676 | Location right = locations->InAt(1); |
| 1677 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1678 | DataType::Type type = condition->InputAt(0)->GetType(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1679 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1680 | case DataType::Type::kInt64: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1681 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1682 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1683 | case DataType::Type::kFloat32: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1684 | GenerateFPCompare(left, right, condition, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1685 | GenerateFPJumps(condition, true_target, false_target); |
| 1686 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1687 | case DataType::Type::kFloat64: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1688 | GenerateFPCompare(left, right, condition, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1689 | GenerateFPJumps(condition, true_target, false_target); |
| 1690 | break; |
| 1691 | default: |
| 1692 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1693 | } |
| 1694 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1695 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1696 | __ jmp(false_target); |
| 1697 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1698 | |
| 1699 | if (fallthrough_target.IsLinked()) { |
| 1700 | __ Bind(&fallthrough_target); |
| 1701 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1702 | } |
| 1703 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1704 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1705 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1706 | // are set only strictly before `branch`. We can't use the eflags on long/FP |
| 1707 | // conditions if they are materialized due to the complex branching. |
| 1708 | return cond->IsCondition() && |
| 1709 | cond->GetNext() == branch && |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1710 | cond->InputAt(0)->GetType() != DataType::Type::kInt64 && |
| 1711 | !DataType::IsFloatingPointType(cond->InputAt(0)->GetType()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1712 | } |
| 1713 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1714 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1715 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1716 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1717 | LabelType* true_target, |
| 1718 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1719 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1720 | |
| 1721 | if (true_target == nullptr && false_target == nullptr) { |
| 1722 | // Nothing to do. The code always falls through. |
| 1723 | return; |
| 1724 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1725 | // Constant condition, statically compared against "true" (integer value 1). |
| 1726 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1727 | if (true_target != nullptr) { |
| 1728 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1729 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1730 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1731 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1732 | if (false_target != nullptr) { |
| 1733 | __ jmp(false_target); |
| 1734 | } |
| 1735 | } |
| 1736 | return; |
| 1737 | } |
| 1738 | |
| 1739 | // The following code generates these patterns: |
| 1740 | // (1) true_target == nullptr && false_target != nullptr |
| 1741 | // - opposite condition true => branch to false_target |
| 1742 | // (2) true_target != nullptr && false_target == nullptr |
| 1743 | // - condition true => branch to true_target |
| 1744 | // (3) true_target != nullptr && false_target != nullptr |
| 1745 | // - condition true => branch to true_target |
| 1746 | // - branch to false_target |
| 1747 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1748 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1749 | if (true_target == nullptr) { |
| 1750 | __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1751 | } else { |
| 1752 | __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); |
| 1753 | } |
| 1754 | } else { |
| 1755 | // Materialized condition, compare against 0. |
| 1756 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1757 | if (lhs.IsRegister()) { |
| 1758 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1759 | } else { |
| 1760 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1761 | } |
| 1762 | if (true_target == nullptr) { |
| 1763 | __ j(kEqual, false_target); |
| 1764 | } else { |
| 1765 | __ j(kNotEqual, true_target); |
| 1766 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1767 | } |
| 1768 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1769 | // Condition has not been materialized, use its inputs as the comparison and |
| 1770 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1771 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1772 | |
| 1773 | // If this is a long or FP comparison that has been folded into |
| 1774 | // the HCondition, generate the comparison directly. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1775 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 1776 | if (type == DataType::Type::kInt64 || DataType::IsFloatingPointType(type)) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1777 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1778 | return; |
| 1779 | } |
| 1780 | |
| 1781 | Location lhs = condition->GetLocations()->InAt(0); |
| 1782 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1783 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition). |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1784 | codegen_->GenerateIntCompare(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1785 | if (true_target == nullptr) { |
| 1786 | __ j(X86Condition(condition->GetOppositeCondition()), false_target); |
| 1787 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1788 | __ j(X86Condition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1789 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1790 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1791 | |
| 1792 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1793 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1794 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1795 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1796 | } |
| 1797 | } |
| 1798 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1799 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1800 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1801 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1802 | locations->SetInAt(0, Location::Any()); |
| 1803 | } |
| 1804 | } |
| 1805 | |
| 1806 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1807 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1808 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1809 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1810 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1811 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1812 | nullptr : codegen_->GetLabelOf(false_successor); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1813 | GenerateTestAndBranch(if_instr, /* condition_input_index= */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1814 | } |
| 1815 | |
| 1816 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1817 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1818 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 1819 | InvokeRuntimeCallingConvention calling_convention; |
| 1820 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 1821 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1822 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1823 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1824 | locations->SetInAt(0, Location::Any()); |
| 1825 | } |
| 1826 | } |
| 1827 | |
| 1828 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1829 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1830 | GenerateTestAndBranch<Label>(deoptimize, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1831 | /* condition_input_index= */ 0, |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1832 | slow_path->GetEntryLabel(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1833 | /* false_target= */ nullptr); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1834 | } |
| 1835 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1836 | void LocationsBuilderX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1837 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1838 | LocationSummary(flag, LocationSummary::kNoCall); |
| 1839 | locations->SetOut(Location::RequiresRegister()); |
| 1840 | } |
| 1841 | |
| 1842 | void InstructionCodeGeneratorX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1843 | __ movl(flag->GetLocations()->Out().AsRegister<Register>(), |
| 1844 | Address(ESP, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1845 | } |
| 1846 | |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1847 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1848 | // There are no conditional move instructions for XMMs. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1849 | if (DataType::IsFloatingPointType(select->GetType())) { |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1850 | return false; |
| 1851 | } |
| 1852 | |
| 1853 | // A FP condition doesn't generate the single CC that we need. |
| 1854 | // In 32 bit mode, a long condition doesn't generate a single CC either. |
| 1855 | HInstruction* condition = select->GetCondition(); |
| 1856 | if (condition->IsCondition()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1857 | DataType::Type compare_type = condition->InputAt(0)->GetType(); |
| 1858 | if (compare_type == DataType::Type::kInt64 || |
| 1859 | DataType::IsFloatingPointType(compare_type)) { |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1860 | return false; |
| 1861 | } |
| 1862 | } |
| 1863 | |
| 1864 | // We can generate a CMOV for this Select. |
| 1865 | return true; |
| 1866 | } |
| 1867 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1868 | void LocationsBuilderX86::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1869 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1870 | if (DataType::IsFloatingPointType(select->GetType())) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1871 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1872 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1873 | } else { |
| 1874 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1875 | if (SelectCanUseCMOV(select)) { |
| 1876 | if (select->InputAt(1)->IsConstant()) { |
| 1877 | // Cmov can't handle a constant value. |
| 1878 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1879 | } else { |
| 1880 | locations->SetInAt(1, Location::Any()); |
| 1881 | } |
| 1882 | } else { |
| 1883 | locations->SetInAt(1, Location::Any()); |
| 1884 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1885 | } |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1886 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1887 | locations->SetInAt(2, Location::RequiresRegister()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1888 | } |
| 1889 | locations->SetOut(Location::SameAsFirstInput()); |
| 1890 | } |
| 1891 | |
| 1892 | void InstructionCodeGeneratorX86::VisitSelect(HSelect* select) { |
| 1893 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1894 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1895 | if (SelectCanUseCMOV(select)) { |
| 1896 | // If both the condition and the source types are integer, we can generate |
| 1897 | // a CMOV to implement Select. |
| 1898 | |
| 1899 | HInstruction* select_condition = select->GetCondition(); |
| 1900 | Condition cond = kNotEqual; |
| 1901 | |
| 1902 | // Figure out how to test the 'condition'. |
| 1903 | if (select_condition->IsCondition()) { |
| 1904 | HCondition* condition = select_condition->AsCondition(); |
| 1905 | if (!condition->IsEmittedAtUseSite()) { |
| 1906 | // This was a previously materialized condition. |
| 1907 | // Can we use the existing condition code? |
| 1908 | if (AreEflagsSetFrom(condition, select)) { |
| 1909 | // Materialization was the previous instruction. Condition codes are right. |
| 1910 | cond = X86Condition(condition->GetCondition()); |
| 1911 | } else { |
| 1912 | // No, we have to recreate the condition code. |
| 1913 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1914 | __ testl(cond_reg, cond_reg); |
| 1915 | } |
| 1916 | } else { |
| 1917 | // We can't handle FP or long here. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1918 | DCHECK_NE(condition->InputAt(0)->GetType(), DataType::Type::kInt64); |
| 1919 | DCHECK(!DataType::IsFloatingPointType(condition->InputAt(0)->GetType())); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1920 | LocationSummary* cond_locations = condition->GetLocations(); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1921 | codegen_->GenerateIntCompare(cond_locations->InAt(0), cond_locations->InAt(1)); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1922 | cond = X86Condition(condition->GetCondition()); |
| 1923 | } |
| 1924 | } else { |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 1925 | // Must be a Boolean condition, which needs to be compared to 0. |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1926 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1927 | __ testl(cond_reg, cond_reg); |
| 1928 | } |
| 1929 | |
| 1930 | // If the condition is true, overwrite the output, which already contains false. |
| 1931 | Location false_loc = locations->InAt(0); |
| 1932 | Location true_loc = locations->InAt(1); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1933 | if (select->GetType() == DataType::Type::kInt64) { |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1934 | // 64 bit conditional move. |
| 1935 | Register false_high = false_loc.AsRegisterPairHigh<Register>(); |
| 1936 | Register false_low = false_loc.AsRegisterPairLow<Register>(); |
| 1937 | if (true_loc.IsRegisterPair()) { |
| 1938 | __ cmovl(cond, false_high, true_loc.AsRegisterPairHigh<Register>()); |
| 1939 | __ cmovl(cond, false_low, true_loc.AsRegisterPairLow<Register>()); |
| 1940 | } else { |
| 1941 | __ cmovl(cond, false_high, Address(ESP, true_loc.GetHighStackIndex(kX86WordSize))); |
| 1942 | __ cmovl(cond, false_low, Address(ESP, true_loc.GetStackIndex())); |
| 1943 | } |
| 1944 | } else { |
| 1945 | // 32 bit conditional move. |
| 1946 | Register false_reg = false_loc.AsRegister<Register>(); |
| 1947 | if (true_loc.IsRegister()) { |
| 1948 | __ cmovl(cond, false_reg, true_loc.AsRegister<Register>()); |
| 1949 | } else { |
| 1950 | __ cmovl(cond, false_reg, Address(ESP, true_loc.GetStackIndex())); |
| 1951 | } |
| 1952 | } |
| 1953 | } else { |
| 1954 | NearLabel false_target; |
| 1955 | GenerateTestAndBranch<NearLabel>( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1956 | select, /* condition_input_index= */ 2, /* true_target= */ nullptr, &false_target); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1957 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1958 | __ Bind(&false_target); |
| 1959 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1960 | } |
| 1961 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1962 | void LocationsBuilderX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1963 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1964 | } |
| 1965 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1966 | void InstructionCodeGeneratorX86::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1967 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1968 | } |
| 1969 | |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1970 | void CodeGeneratorX86::IncreaseFrame(size_t adjustment) { |
| 1971 | __ subl(ESP, Immediate(adjustment)); |
| 1972 | __ cfi().AdjustCFAOffset(adjustment); |
| 1973 | } |
| 1974 | |
| 1975 | void CodeGeneratorX86::DecreaseFrame(size_t adjustment) { |
| 1976 | __ addl(ESP, Immediate(adjustment)); |
| 1977 | __ cfi().AdjustCFAOffset(-adjustment); |
| 1978 | } |
| 1979 | |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1980 | void CodeGeneratorX86::GenerateNop() { |
| 1981 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1982 | } |
| 1983 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1984 | void LocationsBuilderX86::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1985 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1986 | new (GetGraph()->GetAllocator()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1987 | // Handle the long/FP comparisons made in instruction simplification. |
| 1988 | switch (cond->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1989 | case DataType::Type::kInt64: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1990 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1991 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1992 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1993 | locations->SetOut(Location::RequiresRegister()); |
| 1994 | } |
| 1995 | break; |
| 1996 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1997 | case DataType::Type::kFloat32: |
| 1998 | case DataType::Type::kFloat64: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1999 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2000 | if (cond->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2001 | DCHECK(cond->InputAt(1)->IsEmittedAtUseSite()); |
| 2002 | } else if (cond->InputAt(1)->IsConstant()) { |
| 2003 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2004 | } else { |
| 2005 | locations->SetInAt(1, Location::Any()); |
| 2006 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2007 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2008 | locations->SetOut(Location::RequiresRegister()); |
| 2009 | } |
| 2010 | break; |
| 2011 | } |
| 2012 | default: |
| 2013 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2014 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2015 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2016 | // We need a byte register. |
| 2017 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 2018 | } |
| 2019 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2020 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2021 | } |
| 2022 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2023 | void InstructionCodeGeneratorX86::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2024 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2025 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2026 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2027 | |
| 2028 | LocationSummary* locations = cond->GetLocations(); |
| 2029 | Location lhs = locations->InAt(0); |
| 2030 | Location rhs = locations->InAt(1); |
| 2031 | Register reg = locations->Out().AsRegister<Register>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 2032 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2033 | |
| 2034 | switch (cond->InputAt(0)->GetType()) { |
| 2035 | default: { |
| 2036 | // Integer case. |
| 2037 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 2038 | // Clear output register: setb only sets the low byte. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2039 | __ xorl(reg, reg); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2040 | codegen_->GenerateIntCompare(lhs, rhs); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2041 | __ setb(X86Condition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2042 | return; |
| 2043 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2044 | case DataType::Type::kInt64: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2045 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 2046 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2047 | case DataType::Type::kFloat32: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2048 | GenerateFPCompare(lhs, rhs, cond, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2049 | GenerateFPJumps(cond, &true_label, &false_label); |
| 2050 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2051 | case DataType::Type::kFloat64: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2052 | GenerateFPCompare(lhs, rhs, cond, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2053 | GenerateFPJumps(cond, &true_label, &false_label); |
| 2054 | break; |
| 2055 | } |
| 2056 | |
| 2057 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2058 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2059 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2060 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2061 | __ Bind(&false_label); |
| 2062 | __ xorl(reg, reg); |
| 2063 | __ jmp(&done_label); |
| 2064 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2065 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2066 | __ Bind(&true_label); |
| 2067 | __ movl(reg, Immediate(1)); |
| 2068 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2069 | } |
| 2070 | |
| 2071 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2072 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2073 | } |
| 2074 | |
| 2075 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2076 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2077 | } |
| 2078 | |
| 2079 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2080 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2081 | } |
| 2082 | |
| 2083 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2084 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2085 | } |
| 2086 | |
| 2087 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2088 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2089 | } |
| 2090 | |
| 2091 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2092 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2093 | } |
| 2094 | |
| 2095 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2096 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2097 | } |
| 2098 | |
| 2099 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2100 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2101 | } |
| 2102 | |
| 2103 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2104 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2105 | } |
| 2106 | |
| 2107 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2108 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2109 | } |
| 2110 | |
| 2111 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2112 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2113 | } |
| 2114 | |
| 2115 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2116 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2117 | } |
| 2118 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2119 | void LocationsBuilderX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2120 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2121 | } |
| 2122 | |
| 2123 | void InstructionCodeGeneratorX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2124 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2125 | } |
| 2126 | |
| 2127 | void LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2128 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2129 | } |
| 2130 | |
| 2131 | void InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2132 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2133 | } |
| 2134 | |
| 2135 | void LocationsBuilderX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2136 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2137 | } |
| 2138 | |
| 2139 | void InstructionCodeGeneratorX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2140 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2141 | } |
| 2142 | |
| 2143 | void LocationsBuilderX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2144 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2145 | } |
| 2146 | |
| 2147 | void InstructionCodeGeneratorX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2148 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2149 | } |
| 2150 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2151 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2152 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2153 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2154 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2155 | } |
| 2156 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2157 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2158 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2159 | } |
| 2160 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2161 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 2162 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2163 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2164 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2165 | } |
| 2166 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2167 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2168 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2169 | } |
| 2170 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2171 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2172 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2173 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2174 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2175 | } |
| 2176 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2177 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2178 | // Will be generated at use site. |
| 2179 | } |
| 2180 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2181 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 2182 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2183 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2184 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2185 | } |
| 2186 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2187 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2188 | // Will be generated at use site. |
| 2189 | } |
| 2190 | |
| 2191 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2192 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2193 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2194 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2195 | } |
| 2196 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2197 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2198 | // Will be generated at use site. |
| 2199 | } |
| 2200 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2201 | void LocationsBuilderX86::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 2202 | constructor_fence->SetLocations(nullptr); |
| 2203 | } |
| 2204 | |
| 2205 | void InstructionCodeGeneratorX86::VisitConstructorFence( |
| 2206 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 2207 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 2208 | } |
| 2209 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2210 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2211 | memory_barrier->SetLocations(nullptr); |
| 2212 | } |
| 2213 | |
| 2214 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 2215 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2216 | } |
| 2217 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2218 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2219 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2220 | } |
| 2221 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2222 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2223 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2224 | } |
| 2225 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2226 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2227 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2228 | new (GetGraph()->GetAllocator()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2229 | switch (ret->InputAt(0)->GetType()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2230 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2231 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2232 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2233 | case DataType::Type::kInt8: |
| 2234 | case DataType::Type::kUint16: |
| 2235 | case DataType::Type::kInt16: |
| 2236 | case DataType::Type::kInt32: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2237 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2238 | break; |
| 2239 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2240 | case DataType::Type::kInt64: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2241 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2242 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2243 | break; |
| 2244 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2245 | case DataType::Type::kFloat32: |
| 2246 | case DataType::Type::kFloat64: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2247 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2248 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2249 | break; |
| 2250 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2251 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2252 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2253 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2254 | } |
| 2255 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2256 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 57cacb7 | 2019-12-08 22:07:08 +0000 | [diff] [blame] | 2257 | switch (ret->InputAt(0)->GetType()) { |
| 2258 | case DataType::Type::kReference: |
| 2259 | case DataType::Type::kBool: |
| 2260 | case DataType::Type::kUint8: |
| 2261 | case DataType::Type::kInt8: |
| 2262 | case DataType::Type::kUint16: |
| 2263 | case DataType::Type::kInt16: |
| 2264 | case DataType::Type::kInt32: |
| 2265 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
| 2266 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2267 | |
Nicolas Geoffray | 57cacb7 | 2019-12-08 22:07:08 +0000 | [diff] [blame] | 2268 | case DataType::Type::kInt64: |
| 2269 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 2270 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
| 2271 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2272 | |
Nicolas Geoffray | 57cacb7 | 2019-12-08 22:07:08 +0000 | [diff] [blame] | 2273 | case DataType::Type::kFloat32: |
| 2274 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
| 2275 | if (GetGraph()->IsCompilingOsr()) { |
| 2276 | // To simplify callers of an OSR method, we put the return value in both |
| 2277 | // floating point and core registers. |
| 2278 | __ movd(EAX, XMM0); |
| 2279 | } |
| 2280 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2281 | |
Nicolas Geoffray | 57cacb7 | 2019-12-08 22:07:08 +0000 | [diff] [blame] | 2282 | case DataType::Type::kFloat64: |
| 2283 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
| 2284 | if (GetGraph()->IsCompilingOsr()) { |
| 2285 | // To simplify callers of an OSR method, we put the return value in both |
| 2286 | // floating point and core registers. |
| 2287 | __ movd(EAX, XMM0); |
| 2288 | // Use XMM1 as temporary register to not clobber XMM0. |
| 2289 | __ movaps(XMM1, XMM0); |
| 2290 | __ psrlq(XMM1, Immediate(32)); |
| 2291 | __ movd(EDX, XMM1); |
| 2292 | } |
| 2293 | break; |
| 2294 | |
| 2295 | default: |
| 2296 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2297 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2298 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2299 | } |
| 2300 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2301 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2302 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2303 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2304 | // the method_idx. |
| 2305 | HandleInvoke(invoke); |
| 2306 | } |
| 2307 | |
| 2308 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2309 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2310 | } |
| 2311 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2312 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2313 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2314 | // art::PrepareForRegisterAllocation. |
| 2315 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2316 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2317 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2318 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 2319 | if (invoke->GetLocations()->CanCall() && |
| 2320 | invoke->HasPcRelativeMethodLoadKind() && |
| 2321 | invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()).IsInvalid()) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 2322 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2323 | } |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2324 | return; |
| 2325 | } |
| 2326 | |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 2327 | if (invoke->GetCodePtrLocation() == HInvokeStaticOrDirect::CodePtrLocation::kCallCriticalNative) { |
| 2328 | CriticalNativeCallingConventionVisitorX86 calling_convention_visitor( |
| 2329 | /*for_register_allocation=*/ true); |
| 2330 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 2331 | } else { |
| 2332 | HandleInvoke(invoke); |
| 2333 | } |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2334 | |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 2335 | // For PC-relative load kinds the invoke has an extra input, the PC-relative address base. |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 2336 | if (invoke->HasPcRelativeMethodLoadKind()) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2337 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2338 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2339 | } |
| 2340 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2341 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 2342 | if (invoke->GetLocations()->Intrinsified()) { |
| 2343 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 2344 | intrinsic.Dispatch(invoke); |
| 2345 | return true; |
| 2346 | } |
| 2347 | return false; |
| 2348 | } |
| 2349 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2350 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2351 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2352 | // art::PrepareForRegisterAllocation. |
| 2353 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2354 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2355 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2356 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2357 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2358 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2359 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2360 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2361 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2362 | } |
| 2363 | |
| 2364 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 2365 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 2366 | if (intrinsic.TryDispatch(invoke)) { |
| 2367 | return; |
| 2368 | } |
| 2369 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2370 | HandleInvoke(invoke); |
Nicolas Geoffray | 9b5271e | 2019-12-04 14:39:46 +0000 | [diff] [blame] | 2371 | |
| 2372 | if (GetGraph()->IsCompilingBaseline() && !Runtime::Current()->IsAotCompiler()) { |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2373 | // Add one temporary for inline cache update. |
| 2374 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(EBP)); |
| 2375 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2376 | } |
| 2377 | |
| 2378 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2379 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2380 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2381 | } |
| 2382 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2383 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2384 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2385 | return; |
| 2386 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2387 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2388 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2389 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2390 | } |
| 2391 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2392 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2393 | // This call to HandleInvoke allocates a temporary (core) register |
| 2394 | // which is also used to transfer the hidden argument from FP to |
| 2395 | // core register. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2396 | HandleInvoke(invoke); |
| 2397 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2398 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2399 | |
Nicolas Geoffray | 9b5271e | 2019-12-04 14:39:46 +0000 | [diff] [blame] | 2400 | if (GetGraph()->IsCompilingBaseline() && !Runtime::Current()->IsAotCompiler()) { |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2401 | // Add one temporary for inline cache update. |
| 2402 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(EBP)); |
| 2403 | } |
| 2404 | } |
| 2405 | |
| 2406 | void CodeGeneratorX86::MaybeGenerateInlineCacheCheck(HInstruction* instruction, Register klass) { |
| 2407 | DCHECK_EQ(EAX, klass); |
Nicolas Geoffray | 17a39ba | 2019-11-27 20:57:48 +0000 | [diff] [blame] | 2408 | // We know the destination of an intrinsic, so no need to record inline |
| 2409 | // caches (also the intrinsic location builder doesn't request an additional |
| 2410 | // temporary). |
| 2411 | if (!instruction->GetLocations()->Intrinsified() && |
Nicolas Geoffray | 9b5271e | 2019-12-04 14:39:46 +0000 | [diff] [blame] | 2412 | GetGraph()->IsCompilingBaseline() && |
Nicolas Geoffray | 17a39ba | 2019-11-27 20:57:48 +0000 | [diff] [blame] | 2413 | !Runtime::Current()->IsAotCompiler()) { |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2414 | DCHECK(!instruction->GetEnvironment()->IsFromInlinedInvoke()); |
| 2415 | ScopedObjectAccess soa(Thread::Current()); |
| 2416 | ProfilingInfo* info = GetGraph()->GetArtMethod()->GetProfilingInfo(kRuntimePointerSize); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 2417 | if (info != nullptr) { |
| 2418 | InlineCache* cache = info->GetInlineCache(instruction->GetDexPc()); |
| 2419 | uint32_t address = reinterpret_cast32<uint32_t>(cache); |
| 2420 | if (kIsDebugBuild) { |
| 2421 | uint32_t temp_index = instruction->GetLocations()->GetTempCount() - 1u; |
| 2422 | CHECK_EQ(EBP, instruction->GetLocations()->GetTemp(temp_index).AsRegister<Register>()); |
| 2423 | } |
| 2424 | Register temp = EBP; |
| 2425 | NearLabel done; |
| 2426 | __ movl(temp, Immediate(address)); |
| 2427 | // Fast path for a monomorphic cache. |
| 2428 | __ cmpl(klass, Address(temp, InlineCache::ClassesOffset().Int32Value())); |
| 2429 | __ j(kEqual, &done); |
| 2430 | GenerateInvokeRuntime(GetThreadOffset<kX86PointerSize>(kQuickUpdateInlineCache).Int32Value()); |
| 2431 | __ Bind(&done); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2432 | } |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2433 | } |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2434 | } |
| 2435 | |
| 2436 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2437 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2438 | LocationSummary* locations = invoke->GetLocations(); |
| 2439 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2440 | XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2441 | Location receiver = locations->InAt(0); |
| 2442 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2443 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2444 | // Set the hidden argument. This is safe to do this here, as XMM7 |
| 2445 | // won't be modified thereafter, before the `call` instruction. |
| 2446 | DCHECK_EQ(XMM7, hidden_reg); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2447 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2448 | __ movd(hidden_reg, temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2449 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2450 | if (receiver.IsStackSlot()) { |
| 2451 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2452 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2453 | __ movl(temp, Address(temp, class_offset)); |
| 2454 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2455 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2456 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2457 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2458 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2459 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2460 | // emit a read barrier for the previous class reference load. |
| 2461 | // However this is not required in practice, as this is an |
| 2462 | // intermediate/temporary reference and because the current |
| 2463 | // concurrent copying collector keeps the from-space memory |
| 2464 | // intact/accessible until the end of the marking phase (the |
| 2465 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2466 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2467 | |
| 2468 | codegen_->MaybeGenerateInlineCacheCheck(invoke, temp); |
| 2469 | |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2470 | // temp = temp->GetAddressOfIMT() |
| 2471 | __ movl(temp, |
| 2472 | Address(temp, mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2473 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2474 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2475 | invoke->GetImtIndex(), kX86PointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2476 | __ movl(temp, Address(temp, method_offset)); |
| 2477 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2478 | __ call(Address(temp, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2479 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2480 | |
| 2481 | DCHECK(!codegen_->IsLeafMethod()); |
| 2482 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2483 | } |
| 2484 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2485 | void LocationsBuilderX86::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2486 | HandleInvoke(invoke); |
| 2487 | } |
| 2488 | |
| 2489 | void InstructionCodeGeneratorX86::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2490 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 2491 | } |
| 2492 | |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 2493 | void LocationsBuilderX86::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 2494 | HandleInvoke(invoke); |
| 2495 | } |
| 2496 | |
| 2497 | void InstructionCodeGeneratorX86::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 2498 | codegen_->GenerateInvokeCustomCall(invoke); |
| 2499 | } |
| 2500 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2501 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 2502 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2503 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2504 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2505 | case DataType::Type::kInt32: |
| 2506 | case DataType::Type::kInt64: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2507 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2508 | locations->SetOut(Location::SameAsFirstInput()); |
| 2509 | break; |
| 2510 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2511 | case DataType::Type::kFloat32: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2512 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2513 | locations->SetOut(Location::SameAsFirstInput()); |
| 2514 | locations->AddTemp(Location::RequiresRegister()); |
| 2515 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2516 | break; |
| 2517 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2518 | case DataType::Type::kFloat64: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2519 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2520 | locations->SetOut(Location::SameAsFirstInput()); |
| 2521 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2522 | break; |
| 2523 | |
| 2524 | default: |
| 2525 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2526 | } |
| 2527 | } |
| 2528 | |
| 2529 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 2530 | LocationSummary* locations = neg->GetLocations(); |
| 2531 | Location out = locations->Out(); |
| 2532 | Location in = locations->InAt(0); |
| 2533 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2534 | case DataType::Type::kInt32: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2535 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2536 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2537 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2538 | break; |
| 2539 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2540 | case DataType::Type::kInt64: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2541 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2542 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2543 | __ negl(out.AsRegisterPairLow<Register>()); |
| 2544 | // Negation is similar to subtraction from zero. The least |
| 2545 | // significant byte triggers a borrow when it is different from |
| 2546 | // zero; to take it into account, add 1 to the most significant |
| 2547 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 2548 | // operation. |
| 2549 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2550 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 2551 | break; |
| 2552 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2553 | case DataType::Type::kFloat32: { |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2554 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2555 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 2556 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2557 | // Implement float negation with an exclusive or with value |
| 2558 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2559 | // single-precision floating-point number). |
| 2560 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 2561 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2562 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2563 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2564 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2565 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2566 | case DataType::Type::kFloat64: { |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2567 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2568 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2569 | // Implement double negation with an exclusive or with value |
| 2570 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 2571 | // a double-precision floating-point number). |
| 2572 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2573 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2574 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2575 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2576 | |
| 2577 | default: |
| 2578 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2579 | } |
| 2580 | } |
| 2581 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2582 | void LocationsBuilderX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2583 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2584 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2585 | DCHECK(DataType::IsFloatingPointType(neg->GetType())); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2586 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2587 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2588 | locations->SetOut(Location::SameAsFirstInput()); |
| 2589 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2590 | } |
| 2591 | |
| 2592 | void InstructionCodeGeneratorX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2593 | LocationSummary* locations = neg->GetLocations(); |
| 2594 | Location out = locations->Out(); |
| 2595 | DCHECK(locations->InAt(0).Equals(out)); |
| 2596 | |
| 2597 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 2598 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2599 | if (neg->GetType() == DataType::Type::kFloat32) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 2600 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x80000000), |
| 2601 | neg->GetBaseMethodAddress(), |
| 2602 | constant_area)); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2603 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| 2604 | } else { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 2605 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000), |
| 2606 | neg->GetBaseMethodAddress(), |
| 2607 | constant_area)); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2608 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| 2609 | } |
| 2610 | } |
| 2611 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2612 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2613 | DataType::Type result_type = conversion->GetResultType(); |
| 2614 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2615 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 2616 | << input_type << " -> " << result_type; |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2617 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2618 | // The float-to-long and double-to-long type conversions rely on a |
| 2619 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2620 | LocationSummary::CallKind call_kind = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2621 | ((input_type == DataType::Type::kFloat32 || input_type == DataType::Type::kFloat64) |
| 2622 | && result_type == DataType::Type::kInt64) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2623 | ? LocationSummary::kCallOnMainOnly |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2624 | : LocationSummary::kNoCall; |
| 2625 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2626 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, call_kind); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2627 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2628 | switch (result_type) { |
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: |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2631 | switch (input_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2632 | case DataType::Type::kUint8: |
| 2633 | case DataType::Type::kInt8: |
| 2634 | case DataType::Type::kUint16: |
| 2635 | case DataType::Type::kInt16: |
| 2636 | case DataType::Type::kInt32: |
| 2637 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 2638 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2639 | // the validation of the linear scan implementation |
| 2640 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2641 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2642 | case DataType::Type::kInt64: { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2643 | HInstruction* input = conversion->InputAt(0); |
| 2644 | Location input_location = input->IsConstant() |
| 2645 | ? Location::ConstantLocation(input->AsConstant()) |
| 2646 | : Location::RegisterPairLocation(EAX, EDX); |
| 2647 | locations->SetInAt(0, input_location); |
| 2648 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2649 | // the validation of the linear scan implementation |
| 2650 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2651 | break; |
| 2652 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2653 | |
| 2654 | default: |
| 2655 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2656 | << " to " << result_type; |
| 2657 | } |
| 2658 | break; |
| 2659 | |
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: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2662 | DCHECK(DataType::IsIntegralType(input_type)) << input_type; |
| 2663 | locations->SetInAt(0, Location::Any()); |
| 2664 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2665 | break; |
| 2666 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2667 | case DataType::Type::kInt32: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2668 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2669 | case DataType::Type::kInt64: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2670 | locations->SetInAt(0, Location::Any()); |
| 2671 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2672 | break; |
| 2673 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2674 | case DataType::Type::kFloat32: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2675 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2676 | locations->SetOut(Location::RequiresRegister()); |
| 2677 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2678 | break; |
| 2679 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2680 | case DataType::Type::kFloat64: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2681 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2682 | locations->SetOut(Location::RequiresRegister()); |
| 2683 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2684 | break; |
| 2685 | |
| 2686 | default: |
| 2687 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2688 | << " to " << result_type; |
| 2689 | } |
| 2690 | break; |
| 2691 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2692 | case DataType::Type::kInt64: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2693 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2694 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2695 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2696 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2697 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2698 | case DataType::Type::kInt16: |
| 2699 | case DataType::Type::kInt32: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2700 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 2701 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2702 | break; |
| 2703 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2704 | case DataType::Type::kFloat32: |
| 2705 | case DataType::Type::kFloat64: { |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2706 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2707 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 2708 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 2709 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2710 | // The runtime helper puts the result in EAX, EDX. |
| 2711 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2712 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2713 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2714 | |
| 2715 | default: |
| 2716 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2717 | << " to " << result_type; |
| 2718 | } |
| 2719 | break; |
| 2720 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2721 | case DataType::Type::kFloat32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2722 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2723 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2724 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2725 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2726 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2727 | case DataType::Type::kInt16: |
| 2728 | case DataType::Type::kInt32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2729 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2730 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2731 | break; |
| 2732 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2733 | case DataType::Type::kInt64: |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2734 | locations->SetInAt(0, Location::Any()); |
| 2735 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2736 | break; |
| 2737 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2738 | case DataType::Type::kFloat64: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2739 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2740 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2741 | break; |
| 2742 | |
| 2743 | default: |
| 2744 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2745 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 2746 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2747 | break; |
| 2748 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2749 | case DataType::Type::kFloat64: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2750 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2751 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2752 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2753 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2754 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2755 | case DataType::Type::kInt16: |
| 2756 | case DataType::Type::kInt32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2757 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2758 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2759 | break; |
| 2760 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2761 | case DataType::Type::kInt64: |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2762 | locations->SetInAt(0, Location::Any()); |
| 2763 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2764 | break; |
| 2765 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2766 | case DataType::Type::kFloat32: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2767 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2768 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2769 | break; |
| 2770 | |
| 2771 | default: |
| 2772 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2773 | << " to " << result_type; |
| 2774 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2775 | break; |
| 2776 | |
| 2777 | default: |
| 2778 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2779 | << " to " << result_type; |
| 2780 | } |
| 2781 | } |
| 2782 | |
| 2783 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 2784 | LocationSummary* locations = conversion->GetLocations(); |
| 2785 | Location out = locations->Out(); |
| 2786 | Location in = locations->InAt(0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2787 | DataType::Type result_type = conversion->GetResultType(); |
| 2788 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2789 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 2790 | << input_type << " -> " << result_type; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2791 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2792 | case DataType::Type::kUint8: |
| 2793 | switch (input_type) { |
| 2794 | case DataType::Type::kInt8: |
| 2795 | case DataType::Type::kUint16: |
| 2796 | case DataType::Type::kInt16: |
| 2797 | case DataType::Type::kInt32: |
| 2798 | if (in.IsRegister()) { |
| 2799 | __ movzxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
| 2800 | } else { |
| 2801 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2802 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2803 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint8_t>(value))); |
| 2804 | } |
| 2805 | break; |
| 2806 | case DataType::Type::kInt64: |
| 2807 | if (in.IsRegisterPair()) { |
| 2808 | __ movzxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 2809 | } else { |
| 2810 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2811 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2812 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint8_t>(value))); |
| 2813 | } |
| 2814 | break; |
| 2815 | |
| 2816 | default: |
| 2817 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2818 | << " to " << result_type; |
| 2819 | } |
| 2820 | break; |
| 2821 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2822 | case DataType::Type::kInt8: |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2823 | switch (input_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2824 | case DataType::Type::kUint8: |
| 2825 | case DataType::Type::kUint16: |
| 2826 | case DataType::Type::kInt16: |
| 2827 | case DataType::Type::kInt32: |
| 2828 | if (in.IsRegister()) { |
| 2829 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
| 2830 | } else { |
| 2831 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2832 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2833 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2834 | } |
| 2835 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2836 | case DataType::Type::kInt64: |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2837 | if (in.IsRegisterPair()) { |
| 2838 | __ movsxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 2839 | } else { |
| 2840 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2841 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2842 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2843 | } |
| 2844 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2845 | |
| 2846 | default: |
| 2847 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2848 | << " to " << result_type; |
| 2849 | } |
| 2850 | break; |
| 2851 | |
| 2852 | case DataType::Type::kUint16: |
| 2853 | switch (input_type) { |
| 2854 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2855 | case DataType::Type::kInt16: |
| 2856 | case DataType::Type::kInt32: |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2857 | if (in.IsRegister()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2858 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
| 2859 | } else if (in.IsStackSlot()) { |
| 2860 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2861 | } else { |
| 2862 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2863 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2864 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
| 2865 | } |
| 2866 | break; |
| 2867 | case DataType::Type::kInt64: |
| 2868 | if (in.IsRegisterPair()) { |
| 2869 | __ movzxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2870 | } else if (in.IsDoubleStackSlot()) { |
| 2871 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2872 | } else { |
| 2873 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2874 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2875 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2876 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2877 | break; |
| 2878 | |
| 2879 | default: |
| 2880 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2881 | << " to " << result_type; |
| 2882 | } |
| 2883 | break; |
| 2884 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2885 | case DataType::Type::kInt16: |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2886 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2887 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2888 | case DataType::Type::kInt32: |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2889 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2890 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2891 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2892 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2893 | } else { |
| 2894 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2895 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2896 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2897 | } |
| 2898 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2899 | case DataType::Type::kInt64: |
| 2900 | if (in.IsRegisterPair()) { |
| 2901 | __ movsxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2902 | } else if (in.IsDoubleStackSlot()) { |
| 2903 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2904 | } else { |
| 2905 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2906 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2907 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
| 2908 | } |
| 2909 | break; |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2910 | |
| 2911 | default: |
| 2912 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2913 | << " to " << result_type; |
| 2914 | } |
| 2915 | break; |
| 2916 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2917 | case DataType::Type::kInt32: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2918 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2919 | case DataType::Type::kInt64: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2920 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2921 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2922 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2923 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2924 | } else { |
| 2925 | DCHECK(in.IsConstant()); |
| 2926 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2927 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2928 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2929 | } |
| 2930 | break; |
| 2931 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2932 | case DataType::Type::kFloat32: { |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2933 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2934 | Register output = out.AsRegister<Register>(); |
| 2935 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2936 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2937 | |
| 2938 | __ movl(output, Immediate(kPrimIntMax)); |
| 2939 | // temp = int-to-float(output) |
| 2940 | __ cvtsi2ss(temp, output); |
| 2941 | // if input >= temp goto done |
| 2942 | __ comiss(input, temp); |
| 2943 | __ j(kAboveEqual, &done); |
| 2944 | // if input == NaN goto nan |
| 2945 | __ j(kUnordered, &nan); |
| 2946 | // output = float-to-int-truncate(input) |
| 2947 | __ cvttss2si(output, input); |
| 2948 | __ jmp(&done); |
| 2949 | __ Bind(&nan); |
| 2950 | // output = 0 |
| 2951 | __ xorl(output, output); |
| 2952 | __ Bind(&done); |
| 2953 | break; |
| 2954 | } |
| 2955 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2956 | case DataType::Type::kFloat64: { |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2957 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2958 | Register output = out.AsRegister<Register>(); |
| 2959 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2960 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2961 | |
| 2962 | __ movl(output, Immediate(kPrimIntMax)); |
| 2963 | // temp = int-to-double(output) |
| 2964 | __ cvtsi2sd(temp, output); |
| 2965 | // if input >= temp goto done |
| 2966 | __ comisd(input, temp); |
| 2967 | __ j(kAboveEqual, &done); |
| 2968 | // if input == NaN goto nan |
| 2969 | __ j(kUnordered, &nan); |
| 2970 | // output = double-to-int-truncate(input) |
| 2971 | __ cvttsd2si(output, input); |
| 2972 | __ jmp(&done); |
| 2973 | __ Bind(&nan); |
| 2974 | // output = 0 |
| 2975 | __ xorl(output, output); |
| 2976 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2977 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2978 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2979 | |
| 2980 | default: |
| 2981 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2982 | << " to " << result_type; |
| 2983 | } |
| 2984 | break; |
| 2985 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2986 | case DataType::Type::kInt64: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2987 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2988 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2989 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2990 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2991 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2992 | case DataType::Type::kInt16: |
| 2993 | case DataType::Type::kInt32: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2994 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2995 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2996 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2997 | __ cdq(); |
| 2998 | break; |
| 2999 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3000 | case DataType::Type::kFloat32: |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3001 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3002 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3003 | break; |
| 3004 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3005 | case DataType::Type::kFloat64: |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3006 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3007 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3008 | break; |
| 3009 | |
| 3010 | default: |
| 3011 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3012 | << " to " << result_type; |
| 3013 | } |
| 3014 | break; |
| 3015 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3016 | case DataType::Type::kFloat32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3017 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3018 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3019 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3020 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3021 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3022 | case DataType::Type::kInt16: |
| 3023 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3024 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3025 | break; |
| 3026 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3027 | case DataType::Type::kInt64: { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3028 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3029 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3030 | // Create stack space for the call to |
| 3031 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 3032 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3033 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3034 | adjustment = DataType::Size(DataType::Type::kInt64); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 3035 | codegen_->IncreaseFrame(adjustment); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3036 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3037 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3038 | // Load the value to the FP stack, using temporaries if needed. |
| 3039 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 3040 | |
| 3041 | if (out.IsStackSlot()) { |
| 3042 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 3043 | } else { |
| 3044 | __ fstps(Address(ESP, 0)); |
| 3045 | Location stack_temp = Location::StackSlot(0); |
| 3046 | codegen_->Move32(out, stack_temp); |
| 3047 | } |
| 3048 | |
| 3049 | // Remove the temporary stack space we allocated. |
| 3050 | if (adjustment != 0) { |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 3051 | codegen_->DecreaseFrame(adjustment); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3052 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3053 | break; |
| 3054 | } |
| 3055 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3056 | case DataType::Type::kFloat64: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3057 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3058 | break; |
| 3059 | |
| 3060 | default: |
| 3061 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3062 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3063 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3064 | break; |
| 3065 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3066 | case DataType::Type::kFloat64: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3067 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3068 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3069 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3070 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3071 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3072 | case DataType::Type::kInt16: |
| 3073 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3074 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3075 | break; |
| 3076 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3077 | case DataType::Type::kInt64: { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3078 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3079 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3080 | // Create stack space for the call to |
| 3081 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 3082 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3083 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3084 | adjustment = DataType::Size(DataType::Type::kInt64); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 3085 | codegen_->IncreaseFrame(adjustment); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3086 | } |
| 3087 | |
| 3088 | // Load the value to the FP stack, using temporaries if needed. |
| 3089 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 3090 | |
| 3091 | if (out.IsDoubleStackSlot()) { |
| 3092 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 3093 | } else { |
| 3094 | __ fstpl(Address(ESP, 0)); |
| 3095 | Location stack_temp = Location::DoubleStackSlot(0); |
| 3096 | codegen_->Move64(out, stack_temp); |
| 3097 | } |
| 3098 | |
| 3099 | // Remove the temporary stack space we allocated. |
| 3100 | if (adjustment != 0) { |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 3101 | codegen_->DecreaseFrame(adjustment); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3102 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3103 | break; |
| 3104 | } |
| 3105 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3106 | case DataType::Type::kFloat32: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3107 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3108 | break; |
| 3109 | |
| 3110 | default: |
| 3111 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3112 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3113 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3114 | break; |
| 3115 | |
| 3116 | default: |
| 3117 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3118 | << " to " << result_type; |
| 3119 | } |
| 3120 | } |
| 3121 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3122 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3123 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3124 | new (GetGraph()->GetAllocator()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3125 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3126 | case DataType::Type::kInt32: { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3127 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3128 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 3129 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3130 | break; |
| 3131 | } |
| 3132 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3133 | case DataType::Type::kInt64: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3134 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3135 | locations->SetInAt(1, Location::Any()); |
| 3136 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3137 | break; |
| 3138 | } |
| 3139 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3140 | case DataType::Type::kFloat32: |
| 3141 | case DataType::Type::kFloat64: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3142 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3143 | if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3144 | DCHECK(add->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3145 | } else if (add->InputAt(1)->IsConstant()) { |
| 3146 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3147 | } else { |
| 3148 | locations->SetInAt(1, Location::Any()); |
| 3149 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3150 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3151 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3152 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3153 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3154 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3155 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 3156 | UNREACHABLE(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3157 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3158 | } |
| 3159 | |
| 3160 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 3161 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3162 | Location first = locations->InAt(0); |
| 3163 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3164 | Location out = locations->Out(); |
| 3165 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3166 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3167 | case DataType::Type::kInt32: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3168 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3169 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3170 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 3171 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 3172 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3173 | } else { |
| 3174 | __ leal(out.AsRegister<Register>(), Address( |
| 3175 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 3176 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3177 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3178 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3179 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3180 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 3181 | } else { |
| 3182 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 3183 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3184 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3185 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3186 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3187 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3188 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3189 | } |
| 3190 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3191 | case DataType::Type::kInt64: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3192 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3193 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3194 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3195 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3196 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 3197 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3198 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3199 | } else { |
| 3200 | DCHECK(second.IsConstant()) << second; |
| 3201 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3202 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 3203 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3204 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3205 | break; |
| 3206 | } |
| 3207 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3208 | case DataType::Type::kFloat32: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3209 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3210 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3211 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3212 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3213 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3214 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 3215 | codegen_->LiteralFloatAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3216 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3217 | const_area->GetBaseMethodAddress(), |
| 3218 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3219 | } else { |
| 3220 | DCHECK(second.IsStackSlot()); |
| 3221 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3222 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3223 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3224 | } |
| 3225 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3226 | case DataType::Type::kFloat64: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3227 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3228 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3229 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3230 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3231 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3232 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 3233 | codegen_->LiteralDoubleAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3234 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3235 | const_area->GetBaseMethodAddress(), |
| 3236 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3237 | } else { |
| 3238 | DCHECK(second.IsDoubleStackSlot()); |
| 3239 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3240 | } |
| 3241 | break; |
| 3242 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3243 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3244 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3245 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3246 | } |
| 3247 | } |
| 3248 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3249 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3250 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3251 | new (GetGraph()->GetAllocator()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3252 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3253 | case DataType::Type::kInt32: |
| 3254 | case DataType::Type::kInt64: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3255 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3256 | locations->SetInAt(1, Location::Any()); |
| 3257 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3258 | break; |
| 3259 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3260 | case DataType::Type::kFloat32: |
| 3261 | case DataType::Type::kFloat64: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3262 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3263 | if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3264 | DCHECK(sub->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3265 | } else if (sub->InputAt(1)->IsConstant()) { |
| 3266 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3267 | } else { |
| 3268 | locations->SetInAt(1, Location::Any()); |
| 3269 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3270 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3271 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3272 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3273 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3274 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3275 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3276 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3277 | } |
| 3278 | |
| 3279 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 3280 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3281 | Location first = locations->InAt(0); |
| 3282 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3283 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3284 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3285 | case DataType::Type::kInt32: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3286 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3287 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3288 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3289 | __ subl(first.AsRegister<Register>(), |
| 3290 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3291 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3292 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3293 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3294 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3295 | } |
| 3296 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3297 | case DataType::Type::kInt64: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3298 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3299 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3300 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3301 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3302 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3303 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 3304 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3305 | } else { |
| 3306 | DCHECK(second.IsConstant()) << second; |
| 3307 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3308 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 3309 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3310 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3311 | break; |
| 3312 | } |
| 3313 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3314 | case DataType::Type::kFloat32: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3315 | if (second.IsFpuRegister()) { |
| 3316 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3317 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3318 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3319 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3320 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3321 | codegen_->LiteralFloatAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3322 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3323 | const_area->GetBaseMethodAddress(), |
| 3324 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3325 | } else { |
| 3326 | DCHECK(second.IsStackSlot()); |
| 3327 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3328 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3329 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3330 | } |
| 3331 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3332 | case DataType::Type::kFloat64: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3333 | if (second.IsFpuRegister()) { |
| 3334 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3335 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3336 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3337 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3338 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3339 | codegen_->LiteralDoubleAddress( |
| 3340 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3341 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3342 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3343 | } else { |
| 3344 | DCHECK(second.IsDoubleStackSlot()); |
| 3345 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3346 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3347 | break; |
| 3348 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3349 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3350 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3351 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3352 | } |
| 3353 | } |
| 3354 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3355 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 3356 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3357 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3358 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3359 | case DataType::Type::kInt32: |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3360 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3361 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3362 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3363 | // Can use 3 operand multiply. |
| 3364 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3365 | } else { |
| 3366 | locations->SetOut(Location::SameAsFirstInput()); |
| 3367 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3368 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3369 | case DataType::Type::kInt64: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3370 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3371 | locations->SetInAt(1, Location::Any()); |
| 3372 | locations->SetOut(Location::SameAsFirstInput()); |
| 3373 | // Needed for imul on 32bits with 64bits output. |
| 3374 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 3375 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 3376 | break; |
| 3377 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3378 | case DataType::Type::kFloat32: |
| 3379 | case DataType::Type::kFloat64: { |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3380 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3381 | if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3382 | DCHECK(mul->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3383 | } else if (mul->InputAt(1)->IsConstant()) { |
| 3384 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3385 | } else { |
| 3386 | locations->SetInAt(1, Location::Any()); |
| 3387 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3388 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3389 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3390 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3391 | |
| 3392 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3393 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3394 | } |
| 3395 | } |
| 3396 | |
| 3397 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 3398 | LocationSummary* locations = mul->GetLocations(); |
| 3399 | Location first = locations->InAt(0); |
| 3400 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3401 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3402 | |
| 3403 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3404 | case DataType::Type::kInt32: |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3405 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3406 | // problems where the output may not be the same as the first operand. |
| 3407 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3408 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3409 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 3410 | } else if (second.IsRegister()) { |
| 3411 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3412 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3413 | } else { |
| 3414 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3415 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3416 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3417 | } |
| 3418 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3419 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3420 | case DataType::Type::kInt64: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3421 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 3422 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3423 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 3424 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3425 | |
| 3426 | DCHECK_EQ(EAX, eax); |
| 3427 | DCHECK_EQ(EDX, edx); |
| 3428 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3429 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3430 | // output: in1 |
| 3431 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3432 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3433 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3434 | if (second.IsConstant()) { |
| 3435 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3436 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3437 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3438 | int32_t low_value = Low32Bits(value); |
| 3439 | int32_t high_value = High32Bits(value); |
| 3440 | Immediate low(low_value); |
| 3441 | Immediate high(high_value); |
| 3442 | |
| 3443 | __ movl(eax, high); |
| 3444 | // eax <- in1.lo * in2.hi |
| 3445 | __ imull(eax, in1_lo); |
| 3446 | // in1.hi <- in1.hi * in2.lo |
| 3447 | __ imull(in1_hi, low); |
| 3448 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3449 | __ addl(in1_hi, eax); |
| 3450 | // move in2_lo to eax to prepare for double precision |
| 3451 | __ movl(eax, low); |
| 3452 | // edx:eax <- in1.lo * in2.lo |
| 3453 | __ mull(in1_lo); |
| 3454 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3455 | __ addl(in1_hi, edx); |
| 3456 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3457 | __ movl(in1_lo, eax); |
| 3458 | } else if (second.IsRegisterPair()) { |
| 3459 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3460 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3461 | |
| 3462 | __ movl(eax, in2_hi); |
| 3463 | // eax <- in1.lo * in2.hi |
| 3464 | __ imull(eax, in1_lo); |
| 3465 | // in1.hi <- in1.hi * in2.lo |
| 3466 | __ imull(in1_hi, in2_lo); |
| 3467 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3468 | __ addl(in1_hi, eax); |
| 3469 | // move in1_lo to eax to prepare for double precision |
| 3470 | __ movl(eax, in1_lo); |
| 3471 | // edx:eax <- in1.lo * in2.lo |
| 3472 | __ mull(in2_lo); |
| 3473 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3474 | __ addl(in1_hi, edx); |
| 3475 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3476 | __ movl(in1_lo, eax); |
| 3477 | } else { |
| 3478 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 3479 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 3480 | Address in2_lo(ESP, second.GetStackIndex()); |
| 3481 | |
| 3482 | __ movl(eax, in2_hi); |
| 3483 | // eax <- in1.lo * in2.hi |
| 3484 | __ imull(eax, in1_lo); |
| 3485 | // in1.hi <- in1.hi * in2.lo |
| 3486 | __ imull(in1_hi, in2_lo); |
| 3487 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3488 | __ addl(in1_hi, eax); |
| 3489 | // move in1_lo to eax to prepare for double precision |
| 3490 | __ movl(eax, in1_lo); |
| 3491 | // edx:eax <- in1.lo * in2.lo |
| 3492 | __ mull(in2_lo); |
| 3493 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3494 | __ addl(in1_hi, edx); |
| 3495 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3496 | __ movl(in1_lo, eax); |
| 3497 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3498 | |
| 3499 | break; |
| 3500 | } |
| 3501 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3502 | case DataType::Type::kFloat32: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3503 | DCHECK(first.Equals(locations->Out())); |
| 3504 | if (second.IsFpuRegister()) { |
| 3505 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3506 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3507 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3508 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3509 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3510 | codegen_->LiteralFloatAddress( |
| 3511 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3512 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3513 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3514 | } else { |
| 3515 | DCHECK(second.IsStackSlot()); |
| 3516 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3517 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3518 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3519 | } |
| 3520 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3521 | case DataType::Type::kFloat64: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3522 | DCHECK(first.Equals(locations->Out())); |
| 3523 | if (second.IsFpuRegister()) { |
| 3524 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3525 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3526 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3527 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3528 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3529 | codegen_->LiteralDoubleAddress( |
| 3530 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3531 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3532 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3533 | } else { |
| 3534 | DCHECK(second.IsDoubleStackSlot()); |
| 3535 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3536 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3537 | break; |
| 3538 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3539 | |
| 3540 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3541 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3542 | } |
| 3543 | } |
| 3544 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3545 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 3546 | uint32_t temp_offset, |
| 3547 | uint32_t stack_adjustment, |
| 3548 | bool is_fp, |
| 3549 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3550 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3551 | DCHECK(!is_wide); |
| 3552 | if (is_fp) { |
| 3553 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3554 | } else { |
| 3555 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3556 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3557 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3558 | DCHECK(is_wide); |
| 3559 | if (is_fp) { |
| 3560 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3561 | } else { |
| 3562 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3563 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3564 | } else { |
| 3565 | // 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] | 3566 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3567 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3568 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3569 | if (is_fp) { |
| 3570 | __ flds(Address(ESP, temp_offset)); |
| 3571 | } else { |
| 3572 | __ filds(Address(ESP, temp_offset)); |
| 3573 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3574 | } else { |
| 3575 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3576 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3577 | if (is_fp) { |
| 3578 | __ fldl(Address(ESP, temp_offset)); |
| 3579 | } else { |
| 3580 | __ fildl(Address(ESP, temp_offset)); |
| 3581 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3582 | } |
| 3583 | } |
| 3584 | } |
| 3585 | |
| 3586 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3587 | DataType::Type type = rem->GetResultType(); |
| 3588 | bool is_float = type == DataType::Type::kFloat32; |
| 3589 | size_t elem_size = DataType::Size(type); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3590 | LocationSummary* locations = rem->GetLocations(); |
| 3591 | Location first = locations->InAt(0); |
| 3592 | Location second = locations->InAt(1); |
| 3593 | Location out = locations->Out(); |
| 3594 | |
| 3595 | // Create stack space for 2 elements. |
| 3596 | // TODO: enhance register allocator to ask for stack temporaries. |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 3597 | codegen_->IncreaseFrame(2 * elem_size); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3598 | |
| 3599 | // 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] | 3600 | const bool is_wide = !is_float; |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3601 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp= */ true, is_wide); |
| 3602 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp= */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3603 | |
| 3604 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3605 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3606 | __ Bind(&retry); |
| 3607 | __ fprem(); |
| 3608 | |
| 3609 | // Move FP status to AX. |
| 3610 | __ fstsw(); |
| 3611 | |
| 3612 | // And see if the argument reduction is complete. This is signaled by the |
| 3613 | // C2 FPU flag bit set to 0. |
| 3614 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 3615 | __ j(kNotEqual, &retry); |
| 3616 | |
| 3617 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3618 | // Store FP top of stack to real stack. |
| 3619 | if (is_float) { |
| 3620 | __ fsts(Address(ESP, 0)); |
| 3621 | } else { |
| 3622 | __ fstl(Address(ESP, 0)); |
| 3623 | } |
| 3624 | |
| 3625 | // Pop the 2 items from the FP stack. |
| 3626 | __ fucompp(); |
| 3627 | |
| 3628 | // Load the value from the stack into an XMM register. |
| 3629 | DCHECK(out.IsFpuRegister()) << out; |
| 3630 | if (is_float) { |
| 3631 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3632 | } else { |
| 3633 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3634 | } |
| 3635 | |
| 3636 | // And remove the temporary stack space we allocated. |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 3637 | codegen_->DecreaseFrame(2 * elem_size); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3638 | } |
| 3639 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3640 | |
| 3641 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3642 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3643 | |
| 3644 | LocationSummary* locations = instruction->GetLocations(); |
| 3645 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3646 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3647 | |
| 3648 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3649 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3650 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3651 | |
| 3652 | DCHECK(imm == 1 || imm == -1); |
| 3653 | |
| 3654 | if (instruction->IsRem()) { |
| 3655 | __ xorl(out_register, out_register); |
| 3656 | } else { |
| 3657 | __ movl(out_register, input_register); |
| 3658 | if (imm == -1) { |
| 3659 | __ negl(out_register); |
| 3660 | } |
| 3661 | } |
| 3662 | } |
| 3663 | |
Shalini Salomi Bodapati | a66784b | 2018-11-06 13:05:44 +0530 | [diff] [blame] | 3664 | void InstructionCodeGeneratorX86::RemByPowerOfTwo(HRem* instruction) { |
| 3665 | LocationSummary* locations = instruction->GetLocations(); |
| 3666 | Location second = locations->InAt(1); |
| 3667 | |
| 3668 | Register out = locations->Out().AsRegister<Register>(); |
| 3669 | Register numerator = locations->InAt(0).AsRegister<Register>(); |
| 3670 | |
| 3671 | int32_t imm = Int64FromConstant(second.GetConstant()); |
| 3672 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3673 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
| 3674 | |
| 3675 | Register tmp = locations->GetTemp(0).AsRegister<Register>(); |
| 3676 | NearLabel done; |
| 3677 | __ movl(out, numerator); |
| 3678 | __ andl(out, Immediate(abs_imm-1)); |
| 3679 | __ j(Condition::kZero, &done); |
| 3680 | __ leal(tmp, Address(out, static_cast<int32_t>(~(abs_imm-1)))); |
| 3681 | __ testl(numerator, numerator); |
| 3682 | __ cmovl(Condition::kLess, out, tmp); |
| 3683 | __ Bind(&done); |
| 3684 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3685 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3686 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3687 | LocationSummary* locations = instruction->GetLocations(); |
| 3688 | |
| 3689 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3690 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3691 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3692 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3693 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3694 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3695 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 3696 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3697 | __ leal(num, Address(input_register, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3698 | __ testl(input_register, input_register); |
| 3699 | __ cmovl(kGreaterEqual, num, input_register); |
| 3700 | int shift = CTZ(imm); |
| 3701 | __ sarl(num, Immediate(shift)); |
| 3702 | |
| 3703 | if (imm < 0) { |
| 3704 | __ negl(num); |
| 3705 | } |
| 3706 | |
| 3707 | __ movl(out_register, num); |
| 3708 | } |
| 3709 | |
| 3710 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3711 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3712 | |
| 3713 | LocationSummary* locations = instruction->GetLocations(); |
| 3714 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 3715 | |
| 3716 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 3717 | Register out = locations->Out().AsRegister<Register>(); |
| 3718 | Register num; |
| 3719 | Register edx; |
| 3720 | |
| 3721 | if (instruction->IsDiv()) { |
| 3722 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 3723 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 3724 | } else { |
| 3725 | edx = locations->Out().AsRegister<Register>(); |
| 3726 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 3727 | } |
| 3728 | |
| 3729 | DCHECK_EQ(EAX, eax); |
| 3730 | DCHECK_EQ(EDX, edx); |
| 3731 | if (instruction->IsDiv()) { |
| 3732 | DCHECK_EQ(EAX, out); |
| 3733 | } else { |
| 3734 | DCHECK_EQ(EDX, out); |
| 3735 | } |
| 3736 | |
| 3737 | int64_t magic; |
| 3738 | int shift; |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3739 | CalculateMagicAndShiftForDivRem(imm, /* is_long= */ false, &magic, &shift); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3740 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3741 | // Save the numerator. |
| 3742 | __ movl(num, eax); |
| 3743 | |
| 3744 | // EAX = magic |
| 3745 | __ movl(eax, Immediate(magic)); |
| 3746 | |
| 3747 | // EDX:EAX = magic * numerator |
| 3748 | __ imull(num); |
| 3749 | |
| 3750 | if (imm > 0 && magic < 0) { |
| 3751 | // EDX += num |
| 3752 | __ addl(edx, num); |
| 3753 | } else if (imm < 0 && magic > 0) { |
| 3754 | __ subl(edx, num); |
| 3755 | } |
| 3756 | |
| 3757 | // Shift if needed. |
| 3758 | if (shift != 0) { |
| 3759 | __ sarl(edx, Immediate(shift)); |
| 3760 | } |
| 3761 | |
| 3762 | // EDX += 1 if EDX < 0 |
| 3763 | __ movl(eax, edx); |
| 3764 | __ shrl(edx, Immediate(31)); |
| 3765 | __ addl(edx, eax); |
| 3766 | |
| 3767 | if (instruction->IsRem()) { |
| 3768 | __ movl(eax, num); |
| 3769 | __ imull(edx, Immediate(imm)); |
| 3770 | __ subl(eax, edx); |
| 3771 | __ movl(edx, eax); |
| 3772 | } else { |
| 3773 | __ movl(eax, edx); |
| 3774 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3775 | } |
| 3776 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3777 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3778 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3779 | |
| 3780 | LocationSummary* locations = instruction->GetLocations(); |
| 3781 | Location out = locations->Out(); |
| 3782 | Location first = locations->InAt(0); |
| 3783 | Location second = locations->InAt(1); |
| 3784 | bool is_div = instruction->IsDiv(); |
| 3785 | |
| 3786 | switch (instruction->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3787 | case DataType::Type::kInt32: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3788 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 3789 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3790 | |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3791 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3792 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3793 | |
| 3794 | if (imm == 0) { |
| 3795 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 3796 | } else if (imm == 1 || imm == -1) { |
| 3797 | DivRemOneOrMinusOne(instruction); |
Shalini Salomi Bodapati | a66784b | 2018-11-06 13:05:44 +0530 | [diff] [blame] | 3798 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 3799 | if (is_div) { |
| 3800 | DivByPowerOfTwo(instruction->AsDiv()); |
| 3801 | } else { |
| 3802 | RemByPowerOfTwo(instruction->AsRem()); |
| 3803 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3804 | } else { |
| 3805 | DCHECK(imm <= -2 || imm >= 2); |
| 3806 | GenerateDivRemWithAnyConstant(instruction); |
| 3807 | } |
| 3808 | } else { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3809 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) DivRemMinusOneSlowPathX86( |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3810 | instruction, out.AsRegister<Register>(), is_div); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3811 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3812 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3813 | Register second_reg = second.AsRegister<Register>(); |
| 3814 | // 0x80000000/-1 triggers an arithmetic exception! |
| 3815 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 3816 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3817 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3818 | __ cmpl(second_reg, Immediate(-1)); |
| 3819 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3820 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3821 | // edx:eax <- sign-extended of eax |
| 3822 | __ cdq(); |
| 3823 | // eax = quotient, edx = remainder |
| 3824 | __ idivl(second_reg); |
| 3825 | __ Bind(slow_path->GetExitLabel()); |
| 3826 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3827 | break; |
| 3828 | } |
| 3829 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3830 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3831 | InvokeRuntimeCallingConvention calling_convention; |
| 3832 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3833 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3834 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3835 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3836 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 3837 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 3838 | |
| 3839 | if (is_div) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3840 | codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3841 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3842 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3843 | codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3844 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3845 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3846 | break; |
| 3847 | } |
| 3848 | |
| 3849 | default: |
| 3850 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 3851 | } |
| 3852 | } |
| 3853 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3854 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3855 | LocationSummary::CallKind call_kind = (div->GetResultType() == DataType::Type::kInt64) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3856 | ? LocationSummary::kCallOnMainOnly |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3857 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3858 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(div, call_kind); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3859 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3860 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3861 | case DataType::Type::kInt32: { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3862 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3863 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3864 | locations->SetOut(Location::SameAsFirstInput()); |
| 3865 | // Intel uses edx:eax as the dividend. |
| 3866 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3867 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3868 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 3869 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3870 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3871 | locations->AddTemp(Location::RequiresRegister()); |
| 3872 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3873 | break; |
| 3874 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3875 | case DataType::Type::kInt64: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3876 | InvokeRuntimeCallingConvention calling_convention; |
| 3877 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3878 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3879 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3880 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3881 | // Runtime helper puts the result in EAX, EDX. |
| 3882 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3883 | break; |
| 3884 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3885 | case DataType::Type::kFloat32: |
| 3886 | case DataType::Type::kFloat64: { |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3887 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3888 | if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3889 | DCHECK(div->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3890 | } else if (div->InputAt(1)->IsConstant()) { |
| 3891 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3892 | } else { |
| 3893 | locations->SetInAt(1, Location::Any()); |
| 3894 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3895 | locations->SetOut(Location::SameAsFirstInput()); |
| 3896 | break; |
| 3897 | } |
| 3898 | |
| 3899 | default: |
| 3900 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3901 | } |
| 3902 | } |
| 3903 | |
| 3904 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 3905 | LocationSummary* locations = div->GetLocations(); |
| 3906 | Location first = locations->InAt(0); |
| 3907 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3908 | |
| 3909 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3910 | case DataType::Type::kInt32: |
| 3911 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3912 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3913 | break; |
| 3914 | } |
| 3915 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3916 | case DataType::Type::kFloat32: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3917 | if (second.IsFpuRegister()) { |
| 3918 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3919 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3920 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3921 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3922 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3923 | codegen_->LiteralFloatAddress( |
| 3924 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3925 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3926 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3927 | } else { |
| 3928 | DCHECK(second.IsStackSlot()); |
| 3929 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3930 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3931 | break; |
| 3932 | } |
| 3933 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3934 | case DataType::Type::kFloat64: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3935 | if (second.IsFpuRegister()) { |
| 3936 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3937 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3938 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3939 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3940 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3941 | codegen_->LiteralDoubleAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3942 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3943 | const_area->GetBaseMethodAddress(), |
| 3944 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3945 | } else { |
| 3946 | DCHECK(second.IsDoubleStackSlot()); |
| 3947 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3948 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3949 | break; |
| 3950 | } |
| 3951 | |
| 3952 | default: |
| 3953 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3954 | } |
| 3955 | } |
| 3956 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3957 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3958 | DataType::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3959 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3960 | LocationSummary::CallKind call_kind = (rem->GetResultType() == DataType::Type::kInt64) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3961 | ? LocationSummary::kCallOnMainOnly |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3962 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3963 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3964 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3965 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3966 | case DataType::Type::kInt32: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3967 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3968 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3969 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3970 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3971 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 3972 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3973 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3974 | locations->AddTemp(Location::RequiresRegister()); |
| 3975 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3976 | break; |
| 3977 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3978 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3979 | InvokeRuntimeCallingConvention calling_convention; |
| 3980 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3981 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3982 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3983 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3984 | // Runtime helper puts the result in EAX, EDX. |
| 3985 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3986 | break; |
| 3987 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3988 | case DataType::Type::kFloat64: |
| 3989 | case DataType::Type::kFloat32: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3990 | locations->SetInAt(0, Location::Any()); |
| 3991 | locations->SetInAt(1, Location::Any()); |
| 3992 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3993 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3994 | break; |
| 3995 | } |
| 3996 | |
| 3997 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3998 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3999 | } |
| 4000 | } |
| 4001 | |
| 4002 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4003 | DataType::Type type = rem->GetResultType(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4004 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4005 | case DataType::Type::kInt32: |
| 4006 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4007 | GenerateDivRemIntegral(rem); |
| 4008 | break; |
| 4009 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4010 | case DataType::Type::kFloat32: |
| 4011 | case DataType::Type::kFloat64: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 4012 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4013 | break; |
| 4014 | } |
| 4015 | default: |
| 4016 | LOG(FATAL) << "Unexpected rem type " << type; |
| 4017 | } |
| 4018 | } |
| 4019 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4020 | static void CreateMinMaxLocations(ArenaAllocator* allocator, HBinaryOperation* minmax) { |
| 4021 | LocationSummary* locations = new (allocator) LocationSummary(minmax); |
| 4022 | switch (minmax->GetResultType()) { |
| 4023 | case DataType::Type::kInt32: |
| 4024 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4025 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4026 | locations->SetOut(Location::SameAsFirstInput()); |
| 4027 | break; |
| 4028 | case DataType::Type::kInt64: |
| 4029 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4030 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4031 | locations->SetOut(Location::SameAsFirstInput()); |
| 4032 | // Register to use to perform a long subtract to set cc. |
| 4033 | locations->AddTemp(Location::RequiresRegister()); |
| 4034 | break; |
| 4035 | case DataType::Type::kFloat32: |
| 4036 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4037 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4038 | locations->SetOut(Location::SameAsFirstInput()); |
| 4039 | locations->AddTemp(Location::RequiresRegister()); |
| 4040 | break; |
| 4041 | case DataType::Type::kFloat64: |
| 4042 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4043 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4044 | locations->SetOut(Location::SameAsFirstInput()); |
| 4045 | break; |
| 4046 | default: |
| 4047 | LOG(FATAL) << "Unexpected type for HMinMax " << minmax->GetResultType(); |
| 4048 | } |
| 4049 | } |
| 4050 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4051 | void InstructionCodeGeneratorX86::GenerateMinMaxInt(LocationSummary* locations, |
| 4052 | bool is_min, |
| 4053 | DataType::Type type) { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4054 | Location op1_loc = locations->InAt(0); |
| 4055 | Location op2_loc = locations->InAt(1); |
| 4056 | |
| 4057 | // Shortcut for same input locations. |
| 4058 | if (op1_loc.Equals(op2_loc)) { |
| 4059 | // Can return immediately, as op1_loc == out_loc. |
| 4060 | // Note: if we ever support separate registers, e.g., output into memory, we need to check for |
| 4061 | // a copy here. |
| 4062 | DCHECK(locations->Out().Equals(op1_loc)); |
| 4063 | return; |
| 4064 | } |
| 4065 | |
| 4066 | if (type == DataType::Type::kInt64) { |
| 4067 | // Need to perform a subtract to get the sign right. |
| 4068 | // op1 is already in the same location as the output. |
| 4069 | Location output = locations->Out(); |
| 4070 | Register output_lo = output.AsRegisterPairLow<Register>(); |
| 4071 | Register output_hi = output.AsRegisterPairHigh<Register>(); |
| 4072 | |
| 4073 | Register op2_lo = op2_loc.AsRegisterPairLow<Register>(); |
| 4074 | Register op2_hi = op2_loc.AsRegisterPairHigh<Register>(); |
| 4075 | |
| 4076 | // The comparison is performed by subtracting the second operand from |
| 4077 | // the first operand and then setting the status flags in the same |
| 4078 | // manner as the SUB instruction." |
| 4079 | __ cmpl(output_lo, op2_lo); |
| 4080 | |
| 4081 | // Now use a temp and the borrow to finish the subtraction of op2_hi. |
| 4082 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4083 | __ movl(temp, output_hi); |
| 4084 | __ sbbl(temp, op2_hi); |
| 4085 | |
| 4086 | // Now the condition code is correct. |
| 4087 | Condition cond = is_min ? Condition::kGreaterEqual : Condition::kLess; |
| 4088 | __ cmovl(cond, output_lo, op2_lo); |
| 4089 | __ cmovl(cond, output_hi, op2_hi); |
| 4090 | } else { |
| 4091 | DCHECK_EQ(type, DataType::Type::kInt32); |
| 4092 | Register out = locations->Out().AsRegister<Register>(); |
| 4093 | Register op2 = op2_loc.AsRegister<Register>(); |
| 4094 | |
| 4095 | // (out := op1) |
| 4096 | // out <=? op2 |
| 4097 | // if out is min jmp done |
| 4098 | // out := op2 |
| 4099 | // done: |
| 4100 | |
| 4101 | __ cmpl(out, op2); |
| 4102 | Condition cond = is_min ? Condition::kGreater : Condition::kLess; |
| 4103 | __ cmovl(cond, out, op2); |
| 4104 | } |
| 4105 | } |
| 4106 | |
| 4107 | void InstructionCodeGeneratorX86::GenerateMinMaxFP(LocationSummary* locations, |
| 4108 | bool is_min, |
| 4109 | DataType::Type type) { |
| 4110 | Location op1_loc = locations->InAt(0); |
| 4111 | Location op2_loc = locations->InAt(1); |
| 4112 | Location out_loc = locations->Out(); |
| 4113 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
| 4114 | |
| 4115 | // Shortcut for same input locations. |
| 4116 | if (op1_loc.Equals(op2_loc)) { |
| 4117 | DCHECK(out_loc.Equals(op1_loc)); |
| 4118 | return; |
| 4119 | } |
| 4120 | |
| 4121 | // (out := op1) |
| 4122 | // out <=? op2 |
| 4123 | // if Nan jmp Nan_label |
| 4124 | // if out is min jmp done |
| 4125 | // if op2 is min jmp op2_label |
| 4126 | // handle -0/+0 |
| 4127 | // jmp done |
| 4128 | // Nan_label: |
| 4129 | // out := NaN |
| 4130 | // op2_label: |
| 4131 | // out := op2 |
| 4132 | // done: |
| 4133 | // |
| 4134 | // This removes one jmp, but needs to copy one input (op1) to out. |
| 4135 | // |
| 4136 | // TODO: This is straight from Quick (except literal pool). Make NaN an out-of-line slowpath? |
| 4137 | |
| 4138 | XmmRegister op2 = op2_loc.AsFpuRegister<XmmRegister>(); |
| 4139 | |
| 4140 | NearLabel nan, done, op2_label; |
| 4141 | if (type == DataType::Type::kFloat64) { |
| 4142 | __ ucomisd(out, op2); |
| 4143 | } else { |
| 4144 | DCHECK_EQ(type, DataType::Type::kFloat32); |
| 4145 | __ ucomiss(out, op2); |
| 4146 | } |
| 4147 | |
| 4148 | __ j(Condition::kParityEven, &nan); |
| 4149 | |
| 4150 | __ j(is_min ? Condition::kAbove : Condition::kBelow, &op2_label); |
| 4151 | __ j(is_min ? Condition::kBelow : Condition::kAbove, &done); |
| 4152 | |
| 4153 | // Handle 0.0/-0.0. |
| 4154 | if (is_min) { |
| 4155 | if (type == DataType::Type::kFloat64) { |
| 4156 | __ orpd(out, op2); |
| 4157 | } else { |
| 4158 | __ orps(out, op2); |
| 4159 | } |
| 4160 | } else { |
| 4161 | if (type == DataType::Type::kFloat64) { |
| 4162 | __ andpd(out, op2); |
| 4163 | } else { |
| 4164 | __ andps(out, op2); |
| 4165 | } |
| 4166 | } |
| 4167 | __ jmp(&done); |
| 4168 | |
| 4169 | // NaN handling. |
| 4170 | __ Bind(&nan); |
| 4171 | if (type == DataType::Type::kFloat64) { |
| 4172 | // TODO: Use a constant from the constant table (requires extra input). |
| 4173 | __ LoadLongConstant(out, kDoubleNaN); |
| 4174 | } else { |
| 4175 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 4176 | __ movl(constant, Immediate(kFloatNaN)); |
| 4177 | __ movd(out, constant); |
| 4178 | } |
| 4179 | __ jmp(&done); |
| 4180 | |
| 4181 | // out := op2; |
| 4182 | __ Bind(&op2_label); |
| 4183 | if (type == DataType::Type::kFloat64) { |
| 4184 | __ movsd(out, op2); |
| 4185 | } else { |
| 4186 | __ movss(out, op2); |
| 4187 | } |
| 4188 | |
| 4189 | // Done. |
| 4190 | __ Bind(&done); |
| 4191 | } |
| 4192 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4193 | void InstructionCodeGeneratorX86::GenerateMinMax(HBinaryOperation* minmax, bool is_min) { |
| 4194 | DataType::Type type = minmax->GetResultType(); |
| 4195 | switch (type) { |
| 4196 | case DataType::Type::kInt32: |
| 4197 | case DataType::Type::kInt64: |
| 4198 | GenerateMinMaxInt(minmax->GetLocations(), is_min, type); |
| 4199 | break; |
| 4200 | case DataType::Type::kFloat32: |
| 4201 | case DataType::Type::kFloat64: |
| 4202 | GenerateMinMaxFP(minmax->GetLocations(), is_min, type); |
| 4203 | break; |
| 4204 | default: |
| 4205 | LOG(FATAL) << "Unexpected type for HMinMax " << type; |
| 4206 | } |
| 4207 | } |
| 4208 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4209 | void LocationsBuilderX86::VisitMin(HMin* min) { |
| 4210 | CreateMinMaxLocations(GetGraph()->GetAllocator(), min); |
| 4211 | } |
| 4212 | |
| 4213 | void InstructionCodeGeneratorX86::VisitMin(HMin* min) { |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4214 | GenerateMinMax(min, /*is_min*/ true); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4215 | } |
| 4216 | |
| 4217 | void LocationsBuilderX86::VisitMax(HMax* max) { |
| 4218 | CreateMinMaxLocations(GetGraph()->GetAllocator(), max); |
| 4219 | } |
| 4220 | |
| 4221 | void InstructionCodeGeneratorX86::VisitMax(HMax* max) { |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4222 | GenerateMinMax(max, /*is_min*/ false); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4223 | } |
| 4224 | |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 4225 | void LocationsBuilderX86::VisitAbs(HAbs* abs) { |
| 4226 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 4227 | switch (abs->GetResultType()) { |
| 4228 | case DataType::Type::kInt32: |
| 4229 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 4230 | locations->SetOut(Location::SameAsFirstInput()); |
| 4231 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 4232 | break; |
| 4233 | case DataType::Type::kInt64: |
| 4234 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4235 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4236 | locations->AddTemp(Location::RequiresRegister()); |
| 4237 | break; |
| 4238 | case DataType::Type::kFloat32: |
| 4239 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4240 | locations->SetOut(Location::SameAsFirstInput()); |
| 4241 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4242 | locations->AddTemp(Location::RequiresRegister()); |
| 4243 | break; |
| 4244 | case DataType::Type::kFloat64: |
| 4245 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4246 | locations->SetOut(Location::SameAsFirstInput()); |
| 4247 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4248 | break; |
| 4249 | default: |
| 4250 | LOG(FATAL) << "Unexpected type for HAbs " << abs->GetResultType(); |
| 4251 | } |
| 4252 | } |
| 4253 | |
| 4254 | void InstructionCodeGeneratorX86::VisitAbs(HAbs* abs) { |
| 4255 | LocationSummary* locations = abs->GetLocations(); |
| 4256 | switch (abs->GetResultType()) { |
| 4257 | case DataType::Type::kInt32: { |
| 4258 | Register out = locations->Out().AsRegister<Register>(); |
| 4259 | DCHECK_EQ(out, EAX); |
| 4260 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4261 | DCHECK_EQ(temp, EDX); |
| 4262 | // Sign extend EAX into EDX. |
| 4263 | __ cdq(); |
| 4264 | // XOR EAX with sign. |
| 4265 | __ xorl(EAX, EDX); |
| 4266 | // Subtract out sign to correct. |
| 4267 | __ subl(EAX, EDX); |
| 4268 | // The result is in EAX. |
| 4269 | break; |
| 4270 | } |
| 4271 | case DataType::Type::kInt64: { |
| 4272 | Location input = locations->InAt(0); |
| 4273 | Register input_lo = input.AsRegisterPairLow<Register>(); |
| 4274 | Register input_hi = input.AsRegisterPairHigh<Register>(); |
| 4275 | Location output = locations->Out(); |
| 4276 | Register output_lo = output.AsRegisterPairLow<Register>(); |
| 4277 | Register output_hi = output.AsRegisterPairHigh<Register>(); |
| 4278 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4279 | // Compute the sign into the temporary. |
| 4280 | __ movl(temp, input_hi); |
| 4281 | __ sarl(temp, Immediate(31)); |
| 4282 | // Store the sign into the output. |
| 4283 | __ movl(output_lo, temp); |
| 4284 | __ movl(output_hi, temp); |
| 4285 | // XOR the input to the output. |
| 4286 | __ xorl(output_lo, input_lo); |
| 4287 | __ xorl(output_hi, input_hi); |
| 4288 | // Subtract the sign. |
| 4289 | __ subl(output_lo, temp); |
| 4290 | __ sbbl(output_hi, temp); |
| 4291 | break; |
| 4292 | } |
| 4293 | case DataType::Type::kFloat32: { |
| 4294 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4295 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4296 | Register constant = locations->GetTemp(1).AsRegister<Register>(); |
| 4297 | __ movl(constant, Immediate(INT32_C(0x7FFFFFFF))); |
| 4298 | __ movd(temp, constant); |
| 4299 | __ andps(out, temp); |
| 4300 | break; |
| 4301 | } |
| 4302 | case DataType::Type::kFloat64: { |
| 4303 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4304 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4305 | // TODO: Use a constant from the constant table (requires extra input). |
| 4306 | __ LoadLongConstant(temp, INT64_C(0x7FFFFFFFFFFFFFFF)); |
| 4307 | __ andpd(out, temp); |
| 4308 | break; |
| 4309 | } |
| 4310 | default: |
| 4311 | LOG(FATAL) << "Unexpected type for HAbs " << abs->GetResultType(); |
| 4312 | } |
| 4313 | } |
| 4314 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4315 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4316 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4317 | switch (instruction->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4318 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4319 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4320 | case DataType::Type::kInt8: |
| 4321 | case DataType::Type::kUint16: |
| 4322 | case DataType::Type::kInt16: |
| 4323 | case DataType::Type::kInt32: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4324 | locations->SetInAt(0, Location::Any()); |
| 4325 | break; |
| 4326 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4327 | case DataType::Type::kInt64: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4328 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 4329 | if (!instruction->IsConstant()) { |
| 4330 | locations->AddTemp(Location::RequiresRegister()); |
| 4331 | } |
| 4332 | break; |
| 4333 | } |
| 4334 | default: |
| 4335 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 4336 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4337 | } |
| 4338 | |
| 4339 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4340 | SlowPathCode* slow_path = |
| 4341 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathX86(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4342 | codegen_->AddSlowPath(slow_path); |
| 4343 | |
| 4344 | LocationSummary* locations = instruction->GetLocations(); |
| 4345 | Location value = locations->InAt(0); |
| 4346 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4347 | switch (instruction->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4348 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4349 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4350 | case DataType::Type::kInt8: |
| 4351 | case DataType::Type::kUint16: |
| 4352 | case DataType::Type::kInt16: |
| 4353 | case DataType::Type::kInt32: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4354 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4355 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4356 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4357 | } else if (value.IsStackSlot()) { |
| 4358 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 4359 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4360 | } else { |
| 4361 | DCHECK(value.IsConstant()) << value; |
| 4362 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4363 | __ jmp(slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4364 | } |
| 4365 | } |
| 4366 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4367 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4368 | case DataType::Type::kInt64: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4369 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4370 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4371 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 4372 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 4373 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4374 | } else { |
| 4375 | DCHECK(value.IsConstant()) << value; |
| 4376 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 4377 | __ jmp(slow_path->GetEntryLabel()); |
| 4378 | } |
| 4379 | } |
| 4380 | break; |
| 4381 | } |
| 4382 | default: |
| 4383 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4384 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4385 | } |
| 4386 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4387 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 4388 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4389 | |
| 4390 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4391 | new (GetGraph()->GetAllocator()) LocationSummary(op, LocationSummary::kNoCall); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4392 | |
| 4393 | switch (op->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4394 | case DataType::Type::kInt32: |
| 4395 | case DataType::Type::kInt64: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4396 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4397 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4398 | // The shift count needs to be in CL or a constant. |
| 4399 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4400 | locations->SetOut(Location::SameAsFirstInput()); |
| 4401 | break; |
| 4402 | } |
| 4403 | default: |
| 4404 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 4405 | } |
| 4406 | } |
| 4407 | |
| 4408 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 4409 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4410 | |
| 4411 | LocationSummary* locations = op->GetLocations(); |
| 4412 | Location first = locations->InAt(0); |
| 4413 | Location second = locations->InAt(1); |
| 4414 | DCHECK(first.Equals(locations->Out())); |
| 4415 | |
| 4416 | switch (op->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4417 | case DataType::Type::kInt32: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4418 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4419 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4420 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4421 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4422 | DCHECK_EQ(ECX, second_reg); |
| 4423 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4424 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4425 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4426 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4427 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4428 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4429 | } |
| 4430 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4431 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4432 | if (shift == 0) { |
| 4433 | return; |
| 4434 | } |
| 4435 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4436 | if (op->IsShl()) { |
| 4437 | __ shll(first_reg, imm); |
| 4438 | } else if (op->IsShr()) { |
| 4439 | __ sarl(first_reg, imm); |
| 4440 | } else { |
| 4441 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4442 | } |
| 4443 | } |
| 4444 | break; |
| 4445 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4446 | case DataType::Type::kInt64: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4447 | if (second.IsRegister()) { |
| 4448 | Register second_reg = second.AsRegister<Register>(); |
| 4449 | DCHECK_EQ(ECX, second_reg); |
| 4450 | if (op->IsShl()) { |
| 4451 | GenerateShlLong(first, second_reg); |
| 4452 | } else if (op->IsShr()) { |
| 4453 | GenerateShrLong(first, second_reg); |
| 4454 | } else { |
| 4455 | GenerateUShrLong(first, second_reg); |
| 4456 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4457 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4458 | // Shift by a constant. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4459 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4460 | // Nothing to do if the shift is 0, as the input is already the output. |
| 4461 | if (shift != 0) { |
| 4462 | if (op->IsShl()) { |
| 4463 | GenerateShlLong(first, shift); |
| 4464 | } else if (op->IsShr()) { |
| 4465 | GenerateShrLong(first, shift); |
| 4466 | } else { |
| 4467 | GenerateUShrLong(first, shift); |
| 4468 | } |
| 4469 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4470 | } |
| 4471 | break; |
| 4472 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4473 | default: |
| 4474 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 4475 | } |
| 4476 | } |
| 4477 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4478 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 4479 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4480 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 4481 | if (shift == 1) { |
| 4482 | // This is just an addition. |
| 4483 | __ addl(low, low); |
| 4484 | __ adcl(high, high); |
| 4485 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4486 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 4487 | codegen_->EmitParallelMoves( |
| 4488 | loc.ToLow(), |
| 4489 | loc.ToHigh(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4490 | DataType::Type::kInt32, |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4491 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 4492 | loc.ToLow(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4493 | DataType::Type::kInt32); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4494 | } else if (shift > 32) { |
| 4495 | // Low part becomes 0. High part is low part << (shift-32). |
| 4496 | __ movl(high, low); |
| 4497 | __ shll(high, Immediate(shift - 32)); |
| 4498 | __ xorl(low, low); |
| 4499 | } else { |
| 4500 | // Between 1 and 31. |
| 4501 | __ shld(high, low, Immediate(shift)); |
| 4502 | __ shll(low, Immediate(shift)); |
| 4503 | } |
| 4504 | } |
| 4505 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4506 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4507 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4508 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 4509 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 4510 | __ testl(shifter, Immediate(32)); |
| 4511 | __ j(kEqual, &done); |
| 4512 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 4513 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 4514 | __ Bind(&done); |
| 4515 | } |
| 4516 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4517 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 4518 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4519 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 4520 | if (shift == 32) { |
| 4521 | // Need to copy the sign. |
| 4522 | DCHECK_NE(low, high); |
| 4523 | __ movl(low, high); |
| 4524 | __ sarl(high, Immediate(31)); |
| 4525 | } else if (shift > 32) { |
| 4526 | DCHECK_NE(low, high); |
| 4527 | // High part becomes sign. Low part is shifted by shift - 32. |
| 4528 | __ movl(low, high); |
| 4529 | __ sarl(high, Immediate(31)); |
| 4530 | __ sarl(low, Immediate(shift - 32)); |
| 4531 | } else { |
| 4532 | // Between 1 and 31. |
| 4533 | __ shrd(low, high, Immediate(shift)); |
| 4534 | __ sarl(high, Immediate(shift)); |
| 4535 | } |
| 4536 | } |
| 4537 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4538 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4539 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4540 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4541 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4542 | __ testl(shifter, Immediate(32)); |
| 4543 | __ j(kEqual, &done); |
| 4544 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4545 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 4546 | __ Bind(&done); |
| 4547 | } |
| 4548 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4549 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 4550 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4551 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 4552 | if (shift == 32) { |
| 4553 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 4554 | codegen_->EmitParallelMoves( |
| 4555 | loc.ToHigh(), |
| 4556 | loc.ToLow(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4557 | DataType::Type::kInt32, |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4558 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 4559 | loc.ToHigh(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4560 | DataType::Type::kInt32); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4561 | } else if (shift > 32) { |
| 4562 | // Low part is high >> (shift - 32). High part becomes 0. |
| 4563 | __ movl(low, high); |
| 4564 | __ shrl(low, Immediate(shift - 32)); |
| 4565 | __ xorl(high, high); |
| 4566 | } else { |
| 4567 | // Between 1 and 31. |
| 4568 | __ shrd(low, high, Immediate(shift)); |
| 4569 | __ shrl(high, Immediate(shift)); |
| 4570 | } |
| 4571 | } |
| 4572 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4573 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4574 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4575 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4576 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4577 | __ testl(shifter, Immediate(32)); |
| 4578 | __ j(kEqual, &done); |
| 4579 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4580 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 4581 | __ Bind(&done); |
| 4582 | } |
| 4583 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4584 | void LocationsBuilderX86::VisitRor(HRor* ror) { |
| 4585 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4586 | new (GetGraph()->GetAllocator()) LocationSummary(ror, LocationSummary::kNoCall); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4587 | |
| 4588 | switch (ror->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4589 | case DataType::Type::kInt64: |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4590 | // Add the temporary needed. |
| 4591 | locations->AddTemp(Location::RequiresRegister()); |
| 4592 | FALLTHROUGH_INTENDED; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4593 | case DataType::Type::kInt32: |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4594 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4595 | // The shift count needs to be in CL (unless it is a constant). |
| 4596 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); |
| 4597 | locations->SetOut(Location::SameAsFirstInput()); |
| 4598 | break; |
| 4599 | default: |
| 4600 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4601 | UNREACHABLE(); |
| 4602 | } |
| 4603 | } |
| 4604 | |
| 4605 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { |
| 4606 | LocationSummary* locations = ror->GetLocations(); |
| 4607 | Location first = locations->InAt(0); |
| 4608 | Location second = locations->InAt(1); |
| 4609 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4610 | if (ror->GetResultType() == DataType::Type::kInt32) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4611 | Register first_reg = first.AsRegister<Register>(); |
| 4612 | if (second.IsRegister()) { |
| 4613 | Register second_reg = second.AsRegister<Register>(); |
| 4614 | __ rorl(first_reg, second_reg); |
| 4615 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4616 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4617 | __ rorl(first_reg, imm); |
| 4618 | } |
| 4619 | return; |
| 4620 | } |
| 4621 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4622 | DCHECK_EQ(ror->GetResultType(), DataType::Type::kInt64); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4623 | Register first_reg_lo = first.AsRegisterPairLow<Register>(); |
| 4624 | Register first_reg_hi = first.AsRegisterPairHigh<Register>(); |
| 4625 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 4626 | if (second.IsRegister()) { |
| 4627 | Register second_reg = second.AsRegister<Register>(); |
| 4628 | DCHECK_EQ(second_reg, ECX); |
| 4629 | __ movl(temp_reg, first_reg_hi); |
| 4630 | __ shrd(first_reg_hi, first_reg_lo, second_reg); |
| 4631 | __ shrd(first_reg_lo, temp_reg, second_reg); |
| 4632 | __ movl(temp_reg, first_reg_hi); |
| 4633 | __ testl(second_reg, Immediate(32)); |
| 4634 | __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); |
| 4635 | __ cmovl(kNotEqual, first_reg_lo, temp_reg); |
| 4636 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4637 | int32_t shift_amt = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4638 | if (shift_amt == 0) { |
| 4639 | // Already fine. |
| 4640 | return; |
| 4641 | } |
| 4642 | if (shift_amt == 32) { |
| 4643 | // Just swap. |
| 4644 | __ movl(temp_reg, first_reg_lo); |
| 4645 | __ movl(first_reg_lo, first_reg_hi); |
| 4646 | __ movl(first_reg_hi, temp_reg); |
| 4647 | return; |
| 4648 | } |
| 4649 | |
| 4650 | Immediate imm(shift_amt); |
| 4651 | // Save the constents of the low value. |
| 4652 | __ movl(temp_reg, first_reg_lo); |
| 4653 | |
| 4654 | // Shift right into low, feeding bits from high. |
| 4655 | __ shrd(first_reg_lo, first_reg_hi, imm); |
| 4656 | |
| 4657 | // Shift right into high, feeding bits from the original low. |
| 4658 | __ shrd(first_reg_hi, temp_reg, imm); |
| 4659 | |
| 4660 | // Swap if needed. |
| 4661 | if (shift_amt > 32) { |
| 4662 | __ movl(temp_reg, first_reg_lo); |
| 4663 | __ movl(first_reg_lo, first_reg_hi); |
| 4664 | __ movl(first_reg_hi, temp_reg); |
| 4665 | } |
| 4666 | } |
| 4667 | } |
| 4668 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4669 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 4670 | HandleShift(shl); |
| 4671 | } |
| 4672 | |
| 4673 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 4674 | HandleShift(shl); |
| 4675 | } |
| 4676 | |
| 4677 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 4678 | HandleShift(shr); |
| 4679 | } |
| 4680 | |
| 4681 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 4682 | HandleShift(shr); |
| 4683 | } |
| 4684 | |
| 4685 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 4686 | HandleShift(ushr); |
| 4687 | } |
| 4688 | |
| 4689 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 4690 | HandleShift(ushr); |
| 4691 | } |
| 4692 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4693 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4694 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4695 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4696 | locations->SetOut(Location::RegisterLocation(EAX)); |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 4697 | InvokeRuntimeCallingConvention calling_convention; |
| 4698 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4699 | } |
| 4700 | |
| 4701 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 4702 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
| 4703 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| 4704 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4705 | } |
| 4706 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4707 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4708 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4709 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4710 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 4711 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4712 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4713 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4714 | } |
| 4715 | |
| 4716 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 4717 | // Note: if heap poisoning is enabled, the entry point takes care of poisoning the reference. |
| 4718 | QuickEntrypointEnum entrypoint = CodeGenerator::GetArrayAllocationEntrypoint(instruction); |
Nicolas Geoffray | d095844 | 2017-01-30 14:57:16 +0000 | [diff] [blame] | 4719 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4720 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4721 | DCHECK(!codegen_->IsLeafMethod()); |
| 4722 | } |
| 4723 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4724 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4725 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4726 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4727 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4728 | if (location.IsStackSlot()) { |
| 4729 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4730 | } else if (location.IsDoubleStackSlot()) { |
| 4731 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4732 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4733 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4734 | } |
| 4735 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4736 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 4737 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 4738 | } |
| 4739 | |
| 4740 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4741 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4742 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4743 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4744 | } |
| 4745 | |
| 4746 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4747 | } |
| 4748 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4749 | void LocationsBuilderX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4750 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4751 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4752 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4753 | locations->SetOut(Location::RequiresRegister()); |
| 4754 | } |
| 4755 | |
| 4756 | void InstructionCodeGeneratorX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4757 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4758 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4759 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4760 | instruction->GetIndex(), kX86PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4761 | __ movl(locations->Out().AsRegister<Register>(), |
| 4762 | Address(locations->InAt(0).AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4763 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4764 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4765 | instruction->GetIndex(), kX86PointerSize)); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4766 | __ movl(locations->Out().AsRegister<Register>(), |
| 4767 | Address(locations->InAt(0).AsRegister<Register>(), |
| 4768 | mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
| 4769 | // temp = temp->GetImtEntryAt(method_offset); |
| 4770 | __ movl(locations->Out().AsRegister<Register>(), |
| 4771 | Address(locations->Out().AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4772 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4773 | } |
| 4774 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4775 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4776 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4777 | new (GetGraph()->GetAllocator()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4778 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4779 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4780 | } |
| 4781 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4782 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 4783 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4784 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4785 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4786 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4787 | switch (not_->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4788 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4789 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4790 | break; |
| 4791 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4792 | case DataType::Type::kInt64: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4793 | __ notl(out.AsRegisterPairLow<Register>()); |
| 4794 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4795 | break; |
| 4796 | |
| 4797 | default: |
| 4798 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4799 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4800 | } |
| 4801 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4802 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4803 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4804 | new (GetGraph()->GetAllocator()) LocationSummary(bool_not, LocationSummary::kNoCall); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4805 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4806 | locations->SetOut(Location::SameAsFirstInput()); |
| 4807 | } |
| 4808 | |
| 4809 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4810 | LocationSummary* locations = bool_not->GetLocations(); |
| 4811 | Location in = locations->InAt(0); |
| 4812 | Location out = locations->Out(); |
| 4813 | DCHECK(in.Equals(out)); |
| 4814 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 4815 | } |
| 4816 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4817 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4818 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4819 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4820 | switch (compare->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4821 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4822 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4823 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4824 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4825 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4826 | case DataType::Type::kInt32: |
| 4827 | case DataType::Type::kInt64: { |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4828 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4829 | locations->SetInAt(1, Location::Any()); |
| 4830 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4831 | break; |
| 4832 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4833 | case DataType::Type::kFloat32: |
| 4834 | case DataType::Type::kFloat64: { |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4835 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4836 | if (compare->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4837 | DCHECK(compare->InputAt(1)->IsEmittedAtUseSite()); |
| 4838 | } else if (compare->InputAt(1)->IsConstant()) { |
| 4839 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4840 | } else { |
| 4841 | locations->SetInAt(1, Location::Any()); |
| 4842 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4843 | locations->SetOut(Location::RequiresRegister()); |
| 4844 | break; |
| 4845 | } |
| 4846 | default: |
| 4847 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4848 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4849 | } |
| 4850 | |
| 4851 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4852 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4853 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4854 | Location left = locations->InAt(0); |
| 4855 | Location right = locations->InAt(1); |
| 4856 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4857 | NearLabel less, greater, done; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4858 | Condition less_cond = kLess; |
| 4859 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4860 | switch (compare->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4861 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4862 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4863 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4864 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4865 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4866 | case DataType::Type::kInt32: { |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 4867 | codegen_->GenerateIntCompare(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4868 | break; |
| 4869 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4870 | case DataType::Type::kInt64: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4871 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 4872 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 4873 | int32_t val_low = 0; |
| 4874 | int32_t val_high = 0; |
| 4875 | bool right_is_const = false; |
| 4876 | |
| 4877 | if (right.IsConstant()) { |
| 4878 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 4879 | right_is_const = true; |
| 4880 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 4881 | val_low = Low32Bits(val); |
| 4882 | val_high = High32Bits(val); |
| 4883 | } |
| 4884 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4885 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4886 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4887 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4888 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4889 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4890 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4891 | codegen_->Compare32BitValue(left_high, val_high); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4892 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4893 | __ j(kLess, &less); // Signed compare. |
| 4894 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4895 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4896 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4897 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4898 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4899 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4900 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4901 | codegen_->Compare32BitValue(left_low, val_low); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4902 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4903 | less_cond = kBelow; // for CF (unsigned). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4904 | break; |
| 4905 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4906 | case DataType::Type::kFloat32: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4907 | GenerateFPCompare(left, right, compare, false); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4908 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4909 | less_cond = kBelow; // for CF (floats). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4910 | break; |
| 4911 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4912 | case DataType::Type::kFloat64: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4913 | GenerateFPCompare(left, right, compare, true); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4914 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4915 | less_cond = kBelow; // for CF (floats). |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4916 | break; |
| 4917 | } |
| 4918 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4919 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4920 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4921 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4922 | __ movl(out, Immediate(0)); |
| 4923 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4924 | __ j(less_cond, &less); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4925 | |
| 4926 | __ Bind(&greater); |
| 4927 | __ movl(out, Immediate(1)); |
| 4928 | __ jmp(&done); |
| 4929 | |
| 4930 | __ Bind(&less); |
| 4931 | __ movl(out, Immediate(-1)); |
| 4932 | |
| 4933 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4934 | } |
| 4935 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4936 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4937 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4938 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4939 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4940 | locations->SetInAt(i, Location::Any()); |
| 4941 | } |
| 4942 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4943 | } |
| 4944 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4945 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4946 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4947 | } |
| 4948 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4949 | void CodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4950 | /* |
| 4951 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 4952 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 4953 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4954 | */ |
| 4955 | switch (kind) { |
| 4956 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4957 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4958 | break; |
| 4959 | } |
| 4960 | case MemBarrierKind::kAnyStore: |
| 4961 | case MemBarrierKind::kLoadAny: |
| 4962 | case MemBarrierKind::kStoreStore: { |
| 4963 | // nop |
| 4964 | break; |
| 4965 | } |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4966 | case MemBarrierKind::kNTStoreStore: |
| 4967 | // Non-Temporal Store/Store needs an explicit fence. |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4968 | MemoryFence(/* non-temporal= */ true); |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4969 | break; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4970 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4971 | } |
| 4972 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4973 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( |
| 4974 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | bdb2ecc | 2018-09-18 14:33:55 +0100 | [diff] [blame] | 4975 | ArtMethod* method ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4976 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4977 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4978 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4979 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 4980 | Register temp) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4981 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4982 | if (!invoke->GetLocations()->Intrinsified()) { |
| 4983 | return location.AsRegister<Register>(); |
| 4984 | } |
| 4985 | // For intrinsics we allow any location, so it may be on the stack. |
| 4986 | if (!location.IsRegister()) { |
| 4987 | __ movl(temp, Address(ESP, location.GetStackIndex())); |
| 4988 | return temp; |
| 4989 | } |
| 4990 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 4991 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 4992 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 4993 | // simple and more robust approach rather that trying to determine if that's the case. |
| 4994 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
Vladimir Marko | 4ee8e29 | 2017-06-02 15:39:30 +0000 | [diff] [blame] | 4995 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 4996 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 4997 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 4998 | __ movl(temp, Address(ESP, stack_offset)); |
| 4999 | return temp; |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 5000 | } |
| 5001 | return location.AsRegister<Register>(); |
| 5002 | } |
| 5003 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5004 | void CodeGeneratorX86::GenerateStaticOrDirectCall( |
| 5005 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5006 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 5007 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5008 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5009 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5010 | uint32_t offset = |
| 5011 | GetThreadOffset<kX86PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 5012 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5013 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 5014 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5015 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 5016 | callee_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5017 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5018 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 5019 | DCHECK(GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5020 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 5021 | temp.AsRegister<Register>()); |
| 5022 | __ leal(temp.AsRegister<Register>(), Address(base_reg, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5023 | RecordBootImageMethodPatch(invoke); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5024 | break; |
| 5025 | } |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 5026 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageRelRo: { |
| 5027 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 5028 | temp.AsRegister<Register>()); |
| 5029 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
| 5030 | RecordBootImageRelRoPatch( |
| 5031 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(), |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5032 | GetBootImageOffset(invoke)); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 5033 | break; |
| 5034 | } |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5035 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 5036 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 5037 | temp.AsRegister<Register>()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 5038 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5039 | RecordMethodBssEntryPatch(invoke); |
Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 5040 | // No need for memory fence, thanks to the x86 memory model. |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 5041 | break; |
| 5042 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5043 | case HInvokeStaticOrDirect::MethodLoadKind::kJitDirectAddress: |
| 5044 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 5045 | break; |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5046 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 5047 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 5048 | return; // No code pointer retrieval; the runtime performs the call directly. |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 5049 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5050 | } |
| 5051 | |
| 5052 | switch (invoke->GetCodePtrLocation()) { |
| 5053 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 5054 | __ call(GetFrameEntryLabel()); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 5055 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5056 | break; |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 5057 | case HInvokeStaticOrDirect::CodePtrLocation::kCallCriticalNative: { |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 5058 | size_t out_frame_size = |
| 5059 | PrepareCriticalNativeCall<CriticalNativeCallingConventionVisitorX86, |
| 5060 | kNativeStackAlignment, |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 5061 | GetCriticalNativeDirectCallFrameSize>(invoke); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 5062 | // (callee_method + offset_of_jni_entry_point)() |
| 5063 | __ call(Address(callee_method.AsRegister<Register>(), |
| 5064 | ArtMethod::EntryPointFromJniOffset(kX86PointerSize).Int32Value())); |
| 5065 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 5066 | if (out_frame_size == 0u && DataType::IsFloatingPointType(invoke->GetType())) { |
| 5067 | // Create space for conversion. |
| 5068 | out_frame_size = 8u; |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 5069 | IncreaseFrame(out_frame_size); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 5070 | } |
| 5071 | // Zero-/sign-extend or move the result when needed due to native and managed ABI mismatch. |
| 5072 | switch (invoke->GetType()) { |
| 5073 | case DataType::Type::kBool: |
| 5074 | __ movzxb(EAX, AL); |
| 5075 | break; |
| 5076 | case DataType::Type::kInt8: |
| 5077 | __ movsxb(EAX, AL); |
| 5078 | break; |
| 5079 | case DataType::Type::kUint16: |
| 5080 | __ movzxw(EAX, EAX); |
| 5081 | break; |
| 5082 | case DataType::Type::kInt16: |
| 5083 | __ movsxw(EAX, EAX); |
| 5084 | break; |
| 5085 | case DataType::Type::kFloat32: |
| 5086 | __ fstps(Address(ESP, 0)); |
| 5087 | __ movss(XMM0, Address(ESP, 0)); |
| 5088 | break; |
| 5089 | case DataType::Type::kFloat64: |
| 5090 | __ fstpl(Address(ESP, 0)); |
| 5091 | __ movsd(XMM0, Address(ESP, 0)); |
| 5092 | break; |
| 5093 | case DataType::Type::kInt32: |
| 5094 | case DataType::Type::kInt64: |
| 5095 | case DataType::Type::kVoid: |
| 5096 | break; |
| 5097 | default: |
| 5098 | DCHECK(false) << invoke->GetType(); |
| 5099 | break; |
| 5100 | } |
| 5101 | if (out_frame_size != 0u) { |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 5102 | DecreaseFrame(out_frame_size); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 5103 | } |
| 5104 | break; |
| 5105 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5106 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 5107 | // (callee_method + offset_of_quick_compiled_code)() |
| 5108 | __ call(Address(callee_method.AsRegister<Register>(), |
| 5109 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5110 | kX86PointerSize).Int32Value())); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 5111 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5112 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 5113 | } |
| 5114 | |
| 5115 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 5116 | } |
| 5117 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5118 | void CodeGeneratorX86::GenerateVirtualCall( |
| 5119 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5120 | Register temp = temp_in.AsRegister<Register>(); |
| 5121 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 5122 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 5123 | |
| 5124 | // Use the calling convention instead of the location of the receiver, as |
| 5125 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 5126 | // slow path, the arguments have been moved to the right place, so here we are |
| 5127 | // guaranteed that the receiver is the first register of the calling convention. |
| 5128 | InvokeDexCallingConvention calling_convention; |
| 5129 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5130 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5131 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 5132 | __ movl(temp, Address(receiver, class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5133 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5134 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 5135 | // emit a read barrier for the previous class reference load. |
| 5136 | // However this is not required in practice, as this is an |
| 5137 | // intermediate/temporary reference and because the current |
| 5138 | // concurrent copying collector keeps the from-space memory |
| 5139 | // intact/accessible until the end of the marking phase (the |
| 5140 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5141 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 5142 | |
| 5143 | MaybeGenerateInlineCacheCheck(invoke, temp); |
| 5144 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5145 | // temp = temp->GetMethodAt(method_offset); |
| 5146 | __ movl(temp, Address(temp, method_offset)); |
| 5147 | // call temp->GetEntryPoint(); |
| 5148 | __ call(Address( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5149 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 5150 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 5151 | } |
| 5152 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5153 | void CodeGeneratorX86::RecordBootImageIntrinsicPatch(HX86ComputeBaseMethodAddress* method_address, |
| 5154 | uint32_t intrinsic_data) { |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5155 | boot_image_other_patches_.emplace_back( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5156 | method_address, /* target_dex_file= */ nullptr, intrinsic_data); |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5157 | __ Bind(&boot_image_other_patches_.back().label); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5158 | } |
| 5159 | |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 5160 | void CodeGeneratorX86::RecordBootImageRelRoPatch(HX86ComputeBaseMethodAddress* method_address, |
| 5161 | uint32_t boot_image_offset) { |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5162 | boot_image_other_patches_.emplace_back( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5163 | method_address, /* target_dex_file= */ nullptr, boot_image_offset); |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5164 | __ Bind(&boot_image_other_patches_.back().label); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 5165 | } |
| 5166 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5167 | void CodeGeneratorX86::RecordBootImageMethodPatch(HInvokeStaticOrDirect* invoke) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5168 | HX86ComputeBaseMethodAddress* method_address = |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5169 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5170 | boot_image_method_patches_.emplace_back( |
| 5171 | method_address, invoke->GetTargetMethod().dex_file, invoke->GetTargetMethod().index); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5172 | __ Bind(&boot_image_method_patches_.back().label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5173 | } |
| 5174 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5175 | void CodeGeneratorX86::RecordMethodBssEntryPatch(HInvokeStaticOrDirect* invoke) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5176 | HX86ComputeBaseMethodAddress* method_address = |
| 5177 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5178 | // 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] | 5179 | method_bss_entry_patches_.emplace_back( |
| 5180 | method_address, &GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()); |
| 5181 | __ Bind(&method_bss_entry_patches_.back().label); |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5182 | } |
| 5183 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5184 | void CodeGeneratorX86::RecordBootImageTypePatch(HLoadClass* load_class) { |
| 5185 | HX86ComputeBaseMethodAddress* method_address = |
| 5186 | load_class->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 5187 | boot_image_type_patches_.emplace_back( |
| 5188 | method_address, &load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5189 | __ Bind(&boot_image_type_patches_.back().label); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5190 | } |
| 5191 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5192 | Label* CodeGeneratorX86::NewTypeBssEntryPatch(HLoadClass* load_class) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5193 | HX86ComputeBaseMethodAddress* method_address = |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 5194 | load_class->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 5195 | type_bss_entry_patches_.emplace_back( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5196 | method_address, &load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5197 | return &type_bss_entry_patches_.back().label; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5198 | } |
| 5199 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5200 | void CodeGeneratorX86::RecordBootImageStringPatch(HLoadString* load_string) { |
| 5201 | HX86ComputeBaseMethodAddress* method_address = |
| 5202 | load_string->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 5203 | boot_image_string_patches_.emplace_back( |
| 5204 | method_address, &load_string->GetDexFile(), load_string->GetStringIndex().index_); |
| 5205 | __ Bind(&boot_image_string_patches_.back().label); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5206 | } |
| 5207 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5208 | Label* CodeGeneratorX86::NewStringBssEntryPatch(HLoadString* load_string) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5209 | HX86ComputeBaseMethodAddress* method_address = |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 5210 | load_string->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5211 | string_bss_entry_patches_.emplace_back( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5212 | method_address, &load_string->GetDexFile(), load_string->GetStringIndex().index_); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5213 | return &string_bss_entry_patches_.back().label; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5214 | } |
| 5215 | |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5216 | void CodeGeneratorX86::LoadBootImageAddress(Register reg, |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5217 | uint32_t boot_image_reference, |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5218 | HInvokeStaticOrDirect* invoke) { |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5219 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5220 | HX86ComputeBaseMethodAddress* method_address = |
| 5221 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
| 5222 | DCHECK(method_address != nullptr); |
| 5223 | Register method_address_reg = |
| 5224 | invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()).AsRegister<Register>(); |
| 5225 | __ leal(reg, Address(method_address_reg, CodeGeneratorX86::kDummy32BitOffset)); |
| 5226 | RecordBootImageIntrinsicPatch(method_address, boot_image_reference); |
Vladimir Marko | a2da9b9 | 2018-10-10 14:21:55 +0100 | [diff] [blame] | 5227 | } else if (GetCompilerOptions().GetCompilePic()) { |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5228 | HX86ComputeBaseMethodAddress* method_address = |
| 5229 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
| 5230 | DCHECK(method_address != nullptr); |
| 5231 | Register method_address_reg = |
| 5232 | invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()).AsRegister<Register>(); |
| 5233 | __ movl(reg, Address(method_address_reg, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5234 | RecordBootImageRelRoPatch(method_address, boot_image_reference); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5235 | } else { |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 5236 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5237 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 5238 | DCHECK(!heap->GetBootImageSpaces().empty()); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5239 | const uint8_t* address = heap->GetBootImageSpaces()[0]->Begin() + boot_image_reference; |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5240 | __ movl(reg, Immediate(dchecked_integral_cast<uint32_t>(reinterpret_cast<uintptr_t>(address)))); |
| 5241 | } |
| 5242 | } |
| 5243 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5244 | void CodeGeneratorX86::AllocateInstanceForIntrinsic(HInvokeStaticOrDirect* invoke, |
| 5245 | uint32_t boot_image_offset) { |
| 5246 | DCHECK(invoke->IsStatic()); |
| 5247 | InvokeRuntimeCallingConvention calling_convention; |
| 5248 | Register argument = calling_convention.GetRegisterAt(0); |
| 5249 | if (GetCompilerOptions().IsBootImage()) { |
| 5250 | DCHECK_EQ(boot_image_offset, IntrinsicVisitor::IntegerValueOfInfo::kInvalidReference); |
| 5251 | // Load the class the same way as for HLoadClass::LoadKind::kBootImageLinkTimePcRelative. |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5252 | HX86ComputeBaseMethodAddress* method_address = |
| 5253 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
| 5254 | DCHECK(method_address != nullptr); |
| 5255 | Register method_address_reg = |
| 5256 | invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()).AsRegister<Register>(); |
| 5257 | __ leal(argument, Address(method_address_reg, CodeGeneratorX86::kDummy32BitOffset)); |
| 5258 | MethodReference target_method = invoke->GetTargetMethod(); |
| 5259 | dex::TypeIndex type_idx = target_method.dex_file->GetMethodId(target_method.index).class_idx_; |
| 5260 | boot_image_type_patches_.emplace_back(method_address, target_method.dex_file, type_idx.index_); |
| 5261 | __ Bind(&boot_image_type_patches_.back().label); |
| 5262 | } else { |
| 5263 | LoadBootImageAddress(argument, boot_image_offset, invoke); |
| 5264 | } |
| 5265 | InvokeRuntime(kQuickAllocObjectInitialized, invoke, invoke->GetDexPc()); |
| 5266 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| 5267 | } |
| 5268 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5269 | // The label points to the end of the "movl" or another instruction but the literal offset |
| 5270 | // for method patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 5271 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
| 5272 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5273 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5274 | inline void CodeGeneratorX86::EmitPcRelativeLinkerPatches( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 5275 | const ArenaDeque<X86PcRelativePatchInfo>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5276 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 5277 | for (const X86PcRelativePatchInfo& info : infos) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5278 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5279 | linker_patches->push_back(Factory(literal_offset, |
| 5280 | info.target_dex_file, |
| 5281 | GetMethodAddressOffset(info.method_address), |
| 5282 | info.offset_or_index)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5283 | } |
| 5284 | } |
| 5285 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5286 | template <linker::LinkerPatch (*Factory)(size_t, uint32_t, uint32_t)> |
| 5287 | linker::LinkerPatch NoDexFileAdapter(size_t literal_offset, |
| 5288 | const DexFile* target_dex_file, |
| 5289 | uint32_t pc_insn_offset, |
| 5290 | uint32_t boot_image_offset) { |
| 5291 | DCHECK(target_dex_file == nullptr); // Unused for these patches, should be null. |
| 5292 | return Factory(literal_offset, pc_insn_offset, boot_image_offset); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 5293 | } |
| 5294 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5295 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5296 | DCHECK(linker_patches->empty()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 5297 | size_t size = |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5298 | boot_image_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5299 | method_bss_entry_patches_.size() + |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5300 | boot_image_type_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5301 | type_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5302 | boot_image_string_patches_.size() + |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5303 | string_bss_entry_patches_.size() + |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5304 | boot_image_other_patches_.size(); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 5305 | linker_patches->reserve(size); |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 5306 | if (GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5307 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
| 5308 | boot_image_method_patches_, linker_patches); |
| 5309 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
| 5310 | boot_image_type_patches_, linker_patches); |
| 5311 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5312 | boot_image_string_patches_, linker_patches); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5313 | } else { |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5314 | DCHECK(boot_image_method_patches_.empty()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5315 | DCHECK(boot_image_type_patches_.empty()); |
| 5316 | DCHECK(boot_image_string_patches_.empty()); |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5317 | } |
| 5318 | if (GetCompilerOptions().IsBootImage()) { |
| 5319 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::IntrinsicReferencePatch>>( |
| 5320 | boot_image_other_patches_, linker_patches); |
| 5321 | } else { |
| 5322 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::DataBimgRelRoPatch>>( |
| 5323 | boot_image_other_patches_, linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5324 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5325 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 5326 | method_bss_entry_patches_, linker_patches); |
| 5327 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 5328 | type_bss_entry_patches_, linker_patches); |
| 5329 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 5330 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5331 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5332 | } |
| 5333 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5334 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 5335 | Register card, |
| 5336 | Register object, |
| 5337 | Register value, |
| 5338 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 5339 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5340 | if (value_can_be_null) { |
| 5341 | __ testl(value, value); |
| 5342 | __ j(kEqual, &is_null); |
| 5343 | } |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5344 | // Load the address of the card table into `card`. |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5345 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86PointerSize>().Int32Value())); |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5346 | // Calculate the offset (in the card table) of the card corresponding to |
| 5347 | // `object`. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5348 | __ movl(temp, object); |
| 5349 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5350 | // Write the `art::gc::accounting::CardTable::kCardDirty` value into the |
| 5351 | // `object`'s card. |
| 5352 | // |
| 5353 | // Register `card` contains the address of the card table. Note that the card |
| 5354 | // table's base is biased during its creation so that it always starts at an |
| 5355 | // address whose least-significant byte is equal to `kCardDirty` (see |
| 5356 | // art::gc::accounting::CardTable::Create). Therefore the MOVB instruction |
| 5357 | // below writes the `kCardDirty` (byte) value into the `object`'s card |
| 5358 | // (located at `card + object >> kCardShift`). |
| 5359 | // |
| 5360 | // This dual use of the value in register `card` (1. to calculate the location |
| 5361 | // of the card to mark; and 2. to load the `kCardDirty` value) saves a load |
| 5362 | // (no need to explicitly load `kCardDirty` as an immediate value). |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 5363 | __ movb(Address(temp, card, TIMES_1, 0), |
| 5364 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5365 | if (value_can_be_null) { |
| 5366 | __ Bind(&is_null); |
| 5367 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5368 | } |
| 5369 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5370 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 5371 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5372 | |
| 5373 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5374 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5375 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5376 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 5377 | kEmitCompilerReadBarrier |
| 5378 | ? LocationSummary::kCallOnSlowPath |
| 5379 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5380 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5381 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5382 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5383 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5384 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5385 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5386 | locations->SetOut(Location::RequiresFpuRegister()); |
| 5387 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5388 | // The output overlaps in case of long: we don't want the low move |
| 5389 | // to overwrite the object's location. Likewise, in the case of |
| 5390 | // an object field get with read barriers enabled, we do not want |
| 5391 | // the move to overwrite the object's location, as we need it to emit |
| 5392 | // the read barrier. |
| 5393 | locations->SetOut( |
| 5394 | Location::RequiresRegister(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5395 | (object_field_get_with_read_barrier || instruction->GetType() == DataType::Type::kInt64) ? |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5396 | Location::kOutputOverlap : |
| 5397 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5398 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5399 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5400 | if (field_info.IsVolatile() && (field_info.GetFieldType() == DataType::Type::kInt64)) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5401 | // Long values can be loaded atomically into an XMM using movsd. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5402 | // So we use an XMM register as a temp to achieve atomicity (first |
| 5403 | // load the temp into the XMM and then copy the XMM into the |
| 5404 | // output, 32 bits at a time). |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5405 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 5406 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5407 | } |
| 5408 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5409 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 5410 | const FieldInfo& field_info) { |
| 5411 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5412 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5413 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5414 | Location base_loc = locations->InAt(0); |
| 5415 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5416 | Location out = locations->Out(); |
| 5417 | bool is_volatile = field_info.IsVolatile(); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5418 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 5419 | DataType::Type load_type = instruction->GetType(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5420 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5421 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5422 | switch (load_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5423 | case DataType::Type::kBool: |
| 5424 | case DataType::Type::kUint8: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5425 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5426 | break; |
| 5427 | } |
| 5428 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5429 | case DataType::Type::kInt8: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5430 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5431 | break; |
| 5432 | } |
| 5433 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5434 | case DataType::Type::kUint16: { |
| 5435 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5436 | break; |
| 5437 | } |
| 5438 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5439 | case DataType::Type::kInt16: { |
| 5440 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5441 | break; |
| 5442 | } |
| 5443 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5444 | case DataType::Type::kInt32: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5445 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5446 | break; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5447 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5448 | case DataType::Type::kReference: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5449 | // /* HeapReference<Object> */ out = *(base + offset) |
| 5450 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5451 | // Note that a potential implicit null check is handled in this |
| 5452 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 5453 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5454 | instruction, out, base, offset, /* needs_null_check= */ true); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5455 | if (is_volatile) { |
| 5456 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5457 | } |
| 5458 | } else { |
| 5459 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| 5460 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5461 | if (is_volatile) { |
| 5462 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5463 | } |
| 5464 | // If read barriers are enabled, emit read barriers other than |
| 5465 | // Baker's using a slow path (and also unpoison the loaded |
| 5466 | // reference, if heap poisoning is enabled). |
| 5467 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 5468 | } |
| 5469 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5470 | } |
| 5471 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5472 | case DataType::Type::kInt64: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5473 | if (is_volatile) { |
| 5474 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 5475 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5476 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5477 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 5478 | __ psrlq(temp, Immediate(32)); |
| 5479 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 5480 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5481 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5482 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5483 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5484 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 5485 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5486 | break; |
| 5487 | } |
| 5488 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5489 | case DataType::Type::kFloat32: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5490 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5491 | break; |
| 5492 | } |
| 5493 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5494 | case DataType::Type::kFloat64: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5495 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5496 | break; |
| 5497 | } |
| 5498 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5499 | case DataType::Type::kUint32: |
| 5500 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5501 | case DataType::Type::kVoid: |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5502 | LOG(FATAL) << "Unreachable type " << load_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5503 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5504 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5505 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5506 | if (load_type == DataType::Type::kReference || load_type == DataType::Type::kInt64) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5507 | // Potential implicit null checks, in the case of reference or |
| 5508 | // long fields, are handled in the previous switch statement. |
| 5509 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5510 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5511 | } |
| 5512 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5513 | if (is_volatile) { |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5514 | if (load_type == DataType::Type::kReference) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5515 | // Memory barriers, in the case of references, are also handled |
| 5516 | // in the previous switch statement. |
| 5517 | } else { |
| 5518 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5519 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5520 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5521 | } |
| 5522 | |
| 5523 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 5524 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5525 | |
| 5526 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5527 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5528 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5529 | bool is_volatile = field_info.IsVolatile(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5530 | DataType::Type field_type = field_info.GetFieldType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5531 | bool is_byte_type = DataType::Size(field_type) == 1u; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5532 | |
| 5533 | // The register allocator does not support multiple |
| 5534 | // inputs that die at entry with one in a specific register. |
| 5535 | if (is_byte_type) { |
| 5536 | // Ensure the value is in a byte register. |
| 5537 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5538 | } else if (DataType::IsFloatingPointType(field_type)) { |
| 5539 | if (is_volatile && field_type == DataType::Type::kFloat64) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5540 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 5541 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 5542 | } else { |
| 5543 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 5544 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5545 | } else if (is_volatile && field_type == DataType::Type::kInt64) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5546 | // 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] | 5547 | locations->SetInAt(1, Location::RequiresRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5548 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5549 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 5550 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 5551 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 5552 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 5553 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 5554 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 5555 | locations->AddTemp(Location::RequiresFpuRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5556 | } else { |
| 5557 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5558 | |
| 5559 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 5560 | // Temporary registers for the write barrier. |
| 5561 | locations->AddTemp(Location::RequiresRegister()); // May be used for reference poisoning too. |
| 5562 | // Ensure the card is in a byte register. |
| 5563 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 5564 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5565 | } |
| 5566 | } |
| 5567 | |
| 5568 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5569 | const FieldInfo& field_info, |
| 5570 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5571 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5572 | |
| 5573 | LocationSummary* locations = instruction->GetLocations(); |
| 5574 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 5575 | Location value = locations->InAt(1); |
| 5576 | bool is_volatile = field_info.IsVolatile(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5577 | DataType::Type field_type = field_info.GetFieldType(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5578 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5579 | bool needs_write_barrier = |
| 5580 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5581 | |
| 5582 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5583 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5584 | } |
| 5585 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5586 | bool maybe_record_implicit_null_check_done = false; |
| 5587 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5588 | switch (field_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5589 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5590 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5591 | case DataType::Type::kInt8: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5592 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 5593 | break; |
| 5594 | } |
| 5595 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5596 | case DataType::Type::kUint16: |
| 5597 | case DataType::Type::kInt16: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5598 | if (value.IsConstant()) { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5599 | __ movw(Address(base, offset), |
| 5600 | Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5601 | } else { |
| 5602 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 5603 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5604 | break; |
| 5605 | } |
| 5606 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5607 | case DataType::Type::kInt32: |
| 5608 | case DataType::Type::kReference: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5609 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 5610 | // Note that in the case where `value` is a null reference, |
| 5611 | // we do not enter this block, as the reference does not |
| 5612 | // need poisoning. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5613 | DCHECK_EQ(field_type, DataType::Type::kReference); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5614 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5615 | __ movl(temp, value.AsRegister<Register>()); |
| 5616 | __ PoisonHeapReference(temp); |
| 5617 | __ movl(Address(base, offset), temp); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5618 | } else if (value.IsConstant()) { |
| 5619 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5620 | __ movl(Address(base, offset), Immediate(v)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5621 | } else { |
Nicolas Geoffray | 0397163 | 2016-03-17 10:44:24 +0000 | [diff] [blame] | 5622 | DCHECK(value.IsRegister()) << value; |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5623 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 5624 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5625 | break; |
| 5626 | } |
| 5627 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5628 | case DataType::Type::kInt64: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5629 | if (is_volatile) { |
| 5630 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 5631 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 5632 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 5633 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 5634 | __ punpckldq(temp1, temp2); |
| 5635 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5636 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5637 | } else if (value.IsConstant()) { |
| 5638 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 5639 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 5640 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5641 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5642 | } else { |
| 5643 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5644 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5645 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 5646 | } |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5647 | maybe_record_implicit_null_check_done = true; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5648 | break; |
| 5649 | } |
| 5650 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5651 | case DataType::Type::kFloat32: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5652 | if (value.IsConstant()) { |
| 5653 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5654 | __ movl(Address(base, offset), Immediate(v)); |
| 5655 | } else { |
| 5656 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 5657 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5658 | break; |
| 5659 | } |
| 5660 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5661 | case DataType::Type::kFloat64: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5662 | if (value.IsConstant()) { |
| 5663 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 5664 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 5665 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5666 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
| 5667 | maybe_record_implicit_null_check_done = true; |
| 5668 | } else { |
| 5669 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 5670 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5671 | break; |
| 5672 | } |
| 5673 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5674 | case DataType::Type::kUint32: |
| 5675 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5676 | case DataType::Type::kVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5677 | LOG(FATAL) << "Unreachable type " << field_type; |
| 5678 | UNREACHABLE(); |
| 5679 | } |
| 5680 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5681 | if (!maybe_record_implicit_null_check_done) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5682 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5683 | } |
| 5684 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5685 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5686 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5687 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5688 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5689 | } |
| 5690 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5691 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5692 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5693 | } |
| 5694 | } |
| 5695 | |
| 5696 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5697 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5698 | } |
| 5699 | |
| 5700 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5701 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5702 | } |
| 5703 | |
| 5704 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 5705 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5706 | } |
| 5707 | |
| 5708 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5709 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5710 | } |
| 5711 | |
| 5712 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5713 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5714 | } |
| 5715 | |
| 5716 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5717 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5718 | } |
| 5719 | |
| 5720 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5721 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5722 | } |
| 5723 | |
| 5724 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5725 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5726 | } |
| 5727 | |
Vladimir Marko | 552a134 | 2017-10-31 10:56:47 +0000 | [diff] [blame] | 5728 | void LocationsBuilderX86::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 5729 | codegen_->CreateStringBuilderAppendLocations(instruction, Location::RegisterLocation(EAX)); |
| 5730 | } |
| 5731 | |
| 5732 | void InstructionCodeGeneratorX86::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 5733 | __ movl(EAX, Immediate(instruction->GetFormat()->GetValue())); |
| 5734 | codegen_->InvokeRuntime(kQuickStringBuilderAppend, instruction, instruction->GetDexPc()); |
| 5735 | } |
| 5736 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5737 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 5738 | HUnresolvedInstanceFieldGet* instruction) { |
| 5739 | FieldAccessCallingConventionX86 calling_convention; |
| 5740 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5741 | instruction, instruction->GetFieldType(), calling_convention); |
| 5742 | } |
| 5743 | |
| 5744 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 5745 | HUnresolvedInstanceFieldGet* instruction) { |
| 5746 | FieldAccessCallingConventionX86 calling_convention; |
| 5747 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5748 | instruction->GetFieldType(), |
| 5749 | instruction->GetFieldIndex(), |
| 5750 | instruction->GetDexPc(), |
| 5751 | calling_convention); |
| 5752 | } |
| 5753 | |
| 5754 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 5755 | HUnresolvedInstanceFieldSet* instruction) { |
| 5756 | FieldAccessCallingConventionX86 calling_convention; |
| 5757 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5758 | instruction, instruction->GetFieldType(), calling_convention); |
| 5759 | } |
| 5760 | |
| 5761 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 5762 | HUnresolvedInstanceFieldSet* instruction) { |
| 5763 | FieldAccessCallingConventionX86 calling_convention; |
| 5764 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5765 | instruction->GetFieldType(), |
| 5766 | instruction->GetFieldIndex(), |
| 5767 | instruction->GetDexPc(), |
| 5768 | calling_convention); |
| 5769 | } |
| 5770 | |
| 5771 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 5772 | HUnresolvedStaticFieldGet* instruction) { |
| 5773 | FieldAccessCallingConventionX86 calling_convention; |
| 5774 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5775 | instruction, instruction->GetFieldType(), calling_convention); |
| 5776 | } |
| 5777 | |
| 5778 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 5779 | HUnresolvedStaticFieldGet* instruction) { |
| 5780 | FieldAccessCallingConventionX86 calling_convention; |
| 5781 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5782 | instruction->GetFieldType(), |
| 5783 | instruction->GetFieldIndex(), |
| 5784 | instruction->GetDexPc(), |
| 5785 | calling_convention); |
| 5786 | } |
| 5787 | |
| 5788 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 5789 | HUnresolvedStaticFieldSet* instruction) { |
| 5790 | FieldAccessCallingConventionX86 calling_convention; |
| 5791 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5792 | instruction, instruction->GetFieldType(), calling_convention); |
| 5793 | } |
| 5794 | |
| 5795 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 5796 | HUnresolvedStaticFieldSet* instruction) { |
| 5797 | FieldAccessCallingConventionX86 calling_convention; |
| 5798 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5799 | instruction->GetFieldType(), |
| 5800 | instruction->GetFieldIndex(), |
| 5801 | instruction->GetDexPc(), |
| 5802 | calling_convention); |
| 5803 | } |
| 5804 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5805 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5806 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5807 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 5808 | ? Location::RequiresRegister() |
| 5809 | : Location::Any(); |
| 5810 | locations->SetInAt(0, loc); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5811 | } |
| 5812 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5813 | void CodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5814 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5815 | return; |
| 5816 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5817 | LocationSummary* locations = instruction->GetLocations(); |
| 5818 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5819 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5820 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5821 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5822 | } |
| 5823 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5824 | void CodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5825 | SlowPathCode* slow_path = new (GetScopedAllocator()) NullCheckSlowPathX86(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5826 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5827 | |
| 5828 | LocationSummary* locations = instruction->GetLocations(); |
| 5829 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5830 | |
| 5831 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 5832 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5833 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5834 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5835 | } else { |
| 5836 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5837 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5838 | __ jmp(slow_path->GetEntryLabel()); |
| 5839 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5840 | } |
| 5841 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5842 | } |
| 5843 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5844 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5845 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5846 | } |
| 5847 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5848 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5849 | bool object_array_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5850 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5851 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5852 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 5853 | object_array_get_with_read_barrier |
| 5854 | ? LocationSummary::kCallOnSlowPath |
| 5855 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5856 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5857 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5858 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5859 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5860 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5861 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5862 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5863 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5864 | // The output overlaps in case of long: we don't want the low move |
| 5865 | // to overwrite the array's location. Likewise, in the case of an |
| 5866 | // object array get with read barriers enabled, we do not want the |
| 5867 | // move to overwrite the array's location, as we need it to emit |
| 5868 | // the read barrier. |
| 5869 | locations->SetOut( |
| 5870 | Location::RequiresRegister(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5871 | (instruction->GetType() == DataType::Type::kInt64 || object_array_get_with_read_barrier) |
| 5872 | ? Location::kOutputOverlap |
| 5873 | : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5874 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5875 | } |
| 5876 | |
| 5877 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 5878 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5879 | Location obj_loc = locations->InAt(0); |
| 5880 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5881 | Location index = locations->InAt(1); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5882 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5883 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5884 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5885 | DataType::Type type = instruction->GetType(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5886 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5887 | case DataType::Type::kBool: |
| 5888 | case DataType::Type::kUint8: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5889 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5890 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5891 | break; |
| 5892 | } |
| 5893 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5894 | case DataType::Type::kInt8: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5895 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5896 | __ movsxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5897 | break; |
| 5898 | } |
| 5899 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5900 | case DataType::Type::kUint16: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5901 | Register out = out_loc.AsRegister<Register>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5902 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5903 | // Branch cases into compressed and uncompressed for each index's type. |
| 5904 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 5905 | NearLabel done, not_compressed; |
Vladimir Marko | 3c89d42 | 2017-02-17 11:30:23 +0000 | [diff] [blame] | 5906 | __ testb(Address(obj, count_offset), Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5907 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5908 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 5909 | "Expecting 0=compressed, 1=uncompressed"); |
| 5910 | __ j(kNotZero, ¬_compressed); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5911 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| 5912 | __ jmp(&done); |
| 5913 | __ Bind(¬_compressed); |
| 5914 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5915 | __ Bind(&done); |
| 5916 | } else { |
| 5917 | // Common case for charAt of array of char or when string compression's |
| 5918 | // feature is turned off. |
| 5919 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5920 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5921 | break; |
| 5922 | } |
| 5923 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5924 | case DataType::Type::kInt16: { |
| 5925 | Register out = out_loc.AsRegister<Register>(); |
| 5926 | __ movsxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5927 | break; |
| 5928 | } |
| 5929 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5930 | case DataType::Type::kInt32: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5931 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5932 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5933 | break; |
| 5934 | } |
| 5935 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5936 | case DataType::Type::kReference: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5937 | static_assert( |
| 5938 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5939 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5940 | // /* HeapReference<Object> */ out = |
| 5941 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5942 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5943 | // Note that a potential implicit null check is handled in this |
| 5944 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 5945 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5946 | instruction, out_loc, obj, data_offset, index, /* needs_null_check= */ true); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5947 | } else { |
| 5948 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5949 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| 5950 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5951 | // If read barriers are enabled, emit read barriers other than |
| 5952 | // Baker's using a slow path (and also unpoison the loaded |
| 5953 | // reference, if heap poisoning is enabled). |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5954 | if (index.IsConstant()) { |
| 5955 | uint32_t offset = |
| 5956 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5957 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5958 | } else { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5959 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5960 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5961 | } |
| 5962 | } |
| 5963 | break; |
| 5964 | } |
| 5965 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5966 | case DataType::Type::kInt64: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5967 | DCHECK_NE(obj, out_loc.AsRegisterPairLow<Register>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5968 | __ movl(out_loc.AsRegisterPairLow<Register>(), |
| 5969 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
| 5970 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5971 | __ movl(out_loc.AsRegisterPairHigh<Register>(), |
| 5972 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5973 | break; |
| 5974 | } |
| 5975 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5976 | case DataType::Type::kFloat32: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5977 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5978 | __ movss(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5979 | break; |
| 5980 | } |
| 5981 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5982 | case DataType::Type::kFloat64: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5983 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5984 | __ movsd(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5985 | break; |
| 5986 | } |
| 5987 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5988 | case DataType::Type::kUint32: |
| 5989 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5990 | case DataType::Type::kVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5991 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5992 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5993 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5994 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5995 | if (type == DataType::Type::kReference || type == DataType::Type::kInt64) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5996 | // Potential implicit null checks, in the case of reference or |
| 5997 | // long arrays, are handled in the previous switch statement. |
| 5998 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5999 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6000 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6001 | } |
| 6002 | |
| 6003 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6004 | DataType::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6005 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6006 | bool needs_write_barrier = |
| 6007 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6008 | bool needs_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6009 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6010 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 6011 | instruction, |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6012 | needs_type_check ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 6013 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6014 | bool is_byte_type = DataType::Size(value_type) == 1u; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6015 | // We need the inputs to be different than the output in case of long operation. |
| 6016 | // In case of a byte operation, the register allocator does not support multiple |
| 6017 | // inputs that die at entry with one in a specific register. |
| 6018 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6019 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 6020 | if (is_byte_type) { |
| 6021 | // Ensure the value is in a byte register. |
| 6022 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6023 | } else if (DataType::IsFloatingPointType(value_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6024 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6025 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6026 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 6027 | } |
| 6028 | if (needs_write_barrier) { |
| 6029 | // Temporary registers for the write barrier. |
| 6030 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 6031 | // Ensure the card is in a byte register. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 6032 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6033 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6034 | } |
| 6035 | |
| 6036 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 6037 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6038 | Location array_loc = locations->InAt(0); |
| 6039 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6040 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 6041 | Location value = locations->InAt(2); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6042 | DataType::Type value_type = instruction->GetComponentType(); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6043 | bool needs_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6044 | bool needs_write_barrier = |
| 6045 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6046 | |
| 6047 | switch (value_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6048 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6049 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6050 | case DataType::Type::kInt8: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6051 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6052 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_1, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6053 | if (value.IsRegister()) { |
| 6054 | __ movb(address, value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6055 | } else { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 6056 | __ movb(address, Immediate(CodeGenerator::GetInt8ValueOf(value.GetConstant()))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6057 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6058 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6059 | break; |
| 6060 | } |
| 6061 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6062 | case DataType::Type::kUint16: |
| 6063 | case DataType::Type::kInt16: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6064 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6065 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_2, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6066 | if (value.IsRegister()) { |
| 6067 | __ movw(address, value.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6068 | } else { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 6069 | __ movw(address, Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6070 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6071 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6072 | break; |
| 6073 | } |
| 6074 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6075 | case DataType::Type::kReference: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6076 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6077 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6078 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6079 | if (!value.IsRegister()) { |
| 6080 | // Just setting null. |
| 6081 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 6082 | DCHECK(value.IsConstant()) << value; |
| 6083 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6084 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6085 | DCHECK(!needs_write_barrier); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6086 | DCHECK(!needs_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6087 | break; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6088 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6089 | |
| 6090 | DCHECK(needs_write_barrier); |
| 6091 | Register register_value = value.AsRegister<Register>(); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6092 | Location temp_loc = locations->GetTemp(0); |
| 6093 | Register temp = temp_loc.AsRegister<Register>(); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6094 | |
| 6095 | bool can_value_be_null = instruction->GetValueCanBeNull(); |
| 6096 | NearLabel do_store; |
| 6097 | if (can_value_be_null) { |
| 6098 | __ testl(register_value, register_value); |
| 6099 | __ j(kEqual, &do_store); |
| 6100 | } |
| 6101 | |
| 6102 | SlowPathCode* slow_path = nullptr; |
| 6103 | if (needs_type_check) { |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6104 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathX86(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6105 | codegen_->AddSlowPath(slow_path); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6106 | |
| 6107 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6108 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6109 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6110 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6111 | // Note that when Baker read barriers are enabled, the type |
| 6112 | // checks are performed without read barriers. This is fine, |
| 6113 | // even in the case where a class object is in the from-space |
| 6114 | // after the flip, as a comparison involving such a type would |
| 6115 | // not produce a false positive; it may of course produce a |
| 6116 | // false negative, in which case we would take the ArraySet |
| 6117 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6118 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6119 | // /* HeapReference<Class> */ temp = array->klass_ |
| 6120 | __ movl(temp, Address(array, class_offset)); |
| 6121 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6122 | __ MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6123 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6124 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 6125 | __ movl(temp, Address(temp, component_offset)); |
| 6126 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 6127 | // nor the object reference in `register_value->klass`, as |
| 6128 | // we are comparing two poisoned references. |
| 6129 | __ cmpl(temp, Address(register_value, class_offset)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6130 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6131 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6132 | NearLabel do_put; |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6133 | __ j(kEqual, &do_put); |
| 6134 | // If heap poisoning is enabled, the `temp` reference has |
| 6135 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6136 | __ MaybeUnpoisonHeapReference(temp); |
| 6137 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6138 | // If heap poisoning is enabled, no need to unpoison the |
| 6139 | // heap reference loaded below, as it is only used for a |
| 6140 | // comparison with null. |
| 6141 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 6142 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6143 | __ Bind(&do_put); |
| 6144 | } else { |
| 6145 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6146 | } |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6147 | } |
| 6148 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6149 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 6150 | codegen_->MarkGCCard( |
| 6151 | temp, card, array, value.AsRegister<Register>(), /* value_can_be_null= */ false); |
| 6152 | |
| 6153 | if (can_value_be_null) { |
| 6154 | DCHECK(do_store.IsLinked()); |
| 6155 | __ Bind(&do_store); |
| 6156 | } |
| 6157 | |
| 6158 | Register source = register_value; |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6159 | if (kPoisonHeapReferences) { |
| 6160 | __ movl(temp, register_value); |
| 6161 | __ PoisonHeapReference(temp); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6162 | source = temp; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6163 | } |
| 6164 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6165 | __ movl(address, source); |
| 6166 | |
| 6167 | if (can_value_be_null || !needs_type_check) { |
| 6168 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6169 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6170 | |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6171 | if (slow_path != nullptr) { |
| 6172 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6173 | } |
| 6174 | |
| 6175 | break; |
| 6176 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6177 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6178 | case DataType::Type::kInt32: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6179 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6180 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6181 | if (value.IsRegister()) { |
| 6182 | __ movl(address, value.AsRegister<Register>()); |
| 6183 | } else { |
| 6184 | DCHECK(value.IsConstant()) << value; |
| 6185 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 6186 | __ movl(address, Immediate(v)); |
| 6187 | } |
| 6188 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6189 | break; |
| 6190 | } |
| 6191 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6192 | case DataType::Type::kInt64: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6193 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6194 | if (value.IsRegisterPair()) { |
| 6195 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 6196 | value.AsRegisterPairLow<Register>()); |
| 6197 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6198 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 6199 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6200 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6201 | DCHECK(value.IsConstant()); |
| 6202 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
| 6203 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 6204 | Immediate(Low32Bits(val))); |
| 6205 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6206 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 6207 | Immediate(High32Bits(val))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6208 | } |
| 6209 | break; |
| 6210 | } |
| 6211 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6212 | case DataType::Type::kFloat32: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6213 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6214 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6215 | if (value.IsFpuRegister()) { |
| 6216 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 6217 | } else { |
| 6218 | DCHECK(value.IsConstant()); |
| 6219 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 6220 | __ movl(address, Immediate(v)); |
| 6221 | } |
| 6222 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6223 | break; |
| 6224 | } |
| 6225 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6226 | case DataType::Type::kFloat64: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6227 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6228 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6229 | if (value.IsFpuRegister()) { |
| 6230 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 6231 | } else { |
| 6232 | DCHECK(value.IsConstant()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6233 | Address address_hi = |
| 6234 | CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset + kX86WordSize); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6235 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 6236 | __ movl(address, Immediate(Low32Bits(v))); |
| 6237 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6238 | __ movl(address_hi, Immediate(High32Bits(v))); |
| 6239 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6240 | break; |
| 6241 | } |
| 6242 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 6243 | case DataType::Type::kUint32: |
| 6244 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6245 | case DataType::Type::kVoid: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6246 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 6247 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6248 | } |
| 6249 | } |
| 6250 | |
| 6251 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6252 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 6253 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6254 | if (!instruction->IsEmittedAtUseSite()) { |
| 6255 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6256 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6257 | } |
| 6258 | |
| 6259 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6260 | if (instruction->IsEmittedAtUseSite()) { |
| 6261 | return; |
| 6262 | } |
| 6263 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6264 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 6265 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6266 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 6267 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6268 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6269 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6270 | // Mask out most significant bit in case the array is String's array of char. |
| 6271 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6272 | __ shrl(out, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6273 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6274 | } |
| 6275 | |
| 6276 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6277 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6278 | InvokeRuntimeCallingConvention calling_convention; |
| 6279 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6280 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 6281 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 6282 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6283 | HInstruction* length = instruction->InputAt(1); |
| 6284 | if (!length->IsEmittedAtUseSite()) { |
| 6285 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 6286 | } |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6287 | // Need register to see array's length. |
| 6288 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 6289 | locations->AddTemp(Location::RequiresRegister()); |
| 6290 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6291 | } |
| 6292 | |
| 6293 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6294 | const bool is_string_compressed_char_at = |
| 6295 | mirror::kUseStringCompression && instruction->IsStringCharAt(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6296 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 6297 | Location index_loc = locations->InAt(0); |
| 6298 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6299 | SlowPathCode* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6300 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathX86(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6301 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 6302 | if (length_loc.IsConstant()) { |
| 6303 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 6304 | if (index_loc.IsConstant()) { |
| 6305 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 6306 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 6307 | if (index < 0 || index >= length) { |
| 6308 | codegen_->AddSlowPath(slow_path); |
| 6309 | __ jmp(slow_path->GetEntryLabel()); |
| 6310 | } else { |
| 6311 | // Some optimization after BCE may have generated this, and we should not |
| 6312 | // generate a bounds check if it is a valid range. |
| 6313 | } |
| 6314 | return; |
| 6315 | } |
| 6316 | |
| 6317 | // We have to reverse the jump condition because the length is the constant. |
| 6318 | Register index_reg = index_loc.AsRegister<Register>(); |
| 6319 | __ cmpl(index_reg, Immediate(length)); |
| 6320 | codegen_->AddSlowPath(slow_path); |
| 6321 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 6322 | } else { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6323 | HInstruction* array_length = instruction->InputAt(1); |
| 6324 | if (array_length->IsEmittedAtUseSite()) { |
| 6325 | // Address the length field in the array. |
| 6326 | DCHECK(array_length->IsArrayLength()); |
| 6327 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 6328 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 6329 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6330 | if (is_string_compressed_char_at) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6331 | // TODO: if index_loc.IsConstant(), compare twice the index (to compensate for |
| 6332 | // the string compression flag) with the in-memory length and avoid the temporary. |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6333 | Register length_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 6334 | __ movl(length_reg, array_len); |
| 6335 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6336 | __ shrl(length_reg, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6337 | codegen_->GenerateIntCompare(length_reg, index_loc); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6338 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6339 | // Checking bounds for general case: |
| 6340 | // Array of char or string's array with feature compression off. |
| 6341 | if (index_loc.IsConstant()) { |
| 6342 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 6343 | __ cmpl(array_len, Immediate(value)); |
| 6344 | } else { |
| 6345 | __ cmpl(array_len, index_loc.AsRegister<Register>()); |
| 6346 | } |
| 6347 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6348 | } |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 6349 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6350 | codegen_->GenerateIntCompare(length_loc, index_loc); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 6351 | } |
| 6352 | codegen_->AddSlowPath(slow_path); |
| 6353 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 6354 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6355 | } |
| 6356 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6357 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6358 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6359 | } |
| 6360 | |
| 6361 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 6362 | if (instruction->GetNext()->IsSuspendCheck() && |
| 6363 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 6364 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 6365 | // The back edge will generate the suspend check. |
| 6366 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 6367 | } |
| 6368 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6369 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 6370 | } |
| 6371 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6372 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6373 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6374 | instruction, LocationSummary::kCallOnSlowPath); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 6375 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 6376 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 6377 | // registers in full width (since the runtime only saves/restores lower part). |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6378 | locations->SetCustomSlowPathCallerSaves( |
| 6379 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6380 | } |
| 6381 | |
| 6382 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6383 | HBasicBlock* block = instruction->GetBlock(); |
| 6384 | if (block->GetLoopInformation() != nullptr) { |
| 6385 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 6386 | // The back edge will generate the suspend check. |
| 6387 | return; |
| 6388 | } |
| 6389 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 6390 | // The goto will generate the suspend check. |
| 6391 | return; |
| 6392 | } |
| 6393 | GenerateSuspendCheck(instruction, nullptr); |
| 6394 | } |
| 6395 | |
| 6396 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 6397 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6398 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6399 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 6400 | if (slow_path == nullptr) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6401 | slow_path = |
| 6402 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathX86(instruction, successor); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6403 | instruction->SetSlowPath(slow_path); |
| 6404 | codegen_->AddSlowPath(slow_path); |
| 6405 | if (successor != nullptr) { |
| 6406 | DCHECK(successor->IsLoopHeader()); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6407 | } |
| 6408 | } else { |
| 6409 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 6410 | } |
| 6411 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6412 | __ fs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86PointerSize>().Int32Value()), |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6413 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6414 | if (successor == nullptr) { |
| 6415 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6416 | __ Bind(slow_path->GetReturnLabel()); |
| 6417 | } else { |
| 6418 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 6419 | __ jmp(slow_path->GetEntryLabel()); |
| 6420 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6421 | } |
| 6422 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6423 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 6424 | return codegen_->GetAssembler(); |
| 6425 | } |
| 6426 | |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6427 | void ParallelMoveResolverX86::MoveMemoryToMemory(int dst, int src, int number_of_words) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6428 | ScratchRegisterScope ensure_scratch( |
| 6429 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 6430 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 6431 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6432 | |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6433 | // Now that temp register is available (possibly spilled), move blocks of memory. |
| 6434 | for (int i = 0; i < number_of_words; i++) { |
| 6435 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 6436 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 6437 | stack_offset += kX86WordSize; |
| 6438 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6439 | } |
| 6440 | |
| 6441 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6442 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6443 | Location source = move->GetSource(); |
| 6444 | Location destination = move->GetDestination(); |
| 6445 | |
| 6446 | if (source.IsRegister()) { |
| 6447 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6448 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6449 | } else if (destination.IsFpuRegister()) { |
| 6450 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6451 | } else { |
| 6452 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6453 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6454 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6455 | } else if (source.IsRegisterPair()) { |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 6456 | if (destination.IsRegisterPair()) { |
| 6457 | __ movl(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 6458 | DCHECK_NE(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>()); |
| 6459 | __ movl(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
| 6460 | } else if (destination.IsFpuRegister()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6461 | size_t elem_size = DataType::Size(DataType::Type::kInt32); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 6462 | // Push the 2 source registers to the stack. |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 6463 | __ pushl(source.AsRegisterPairHigh<Register>()); |
| 6464 | __ cfi().AdjustCFAOffset(elem_size); |
| 6465 | __ pushl(source.AsRegisterPairLow<Register>()); |
| 6466 | __ cfi().AdjustCFAOffset(elem_size); |
| 6467 | // Load the destination register. |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6468 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 6469 | // And remove the temporary stack space we allocated. |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 6470 | codegen_->DecreaseFrame(2 * elem_size); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 6471 | } else { |
| 6472 | DCHECK(destination.IsDoubleStackSlot()); |
| 6473 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
| 6474 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
| 6475 | source.AsRegisterPairHigh<Register>()); |
| 6476 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6477 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6478 | if (destination.IsRegister()) { |
| 6479 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
| 6480 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6481 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6482 | } else if (destination.IsRegisterPair()) { |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 6483 | size_t elem_size = DataType::Size(DataType::Type::kInt32); |
| 6484 | // Create stack space for 2 elements. |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 6485 | codegen_->IncreaseFrame(2 * elem_size); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 6486 | // Store the source register. |
| 6487 | __ movsd(Address(ESP, 0), source.AsFpuRegister<XmmRegister>()); |
| 6488 | // And pop the values into destination registers. |
| 6489 | __ popl(destination.AsRegisterPairLow<Register>()); |
| 6490 | __ cfi().AdjustCFAOffset(-elem_size); |
| 6491 | __ popl(destination.AsRegisterPairHigh<Register>()); |
| 6492 | __ cfi().AdjustCFAOffset(-elem_size); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6493 | } else if (destination.IsStackSlot()) { |
| 6494 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6495 | } else if (destination.IsDoubleStackSlot()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6496 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6497 | } else { |
| 6498 | DCHECK(destination.IsSIMDStackSlot()); |
| 6499 | __ movups(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6500 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6501 | } else if (source.IsStackSlot()) { |
| 6502 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6503 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6504 | } else if (destination.IsFpuRegister()) { |
| 6505 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6506 | } else { |
| 6507 | DCHECK(destination.IsStackSlot()); |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6508 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 1); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6509 | } |
| 6510 | } else if (source.IsDoubleStackSlot()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6511 | if (destination.IsRegisterPair()) { |
| 6512 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 6513 | __ movl(destination.AsRegisterPairHigh<Register>(), |
| 6514 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 6515 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6516 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 6517 | } else { |
| 6518 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6519 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 2); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6520 | } |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6521 | } else if (source.IsSIMDStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6522 | if (destination.IsFpuRegister()) { |
| 6523 | __ movups(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 6524 | } else { |
| 6525 | DCHECK(destination.IsSIMDStackSlot()); |
| 6526 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 4); |
| 6527 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 6528 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6529 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 6530 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 6531 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6532 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 6533 | if (value == 0) { |
| 6534 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 6535 | } else { |
| 6536 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 6537 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6538 | } else { |
| 6539 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 6540 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6541 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6542 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6543 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 6544 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6545 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6546 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6547 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 6548 | if (value == 0) { |
| 6549 | // Easy handling of 0.0. |
| 6550 | __ xorps(dest, dest); |
| 6551 | } else { |
| 6552 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6553 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 6554 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 6555 | __ movl(temp, Immediate(value)); |
| 6556 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6557 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6558 | } else { |
| 6559 | DCHECK(destination.IsStackSlot()) << destination; |
| 6560 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 6561 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6562 | } else if (constant->IsLongConstant()) { |
| 6563 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 6564 | int32_t low_value = Low32Bits(value); |
| 6565 | int32_t high_value = High32Bits(value); |
| 6566 | Immediate low(low_value); |
| 6567 | Immediate high(high_value); |
| 6568 | if (destination.IsDoubleStackSlot()) { |
| 6569 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 6570 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 6571 | } else { |
| 6572 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 6573 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 6574 | } |
| 6575 | } else { |
| 6576 | DCHECK(constant->IsDoubleConstant()); |
| 6577 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 6578 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6579 | int32_t low_value = Low32Bits(value); |
| 6580 | int32_t high_value = High32Bits(value); |
| 6581 | Immediate low(low_value); |
| 6582 | Immediate high(high_value); |
| 6583 | if (destination.IsFpuRegister()) { |
| 6584 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 6585 | if (value == 0) { |
| 6586 | // Easy handling of 0.0. |
| 6587 | __ xorpd(dest, dest); |
| 6588 | } else { |
| 6589 | __ pushl(high); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 6590 | __ cfi().AdjustCFAOffset(4); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6591 | __ pushl(low); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 6592 | __ cfi().AdjustCFAOffset(4); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6593 | __ movsd(dest, Address(ESP, 0)); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 6594 | codegen_->DecreaseFrame(8); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6595 | } |
| 6596 | } else { |
| 6597 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6598 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 6599 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 6600 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 6601 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6602 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 6603 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6604 | } |
| 6605 | } |
| 6606 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 6607 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6608 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 6609 | ScratchRegisterScope ensure_scratch( |
| 6610 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 6611 | |
| 6612 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 6613 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 6614 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 6615 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6616 | } |
| 6617 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6618 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6619 | ScratchRegisterScope ensure_scratch( |
| 6620 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 6621 | |
| 6622 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 6623 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 6624 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 6625 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 6626 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6627 | } |
| 6628 | |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6629 | void ParallelMoveResolverX86::Exchange128(XmmRegister reg, int mem) { |
| 6630 | size_t extra_slot = 4 * kX86WordSize; |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 6631 | codegen_->IncreaseFrame(extra_slot); |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6632 | __ movups(Address(ESP, 0), XmmRegister(reg)); |
| 6633 | ExchangeMemory(0, mem + extra_slot, 4); |
| 6634 | __ movups(XmmRegister(reg), Address(ESP, 0)); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 6635 | codegen_->DecreaseFrame(extra_slot); |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6636 | } |
| 6637 | |
| 6638 | void ParallelMoveResolverX86::ExchangeMemory(int mem1, int mem2, int number_of_words) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6639 | ScratchRegisterScope ensure_scratch1( |
| 6640 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6641 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6642 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 6643 | ScratchRegisterScope ensure_scratch2( |
| 6644 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6645 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6646 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 6647 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6648 | |
| 6649 | // Now that temp registers are available (possibly spilled), exchange blocks of memory. |
| 6650 | for (int i = 0; i < number_of_words; i++) { |
| 6651 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 6652 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 6653 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 6654 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
| 6655 | stack_offset += kX86WordSize; |
| 6656 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6657 | } |
| 6658 | |
| 6659 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6660 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6661 | Location source = move->GetSource(); |
| 6662 | Location destination = move->GetDestination(); |
| 6663 | |
| 6664 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 6665 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 6666 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 6667 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 6668 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 6669 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6670 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6671 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6672 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6673 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6674 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6675 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 1); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6676 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 6677 | // Use XOR Swap algorithm to avoid a temporary. |
| 6678 | DCHECK_NE(source.reg(), destination.reg()); |
| 6679 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 6680 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 6681 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 6682 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 6683 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 6684 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 6685 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6686 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 6687 | // Take advantage of the 16 bytes in the XMM register. |
| 6688 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 6689 | Address stack(ESP, destination.GetStackIndex()); |
| 6690 | // Load the double into the high doubleword. |
| 6691 | __ movhpd(reg, stack); |
| 6692 | |
| 6693 | // Store the low double into the destination. |
| 6694 | __ movsd(stack, reg); |
| 6695 | |
| 6696 | // Move the high double to the low double. |
| 6697 | __ psrldq(reg, Immediate(8)); |
| 6698 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 6699 | // Take advantage of the 16 bytes in the XMM register. |
| 6700 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 6701 | Address stack(ESP, source.GetStackIndex()); |
| 6702 | // Load the double into the high doubleword. |
| 6703 | __ movhpd(reg, stack); |
| 6704 | |
| 6705 | // Store the low double into the destination. |
| 6706 | __ movsd(stack, reg); |
| 6707 | |
| 6708 | // Move the high double to the low double. |
| 6709 | __ psrldq(reg, Immediate(8)); |
| 6710 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6711 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 2); |
| 6712 | } else if (source.IsSIMDStackSlot() && destination.IsSIMDStackSlot()) { |
| 6713 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 4); |
| 6714 | } else if (source.IsFpuRegister() && destination.IsSIMDStackSlot()) { |
| 6715 | Exchange128(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 6716 | } else if (destination.IsFpuRegister() && source.IsSIMDStackSlot()) { |
| 6717 | Exchange128(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6718 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6719 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6720 | } |
| 6721 | } |
| 6722 | |
| 6723 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 6724 | __ pushl(static_cast<Register>(reg)); |
| 6725 | } |
| 6726 | |
| 6727 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 6728 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6729 | } |
| 6730 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6731 | HLoadClass::LoadKind CodeGeneratorX86::GetSupportedLoadClassKind( |
| 6732 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6733 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6734 | case HLoadClass::LoadKind::kInvalid: |
| 6735 | LOG(FATAL) << "UNREACHABLE"; |
| 6736 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6737 | case HLoadClass::LoadKind::kReferrersClass: |
| 6738 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6739 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6740 | case HLoadClass::LoadKind::kBootImageRelRo: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6741 | case HLoadClass::LoadKind::kBssEntry: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 6742 | DCHECK(!GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6743 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6744 | case HLoadClass::LoadKind::kJitBootImageAddress: |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6745 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 6746 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6747 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6748 | case HLoadClass::LoadKind::kRuntimeCall: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6749 | break; |
| 6750 | } |
| 6751 | return desired_class_load_kind; |
| 6752 | } |
| 6753 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6754 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6755 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6756 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6757 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6758 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6759 | cls, |
| 6760 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6761 | Location::RegisterLocation(EAX)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6762 | DCHECK_EQ(calling_convention.GetRegisterAt(0), EAX); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6763 | return; |
| 6764 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6765 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6766 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6767 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 6768 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6769 | ? LocationSummary::kCallOnSlowPath |
| 6770 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6771 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6772 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6773 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6774 | } |
| 6775 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6776 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6777 | load_kind == HLoadClass::LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6778 | load_kind == HLoadClass::LoadKind::kBootImageRelRo || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6779 | load_kind == HLoadClass::LoadKind::kBssEntry) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6780 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6781 | } |
| 6782 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6783 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 6784 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 6785 | // Rely on the type resolution and/or initialization to save everything. |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 6786 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6787 | } else { |
| 6788 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6789 | } |
| 6790 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6791 | } |
| 6792 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6793 | Label* CodeGeneratorX86::NewJitRootClassPatch(const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6794 | dex::TypeIndex type_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6795 | Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6796 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6797 | // Add a patch entry and return the label. |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6798 | jit_class_patches_.emplace_back(&dex_file, type_index.index_); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6799 | PatchInfo<Label>* info = &jit_class_patches_.back(); |
| 6800 | return &info->label; |
| 6801 | } |
| 6802 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6803 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6804 | // move. |
| 6805 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6806 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6807 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6808 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6809 | return; |
| 6810 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6811 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6812 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6813 | LocationSummary* locations = cls->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6814 | Location out_loc = locations->Out(); |
| 6815 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6816 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6817 | bool generate_null_check = false; |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6818 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 6819 | ? kWithoutReadBarrier |
| 6820 | : kCompilerReadBarrierOption; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6821 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6822 | case HLoadClass::LoadKind::kReferrersClass: { |
| 6823 | DCHECK(!cls->CanCallRuntime()); |
| 6824 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 6825 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6826 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 6827 | GenerateGcRootFieldLoad( |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6828 | cls, |
| 6829 | out_loc, |
| 6830 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6831 | /* fixup_label= */ nullptr, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6832 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6833 | break; |
| 6834 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6835 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 6836 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 6837 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6838 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6839 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6840 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6841 | codegen_->RecordBootImageTypePatch(cls); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6842 | break; |
| 6843 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6844 | case HLoadClass::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6845 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 6846 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6847 | __ movl(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6848 | codegen_->RecordBootImageRelRoPatch(cls->InputAt(0)->AsX86ComputeBaseMethodAddress(), |
| 6849 | codegen_->GetBootImageOffset(cls)); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6850 | break; |
| 6851 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6852 | case HLoadClass::LoadKind::kBssEntry: { |
| 6853 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6854 | Address address(method_address, CodeGeneratorX86::kDummy32BitOffset); |
| 6855 | Label* fixup_label = codegen_->NewTypeBssEntryPatch(cls); |
| 6856 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 6857 | // No need for memory fence, thanks to the x86 memory model. |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6858 | generate_null_check = true; |
| 6859 | break; |
| 6860 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6861 | case HLoadClass::LoadKind::kJitBootImageAddress: { |
| 6862 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 6863 | uint32_t address = reinterpret_cast32<uint32_t>(cls->GetClass().Get()); |
| 6864 | DCHECK_NE(address, 0u); |
| 6865 | __ movl(out, Immediate(address)); |
| 6866 | break; |
| 6867 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6868 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 6869 | Address address = Address::Absolute(CodeGeneratorX86::kDummy32BitOffset); |
| 6870 | Label* fixup_label = codegen_->NewJitRootClassPatch( |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6871 | cls->GetDexFile(), cls->GetTypeIndex(), cls->GetClass()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6872 | // /* GcRoot<mirror::Class> */ out = *address |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6873 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6874 | break; |
| 6875 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6876 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6877 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6878 | LOG(FATAL) << "UNREACHABLE"; |
| 6879 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6880 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6881 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6882 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6883 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 6884 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86(cls, cls); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6885 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6886 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6887 | if (generate_null_check) { |
| 6888 | __ testl(out, out); |
| 6889 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6890 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6891 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6892 | if (cls->MustGenerateClinitCheck()) { |
| 6893 | GenerateClassInitializationCheck(slow_path, out); |
| 6894 | } else { |
| 6895 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6896 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6897 | } |
| 6898 | } |
| 6899 | |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 6900 | void LocationsBuilderX86::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 6901 | InvokeRuntimeCallingConvention calling_convention; |
| 6902 | Location location = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 6903 | CodeGenerator::CreateLoadMethodHandleRuntimeCallLocationSummary(load, location, location); |
| 6904 | } |
| 6905 | |
| 6906 | void InstructionCodeGeneratorX86::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 6907 | codegen_->GenerateLoadMethodHandleRuntimeCall(load); |
| 6908 | } |
| 6909 | |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6910 | void LocationsBuilderX86::VisitLoadMethodType(HLoadMethodType* load) { |
| 6911 | InvokeRuntimeCallingConvention calling_convention; |
| 6912 | Location location = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 6913 | CodeGenerator::CreateLoadMethodTypeRuntimeCallLocationSummary(load, location, location); |
| 6914 | } |
| 6915 | |
| 6916 | void InstructionCodeGeneratorX86::VisitLoadMethodType(HLoadMethodType* load) { |
| 6917 | codegen_->GenerateLoadMethodTypeRuntimeCall(load); |
| 6918 | } |
| 6919 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6920 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 6921 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6922 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6923 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6924 | if (check->HasUses()) { |
| 6925 | locations->SetOut(Location::SameAsFirstInput()); |
| 6926 | } |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 6927 | // Rely on the type initialization to save everything we need. |
| 6928 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6929 | } |
| 6930 | |
| 6931 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6932 | // We assume the class to not be null. |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 6933 | SlowPathCode* slow_path = |
| 6934 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86(check->GetLoadClass(), check); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6935 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6936 | GenerateClassInitializationCheck(slow_path, |
| 6937 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6938 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6939 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6940 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6941 | SlowPathCode* slow_path, Register class_reg) { |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 6942 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
| 6943 | const size_t status_byte_offset = |
| 6944 | mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte); |
Vladimir Marko | bf12191 | 2019-06-04 13:49:05 +0100 | [diff] [blame] | 6945 | constexpr uint32_t shifted_visibly_initialized_value = |
| 6946 | enum_cast<uint32_t>(ClassStatus::kVisiblyInitialized) << (status_lsb_position % kBitsPerByte); |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 6947 | |
Vladimir Marko | bf12191 | 2019-06-04 13:49:05 +0100 | [diff] [blame] | 6948 | __ cmpb(Address(class_reg, status_byte_offset), Immediate(shifted_visibly_initialized_value)); |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 6949 | __ j(kBelow, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6950 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6951 | } |
| 6952 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6953 | void InstructionCodeGeneratorX86::GenerateBitstringTypeCheckCompare(HTypeCheckInstruction* check, |
| 6954 | Register temp) { |
| 6955 | uint32_t path_to_root = check->GetBitstringPathToRoot(); |
| 6956 | uint32_t mask = check->GetBitstringMask(); |
| 6957 | DCHECK(IsPowerOfTwo(mask + 1)); |
| 6958 | size_t mask_bits = WhichPowerOf2(mask + 1); |
| 6959 | |
| 6960 | if (mask_bits == 16u) { |
| 6961 | // Compare the bitstring in memory. |
| 6962 | __ cmpw(Address(temp, mirror::Class::StatusOffset()), Immediate(path_to_root)); |
| 6963 | } else { |
| 6964 | // /* uint32_t */ temp = temp->status_ |
| 6965 | __ movl(temp, Address(temp, mirror::Class::StatusOffset())); |
| 6966 | // Compare the bitstring bits using SUB. |
| 6967 | __ subl(temp, Immediate(path_to_root)); |
| 6968 | // Shift out bits that do not contribute to the comparison. |
| 6969 | __ shll(temp, Immediate(32u - mask_bits)); |
| 6970 | } |
| 6971 | } |
| 6972 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6973 | HLoadString::LoadKind CodeGeneratorX86::GetSupportedLoadStringKind( |
| 6974 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6975 | switch (desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6976 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6977 | case HLoadString::LoadKind::kBootImageRelRo: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6978 | case HLoadString::LoadKind::kBssEntry: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 6979 | DCHECK(!GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6980 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6981 | case HLoadString::LoadKind::kJitBootImageAddress: |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6982 | case HLoadString::LoadKind::kJitTableAddress: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 6983 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6984 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6985 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6986 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6987 | } |
| 6988 | return desired_string_load_kind; |
| 6989 | } |
| 6990 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6991 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6992 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6993 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6994 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6995 | if (load_kind == HLoadString::LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6996 | load_kind == HLoadString::LoadKind::kBootImageRelRo || |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6997 | load_kind == HLoadString::LoadKind::kBssEntry) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6998 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6999 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7000 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 7001 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 7002 | } else { |
| 7003 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 7004 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 7005 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7006 | // Rely on the pResolveString to save everything. |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 7007 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 7008 | } else { |
| 7009 | // For non-Baker read barrier we have a temp-clobbering call. |
| 7010 | } |
| 7011 | } |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 7012 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 7013 | } |
| 7014 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7015 | Label* CodeGeneratorX86::NewJitRootStringPatch(const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7016 | dex::StringIndex string_index, |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7017 | Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7018 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7019 | // Add a patch entry and return the label. |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7020 | jit_string_patches_.emplace_back(&dex_file, string_index.index_); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7021 | PatchInfo<Label>* info = &jit_string_patches_.back(); |
| 7022 | return &info->label; |
| 7023 | } |
| 7024 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7025 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 7026 | // move. |
| 7027 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 7028 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7029 | Location out_loc = locations->Out(); |
| 7030 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7031 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7032 | switch (load->GetLoadKind()) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7033 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 7034 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 7035 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7036 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 7037 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7038 | codegen_->RecordBootImageStringPatch(load); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7039 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7040 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7041 | case HLoadString::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7042 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 7043 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 7044 | __ movl(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7045 | codegen_->RecordBootImageRelRoPatch(load->InputAt(0)->AsX86ComputeBaseMethodAddress(), |
| 7046 | codegen_->GetBootImageOffset(load)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7047 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7048 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7049 | case HLoadString::LoadKind::kBssEntry: { |
| 7050 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 7051 | Address address = Address(method_address, CodeGeneratorX86::kDummy32BitOffset); |
| 7052 | Label* fixup_label = codegen_->NewStringBssEntryPatch(load); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7053 | // /* GcRoot<mirror::String> */ out = *address /* PC-relative */ |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7054 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 7055 | // No need for memory fence, thanks to the x86 memory model. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7056 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadStringSlowPathX86(load); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7057 | codegen_->AddSlowPath(slow_path); |
| 7058 | __ testl(out, out); |
| 7059 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 7060 | __ Bind(slow_path->GetExitLabel()); |
| 7061 | return; |
| 7062 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7063 | case HLoadString::LoadKind::kJitBootImageAddress: { |
| 7064 | uint32_t address = reinterpret_cast32<uint32_t>(load->GetString().Get()); |
| 7065 | DCHECK_NE(address, 0u); |
| 7066 | __ movl(out, Immediate(address)); |
| 7067 | return; |
| 7068 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7069 | case HLoadString::LoadKind::kJitTableAddress: { |
| 7070 | Address address = Address::Absolute(CodeGeneratorX86::kDummy32BitOffset); |
| 7071 | Label* fixup_label = codegen_->NewJitRootStringPatch( |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7072 | load->GetDexFile(), load->GetStringIndex(), load->GetString()); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7073 | // /* GcRoot<mirror::String> */ out = *address |
| 7074 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
| 7075 | return; |
| 7076 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7077 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 7078 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7079 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7080 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 7081 | // 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] | 7082 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 7083 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7084 | __ movl(calling_convention.GetRegisterAt(0), Immediate(load->GetStringIndex().index_)); |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 7085 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 7086 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 7087 | } |
| 7088 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7089 | static Address GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7090 | return Address::Absolute(Thread::ExceptionOffset<kX86PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7091 | } |
| 7092 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7093 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 7094 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7095 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7096 | locations->SetOut(Location::RequiresRegister()); |
| 7097 | } |
| 7098 | |
| 7099 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7100 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 7101 | } |
| 7102 | |
| 7103 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7104 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7105 | } |
| 7106 | |
| 7107 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 7108 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7109 | } |
| 7110 | |
| 7111 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7112 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 7113 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7114 | InvokeRuntimeCallingConvention calling_convention; |
| 7115 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 7116 | } |
| 7117 | |
| 7118 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 7119 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7120 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7121 | } |
| 7122 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7123 | // Temp is used for read barrier. |
| 7124 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 7125 | if (kEmitCompilerReadBarrier && |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7126 | !kUseBakerReadBarrier && |
| 7127 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7128 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7129 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 7130 | return 1; |
| 7131 | } |
| 7132 | return 0; |
| 7133 | } |
| 7134 | |
Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 7135 | // Interface case has 2 temps, one for holding the number of interfaces, one for the current |
| 7136 | // interface pointer, the current interface is compared in memory. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7137 | // The other checks have one temp for loading the object's class. |
| 7138 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 7139 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7140 | return 2; |
| 7141 | } |
| 7142 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7143 | } |
| 7144 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7145 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7146 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7147 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7148 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7149 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7150 | case TypeCheckKind::kExactCheck: |
| 7151 | case TypeCheckKind::kAbstractClassCheck: |
| 7152 | case TypeCheckKind::kClassHierarchyCheck: |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7153 | case TypeCheckKind::kArrayObjectCheck: { |
| 7154 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 7155 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 7156 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7157 | break; |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7158 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7159 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7160 | case TypeCheckKind::kUnresolvedCheck: |
| 7161 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7162 | call_kind = LocationSummary::kCallOnSlowPath; |
| 7163 | break; |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7164 | case TypeCheckKind::kBitstringCheck: |
| 7165 | break; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7166 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7167 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7168 | LocationSummary* locations = |
| 7169 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7170 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 7171 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7172 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7173 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7174 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 7175 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 7176 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 7177 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 7178 | } else { |
| 7179 | locations->SetInAt(1, Location::Any()); |
| 7180 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7181 | // Note that TypeCheckSlowPathX86 uses this "out" register too. |
| 7182 | locations->SetOut(Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7183 | // When read barriers are enabled, we need a temporary register for some cases. |
| 7184 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7185 | } |
| 7186 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7187 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7188 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7189 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7190 | Location obj_loc = locations->InAt(0); |
| 7191 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7192 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7193 | Location out_loc = locations->Out(); |
| 7194 | Register out = out_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7195 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 7196 | DCHECK_LE(num_temps, 1u); |
| 7197 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7198 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7199 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7200 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7201 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7202 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7203 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7204 | |
| 7205 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7206 | // Avoid null check if we know obj is not null. |
| 7207 | if (instruction->MustDoNullCheck()) { |
| 7208 | __ testl(obj, obj); |
| 7209 | __ j(kEqual, &zero); |
| 7210 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7211 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7212 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7213 | case TypeCheckKind::kExactCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7214 | ReadBarrierOption read_barrier_option = |
| 7215 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7216 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7217 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7218 | out_loc, |
| 7219 | obj_loc, |
| 7220 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7221 | read_barrier_option); |
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 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7228 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7229 | // Classes must be equal for the instanceof to succeed. |
| 7230 | __ j(kNotEqual, &zero); |
| 7231 | __ movl(out, Immediate(1)); |
| 7232 | __ jmp(&done); |
| 7233 | break; |
| 7234 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7235 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7236 | case TypeCheckKind::kAbstractClassCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7237 | ReadBarrierOption read_barrier_option = |
| 7238 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7239 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7240 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7241 | out_loc, |
| 7242 | obj_loc, |
| 7243 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7244 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7245 | // If the class is abstract, we eagerly fetch the super class of the |
| 7246 | // object to avoid doing a comparison we know will fail. |
| 7247 | NearLabel loop; |
| 7248 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7249 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7250 | GenerateReferenceLoadOneRegister(instruction, |
| 7251 | out_loc, |
| 7252 | super_offset, |
| 7253 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7254 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7255 | __ testl(out, out); |
| 7256 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7257 | __ j(kEqual, &done); |
| 7258 | if (cls.IsRegister()) { |
| 7259 | __ cmpl(out, cls.AsRegister<Register>()); |
| 7260 | } else { |
| 7261 | DCHECK(cls.IsStackSlot()) << cls; |
| 7262 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 7263 | } |
| 7264 | __ j(kNotEqual, &loop); |
| 7265 | __ movl(out, Immediate(1)); |
| 7266 | if (zero.IsLinked()) { |
| 7267 | __ jmp(&done); |
| 7268 | } |
| 7269 | break; |
| 7270 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7271 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7272 | case TypeCheckKind::kClassHierarchyCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7273 | ReadBarrierOption read_barrier_option = |
| 7274 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7275 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7276 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7277 | out_loc, |
| 7278 | obj_loc, |
| 7279 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7280 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7281 | // Walk over the class hierarchy to find a match. |
| 7282 | NearLabel loop, success; |
| 7283 | __ Bind(&loop); |
| 7284 | if (cls.IsRegister()) { |
| 7285 | __ cmpl(out, cls.AsRegister<Register>()); |
| 7286 | } else { |
| 7287 | DCHECK(cls.IsStackSlot()) << cls; |
| 7288 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 7289 | } |
| 7290 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7291 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7292 | GenerateReferenceLoadOneRegister(instruction, |
| 7293 | out_loc, |
| 7294 | super_offset, |
| 7295 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7296 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7297 | __ testl(out, out); |
| 7298 | __ j(kNotEqual, &loop); |
| 7299 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7300 | __ jmp(&done); |
| 7301 | __ Bind(&success); |
| 7302 | __ movl(out, Immediate(1)); |
| 7303 | if (zero.IsLinked()) { |
| 7304 | __ jmp(&done); |
| 7305 | } |
| 7306 | break; |
| 7307 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7308 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7309 | case TypeCheckKind::kArrayObjectCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7310 | ReadBarrierOption read_barrier_option = |
| 7311 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7312 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7313 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7314 | out_loc, |
| 7315 | obj_loc, |
| 7316 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7317 | read_barrier_option); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7318 | // Do an exact check. |
| 7319 | NearLabel exact_check; |
| 7320 | if (cls.IsRegister()) { |
| 7321 | __ cmpl(out, cls.AsRegister<Register>()); |
| 7322 | } else { |
| 7323 | DCHECK(cls.IsStackSlot()) << cls; |
| 7324 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 7325 | } |
| 7326 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7327 | // 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] | 7328 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7329 | GenerateReferenceLoadOneRegister(instruction, |
| 7330 | out_loc, |
| 7331 | component_offset, |
| 7332 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7333 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7334 | __ testl(out, out); |
| 7335 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7336 | __ j(kEqual, &done); |
| 7337 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 7338 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7339 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7340 | __ movl(out, Immediate(1)); |
| 7341 | __ jmp(&done); |
| 7342 | break; |
| 7343 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7344 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7345 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7346 | // No read barrier since the slow path will retry upon failure. |
| 7347 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7348 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7349 | out_loc, |
| 7350 | obj_loc, |
| 7351 | class_offset, |
| 7352 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7353 | if (cls.IsRegister()) { |
| 7354 | __ cmpl(out, cls.AsRegister<Register>()); |
| 7355 | } else { |
| 7356 | DCHECK(cls.IsStackSlot()) << cls; |
| 7357 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 7358 | } |
| 7359 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7360 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7361 | instruction, /* is_fatal= */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7362 | codegen_->AddSlowPath(slow_path); |
| 7363 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 7364 | __ movl(out, Immediate(1)); |
| 7365 | if (zero.IsLinked()) { |
| 7366 | __ jmp(&done); |
| 7367 | } |
| 7368 | break; |
| 7369 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7370 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 7371 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7372 | case TypeCheckKind::kInterfaceCheck: { |
| 7373 | // 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] | 7374 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7375 | // cases. |
| 7376 | // |
| 7377 | // We cannot directly call the InstanceofNonTrivial runtime |
| 7378 | // entry point without resorting to a type checking slow path |
| 7379 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 7380 | // require to assign fixed registers for the inputs of this |
| 7381 | // HInstanceOf instruction (following the runtime calling |
| 7382 | // convention), which might be cluttered by the potential first |
| 7383 | // read barrier emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7384 | // |
| 7385 | // TODO: Introduce a new runtime entry point taking the object |
| 7386 | // to test (instead of its class) as argument, and let it deal |
| 7387 | // with the read barrier issues. This will let us refactor this |
| 7388 | // case of the `switch` code as it was previously (with a direct |
| 7389 | // call to the runtime not using a type checking slow path). |
| 7390 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7391 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7392 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7393 | instruction, /* is_fatal= */ false); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7394 | codegen_->AddSlowPath(slow_path); |
| 7395 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7396 | if (zero.IsLinked()) { |
| 7397 | __ jmp(&done); |
| 7398 | } |
| 7399 | break; |
| 7400 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7401 | |
| 7402 | case TypeCheckKind::kBitstringCheck: { |
| 7403 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7404 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7405 | out_loc, |
| 7406 | obj_loc, |
| 7407 | class_offset, |
| 7408 | kWithoutReadBarrier); |
| 7409 | |
| 7410 | GenerateBitstringTypeCheckCompare(instruction, out); |
| 7411 | __ j(kNotEqual, &zero); |
| 7412 | __ movl(out, Immediate(1)); |
| 7413 | __ jmp(&done); |
| 7414 | break; |
| 7415 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7416 | } |
| 7417 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7418 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7419 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7420 | __ xorl(out, out); |
| 7421 | } |
| 7422 | |
| 7423 | if (done.IsLinked()) { |
| 7424 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7425 | } |
| 7426 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7427 | if (slow_path != nullptr) { |
| 7428 | __ Bind(slow_path->GetExitLabel()); |
| 7429 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7430 | } |
| 7431 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7432 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7433 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7434 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7435 | LocationSummary* locations = |
| 7436 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7437 | locations->SetInAt(0, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7438 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 7439 | // Require a register for the interface check since there is a loop that compares the class to |
| 7440 | // a memory address. |
| 7441 | locations->SetInAt(1, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7442 | } else if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 7443 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 7444 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 7445 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7446 | } else { |
| 7447 | locations->SetInAt(1, Location::Any()); |
| 7448 | } |
Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 7449 | // 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] | 7450 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
| 7451 | } |
| 7452 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7453 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7454 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7455 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7456 | Location obj_loc = locations->InAt(0); |
| 7457 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7458 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7459 | Location temp_loc = locations->GetTemp(0); |
| 7460 | Register temp = temp_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7461 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 7462 | DCHECK_GE(num_temps, 1u); |
| 7463 | DCHECK_LE(num_temps, 2u); |
| 7464 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 7465 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7466 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7467 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7468 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 7469 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 7470 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 7471 | const uint32_t object_array_data_offset = |
| 7472 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7473 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7474 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7475 | SlowPathCode* type_check_slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7476 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
| 7477 | instruction, is_type_check_slow_path_fatal); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7478 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7479 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7480 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7481 | // Avoid null check if we know obj is not null. |
| 7482 | if (instruction->MustDoNullCheck()) { |
| 7483 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7484 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7485 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7486 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7487 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7488 | case TypeCheckKind::kExactCheck: |
| 7489 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7490 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7491 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7492 | temp_loc, |
| 7493 | obj_loc, |
| 7494 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7495 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7496 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7497 | if (cls.IsRegister()) { |
| 7498 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 7499 | } else { |
| 7500 | DCHECK(cls.IsStackSlot()) << cls; |
| 7501 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 7502 | } |
| 7503 | // Jump to slow path for throwing the exception or doing a |
| 7504 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7505 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7506 | break; |
| 7507 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7508 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7509 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7510 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7511 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7512 | temp_loc, |
| 7513 | obj_loc, |
| 7514 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7515 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7516 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7517 | // If the class is abstract, we eagerly fetch the super class of the |
| 7518 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7519 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7520 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7521 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7522 | GenerateReferenceLoadOneRegister(instruction, |
| 7523 | temp_loc, |
| 7524 | super_offset, |
| 7525 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7526 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7527 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7528 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 7529 | // exception. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7530 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7531 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7532 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7533 | // Otherwise, compare the classes |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7534 | if (cls.IsRegister()) { |
| 7535 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 7536 | } else { |
| 7537 | DCHECK(cls.IsStackSlot()) << cls; |
| 7538 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 7539 | } |
| 7540 | __ j(kNotEqual, &loop); |
| 7541 | break; |
| 7542 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7543 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7544 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7545 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7546 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7547 | temp_loc, |
| 7548 | obj_loc, |
| 7549 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7550 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7551 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7552 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7553 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7554 | __ Bind(&loop); |
| 7555 | if (cls.IsRegister()) { |
| 7556 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 7557 | } else { |
| 7558 | DCHECK(cls.IsStackSlot()) << cls; |
| 7559 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 7560 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7561 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7562 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7563 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7564 | GenerateReferenceLoadOneRegister(instruction, |
| 7565 | temp_loc, |
| 7566 | super_offset, |
| 7567 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7568 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7569 | |
| 7570 | // If the class reference currently in `temp` is not null, jump |
| 7571 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7572 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7573 | __ j(kNotZero, &loop); |
| 7574 | // Otherwise, jump to the slow path to throw the exception.; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7575 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7576 | break; |
| 7577 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7578 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7579 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7580 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7581 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7582 | temp_loc, |
| 7583 | obj_loc, |
| 7584 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7585 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7586 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7587 | // Do an exact check. |
| 7588 | if (cls.IsRegister()) { |
| 7589 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 7590 | } else { |
| 7591 | DCHECK(cls.IsStackSlot()) << cls; |
| 7592 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 7593 | } |
| 7594 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7595 | |
| 7596 | // 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] | 7597 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7598 | GenerateReferenceLoadOneRegister(instruction, |
| 7599 | temp_loc, |
| 7600 | component_offset, |
| 7601 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7602 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7603 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7604 | // If the component type is null (i.e. the object not an array), jump to the slow path to |
| 7605 | // throw the exception. Otherwise proceed with the check. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7606 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7607 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7608 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7609 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7610 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7611 | break; |
| 7612 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7613 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 7614 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7615 | // 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] | 7616 | // We cannot directly call the CheckCast runtime entry point |
| 7617 | // without resorting to a type checking slow path here (i.e. by |
| 7618 | // calling InvokeRuntime directly), as it would require to |
| 7619 | // assign fixed registers for the inputs of this HInstanceOf |
| 7620 | // instruction (following the runtime calling convention), which |
| 7621 | // might be cluttered by the potential first read barrier |
| 7622 | // emission at the beginning of this method. |
| 7623 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7624 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7625 | |
| 7626 | case TypeCheckKind::kInterfaceCheck: { |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 7627 | // Fast path for the interface check. Try to avoid read barriers to improve the fast path. |
| 7628 | // We can not get false positives by doing this. |
| 7629 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7630 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7631 | temp_loc, |
| 7632 | obj_loc, |
| 7633 | class_offset, |
| 7634 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7635 | |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 7636 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 7637 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7638 | temp_loc, |
| 7639 | temp_loc, |
| 7640 | iftable_offset, |
| 7641 | kWithoutReadBarrier); |
| 7642 | // Iftable is never null. |
| 7643 | __ movl(maybe_temp2_loc.AsRegister<Register>(), Address(temp, array_length_offset)); |
| 7644 | // Maybe poison the `cls` for direct comparison with memory. |
| 7645 | __ MaybePoisonHeapReference(cls.AsRegister<Register>()); |
| 7646 | // Loop through the iftable and check if any class matches. |
| 7647 | NearLabel start_loop; |
| 7648 | __ Bind(&start_loop); |
| 7649 | // Need to subtract first to handle the empty array case. |
| 7650 | __ subl(maybe_temp2_loc.AsRegister<Register>(), Immediate(2)); |
| 7651 | __ j(kNegative, type_check_slow_path->GetEntryLabel()); |
| 7652 | // Go to next interface if the classes do not match. |
| 7653 | __ cmpl(cls.AsRegister<Register>(), |
| 7654 | CodeGeneratorX86::ArrayAddress(temp, |
| 7655 | maybe_temp2_loc, |
| 7656 | TIMES_4, |
| 7657 | object_array_data_offset)); |
| 7658 | __ j(kNotEqual, &start_loop); |
| 7659 | // If `cls` was poisoned above, unpoison it. |
| 7660 | __ MaybeUnpoisonHeapReference(cls.AsRegister<Register>()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7661 | break; |
| 7662 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7663 | |
| 7664 | case TypeCheckKind::kBitstringCheck: { |
| 7665 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7666 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7667 | temp_loc, |
| 7668 | obj_loc, |
| 7669 | class_offset, |
| 7670 | kWithoutReadBarrier); |
| 7671 | |
| 7672 | GenerateBitstringTypeCheckCompare(instruction, temp); |
| 7673 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
| 7674 | break; |
| 7675 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7676 | } |
| 7677 | __ Bind(&done); |
| 7678 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7679 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7680 | } |
| 7681 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7682 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7683 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 7684 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7685 | InvokeRuntimeCallingConvention calling_convention; |
| 7686 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 7687 | } |
| 7688 | |
| 7689 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 7690 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject |
| 7691 | : kQuickUnlockObject, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 7692 | instruction, |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 7693 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7694 | if (instruction->IsEnter()) { |
| 7695 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 7696 | } else { |
| 7697 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 7698 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7699 | } |
| 7700 | |
Shalini Salomi Bodapati | dd121f6 | 2018-10-26 15:03:53 +0530 | [diff] [blame] | 7701 | void LocationsBuilderX86::VisitX86AndNot(HX86AndNot* instruction) { |
| 7702 | DCHECK(codegen_->GetInstructionSetFeatures().HasAVX2()); |
| 7703 | DCHECK(DataType::IsIntOrLongType(instruction->GetType())) << instruction->GetType(); |
| 7704 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| 7705 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7706 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7707 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7708 | } |
| 7709 | |
| 7710 | void InstructionCodeGeneratorX86::VisitX86AndNot(HX86AndNot* instruction) { |
| 7711 | LocationSummary* locations = instruction->GetLocations(); |
| 7712 | Location first = locations->InAt(0); |
| 7713 | Location second = locations->InAt(1); |
| 7714 | Location dest = locations->Out(); |
| 7715 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
| 7716 | __ andn(dest.AsRegister<Register>(), |
| 7717 | first.AsRegister<Register>(), |
| 7718 | second.AsRegister<Register>()); |
| 7719 | } else { |
| 7720 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
| 7721 | __ andn(dest.AsRegisterPairLow<Register>(), |
| 7722 | first.AsRegisterPairLow<Register>(), |
| 7723 | second.AsRegisterPairLow<Register>()); |
| 7724 | __ andn(dest.AsRegisterPairHigh<Register>(), |
| 7725 | first.AsRegisterPairHigh<Register>(), |
| 7726 | second.AsRegisterPairHigh<Register>()); |
| 7727 | } |
| 7728 | } |
| 7729 | |
| 7730 | void LocationsBuilderX86::VisitX86MaskOrResetLeastSetBit(HX86MaskOrResetLeastSetBit* instruction) { |
| 7731 | DCHECK(codegen_->GetInstructionSetFeatures().HasAVX2()); |
| 7732 | DCHECK(instruction->GetType() == DataType::Type::kInt32) << instruction->GetType(); |
| 7733 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| 7734 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7735 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7736 | } |
| 7737 | |
| 7738 | void InstructionCodeGeneratorX86::VisitX86MaskOrResetLeastSetBit( |
| 7739 | HX86MaskOrResetLeastSetBit* instruction) { |
| 7740 | LocationSummary* locations = instruction->GetLocations(); |
| 7741 | Location src = locations->InAt(0); |
| 7742 | Location dest = locations->Out(); |
| 7743 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
| 7744 | switch (instruction->GetOpKind()) { |
| 7745 | case HInstruction::kAnd: |
| 7746 | __ blsr(dest.AsRegister<Register>(), src.AsRegister<Register>()); |
| 7747 | break; |
| 7748 | case HInstruction::kXor: |
| 7749 | __ blsmsk(dest.AsRegister<Register>(), src.AsRegister<Register>()); |
| 7750 | break; |
| 7751 | default: |
| 7752 | LOG(FATAL) << "Unreachable"; |
| 7753 | } |
| 7754 | } |
| 7755 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7756 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 7757 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 7758 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 7759 | |
| 7760 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 7761 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7762 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7763 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 |
| 7764 | || instruction->GetResultType() == DataType::Type::kInt64); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7765 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7766 | locations->SetInAt(1, Location::Any()); |
| 7767 | locations->SetOut(Location::SameAsFirstInput()); |
| 7768 | } |
| 7769 | |
| 7770 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 7771 | HandleBitwiseOperation(instruction); |
| 7772 | } |
| 7773 | |
| 7774 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 7775 | HandleBitwiseOperation(instruction); |
| 7776 | } |
| 7777 | |
| 7778 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 7779 | HandleBitwiseOperation(instruction); |
| 7780 | } |
| 7781 | |
| 7782 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 7783 | LocationSummary* locations = instruction->GetLocations(); |
| 7784 | Location first = locations->InAt(0); |
| 7785 | Location second = locations->InAt(1); |
| 7786 | DCHECK(first.Equals(locations->Out())); |
| 7787 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7788 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7789 | if (second.IsRegister()) { |
| 7790 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7791 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7792 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7793 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7794 | } else { |
| 7795 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7796 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7797 | } |
| 7798 | } else if (second.IsConstant()) { |
| 7799 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 7800 | __ andl(first.AsRegister<Register>(), |
| 7801 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7802 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 7803 | __ orl(first.AsRegister<Register>(), |
| 7804 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7805 | } else { |
| 7806 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 7807 | __ xorl(first.AsRegister<Register>(), |
| 7808 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7809 | } |
| 7810 | } else { |
| 7811 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7812 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7813 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7814 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7815 | } else { |
| 7816 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7817 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7818 | } |
| 7819 | } |
| 7820 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7821 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7822 | if (second.IsRegisterPair()) { |
| 7823 | if (instruction->IsAnd()) { |
| 7824 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 7825 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 7826 | } else if (instruction->IsOr()) { |
| 7827 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 7828 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 7829 | } else { |
| 7830 | DCHECK(instruction->IsXor()); |
| 7831 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 7832 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 7833 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7834 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7835 | if (instruction->IsAnd()) { |
| 7836 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7837 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 7838 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7839 | } else if (instruction->IsOr()) { |
| 7840 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7841 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 7842 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7843 | } else { |
| 7844 | DCHECK(instruction->IsXor()); |
| 7845 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7846 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 7847 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7848 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7849 | } else { |
| 7850 | DCHECK(second.IsConstant()) << second; |
| 7851 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7852 | int32_t low_value = Low32Bits(value); |
| 7853 | int32_t high_value = High32Bits(value); |
| 7854 | Immediate low(low_value); |
| 7855 | Immediate high(high_value); |
| 7856 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 7857 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7858 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7859 | if (low_value == 0) { |
| 7860 | __ xorl(first_low, first_low); |
| 7861 | } else if (low_value != -1) { |
| 7862 | __ andl(first_low, low); |
| 7863 | } |
| 7864 | if (high_value == 0) { |
| 7865 | __ xorl(first_high, first_high); |
| 7866 | } else if (high_value != -1) { |
| 7867 | __ andl(first_high, high); |
| 7868 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7869 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7870 | if (low_value != 0) { |
| 7871 | __ orl(first_low, low); |
| 7872 | } |
| 7873 | if (high_value != 0) { |
| 7874 | __ orl(first_high, high); |
| 7875 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7876 | } else { |
| 7877 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7878 | if (low_value != 0) { |
| 7879 | __ xorl(first_low, low); |
| 7880 | } |
| 7881 | if (high_value != 0) { |
| 7882 | __ xorl(first_high, high); |
| 7883 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7884 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7885 | } |
| 7886 | } |
| 7887 | } |
| 7888 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7889 | void InstructionCodeGeneratorX86::GenerateReferenceLoadOneRegister( |
| 7890 | HInstruction* instruction, |
| 7891 | Location out, |
| 7892 | uint32_t offset, |
| 7893 | Location maybe_temp, |
| 7894 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7895 | Register out_reg = out.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7896 | if (read_barrier_option == kWithReadBarrier) { |
| 7897 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7898 | if (kUseBakerReadBarrier) { |
| 7899 | // Load with fast path based Baker's read barrier. |
| 7900 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7901 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7902 | instruction, out, out_reg, offset, /* needs_null_check= */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7903 | } else { |
| 7904 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7905 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7906 | // in the following move operation, as we will need it for the |
| 7907 | // read barrier below. |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7908 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7909 | __ movl(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7910 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7911 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7912 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7913 | } |
| 7914 | } else { |
| 7915 | // Plain load with no read barrier. |
| 7916 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7917 | __ movl(out_reg, Address(out_reg, offset)); |
| 7918 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7919 | } |
| 7920 | } |
| 7921 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7922 | void InstructionCodeGeneratorX86::GenerateReferenceLoadTwoRegisters( |
| 7923 | HInstruction* instruction, |
| 7924 | Location out, |
| 7925 | Location obj, |
| 7926 | uint32_t offset, |
| 7927 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7928 | Register out_reg = out.AsRegister<Register>(); |
| 7929 | Register obj_reg = obj.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7930 | if (read_barrier_option == kWithReadBarrier) { |
| 7931 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7932 | if (kUseBakerReadBarrier) { |
| 7933 | // Load with fast path based Baker's read barrier. |
| 7934 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7935 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7936 | instruction, out, obj_reg, offset, /* needs_null_check= */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7937 | } else { |
| 7938 | // Load with slow path based read barrier. |
| 7939 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7940 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7941 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 7942 | } |
| 7943 | } else { |
| 7944 | // Plain load with no read barrier. |
| 7945 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7946 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7947 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7948 | } |
| 7949 | } |
| 7950 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7951 | void InstructionCodeGeneratorX86::GenerateGcRootFieldLoad( |
| 7952 | HInstruction* instruction, |
| 7953 | Location root, |
| 7954 | const Address& address, |
| 7955 | Label* fixup_label, |
| 7956 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7957 | Register root_reg = root.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7958 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7959 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7960 | if (kUseBakerReadBarrier) { |
| 7961 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 7962 | // Baker's read barrier are used: |
| 7963 | // |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7964 | // root = obj.field; |
| 7965 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 7966 | // if (temp != null) { |
| 7967 | // root = temp(root) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7968 | // } |
| 7969 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7970 | // /* GcRoot<mirror::Object> */ root = *address |
| 7971 | __ movl(root_reg, address); |
| 7972 | if (fixup_label != nullptr) { |
| 7973 | __ Bind(fixup_label); |
| 7974 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7975 | static_assert( |
| 7976 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 7977 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 7978 | "have different sizes."); |
| 7979 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 7980 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 7981 | "have different sizes."); |
| 7982 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7983 | // Slow path marking the GC root `root`. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7984 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathX86( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7985 | instruction, root, /* unpoison_ref_before_marking= */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7986 | codegen_->AddSlowPath(slow_path); |
| 7987 | |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7988 | // Test the entrypoint (`Thread::Current()->pReadBarrierMarkReg ## root.reg()`). |
| 7989 | const int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 7990 | Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(root.reg()); |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7991 | __ fs()->cmpl(Address::Absolute(entry_point_offset), Immediate(0)); |
| 7992 | // The entrypoint is null when the GC is not marking. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7993 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 7994 | __ Bind(slow_path->GetExitLabel()); |
| 7995 | } else { |
| 7996 | // GC root loaded through a slow path for read barriers other |
| 7997 | // than Baker's. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7998 | // /* GcRoot<mirror::Object>* */ root = address |
| 7999 | __ leal(root_reg, address); |
| 8000 | if (fixup_label != nullptr) { |
| 8001 | __ Bind(fixup_label); |
| 8002 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8003 | // /* mirror::Object* */ root = root->Read() |
| 8004 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 8005 | } |
| 8006 | } else { |
| 8007 | // Plain GC root load with no read barrier. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8008 | // /* GcRoot<mirror::Object> */ root = *address |
| 8009 | __ movl(root_reg, address); |
| 8010 | if (fixup_label != nullptr) { |
| 8011 | __ Bind(fixup_label); |
| 8012 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 8013 | // Note that GC roots are not affected by heap poisoning, thus we |
| 8014 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8015 | } |
| 8016 | } |
| 8017 | |
| 8018 | void CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8019 | Location ref, |
| 8020 | Register obj, |
| 8021 | uint32_t offset, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8022 | bool needs_null_check) { |
| 8023 | DCHECK(kEmitCompilerReadBarrier); |
| 8024 | DCHECK(kUseBakerReadBarrier); |
| 8025 | |
| 8026 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 8027 | Address src(obj, offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 8028 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8029 | } |
| 8030 | |
| 8031 | void CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8032 | Location ref, |
| 8033 | Register obj, |
| 8034 | uint32_t data_offset, |
| 8035 | Location index, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8036 | bool needs_null_check) { |
| 8037 | DCHECK(kEmitCompilerReadBarrier); |
| 8038 | DCHECK(kUseBakerReadBarrier); |
| 8039 | |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 8040 | static_assert( |
| 8041 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 8042 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8043 | // /* HeapReference<Object> */ ref = |
| 8044 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8045 | Address src = CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 8046 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8047 | } |
| 8048 | |
| 8049 | void CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8050 | Location ref, |
| 8051 | Register obj, |
| 8052 | const Address& src, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 8053 | bool needs_null_check, |
| 8054 | bool always_update_field, |
| 8055 | Register* temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8056 | DCHECK(kEmitCompilerReadBarrier); |
| 8057 | DCHECK(kUseBakerReadBarrier); |
| 8058 | |
| 8059 | // In slow path based read barriers, the read barrier call is |
| 8060 | // inserted after the original load. However, in fast path based |
| 8061 | // Baker's read barriers, we need to perform the load of |
| 8062 | // mirror::Object::monitor_ *before* the original reference load. |
| 8063 | // This load-load ordering is required by the read barrier. |
| 8064 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 8065 | // |
| 8066 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 8067 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 8068 | // HeapReference<Object> ref = *src; // Original reference load. |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 8069 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8070 | // if (is_gray) { |
| 8071 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 8072 | // } |
| 8073 | // |
| 8074 | // Note: the original implementation in ReadBarrier::Barrier is |
| 8075 | // slightly more complex as: |
| 8076 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 8077 | // the high-bits of rb_state, which are expected to be all zeroes |
| 8078 | // (we use CodeGeneratorX86::GenerateMemoryBarrier instead here, |
| 8079 | // which is a no-op thanks to the x86 memory model); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8080 | // - it performs additional checks that we do not do here for |
| 8081 | // performance reasons. |
| 8082 | |
| 8083 | Register ref_reg = ref.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8084 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 8085 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 8086 | // 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] | 8087 | static_assert(ReadBarrier::NonGrayState() == 0, "Expecting non-gray to have value 0"); |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 8088 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 8089 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 8090 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 8091 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 8092 | |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 8093 | // if (rb_state == ReadBarrier::GrayState()) |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 8094 | // ref = ReadBarrier::Mark(ref); |
| 8095 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 8096 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8097 | if (needs_null_check) { |
| 8098 | MaybeRecordImplicitNullCheck(instruction); |
| 8099 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8100 | |
| 8101 | // Load fence to prevent load-load reordering. |
| 8102 | // Note that this is a no-op, thanks to the x86 memory model. |
| 8103 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 8104 | |
| 8105 | // The actual reference load. |
| 8106 | // /* HeapReference<Object> */ ref = *src |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 8107 | __ movl(ref_reg, src); // Flags are unaffected. |
| 8108 | |
| 8109 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 8110 | // Slow path marking the object `ref` when it is gray. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 8111 | SlowPathCode* slow_path; |
| 8112 | if (always_update_field) { |
| 8113 | DCHECK(temp != nullptr); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8114 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkAndUpdateFieldSlowPathX86( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8115 | instruction, ref, obj, src, /* unpoison_ref_before_marking= */ true, *temp); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 8116 | } else { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8117 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkSlowPathX86( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8118 | instruction, ref, /* unpoison_ref_before_marking= */ true); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 8119 | } |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 8120 | AddSlowPath(slow_path); |
| 8121 | |
| 8122 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 8123 | __ j(kNotZero, slow_path->GetEntryLabel()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8124 | |
| 8125 | // Object* ref = ref_addr->AsMirrorPtr() |
| 8126 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 8127 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8128 | __ Bind(slow_path->GetExitLabel()); |
| 8129 | } |
| 8130 | |
| 8131 | void CodeGeneratorX86::GenerateReadBarrierSlow(HInstruction* instruction, |
| 8132 | Location out, |
| 8133 | Location ref, |
| 8134 | Location obj, |
| 8135 | uint32_t offset, |
| 8136 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8137 | DCHECK(kEmitCompilerReadBarrier); |
| 8138 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8139 | // Insert a slow path based read barrier *after* the reference load. |
| 8140 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8141 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 8142 | // reference will be carried out by the runtime within the slow |
| 8143 | // path. |
| 8144 | // |
| 8145 | // Note that `ref` currently does not get unpoisoned (when heap |
| 8146 | // poisoning is enabled), which is alright as the `ref` argument is |
| 8147 | // not used by the artReadBarrierSlow entry point. |
| 8148 | // |
| 8149 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8150 | SlowPathCode* slow_path = new (GetScopedAllocator()) |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8151 | ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); |
| 8152 | AddSlowPath(slow_path); |
| 8153 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8154 | __ jmp(slow_path->GetEntryLabel()); |
| 8155 | __ Bind(slow_path->GetExitLabel()); |
| 8156 | } |
| 8157 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8158 | void CodeGeneratorX86::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 8159 | Location out, |
| 8160 | Location ref, |
| 8161 | Location obj, |
| 8162 | uint32_t offset, |
| 8163 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8164 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8165 | // Baker's read barriers shall be handled by the fast path |
| 8166 | // (CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier). |
| 8167 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8168 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 8169 | // by the runtime within the slow path. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8170 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8171 | } else if (kPoisonHeapReferences) { |
| 8172 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 8173 | } |
| 8174 | } |
| 8175 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8176 | void CodeGeneratorX86::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 8177 | Location out, |
| 8178 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8179 | DCHECK(kEmitCompilerReadBarrier); |
| 8180 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 8181 | // Insert a slow path based read barrier *after* the GC root load. |
| 8182 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8183 | // Note that GC roots are not affected by heap poisoning, so we do |
| 8184 | // not need to do anything special for this here. |
| 8185 | SlowPathCode* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8186 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathX86(instruction, out, root); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8187 | AddSlowPath(slow_path); |
| 8188 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 8189 | __ jmp(slow_path->GetEntryLabel()); |
| 8190 | __ Bind(slow_path->GetExitLabel()); |
| 8191 | } |
| 8192 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 8193 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8194 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8195 | LOG(FATAL) << "Unreachable"; |
| 8196 | } |
| 8197 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 8198 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8199 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8200 | LOG(FATAL) << "Unreachable"; |
| 8201 | } |
| 8202 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8203 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 8204 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 8205 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8206 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8207 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8208 | } |
| 8209 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8210 | void InstructionCodeGeneratorX86::GenPackedSwitchWithCompares(Register value_reg, |
| 8211 | int32_t lower_bound, |
| 8212 | uint32_t num_entries, |
| 8213 | HBasicBlock* switch_block, |
| 8214 | HBasicBlock* default_block) { |
| 8215 | // Figure out the correct compare values and jump conditions. |
| 8216 | // Handle the first compare/branch as a special case because it might |
| 8217 | // jump to the default case. |
| 8218 | DCHECK_GT(num_entries, 2u); |
| 8219 | Condition first_condition; |
| 8220 | uint32_t index; |
| 8221 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 8222 | if (lower_bound != 0) { |
| 8223 | first_condition = kLess; |
| 8224 | __ cmpl(value_reg, Immediate(lower_bound)); |
| 8225 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 8226 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8227 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8228 | index = 1; |
| 8229 | } else { |
| 8230 | // Handle all the compare/jumps below. |
| 8231 | first_condition = kBelow; |
| 8232 | index = 0; |
| 8233 | } |
| 8234 | |
| 8235 | // Handle the rest of the compare/jumps. |
| 8236 | for (; index + 1 < num_entries; index += 2) { |
| 8237 | int32_t compare_to_value = lower_bound + index + 1; |
| 8238 | __ cmpl(value_reg, Immediate(compare_to_value)); |
| 8239 | // Jump to successors[index] if value < case_value[index]. |
| 8240 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 8241 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 8242 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 8243 | } |
| 8244 | |
| 8245 | if (index != num_entries) { |
| 8246 | // There are an odd number of entries. Handle the last one. |
| 8247 | DCHECK_EQ(index + 1, num_entries); |
| 8248 | __ cmpl(value_reg, Immediate(lower_bound + index)); |
| 8249 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8250 | } |
| 8251 | |
| 8252 | // And the default for any other value. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8253 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
| 8254 | __ jmp(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8255 | } |
| 8256 | } |
| 8257 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8258 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 8259 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 8260 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 8261 | LocationSummary* locations = switch_instr->GetLocations(); |
| 8262 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 8263 | |
| 8264 | GenPackedSwitchWithCompares(value_reg, |
| 8265 | lower_bound, |
| 8266 | num_entries, |
| 8267 | switch_instr->GetBlock(), |
| 8268 | switch_instr->GetDefaultBlock()); |
| 8269 | } |
| 8270 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8271 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 8272 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8273 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8274 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8275 | |
| 8276 | // Constant area pointer. |
| 8277 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8278 | |
| 8279 | // And the temporary we need. |
| 8280 | locations->AddTemp(Location::RequiresRegister()); |
| 8281 | } |
| 8282 | |
| 8283 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 8284 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8285 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8286 | LocationSummary* locations = switch_instr->GetLocations(); |
| 8287 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 8288 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 8289 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8290 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 8291 | GenPackedSwitchWithCompares(value_reg, |
| 8292 | lower_bound, |
| 8293 | num_entries, |
| 8294 | switch_instr->GetBlock(), |
| 8295 | default_block); |
| 8296 | return; |
| 8297 | } |
| 8298 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8299 | // Optimizing has a jump area. |
| 8300 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 8301 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 8302 | |
| 8303 | // Remove the bias, if needed. |
| 8304 | if (lower_bound != 0) { |
| 8305 | __ leal(temp_reg, Address(value_reg, -lower_bound)); |
| 8306 | value_reg = temp_reg; |
| 8307 | } |
| 8308 | |
| 8309 | // Is the value in range? |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8310 | DCHECK_GE(num_entries, 1u); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8311 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 8312 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| 8313 | |
| 8314 | // We are in the range of the table. |
| 8315 | // Load (target-constant_area) from the jump table, indexing by the value. |
| 8316 | __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); |
| 8317 | |
| 8318 | // Compute the actual target address by adding in constant_area. |
| 8319 | __ addl(temp_reg, constant_area); |
| 8320 | |
| 8321 | // And jump. |
| 8322 | __ jmp(temp_reg); |
| 8323 | } |
| 8324 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8325 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 8326 | HX86ComputeBaseMethodAddress* insn) { |
| 8327 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8328 | new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8329 | locations->SetOut(Location::RequiresRegister()); |
| 8330 | } |
| 8331 | |
| 8332 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 8333 | HX86ComputeBaseMethodAddress* insn) { |
| 8334 | LocationSummary* locations = insn->GetLocations(); |
| 8335 | Register reg = locations->Out().AsRegister<Register>(); |
| 8336 | |
| 8337 | // Generate call to next instruction. |
| 8338 | Label next_instruction; |
| 8339 | __ call(&next_instruction); |
| 8340 | __ Bind(&next_instruction); |
| 8341 | |
| 8342 | // Remember this offset for later use with constant area. |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8343 | codegen_->AddMethodAddressOffset(insn, GetAssembler()->CodeSize()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8344 | |
| 8345 | // Grab the return address off the stack. |
| 8346 | __ popl(reg); |
| 8347 | } |
| 8348 | |
| 8349 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 8350 | HX86LoadFromConstantTable* insn) { |
| 8351 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8352 | new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8353 | |
| 8354 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8355 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 8356 | |
| 8357 | // 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] | 8358 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8359 | return; |
| 8360 | } |
| 8361 | |
| 8362 | switch (insn->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8363 | case DataType::Type::kFloat32: |
| 8364 | case DataType::Type::kFloat64: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8365 | locations->SetOut(Location::RequiresFpuRegister()); |
| 8366 | break; |
| 8367 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8368 | case DataType::Type::kInt32: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8369 | locations->SetOut(Location::RequiresRegister()); |
| 8370 | break; |
| 8371 | |
| 8372 | default: |
| 8373 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 8374 | } |
| 8375 | } |
| 8376 | |
| 8377 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 8378 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8379 | return; |
| 8380 | } |
| 8381 | |
| 8382 | LocationSummary* locations = insn->GetLocations(); |
| 8383 | Location out = locations->Out(); |
| 8384 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 8385 | HConstant *value = insn->GetConstant(); |
| 8386 | |
| 8387 | switch (insn->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8388 | case DataType::Type::kFloat32: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8389 | __ movss(out.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8390 | codegen_->LiteralFloatAddress( |
| 8391 | value->AsFloatConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8392 | break; |
| 8393 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8394 | case DataType::Type::kFloat64: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8395 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8396 | codegen_->LiteralDoubleAddress( |
| 8397 | value->AsDoubleConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8398 | break; |
| 8399 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8400 | case DataType::Type::kInt32: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8401 | __ movl(out.AsRegister<Register>(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8402 | codegen_->LiteralInt32Address( |
| 8403 | value->AsIntConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8404 | break; |
| 8405 | |
| 8406 | default: |
| 8407 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 8408 | } |
| 8409 | } |
| 8410 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8411 | /** |
| 8412 | * Class to handle late fixup of offsets into constant area. |
| 8413 | */ |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 8414 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8415 | public: |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8416 | RIPFixup(CodeGeneratorX86& codegen, |
| 8417 | HX86ComputeBaseMethodAddress* base_method_address, |
| 8418 | size_t offset) |
| 8419 | : codegen_(&codegen), |
| 8420 | base_method_address_(base_method_address), |
| 8421 | offset_into_constant_area_(offset) {} |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8422 | |
| 8423 | protected: |
| 8424 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 8425 | |
| 8426 | CodeGeneratorX86* codegen_; |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8427 | HX86ComputeBaseMethodAddress* base_method_address_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8428 | |
| 8429 | private: |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8430 | void Process(const MemoryRegion& region, int pos) override { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8431 | // Patch the correct offset for the instruction. The place to patch is the |
| 8432 | // last 4 bytes of the instruction. |
| 8433 | // The value to patch is the distance from the offset in the constant area |
| 8434 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8435 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8436 | int32_t relative_position = |
| 8437 | constant_offset - codegen_->GetMethodAddressOffset(base_method_address_); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8438 | |
| 8439 | // Patch in the right value. |
| 8440 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 8441 | } |
| 8442 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8443 | // Location in constant area that the fixup refers to. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8444 | int32_t offset_into_constant_area_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8445 | }; |
| 8446 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8447 | /** |
| 8448 | * Class to handle late fixup of offsets to a jump table that will be created in the |
| 8449 | * constant area. |
| 8450 | */ |
| 8451 | class JumpTableRIPFixup : public RIPFixup { |
| 8452 | public: |
| 8453 | JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8454 | : RIPFixup(codegen, switch_instr->GetBaseMethodAddress(), static_cast<size_t>(-1)), |
| 8455 | switch_instr_(switch_instr) {} |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8456 | |
| 8457 | void CreateJumpTable() { |
| 8458 | X86Assembler* assembler = codegen_->GetAssembler(); |
| 8459 | |
| 8460 | // Ensure that the reference to the jump table has the correct offset. |
| 8461 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 8462 | SetOffset(offset_in_constant_table); |
| 8463 | |
| 8464 | // The label values in the jump table are computed relative to the |
| 8465 | // instruction addressing the constant area. |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8466 | const int32_t relative_offset = codegen_->GetMethodAddressOffset(base_method_address_); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8467 | |
| 8468 | // Populate the jump table with the correct values for the jump table. |
| 8469 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 8470 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 8471 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 8472 | // The value that we want is the target offset - the position of the table. |
| 8473 | for (int32_t i = 0; i < num_entries; i++) { |
| 8474 | HBasicBlock* b = successors[i]; |
| 8475 | Label* l = codegen_->GetLabelOf(b); |
| 8476 | DCHECK(l->IsBound()); |
| 8477 | int32_t offset_to_block = l->Position() - relative_offset; |
| 8478 | assembler->AppendInt32(offset_to_block); |
| 8479 | } |
| 8480 | } |
| 8481 | |
| 8482 | private: |
| 8483 | const HX86PackedSwitch* switch_instr_; |
| 8484 | }; |
| 8485 | |
| 8486 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 8487 | // Generate the constant area if needed. |
| 8488 | X86Assembler* assembler = GetAssembler(); |
jaishank | 20d1c94 | 2019-03-08 15:08:17 +0530 | [diff] [blame] | 8489 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8490 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 8491 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 8492 | // byte values. |
| 8493 | assembler->Align(4, 0); |
| 8494 | constant_area_start_ = assembler->CodeSize(); |
| 8495 | |
| 8496 | // Populate any jump tables. |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 8497 | for (JumpTableRIPFixup* jump_table : fixups_to_jump_tables_) { |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8498 | jump_table->CreateJumpTable(); |
| 8499 | } |
| 8500 | |
| 8501 | // And now add the constant area to the generated code. |
| 8502 | assembler->AddConstantArea(); |
| 8503 | } |
| 8504 | |
| 8505 | // And finish up. |
| 8506 | CodeGenerator::Finalize(allocator); |
| 8507 | } |
| 8508 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8509 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, |
| 8510 | HX86ComputeBaseMethodAddress* method_base, |
| 8511 | Register reg) { |
| 8512 | AssemblerFixup* fixup = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8513 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddDouble(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8514 | return Address(reg, kDummy32BitOffset, fixup); |
| 8515 | } |
| 8516 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8517 | Address CodeGeneratorX86::LiteralFloatAddress(float v, |
| 8518 | HX86ComputeBaseMethodAddress* method_base, |
| 8519 | Register reg) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8520 | AssemblerFixup* fixup = |
| 8521 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddFloat(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8522 | return Address(reg, kDummy32BitOffset, fixup); |
| 8523 | } |
| 8524 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8525 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, |
| 8526 | HX86ComputeBaseMethodAddress* method_base, |
| 8527 | Register reg) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8528 | AssemblerFixup* fixup = |
| 8529 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddInt32(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8530 | return Address(reg, kDummy32BitOffset, fixup); |
| 8531 | } |
| 8532 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8533 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, |
| 8534 | HX86ComputeBaseMethodAddress* method_base, |
| 8535 | Register reg) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8536 | AssemblerFixup* fixup = |
| 8537 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddInt64(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8538 | return Address(reg, kDummy32BitOffset, fixup); |
| 8539 | } |
| 8540 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 8541 | void CodeGeneratorX86::Load32BitValue(Register dest, int32_t value) { |
| 8542 | if (value == 0) { |
| 8543 | __ xorl(dest, dest); |
| 8544 | } else { |
| 8545 | __ movl(dest, Immediate(value)); |
| 8546 | } |
| 8547 | } |
| 8548 | |
| 8549 | void CodeGeneratorX86::Compare32BitValue(Register dest, int32_t value) { |
| 8550 | if (value == 0) { |
| 8551 | __ testl(dest, dest); |
| 8552 | } else { |
| 8553 | __ cmpl(dest, Immediate(value)); |
| 8554 | } |
| 8555 | } |
| 8556 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8557 | void CodeGeneratorX86::GenerateIntCompare(Location lhs, Location rhs) { |
| 8558 | Register lhs_reg = lhs.AsRegister<Register>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8559 | GenerateIntCompare(lhs_reg, rhs); |
| 8560 | } |
| 8561 | |
| 8562 | void CodeGeneratorX86::GenerateIntCompare(Register lhs, Location rhs) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8563 | if (rhs.IsConstant()) { |
| 8564 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8565 | Compare32BitValue(lhs, value); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8566 | } else if (rhs.IsStackSlot()) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8567 | __ cmpl(lhs, Address(ESP, rhs.GetStackIndex())); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8568 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8569 | __ cmpl(lhs, rhs.AsRegister<Register>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8570 | } |
| 8571 | } |
| 8572 | |
| 8573 | Address CodeGeneratorX86::ArrayAddress(Register obj, |
| 8574 | Location index, |
| 8575 | ScaleFactor scale, |
| 8576 | uint32_t data_offset) { |
| 8577 | return index.IsConstant() ? |
| 8578 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) : |
| 8579 | Address(obj, index.AsRegister<Register>(), scale, data_offset); |
| 8580 | } |
| 8581 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8582 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, |
| 8583 | Register reg, |
| 8584 | Register value) { |
| 8585 | // Create a fixup to be used to create and address the jump table. |
| 8586 | JumpTableRIPFixup* table_fixup = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8587 | new (GetGraph()->GetAllocator()) JumpTableRIPFixup(*this, switch_instr); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8588 | |
| 8589 | // We have to populate the jump tables. |
| 8590 | fixups_to_jump_tables_.push_back(table_fixup); |
| 8591 | |
| 8592 | // We want a scaled address, as we are extracting the correct offset from the table. |
| 8593 | return Address(reg, value, TIMES_4, kDummy32BitOffset, table_fixup); |
| 8594 | } |
| 8595 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8596 | // TODO: target as memory. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8597 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, DataType::Type type) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8598 | if (!target.IsValid()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8599 | DCHECK_EQ(type, DataType::Type::kVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8600 | return; |
| 8601 | } |
| 8602 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8603 | DCHECK_NE(type, DataType::Type::kVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8604 | |
| 8605 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 8606 | if (target.Equals(return_loc)) { |
| 8607 | return; |
| 8608 | } |
| 8609 | |
| 8610 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 8611 | // with the else branch. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8612 | if (type == DataType::Type::kInt64) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8613 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8614 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), DataType::Type::kInt32, nullptr); |
| 8615 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), DataType::Type::kInt32, nullptr); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8616 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 8617 | } else { |
| 8618 | // Let the parallel move resolver take care of all of this. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8619 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8620 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 8621 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 8622 | } |
| 8623 | } |
| 8624 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8625 | void CodeGeneratorX86::PatchJitRootUse(uint8_t* code, |
| 8626 | const uint8_t* roots_data, |
| 8627 | const PatchInfo<Label>& info, |
| 8628 | uint64_t index_in_table) const { |
| 8629 | uint32_t code_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 8630 | uintptr_t address = |
| 8631 | 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] | 8632 | using unaligned_uint32_t __attribute__((__aligned__(1))) = uint32_t; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8633 | reinterpret_cast<unaligned_uint32_t*>(code + code_offset)[0] = |
| 8634 | dchecked_integral_cast<uint32_t>(address); |
| 8635 | } |
| 8636 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 8637 | void CodeGeneratorX86::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 8638 | for (const PatchInfo<Label>& info : jit_string_patches_) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8639 | 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] | 8640 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 8641 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8642 | } |
| 8643 | |
| 8644 | for (const PatchInfo<Label>& info : jit_class_patches_) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8645 | 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] | 8646 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 8647 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 8648 | } |
| 8649 | } |
| 8650 | |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 8651 | void LocationsBuilderX86::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 8652 | ATTRIBUTE_UNUSED) { |
| 8653 | LOG(FATAL) << "Unreachable"; |
| 8654 | } |
| 8655 | |
| 8656 | void InstructionCodeGeneratorX86::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 8657 | ATTRIBUTE_UNUSED) { |
| 8658 | LOG(FATAL) << "Unreachable"; |
| 8659 | } |
| 8660 | |
Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 8661 | bool LocationsBuilderX86::CpuHasAvxFeatureFlag() { |
| 8662 | return codegen_->GetInstructionSetFeatures().HasAVX(); |
| 8663 | } |
| 8664 | bool LocationsBuilderX86::CpuHasAvx2FeatureFlag() { |
| 8665 | return codegen_->GetInstructionSetFeatures().HasAVX2(); |
| 8666 | } |
| 8667 | bool InstructionCodeGeneratorX86::CpuHasAvxFeatureFlag() { |
| 8668 | return codegen_->GetInstructionSetFeatures().HasAVX(); |
| 8669 | } |
| 8670 | bool InstructionCodeGeneratorX86::CpuHasAvx2FeatureFlag() { |
| 8671 | return codegen_->GetInstructionSetFeatures().HasAVX2(); |
| 8672 | } |
| 8673 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 8674 | #undef __ |
| 8675 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 8676 | } // namespace x86 |
| 8677 | } // namespace art |