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 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 19 | #include "art_method.h" |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 20 | #include "class_table.h" |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 21 | #include "code_generator_utils.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 22 | #include "compiled_method.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 23 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 24 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 25 | #include "gc/accounting/card_table.h" |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 26 | #include "gc/space/image_space.h" |
Andreas Gampe | 09659c2 | 2017-09-18 18:23:32 -0700 | [diff] [blame] | 27 | #include "heap_poisoning.h" |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 28 | #include "intrinsics.h" |
| 29 | #include "intrinsics_x86.h" |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 30 | #include "linker/linker_patch.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 31 | #include "lock_word.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 32 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 33 | #include "mirror/class-inl.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 34 | #include "thread.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 35 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 36 | #include "utils/stack_checks.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 37 | #include "utils/x86/assembler_x86.h" |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 38 | #include "utils/x86/managed_register_x86.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 39 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 40 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 41 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 42 | template<class MirrorType> |
| 43 | class GcRoot; |
| 44 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 45 | namespace x86 { |
| 46 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 47 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 48 | static constexpr Register kMethodRegisterArgument = EAX; |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 49 | static constexpr Register kCoreCalleeSaves[] = { EBP, ESI, EDI }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 50 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 51 | static constexpr int kC2ConditionMask = 0x400; |
| 52 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 53 | static constexpr int kFakeReturnRegister = Register(8); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 54 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 55 | static constexpr int64_t kDoubleNaN = INT64_C(0x7FF8000000000000); |
| 56 | static constexpr int32_t kFloatNaN = INT32_C(0x7FC00000); |
| 57 | |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 58 | static RegisterSet OneRegInReferenceOutSaveEverythingCallerSaves() { |
| 59 | InvokeRuntimeCallingConvention calling_convention; |
| 60 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 61 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 62 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 63 | // that the the kPrimNot result register is the same as the first argument register. |
| 64 | return caller_saves; |
| 65 | } |
| 66 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 67 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 68 | #define __ down_cast<X86Assembler*>(codegen->GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 69 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86PointerSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 70 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 71 | class NullCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 72 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 73 | explicit NullCheckSlowPathX86(HNullCheck* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 74 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 75 | void EmitNativeCode(CodeGenerator* codegen) override { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 76 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 77 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 78 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 79 | // Live registers will be restored in the catch block if caught. |
| 80 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 81 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 82 | x86_codegen->InvokeRuntime(kQuickThrowNullPointer, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 83 | instruction_, |
| 84 | instruction_->GetDexPc(), |
| 85 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 86 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 87 | } |
| 88 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 89 | bool IsFatal() const override { return true; } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 90 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 91 | const char* GetDescription() const override { return "NullCheckSlowPathX86"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 92 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 93 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 94 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86); |
| 95 | }; |
| 96 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 97 | class DivZeroCheckSlowPathX86 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 98 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 99 | explicit DivZeroCheckSlowPathX86(HDivZeroCheck* instruction) : SlowPathCode(instruction) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 100 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 101 | void EmitNativeCode(CodeGenerator* codegen) override { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 102 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 103 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 104 | x86_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 105 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 106 | } |
| 107 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 108 | bool IsFatal() const override { return true; } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 109 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 110 | const char* GetDescription() const override { return "DivZeroCheckSlowPathX86"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 111 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 112 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 113 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86); |
| 114 | }; |
| 115 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 116 | class DivRemMinusOneSlowPathX86 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 117 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 118 | DivRemMinusOneSlowPathX86(HInstruction* instruction, Register reg, bool is_div) |
| 119 | : SlowPathCode(instruction), reg_(reg), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 120 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 121 | void EmitNativeCode(CodeGenerator* codegen) override { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 122 | __ Bind(GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 123 | if (is_div_) { |
| 124 | __ negl(reg_); |
| 125 | } else { |
| 126 | __ movl(reg_, Immediate(0)); |
| 127 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 128 | __ jmp(GetExitLabel()); |
| 129 | } |
| 130 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 131 | const char* GetDescription() const override { return "DivRemMinusOneSlowPathX86"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 132 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 133 | private: |
| 134 | Register reg_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 135 | bool is_div_; |
| 136 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 137 | }; |
| 138 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 139 | class BoundsCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 140 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 141 | explicit BoundsCheckSlowPathX86(HBoundsCheck* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 142 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 143 | void EmitNativeCode(CodeGenerator* codegen) override { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 144 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 145 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 146 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 147 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 148 | // move resolver. |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 149 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 150 | // Live registers will be restored in the catch block if caught. |
| 151 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 152 | } |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 153 | |
| 154 | // Are we using an array length from memory? |
| 155 | HInstruction* array_length = instruction_->InputAt(1); |
| 156 | Location length_loc = locations->InAt(1); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 157 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 158 | if (array_length->IsArrayLength() && array_length->IsEmittedAtUseSite()) { |
| 159 | // Load the array length into our temporary. |
Nicolas Geoffray | 0aff3a8 | 2017-10-13 13:12:36 +0100 | [diff] [blame] | 160 | HArrayLength* length = array_length->AsArrayLength(); |
| 161 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(length); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 162 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 163 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
| 164 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(1)); |
| 165 | // Check for conflicts with index. |
| 166 | if (length_loc.Equals(locations->InAt(0))) { |
| 167 | // We know we aren't using parameter 2. |
| 168 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(2)); |
| 169 | } |
| 170 | __ movl(length_loc.AsRegister<Register>(), array_len); |
Nicolas Geoffray | 0aff3a8 | 2017-10-13 13:12:36 +0100 | [diff] [blame] | 171 | if (mirror::kUseStringCompression && length->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 172 | __ shrl(length_loc.AsRegister<Register>(), Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 173 | } |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 174 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 175 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 176 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 177 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 178 | DataType::Type::kInt32, |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 179 | length_loc, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 180 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 181 | DataType::Type::kInt32); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 182 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 183 | ? kQuickThrowStringBounds |
| 184 | : kQuickThrowArrayBounds; |
| 185 | x86_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 186 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 187 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 188 | } |
| 189 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 190 | bool IsFatal() const override { return true; } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 191 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 192 | const char* GetDescription() const override { return "BoundsCheckSlowPathX86"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 193 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 194 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 195 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86); |
| 196 | }; |
| 197 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 198 | class SuspendCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 199 | public: |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 200 | SuspendCheckSlowPathX86(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 201 | : SlowPathCode(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 202 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 203 | void EmitNativeCode(CodeGenerator* codegen) override { |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 204 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 205 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 206 | __ Bind(GetEntryLabel()); |
Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 207 | SaveLiveRegisters(codegen, locations); // Only saves full width XMM for SIMD. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 208 | x86_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 209 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 210 | RestoreLiveRegisters(codegen, locations); // Only restores full width XMM for SIMD. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 211 | if (successor_ == nullptr) { |
| 212 | __ jmp(GetReturnLabel()); |
| 213 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 214 | __ jmp(x86_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 215 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 216 | } |
| 217 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 218 | Label* GetReturnLabel() { |
| 219 | DCHECK(successor_ == nullptr); |
| 220 | return &return_label_; |
| 221 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 222 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 223 | HBasicBlock* GetSuccessor() const { |
| 224 | return successor_; |
| 225 | } |
| 226 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 227 | const char* GetDescription() const override { return "SuspendCheckSlowPathX86"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 228 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 229 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 230 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 231 | Label return_label_; |
| 232 | |
| 233 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86); |
| 234 | }; |
| 235 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 236 | class LoadStringSlowPathX86 : public SlowPathCode { |
| 237 | public: |
| 238 | explicit LoadStringSlowPathX86(HLoadString* instruction): SlowPathCode(instruction) {} |
| 239 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 240 | void EmitNativeCode(CodeGenerator* codegen) override { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 241 | LocationSummary* locations = instruction_->GetLocations(); |
| 242 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 243 | |
| 244 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 245 | __ Bind(GetEntryLabel()); |
| 246 | SaveLiveRegisters(codegen, locations); |
| 247 | |
| 248 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 249 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 250 | __ movl(calling_convention.GetRegisterAt(0), Immediate(string_index.index_)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 251 | x86_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 252 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 253 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 254 | RestoreLiveRegisters(codegen, locations); |
| 255 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 256 | __ jmp(GetExitLabel()); |
| 257 | } |
| 258 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 259 | const char* GetDescription() const override { return "LoadStringSlowPathX86"; } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 260 | |
| 261 | private: |
| 262 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86); |
| 263 | }; |
| 264 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 265 | class LoadClassSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 266 | public: |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 267 | LoadClassSlowPathX86(HLoadClass* cls, HInstruction* at) |
| 268 | : SlowPathCode(at), cls_(cls) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 269 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 270 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 271 | } |
| 272 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 273 | void EmitNativeCode(CodeGenerator* codegen) override { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 274 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 275 | Location out = locations->Out(); |
| 276 | const uint32_t dex_pc = instruction_->GetDexPc(); |
| 277 | bool must_resolve_type = instruction_->IsLoadClass() && cls_->MustResolveTypeOnSlowPath(); |
| 278 | bool must_do_clinit = instruction_->IsClinitCheck() || cls_->MustGenerateClinitCheck(); |
| 279 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 280 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 281 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 282 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 283 | |
| 284 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 285 | if (must_resolve_type) { |
| 286 | DCHECK(IsSameDexFile(cls_->GetDexFile(), x86_codegen->GetGraph()->GetDexFile())); |
| 287 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 288 | __ movl(calling_convention.GetRegisterAt(0), Immediate(type_index.index_)); |
Vladimir Marko | 9d47925 | 2018-07-24 11:35:20 +0100 | [diff] [blame] | 289 | x86_codegen->InvokeRuntime(kQuickResolveType, instruction_, dex_pc, this); |
| 290 | CheckEntrypointTypes<kQuickResolveType, void*, uint32_t>(); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 291 | // If we also must_do_clinit, the resolved type is now in the correct register. |
| 292 | } else { |
| 293 | DCHECK(must_do_clinit); |
| 294 | Location source = instruction_->IsLoadClass() ? out : locations->InAt(0); |
| 295 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), source); |
| 296 | } |
| 297 | if (must_do_clinit) { |
| 298 | x86_codegen->InvokeRuntime(kQuickInitializeStaticStorage, instruction_, dex_pc, this); |
| 299 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, mirror::Class*>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 300 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 301 | |
| 302 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 303 | if (out.IsValid()) { |
| 304 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 305 | x86_codegen->Move32(out, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 306 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 307 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 308 | __ jmp(GetExitLabel()); |
| 309 | } |
| 310 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 311 | const char* GetDescription() const override { return "LoadClassSlowPathX86"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 312 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 313 | private: |
| 314 | // The class this slow path will load. |
| 315 | HLoadClass* const cls_; |
| 316 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 317 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86); |
| 318 | }; |
| 319 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 320 | class TypeCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 321 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 322 | TypeCheckSlowPathX86(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 323 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 324 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 325 | void EmitNativeCode(CodeGenerator* codegen) override { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 326 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 327 | DCHECK(instruction_->IsCheckCast() |
| 328 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 329 | |
| 330 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 331 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 332 | |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 333 | if (kPoisonHeapReferences && |
| 334 | instruction_->IsCheckCast() && |
| 335 | instruction_->AsCheckCast()->GetTypeCheckKind() == TypeCheckKind::kInterfaceCheck) { |
| 336 | // First, unpoison the `cls` reference that was poisoned for direct memory comparison. |
| 337 | __ UnpoisonHeapReference(locations->InAt(1).AsRegister<Register>()); |
| 338 | } |
| 339 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 340 | if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 341 | SaveLiveRegisters(codegen, locations); |
| 342 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 343 | |
| 344 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 345 | // move resolver. |
| 346 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 347 | x86_codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 348 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 349 | DataType::Type::kReference, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 350 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 351 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 352 | DataType::Type::kReference); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 353 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 354 | x86_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 355 | instruction_, |
| 356 | instruction_->GetDexPc(), |
| 357 | this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 358 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 359 | } else { |
| 360 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 361 | x86_codegen->InvokeRuntime(kQuickCheckInstanceOf, |
| 362 | instruction_, |
| 363 | instruction_->GetDexPc(), |
| 364 | this); |
| 365 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 366 | } |
| 367 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 368 | if (!is_fatal_) { |
| 369 | if (instruction_->IsInstanceOf()) { |
| 370 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 371 | } |
| 372 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 373 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 374 | __ jmp(GetExitLabel()); |
| 375 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 376 | } |
| 377 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 378 | const char* GetDescription() const override { return "TypeCheckSlowPathX86"; } |
| 379 | bool IsFatal() const override { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 380 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 381 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 382 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 383 | |
| 384 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86); |
| 385 | }; |
| 386 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 387 | class DeoptimizationSlowPathX86 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 388 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 389 | explicit DeoptimizationSlowPathX86(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 390 | : SlowPathCode(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 391 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 392 | void EmitNativeCode(CodeGenerator* codegen) override { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 393 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 394 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 395 | LocationSummary* locations = instruction_->GetLocations(); |
| 396 | SaveLiveRegisters(codegen, locations); |
| 397 | InvokeRuntimeCallingConvention calling_convention; |
| 398 | x86_codegen->Load32BitValue( |
| 399 | calling_convention.GetRegisterAt(0), |
| 400 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 401 | x86_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 402 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 403 | } |
| 404 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 405 | const char* GetDescription() const override { return "DeoptimizationSlowPathX86"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 406 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 407 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 408 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86); |
| 409 | }; |
| 410 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 411 | class ArraySetSlowPathX86 : public SlowPathCode { |
| 412 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 413 | explicit ArraySetSlowPathX86(HInstruction* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 414 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 415 | void EmitNativeCode(CodeGenerator* codegen) override { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 416 | LocationSummary* locations = instruction_->GetLocations(); |
| 417 | __ Bind(GetEntryLabel()); |
| 418 | SaveLiveRegisters(codegen, locations); |
| 419 | |
| 420 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 421 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 422 | parallel_move.AddMove( |
| 423 | locations->InAt(0), |
| 424 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 425 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 426 | nullptr); |
| 427 | parallel_move.AddMove( |
| 428 | locations->InAt(1), |
| 429 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 430 | DataType::Type::kInt32, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 431 | nullptr); |
| 432 | parallel_move.AddMove( |
| 433 | locations->InAt(2), |
| 434 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 435 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 436 | nullptr); |
| 437 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 438 | |
| 439 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 440 | x86_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 441 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 442 | RestoreLiveRegisters(codegen, locations); |
| 443 | __ jmp(GetExitLabel()); |
| 444 | } |
| 445 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 446 | const char* GetDescription() const override { return "ArraySetSlowPathX86"; } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 447 | |
| 448 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 449 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86); |
| 450 | }; |
| 451 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 452 | // Slow path marking an object reference `ref` during a read |
| 453 | // barrier. The field `obj.field` in the object `obj` holding this |
| 454 | // reference does not get updated by this slow path after marking (see |
| 455 | // ReadBarrierMarkAndUpdateFieldSlowPathX86 below for that). |
| 456 | // |
| 457 | // This means that after the execution of this slow path, `ref` will |
| 458 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 459 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 460 | // probably still be a from-space reference (unless it gets updated by |
| 461 | // another thread, or if another thread installed another object |
| 462 | // reference (different from `ref`) in `obj.field`). |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 463 | class ReadBarrierMarkSlowPathX86 : public SlowPathCode { |
| 464 | public: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 465 | ReadBarrierMarkSlowPathX86(HInstruction* instruction, |
| 466 | Location ref, |
| 467 | bool unpoison_ref_before_marking) |
| 468 | : SlowPathCode(instruction), |
| 469 | ref_(ref), |
| 470 | unpoison_ref_before_marking_(unpoison_ref_before_marking) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 471 | DCHECK(kEmitCompilerReadBarrier); |
| 472 | } |
| 473 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 474 | const char* GetDescription() const override { return "ReadBarrierMarkSlowPathX86"; } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 475 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 476 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 477 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 478 | Register ref_reg = ref_.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 479 | DCHECK(locations->CanCall()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 480 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 481 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 482 | instruction_->IsStaticFieldGet() || |
| 483 | instruction_->IsArrayGet() || |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 484 | instruction_->IsArraySet() || |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 485 | instruction_->IsLoadClass() || |
| 486 | instruction_->IsLoadString() || |
| 487 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 488 | instruction_->IsCheckCast() || |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 489 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 490 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 491 | << "Unexpected instruction in read barrier marking slow path: " |
| 492 | << instruction_->DebugName(); |
| 493 | |
| 494 | __ Bind(GetEntryLabel()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 495 | if (unpoison_ref_before_marking_) { |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 496 | // Object* ref = ref_addr->AsMirrorPtr() |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 497 | __ MaybeUnpoisonHeapReference(ref_reg); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 498 | } |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 499 | // No need to save live registers; it's taken care of by the |
| 500 | // entrypoint. Also, there is no need to update the stack mask, |
| 501 | // as this runtime call will not trigger a garbage collection. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 502 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 503 | DCHECK_NE(ref_reg, ESP); |
| 504 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 505 | // "Compact" slow path, saving two moves. |
| 506 | // |
| 507 | // Instead of using the standard runtime calling convention (input |
| 508 | // and output in EAX): |
| 509 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 510 | // EAX <- ref |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 511 | // EAX <- ReadBarrierMark(EAX) |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 512 | // ref <- EAX |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 513 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 514 | // we just use rX (the register containing `ref`) as input and output |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 515 | // of a dedicated entrypoint: |
| 516 | // |
| 517 | // rX <- ReadBarrierMarkRegX(rX) |
| 518 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 519 | int32_t entry_point_offset = Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(ref_reg); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 520 | // This runtime call does not require a stack map. |
| 521 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 522 | __ jmp(GetExitLabel()); |
| 523 | } |
| 524 | |
| 525 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 526 | // The location (register) of the marked object reference. |
| 527 | const Location ref_; |
| 528 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 529 | const bool unpoison_ref_before_marking_; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 530 | |
| 531 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86); |
| 532 | }; |
| 533 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 534 | // Slow path marking an object reference `ref` during a read barrier, |
| 535 | // and if needed, atomically updating the field `obj.field` in the |
| 536 | // object `obj` holding this reference after marking (contrary to |
| 537 | // ReadBarrierMarkSlowPathX86 above, which never tries to update |
| 538 | // `obj.field`). |
| 539 | // |
| 540 | // This means that after the execution of this slow path, both `ref` |
| 541 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 542 | // hold the same to-space reference (unless another thread installed |
| 543 | // another object reference (different from `ref`) in `obj.field`). |
| 544 | class ReadBarrierMarkAndUpdateFieldSlowPathX86 : public SlowPathCode { |
| 545 | public: |
| 546 | ReadBarrierMarkAndUpdateFieldSlowPathX86(HInstruction* instruction, |
| 547 | Location ref, |
| 548 | Register obj, |
| 549 | const Address& field_addr, |
| 550 | bool unpoison_ref_before_marking, |
| 551 | Register temp) |
| 552 | : SlowPathCode(instruction), |
| 553 | ref_(ref), |
| 554 | obj_(obj), |
| 555 | field_addr_(field_addr), |
| 556 | unpoison_ref_before_marking_(unpoison_ref_before_marking), |
| 557 | temp_(temp) { |
| 558 | DCHECK(kEmitCompilerReadBarrier); |
| 559 | } |
| 560 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 561 | const char* GetDescription() const override { return "ReadBarrierMarkAndUpdateFieldSlowPathX86"; } |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 562 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 563 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 564 | LocationSummary* locations = instruction_->GetLocations(); |
| 565 | Register ref_reg = ref_.AsRegister<Register>(); |
| 566 | DCHECK(locations->CanCall()); |
| 567 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 568 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 569 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 570 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 571 | << instruction_->DebugName(); |
| 572 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 573 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 574 | |
| 575 | __ Bind(GetEntryLabel()); |
| 576 | if (unpoison_ref_before_marking_) { |
| 577 | // Object* ref = ref_addr->AsMirrorPtr() |
| 578 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 579 | } |
| 580 | |
| 581 | // Save the old (unpoisoned) reference. |
| 582 | __ movl(temp_, ref_reg); |
| 583 | |
| 584 | // No need to save live registers; it's taken care of by the |
| 585 | // entrypoint. Also, there is no need to update the stack mask, |
| 586 | // as this runtime call will not trigger a garbage collection. |
| 587 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 588 | DCHECK_NE(ref_reg, ESP); |
| 589 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
| 590 | // "Compact" slow path, saving two moves. |
| 591 | // |
| 592 | // Instead of using the standard runtime calling convention (input |
| 593 | // and output in EAX): |
| 594 | // |
| 595 | // EAX <- ref |
| 596 | // EAX <- ReadBarrierMark(EAX) |
| 597 | // ref <- EAX |
| 598 | // |
| 599 | // we just use rX (the register containing `ref`) as input and output |
| 600 | // of a dedicated entrypoint: |
| 601 | // |
| 602 | // rX <- ReadBarrierMarkRegX(rX) |
| 603 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 604 | int32_t entry_point_offset = Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(ref_reg); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 605 | // This runtime call does not require a stack map. |
| 606 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 607 | |
| 608 | // If the new reference is different from the old reference, |
| 609 | // update the field in the holder (`*field_addr`). |
| 610 | // |
| 611 | // Note that this field could also hold a different object, if |
| 612 | // another thread had concurrently changed it. In that case, the |
| 613 | // LOCK CMPXCHGL instruction in the compare-and-set (CAS) |
| 614 | // operation below would abort the CAS, leaving the field as-is. |
| 615 | NearLabel done; |
| 616 | __ cmpl(temp_, ref_reg); |
| 617 | __ j(kEqual, &done); |
| 618 | |
| 619 | // Update the the holder's field atomically. This may fail if |
| 620 | // mutator updates before us, but it's OK. This is achieved |
| 621 | // using a strong compare-and-set (CAS) operation with relaxed |
| 622 | // memory synchronization ordering, where the expected value is |
| 623 | // the old reference and the desired value is the new reference. |
| 624 | // This operation is implemented with a 32-bit LOCK CMPXLCHG |
| 625 | // instruction, which requires the expected value (the old |
| 626 | // reference) to be in EAX. Save EAX beforehand, and move the |
| 627 | // expected value (stored in `temp_`) into EAX. |
| 628 | __ pushl(EAX); |
| 629 | __ movl(EAX, temp_); |
| 630 | |
| 631 | // Convenience aliases. |
| 632 | Register base = obj_; |
| 633 | Register expected = EAX; |
| 634 | Register value = ref_reg; |
| 635 | |
| 636 | bool base_equals_value = (base == value); |
| 637 | if (kPoisonHeapReferences) { |
| 638 | if (base_equals_value) { |
| 639 | // If `base` and `value` are the same register location, move |
| 640 | // `value` to a temporary register. This way, poisoning |
| 641 | // `value` won't invalidate `base`. |
| 642 | value = temp_; |
| 643 | __ movl(value, base); |
| 644 | } |
| 645 | |
| 646 | // Check that the register allocator did not assign the location |
| 647 | // of `expected` (EAX) to `value` nor to `base`, so that heap |
| 648 | // poisoning (when enabled) works as intended below. |
| 649 | // - If `value` were equal to `expected`, both references would |
| 650 | // be poisoned twice, meaning they would not be poisoned at |
| 651 | // all, as heap poisoning uses address negation. |
| 652 | // - If `base` were equal to `expected`, poisoning `expected` |
| 653 | // would invalidate `base`. |
| 654 | DCHECK_NE(value, expected); |
| 655 | DCHECK_NE(base, expected); |
| 656 | |
| 657 | __ PoisonHeapReference(expected); |
| 658 | __ PoisonHeapReference(value); |
| 659 | } |
| 660 | |
| 661 | __ LockCmpxchgl(field_addr_, value); |
| 662 | |
| 663 | // If heap poisoning is enabled, we need to unpoison the values |
| 664 | // that were poisoned earlier. |
| 665 | if (kPoisonHeapReferences) { |
| 666 | if (base_equals_value) { |
| 667 | // `value` has been moved to a temporary register, no need |
| 668 | // to unpoison it. |
| 669 | } else { |
| 670 | __ UnpoisonHeapReference(value); |
| 671 | } |
| 672 | // No need to unpoison `expected` (EAX), as it is be overwritten below. |
| 673 | } |
| 674 | |
| 675 | // Restore EAX. |
| 676 | __ popl(EAX); |
| 677 | |
| 678 | __ Bind(&done); |
| 679 | __ jmp(GetExitLabel()); |
| 680 | } |
| 681 | |
| 682 | private: |
| 683 | // The location (register) of the marked object reference. |
| 684 | const Location ref_; |
| 685 | // The register containing the object holding the marked object reference field. |
| 686 | const Register obj_; |
| 687 | // The address of the marked reference field. The base of this address must be `obj_`. |
| 688 | const Address field_addr_; |
| 689 | |
| 690 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 691 | const bool unpoison_ref_before_marking_; |
| 692 | |
| 693 | const Register temp_; |
| 694 | |
| 695 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathX86); |
| 696 | }; |
| 697 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 698 | // Slow path generating a read barrier for a heap reference. |
| 699 | class ReadBarrierForHeapReferenceSlowPathX86 : public SlowPathCode { |
| 700 | public: |
| 701 | ReadBarrierForHeapReferenceSlowPathX86(HInstruction* instruction, |
| 702 | Location out, |
| 703 | Location ref, |
| 704 | Location obj, |
| 705 | uint32_t offset, |
| 706 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 707 | : SlowPathCode(instruction), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 708 | out_(out), |
| 709 | ref_(ref), |
| 710 | obj_(obj), |
| 711 | offset_(offset), |
| 712 | index_(index) { |
| 713 | DCHECK(kEmitCompilerReadBarrier); |
| 714 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 715 | // has been overwritten by (or after) the heap object reference load |
| 716 | // to be instrumented, e.g.: |
| 717 | // |
| 718 | // __ movl(out, Address(out, offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 719 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 720 | // |
| 721 | // In that case, we have lost the information about the original |
| 722 | // object, and the emitted read barrier cannot work properly. |
| 723 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 724 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 725 | } |
| 726 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 727 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 728 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 729 | LocationSummary* locations = instruction_->GetLocations(); |
| 730 | Register reg_out = out_.AsRegister<Register>(); |
| 731 | DCHECK(locations->CanCall()); |
| 732 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 733 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 734 | instruction_->IsStaticFieldGet() || |
| 735 | instruction_->IsArrayGet() || |
| 736 | instruction_->IsInstanceOf() || |
| 737 | instruction_->IsCheckCast() || |
Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 738 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 739 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 740 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 741 | |
| 742 | __ Bind(GetEntryLabel()); |
| 743 | SaveLiveRegisters(codegen, locations); |
| 744 | |
| 745 | // We may have to change the index's value, but as `index_` is a |
| 746 | // constant member (like other "inputs" of this slow path), |
| 747 | // introduce a copy of it, `index`. |
| 748 | Location index = index_; |
| 749 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 750 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 751 | if (instruction_->IsArrayGet()) { |
| 752 | // Compute the actual memory offset and store it in `index`. |
| 753 | Register index_reg = index_.AsRegister<Register>(); |
| 754 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 755 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 756 | // We are about to change the value of `index_reg` (see the |
| 757 | // calls to art::x86::X86Assembler::shll and |
| 758 | // art::x86::X86Assembler::AddImmediate below), but it has |
| 759 | // not been saved by the previous call to |
| 760 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 761 | // callee-save register -- |
| 762 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 763 | // callee-save registers, as it has been designed with the |
| 764 | // assumption that callee-save registers are supposed to be |
| 765 | // handled by the called function. So, as a callee-save |
| 766 | // register, `index_reg` _would_ eventually be saved onto |
| 767 | // the stack, but it would be too late: we would have |
| 768 | // changed its value earlier. Therefore, we manually save |
| 769 | // it here into another freely available register, |
| 770 | // `free_reg`, chosen of course among the caller-save |
| 771 | // registers (as a callee-save `free_reg` register would |
| 772 | // exhibit the same problem). |
| 773 | // |
| 774 | // Note we could have requested a temporary register from |
| 775 | // the register allocator instead; but we prefer not to, as |
| 776 | // this is a slow path, and we know we can find a |
| 777 | // caller-save register that is available. |
| 778 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 779 | __ movl(free_reg, index_reg); |
| 780 | index_reg = free_reg; |
| 781 | index = Location::RegisterLocation(index_reg); |
| 782 | } else { |
| 783 | // The initial register stored in `index_` has already been |
| 784 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 785 | // (as it is not a callee-save register), so we can freely |
| 786 | // use it. |
| 787 | } |
| 788 | // Shifting the index value contained in `index_reg` by the scale |
| 789 | // factor (2) cannot overflow in practice, as the runtime is |
| 790 | // unable to allocate object arrays with a size larger than |
| 791 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 792 | __ shll(index_reg, Immediate(TIMES_4)); |
| 793 | static_assert( |
| 794 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 795 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 796 | __ AddImmediate(index_reg, Immediate(offset_)); |
| 797 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 798 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 799 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 800 | // (as in the case of ArrayGet), as it is actually an offset |
| 801 | // to an object field within an object. |
| 802 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 803 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 804 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 805 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 806 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 807 | DCHECK_EQ(offset_, 0U); |
| 808 | DCHECK(index_.IsRegisterPair()); |
| 809 | // UnsafeGet's offset location is a register pair, the low |
| 810 | // part contains the correct offset. |
| 811 | index = index_.ToLow(); |
| 812 | } |
| 813 | } |
| 814 | |
| 815 | // We're moving two or three locations to locations that could |
| 816 | // overlap, so we need a parallel move resolver. |
| 817 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 818 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 819 | parallel_move.AddMove(ref_, |
| 820 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 821 | DataType::Type::kReference, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 822 | nullptr); |
| 823 | parallel_move.AddMove(obj_, |
| 824 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 825 | DataType::Type::kReference, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 826 | nullptr); |
| 827 | if (index.IsValid()) { |
| 828 | parallel_move.AddMove(index, |
| 829 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 830 | DataType::Type::kInt32, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 831 | nullptr); |
| 832 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 833 | } else { |
| 834 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 835 | __ movl(calling_convention.GetRegisterAt(2), Immediate(offset_)); |
| 836 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 837 | x86_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 838 | CheckEntrypointTypes< |
| 839 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 840 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 841 | |
| 842 | RestoreLiveRegisters(codegen, locations); |
| 843 | __ jmp(GetExitLabel()); |
| 844 | } |
| 845 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 846 | const char* GetDescription() const override { return "ReadBarrierForHeapReferenceSlowPathX86"; } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 847 | |
| 848 | private: |
| 849 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 850 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 851 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 852 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 853 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 854 | return static_cast<Register>(i); |
| 855 | } |
| 856 | } |
| 857 | // We shall never fail to find a free caller-save register, as |
| 858 | // there are more than two core caller-save registers on x86 |
| 859 | // (meaning it is possible to find one which is different from |
| 860 | // `ref` and `obj`). |
| 861 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 862 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 863 | UNREACHABLE(); |
| 864 | } |
| 865 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 866 | const Location out_; |
| 867 | const Location ref_; |
| 868 | const Location obj_; |
| 869 | const uint32_t offset_; |
| 870 | // An additional location containing an index to an array. |
| 871 | // Only used for HArrayGet and the UnsafeGetObject & |
| 872 | // UnsafeGetObjectVolatile intrinsics. |
| 873 | const Location index_; |
| 874 | |
| 875 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86); |
| 876 | }; |
| 877 | |
| 878 | // Slow path generating a read barrier for a GC root. |
| 879 | class ReadBarrierForRootSlowPathX86 : public SlowPathCode { |
| 880 | public: |
| 881 | ReadBarrierForRootSlowPathX86(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 882 | : SlowPathCode(instruction), out_(out), root_(root) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 883 | DCHECK(kEmitCompilerReadBarrier); |
| 884 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 885 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 886 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 887 | LocationSummary* locations = instruction_->GetLocations(); |
| 888 | Register reg_out = out_.AsRegister<Register>(); |
| 889 | DCHECK(locations->CanCall()); |
| 890 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 891 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 892 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 893 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 894 | |
| 895 | __ Bind(GetEntryLabel()); |
| 896 | SaveLiveRegisters(codegen, locations); |
| 897 | |
| 898 | InvokeRuntimeCallingConvention calling_convention; |
| 899 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 900 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 901 | x86_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 902 | instruction_, |
| 903 | instruction_->GetDexPc(), |
| 904 | this); |
| 905 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 906 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 907 | |
| 908 | RestoreLiveRegisters(codegen, locations); |
| 909 | __ jmp(GetExitLabel()); |
| 910 | } |
| 911 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 912 | const char* GetDescription() const override { return "ReadBarrierForRootSlowPathX86"; } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 913 | |
| 914 | private: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 915 | const Location out_; |
| 916 | const Location root_; |
| 917 | |
| 918 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86); |
| 919 | }; |
| 920 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 921 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 922 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 923 | #define __ down_cast<X86Assembler*>(GetAssembler())-> // NOLINT |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 924 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 925 | inline Condition X86Condition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 926 | switch (cond) { |
| 927 | case kCondEQ: return kEqual; |
| 928 | case kCondNE: return kNotEqual; |
| 929 | case kCondLT: return kLess; |
| 930 | case kCondLE: return kLessEqual; |
| 931 | case kCondGT: return kGreater; |
| 932 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 933 | case kCondB: return kBelow; |
| 934 | case kCondBE: return kBelowEqual; |
| 935 | case kCondA: return kAbove; |
| 936 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 937 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 938 | LOG(FATAL) << "Unreachable"; |
| 939 | UNREACHABLE(); |
| 940 | } |
| 941 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 942 | // Maps signed condition to unsigned condition and FP condition to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 943 | inline Condition X86UnsignedOrFPCondition(IfCondition cond) { |
| 944 | switch (cond) { |
| 945 | case kCondEQ: return kEqual; |
| 946 | case kCondNE: return kNotEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 947 | // Signed to unsigned, and FP to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 948 | case kCondLT: return kBelow; |
| 949 | case kCondLE: return kBelowEqual; |
| 950 | case kCondGT: return kAbove; |
| 951 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 952 | // Unsigned remain unchanged. |
| 953 | case kCondB: return kBelow; |
| 954 | case kCondBE: return kBelowEqual; |
| 955 | case kCondA: return kAbove; |
| 956 | case kCondAE: return kAboveEqual; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 957 | } |
| 958 | LOG(FATAL) << "Unreachable"; |
| 959 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 960 | } |
| 961 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 962 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 963 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 964 | } |
| 965 | |
| 966 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 967 | stream << XmmRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 968 | } |
| 969 | |
Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 970 | const X86InstructionSetFeatures& CodeGeneratorX86::GetInstructionSetFeatures() const { |
| 971 | return *GetCompilerOptions().GetInstructionSetFeatures()->AsX86InstructionSetFeatures(); |
| 972 | } |
| 973 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 974 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 975 | __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); |
| 976 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 977 | } |
| 978 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 979 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 980 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); |
| 981 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 982 | } |
| 983 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 984 | size_t CodeGeneratorX86::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 985 | if (GetGraph()->HasSIMD()) { |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 986 | __ movups(Address(ESP, stack_index), XmmRegister(reg_id)); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 987 | } else { |
| 988 | __ movsd(Address(ESP, stack_index), XmmRegister(reg_id)); |
| 989 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 990 | return GetFloatingPointSpillSlotSize(); |
| 991 | } |
| 992 | |
| 993 | size_t CodeGeneratorX86::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 994 | if (GetGraph()->HasSIMD()) { |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 995 | __ movups(XmmRegister(reg_id), Address(ESP, stack_index)); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 996 | } else { |
| 997 | __ movsd(XmmRegister(reg_id), Address(ESP, stack_index)); |
| 998 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 999 | return GetFloatingPointSpillSlotSize(); |
| 1000 | } |
| 1001 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1002 | void CodeGeneratorX86::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1003 | HInstruction* instruction, |
| 1004 | uint32_t dex_pc, |
| 1005 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1006 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1007 | GenerateInvokeRuntime(GetThreadOffset<kX86PointerSize>(entrypoint).Int32Value()); |
| 1008 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1009 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1010 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 1011 | } |
| 1012 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1013 | void CodeGeneratorX86::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1014 | HInstruction* instruction, |
| 1015 | SlowPathCode* slow_path) { |
| 1016 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1017 | GenerateInvokeRuntime(entry_point_offset); |
| 1018 | } |
| 1019 | |
| 1020 | void CodeGeneratorX86::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1021 | __ fs()->call(Address::Absolute(entry_point_offset)); |
| 1022 | } |
| 1023 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1024 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1025 | const CompilerOptions& compiler_options, |
| 1026 | OptimizingCompilerStats* stats) |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1027 | : CodeGenerator(graph, |
| 1028 | kNumberOfCpuRegisters, |
| 1029 | kNumberOfXmmRegisters, |
| 1030 | kNumberOfRegisterPairs, |
| 1031 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1032 | arraysize(kCoreCalleeSaves)) |
| 1033 | | (1 << kFakeReturnRegister), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1034 | 0, |
| 1035 | compiler_options, |
| 1036 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1037 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1038 | location_builder_(graph, this), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1039 | instruction_visitor_(graph, this), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1040 | move_resolver_(graph->GetAllocator(), this), |
| 1041 | assembler_(graph->GetAllocator()), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1042 | boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1043 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1044 | boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1045 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1046 | boot_image_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1047 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1048 | boot_image_intrinsic_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1049 | jit_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1050 | jit_class_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1051 | constant_area_start_(-1), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1052 | fixups_to_jump_tables_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1053 | method_address_offset_(std::less<uint32_t>(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1054 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1055 | // Use a fake return address register to mimic Quick. |
| 1056 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1057 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1058 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1059 | void CodeGeneratorX86::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1060 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1061 | blocked_core_registers_[ESP] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1062 | } |
| 1063 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1064 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1065 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1066 | assembler_(codegen->GetAssembler()), |
| 1067 | codegen_(codegen) {} |
| 1068 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1069 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1070 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1071 | } |
| 1072 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1073 | void CodeGeneratorX86::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1074 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1075 | __ Bind(&frame_entry_label_); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1076 | bool skip_overflow_check = |
| 1077 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1078 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 1079 | |
Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 1080 | if (GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 1081 | __ addw(Address(kMethodRegisterArgument, ArtMethod::HotnessCountOffset().Int32Value()), |
| 1082 | Immediate(1)); |
| 1083 | } |
| 1084 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1085 | if (!skip_overflow_check) { |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1086 | size_t reserved_bytes = GetStackOverflowReservedBytes(InstructionSet::kX86); |
| 1087 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(reserved_bytes))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1088 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 1089 | } |
| 1090 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1091 | if (HasEmptyFrame()) { |
| 1092 | return; |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1093 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1094 | |
| 1095 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 1096 | Register reg = kCoreCalleeSaves[i]; |
| 1097 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1098 | __ pushl(reg); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1099 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 1100 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1101 | } |
| 1102 | } |
| 1103 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1104 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1105 | __ subl(ESP, Immediate(adjust)); |
| 1106 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1107 | // Save the current method if we need it. Note that we do not |
| 1108 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1109 | // in the SSA graph. |
| 1110 | if (RequiresCurrentMethod()) { |
| 1111 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
| 1112 | } |
Nicolas Geoffray | f789353 | 2017-06-15 12:34:36 +0100 | [diff] [blame] | 1113 | |
| 1114 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1115 | // Initialize should_deoptimize flag to 0. |
| 1116 | __ movl(Address(ESP, GetStackOffsetOfShouldDeoptimizeFlag()), Immediate(0)); |
| 1117 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1118 | } |
| 1119 | |
| 1120 | void CodeGeneratorX86::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1121 | __ cfi().RememberState(); |
| 1122 | if (!HasEmptyFrame()) { |
| 1123 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1124 | __ addl(ESP, Immediate(adjust)); |
| 1125 | __ cfi().AdjustCFAOffset(-adjust); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1126 | |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1127 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1128 | Register reg = kCoreCalleeSaves[i]; |
| 1129 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1130 | __ popl(reg); |
| 1131 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 1132 | __ cfi().Restore(DWARFReg(reg)); |
| 1133 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1134 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1135 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1136 | __ ret(); |
| 1137 | __ cfi().RestoreState(); |
| 1138 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1139 | } |
| 1140 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1141 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 1142 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1143 | } |
| 1144 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1145 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(DataType::Type type) const { |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1146 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1147 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1148 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1149 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1150 | case DataType::Type::kInt8: |
| 1151 | case DataType::Type::kUint16: |
| 1152 | case DataType::Type::kInt16: |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1153 | case DataType::Type::kUint32: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1154 | case DataType::Type::kInt32: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1155 | return Location::RegisterLocation(EAX); |
| 1156 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1157 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1158 | case DataType::Type::kInt64: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1159 | return Location::RegisterPairLocation(EAX, EDX); |
| 1160 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1161 | case DataType::Type::kVoid: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1162 | return Location::NoLocation(); |
| 1163 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1164 | case DataType::Type::kFloat64: |
| 1165 | case DataType::Type::kFloat32: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1166 | return Location::FpuRegisterLocation(XMM0); |
| 1167 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1168 | |
| 1169 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1170 | } |
| 1171 | |
| 1172 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 1173 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1174 | } |
| 1175 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1176 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(DataType::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1177 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1178 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1179 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1180 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1181 | case DataType::Type::kInt8: |
| 1182 | case DataType::Type::kUint16: |
| 1183 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1184 | case DataType::Type::kInt32: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1185 | uint32_t index = gp_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1186 | stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1187 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1188 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1189 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1190 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1191 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1192 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1193 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1194 | case DataType::Type::kInt64: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1195 | uint32_t index = gp_index_; |
| 1196 | gp_index_ += 2; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1197 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1198 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1199 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 1200 | calling_convention.GetRegisterPairAt(index)); |
| 1201 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1202 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1203 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1204 | } |
| 1205 | } |
| 1206 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1207 | case DataType::Type::kFloat32: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1208 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1209 | stack_index_++; |
| 1210 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1211 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1212 | } else { |
| 1213 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1214 | } |
| 1215 | } |
| 1216 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1217 | case DataType::Type::kFloat64: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1218 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1219 | stack_index_ += 2; |
| 1220 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1221 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1222 | } else { |
| 1223 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1224 | } |
| 1225 | } |
| 1226 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1227 | case DataType::Type::kUint32: |
| 1228 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1229 | case DataType::Type::kVoid: |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1230 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1231 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1232 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1233 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1234 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1235 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1236 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 1237 | if (source.Equals(destination)) { |
| 1238 | return; |
| 1239 | } |
| 1240 | if (destination.IsRegister()) { |
| 1241 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1242 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1243 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1244 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1245 | } else { |
| 1246 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1247 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1248 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1249 | } else if (destination.IsFpuRegister()) { |
| 1250 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1251 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1252 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1253 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1254 | } else { |
| 1255 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1256 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1257 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1258 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1259 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1260 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1261 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1262 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1263 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1264 | } else if (source.IsConstant()) { |
| 1265 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1266 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1267 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1268 | } else { |
| 1269 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1270 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 1271 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1272 | } |
| 1273 | } |
| 1274 | } |
| 1275 | |
| 1276 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 1277 | if (source.Equals(destination)) { |
| 1278 | return; |
| 1279 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1280 | if (destination.IsRegisterPair()) { |
| 1281 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1282 | EmitParallelMoves( |
| 1283 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1284 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1285 | DataType::Type::kInt32, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1286 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1287 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1288 | DataType::Type::kInt32); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1289 | } else if (source.IsFpuRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1290 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 1291 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 1292 | __ psrlq(src_reg, Immediate(32)); |
| 1293 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1294 | } else { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1295 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1296 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1297 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 1298 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1299 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 1300 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1301 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1302 | if (source.IsFpuRegister()) { |
| 1303 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 1304 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1305 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1306 | } else if (source.IsRegisterPair()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1307 | size_t elem_size = DataType::Size(DataType::Type::kInt32); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1308 | // Create stack space for 2 elements. |
| 1309 | __ subl(ESP, Immediate(2 * elem_size)); |
| 1310 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 1311 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 1312 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 1313 | // And remove the temporary stack space we allocated. |
| 1314 | __ addl(ESP, Immediate(2 * elem_size)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1315 | } else { |
| 1316 | LOG(FATAL) << "Unimplemented"; |
| 1317 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1318 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1319 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1320 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1321 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1322 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1323 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1324 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1325 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1326 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1327 | } else if (source.IsConstant()) { |
| 1328 | HConstant* constant = source.GetConstant(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1329 | DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant()); |
| 1330 | int64_t value = GetInt64ValueOf(constant); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1331 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1332 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
| 1333 | Immediate(High32Bits(value))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1334 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1335 | DCHECK(source.IsDoubleStackSlot()) << source; |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1336 | EmitParallelMoves( |
| 1337 | Location::StackSlot(source.GetStackIndex()), |
| 1338 | Location::StackSlot(destination.GetStackIndex()), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1339 | DataType::Type::kInt32, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1340 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1341 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1342 | DataType::Type::kInt32); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1343 | } |
| 1344 | } |
| 1345 | } |
| 1346 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1347 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { |
| 1348 | DCHECK(location.IsRegister()); |
| 1349 | __ movl(location.AsRegister<Register>(), Immediate(value)); |
| 1350 | } |
| 1351 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1352 | void CodeGeneratorX86::MoveLocation(Location dst, Location src, DataType::Type dst_type) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1353 | HParallelMove move(GetGraph()->GetAllocator()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1354 | if (dst_type == DataType::Type::kInt64 && !src.IsConstant() && !src.IsFpuRegister()) { |
| 1355 | move.AddMove(src.ToLow(), dst.ToLow(), DataType::Type::kInt32, nullptr); |
| 1356 | move.AddMove(src.ToHigh(), dst.ToHigh(), DataType::Type::kInt32, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1357 | } else { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1358 | move.AddMove(src, dst, dst_type, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1359 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1360 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1361 | } |
| 1362 | |
| 1363 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1364 | if (location.IsRegister()) { |
| 1365 | locations->AddTemp(location); |
| 1366 | } else if (location.IsRegisterPair()) { |
| 1367 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1368 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1369 | } else { |
| 1370 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1371 | } |
| 1372 | } |
| 1373 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1374 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 1375 | if (successor->IsExitBlock()) { |
| 1376 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 1377 | return; // no code needed |
| 1378 | } |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1379 | |
| 1380 | HBasicBlock* block = got->GetBlock(); |
| 1381 | HInstruction* previous = got->GetPrevious(); |
| 1382 | |
| 1383 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1384 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 1385 | if (codegen_->GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 1386 | __ pushl(EAX); |
| 1387 | __ movl(EAX, Address(ESP, kX86WordSize)); |
| 1388 | __ addw(Address(EAX, ArtMethod::HotnessCountOffset().Int32Value()), Immediate(1)); |
| 1389 | __ popl(EAX); |
| 1390 | } |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1391 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1392 | return; |
| 1393 | } |
| 1394 | |
| 1395 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1396 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1397 | } |
| 1398 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1399 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1400 | } |
| 1401 | } |
| 1402 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1403 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 1404 | got->SetLocations(nullptr); |
| 1405 | } |
| 1406 | |
| 1407 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 1408 | HandleGoto(got, got->GetSuccessor()); |
| 1409 | } |
| 1410 | |
| 1411 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1412 | try_boundary->SetLocations(nullptr); |
| 1413 | } |
| 1414 | |
| 1415 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1416 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1417 | if (!successor->IsExitBlock()) { |
| 1418 | HandleGoto(try_boundary, successor); |
| 1419 | } |
| 1420 | } |
| 1421 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1422 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1423 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1424 | } |
| 1425 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1426 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1427 | } |
| 1428 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1429 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1430 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1431 | LabelType* true_label, |
| 1432 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1433 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1434 | __ j(kUnordered, true_label); |
| 1435 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1436 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1437 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1438 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1439 | } |
| 1440 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1441 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1442 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1443 | LabelType* true_label, |
| 1444 | LabelType* false_label) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1445 | LocationSummary* locations = cond->GetLocations(); |
| 1446 | Location left = locations->InAt(0); |
| 1447 | Location right = locations->InAt(1); |
| 1448 | IfCondition if_cond = cond->GetCondition(); |
| 1449 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1450 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1451 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1452 | IfCondition true_high_cond = if_cond; |
| 1453 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1454 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); // unsigned on lower part |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1455 | |
| 1456 | // Set the conditions for the test, remembering that == needs to be |
| 1457 | // decided using the low words. |
| 1458 | switch (if_cond) { |
| 1459 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1460 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1461 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1462 | break; |
| 1463 | case kCondLT: |
| 1464 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1465 | break; |
| 1466 | case kCondLE: |
| 1467 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1468 | break; |
| 1469 | case kCondGT: |
| 1470 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1471 | break; |
| 1472 | case kCondGE: |
| 1473 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1474 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1475 | case kCondB: |
| 1476 | false_high_cond = kCondA; |
| 1477 | break; |
| 1478 | case kCondBE: |
| 1479 | true_high_cond = kCondB; |
| 1480 | break; |
| 1481 | case kCondA: |
| 1482 | false_high_cond = kCondB; |
| 1483 | break; |
| 1484 | case kCondAE: |
| 1485 | true_high_cond = kCondA; |
| 1486 | break; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1487 | } |
| 1488 | |
| 1489 | if (right.IsConstant()) { |
| 1490 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1491 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1492 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1493 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1494 | codegen_->Compare32BitValue(left_high, val_high); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1495 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1496 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1497 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1498 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1499 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1500 | __ j(X86Condition(true_high_cond), true_label); |
| 1501 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1502 | } |
| 1503 | // Must be equal high, so compare the lows. |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1504 | codegen_->Compare32BitValue(left_low, val_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1505 | } else if (right.IsRegisterPair()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1506 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1507 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1508 | |
| 1509 | __ cmpl(left_high, right_high); |
| 1510 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1511 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1512 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1513 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1514 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1515 | __ j(X86Condition(true_high_cond), true_label); |
| 1516 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1517 | } |
| 1518 | // Must be equal high, so compare the lows. |
| 1519 | __ cmpl(left_low, right_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1520 | } else { |
| 1521 | DCHECK(right.IsDoubleStackSlot()); |
| 1522 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
| 1523 | if (if_cond == kCondNE) { |
| 1524 | __ j(X86Condition(true_high_cond), true_label); |
| 1525 | } else if (if_cond == kCondEQ) { |
| 1526 | __ j(X86Condition(false_high_cond), false_label); |
| 1527 | } else { |
| 1528 | __ j(X86Condition(true_high_cond), true_label); |
| 1529 | __ j(X86Condition(false_high_cond), false_label); |
| 1530 | } |
| 1531 | // Must be equal high, so compare the lows. |
| 1532 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1533 | } |
| 1534 | // The last comparison might be unsigned. |
| 1535 | __ j(final_condition, true_label); |
| 1536 | } |
| 1537 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1538 | void InstructionCodeGeneratorX86::GenerateFPCompare(Location lhs, |
| 1539 | Location rhs, |
| 1540 | HInstruction* insn, |
| 1541 | bool is_double) { |
| 1542 | HX86LoadFromConstantTable* const_area = insn->InputAt(1)->AsX86LoadFromConstantTable(); |
| 1543 | if (is_double) { |
| 1544 | if (rhs.IsFpuRegister()) { |
| 1545 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1546 | } else if (const_area != nullptr) { |
| 1547 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1548 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), |
| 1549 | codegen_->LiteralDoubleAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1550 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 1551 | const_area->GetBaseMethodAddress(), |
| 1552 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1553 | } else { |
| 1554 | DCHECK(rhs.IsDoubleStackSlot()); |
| 1555 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1556 | } |
| 1557 | } else { |
| 1558 | if (rhs.IsFpuRegister()) { |
| 1559 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1560 | } else if (const_area != nullptr) { |
| 1561 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1562 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), |
| 1563 | codegen_->LiteralFloatAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1564 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 1565 | const_area->GetBaseMethodAddress(), |
| 1566 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1567 | } else { |
| 1568 | DCHECK(rhs.IsStackSlot()); |
| 1569 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1570 | } |
| 1571 | } |
| 1572 | } |
| 1573 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1574 | template<class LabelType> |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1575 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1576 | LabelType* true_target_in, |
| 1577 | LabelType* false_target_in) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1578 | // Generated branching requires both targets to be explicit. If either of the |
| 1579 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1580 | LabelType fallthrough_target; |
| 1581 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1582 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1583 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1584 | LocationSummary* locations = condition->GetLocations(); |
| 1585 | Location left = locations->InAt(0); |
| 1586 | Location right = locations->InAt(1); |
| 1587 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1588 | DataType::Type type = condition->InputAt(0)->GetType(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1589 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1590 | case DataType::Type::kInt64: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1591 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1592 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1593 | case DataType::Type::kFloat32: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1594 | GenerateFPCompare(left, right, condition, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1595 | GenerateFPJumps(condition, true_target, false_target); |
| 1596 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1597 | case DataType::Type::kFloat64: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1598 | GenerateFPCompare(left, right, condition, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1599 | GenerateFPJumps(condition, true_target, false_target); |
| 1600 | break; |
| 1601 | default: |
| 1602 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1603 | } |
| 1604 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1605 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1606 | __ jmp(false_target); |
| 1607 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1608 | |
| 1609 | if (fallthrough_target.IsLinked()) { |
| 1610 | __ Bind(&fallthrough_target); |
| 1611 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1612 | } |
| 1613 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1614 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1615 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1616 | // are set only strictly before `branch`. We can't use the eflags on long/FP |
| 1617 | // conditions if they are materialized due to the complex branching. |
| 1618 | return cond->IsCondition() && |
| 1619 | cond->GetNext() == branch && |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1620 | cond->InputAt(0)->GetType() != DataType::Type::kInt64 && |
| 1621 | !DataType::IsFloatingPointType(cond->InputAt(0)->GetType()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1622 | } |
| 1623 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1624 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1625 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1626 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1627 | LabelType* true_target, |
| 1628 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1629 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1630 | |
| 1631 | if (true_target == nullptr && false_target == nullptr) { |
| 1632 | // Nothing to do. The code always falls through. |
| 1633 | return; |
| 1634 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1635 | // Constant condition, statically compared against "true" (integer value 1). |
| 1636 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1637 | if (true_target != nullptr) { |
| 1638 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1639 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1640 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1641 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1642 | if (false_target != nullptr) { |
| 1643 | __ jmp(false_target); |
| 1644 | } |
| 1645 | } |
| 1646 | return; |
| 1647 | } |
| 1648 | |
| 1649 | // The following code generates these patterns: |
| 1650 | // (1) true_target == nullptr && false_target != nullptr |
| 1651 | // - opposite condition true => branch to false_target |
| 1652 | // (2) true_target != nullptr && false_target == nullptr |
| 1653 | // - condition true => branch to true_target |
| 1654 | // (3) true_target != nullptr && false_target != nullptr |
| 1655 | // - condition true => branch to true_target |
| 1656 | // - branch to false_target |
| 1657 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1658 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1659 | if (true_target == nullptr) { |
| 1660 | __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1661 | } else { |
| 1662 | __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); |
| 1663 | } |
| 1664 | } else { |
| 1665 | // Materialized condition, compare against 0. |
| 1666 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1667 | if (lhs.IsRegister()) { |
| 1668 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1669 | } else { |
| 1670 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1671 | } |
| 1672 | if (true_target == nullptr) { |
| 1673 | __ j(kEqual, false_target); |
| 1674 | } else { |
| 1675 | __ j(kNotEqual, true_target); |
| 1676 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1677 | } |
| 1678 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1679 | // Condition has not been materialized, use its inputs as the comparison and |
| 1680 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1681 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1682 | |
| 1683 | // If this is a long or FP comparison that has been folded into |
| 1684 | // the HCondition, generate the comparison directly. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1685 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 1686 | if (type == DataType::Type::kInt64 || DataType::IsFloatingPointType(type)) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1687 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1688 | return; |
| 1689 | } |
| 1690 | |
| 1691 | Location lhs = condition->GetLocations()->InAt(0); |
| 1692 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1693 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition). |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1694 | codegen_->GenerateIntCompare(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1695 | if (true_target == nullptr) { |
| 1696 | __ j(X86Condition(condition->GetOppositeCondition()), false_target); |
| 1697 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1698 | __ j(X86Condition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1699 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1700 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1701 | |
| 1702 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1703 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1704 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1705 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1706 | } |
| 1707 | } |
| 1708 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1709 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1710 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1711 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1712 | locations->SetInAt(0, Location::Any()); |
| 1713 | } |
| 1714 | } |
| 1715 | |
| 1716 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1717 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1718 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1719 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1720 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1721 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1722 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1723 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1724 | } |
| 1725 | |
| 1726 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1727 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1728 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 1729 | InvokeRuntimeCallingConvention calling_convention; |
| 1730 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 1731 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1732 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1733 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1734 | locations->SetInAt(0, Location::Any()); |
| 1735 | } |
| 1736 | } |
| 1737 | |
| 1738 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1739 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1740 | GenerateTestAndBranch<Label>(deoptimize, |
| 1741 | /* condition_input_index */ 0, |
| 1742 | slow_path->GetEntryLabel(), |
| 1743 | /* false_target */ nullptr); |
| 1744 | } |
| 1745 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1746 | void LocationsBuilderX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1747 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1748 | LocationSummary(flag, LocationSummary::kNoCall); |
| 1749 | locations->SetOut(Location::RequiresRegister()); |
| 1750 | } |
| 1751 | |
| 1752 | void InstructionCodeGeneratorX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1753 | __ movl(flag->GetLocations()->Out().AsRegister<Register>(), |
| 1754 | Address(ESP, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1755 | } |
| 1756 | |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1757 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1758 | // There are no conditional move instructions for XMMs. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1759 | if (DataType::IsFloatingPointType(select->GetType())) { |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1760 | return false; |
| 1761 | } |
| 1762 | |
| 1763 | // A FP condition doesn't generate the single CC that we need. |
| 1764 | // In 32 bit mode, a long condition doesn't generate a single CC either. |
| 1765 | HInstruction* condition = select->GetCondition(); |
| 1766 | if (condition->IsCondition()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1767 | DataType::Type compare_type = condition->InputAt(0)->GetType(); |
| 1768 | if (compare_type == DataType::Type::kInt64 || |
| 1769 | DataType::IsFloatingPointType(compare_type)) { |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1770 | return false; |
| 1771 | } |
| 1772 | } |
| 1773 | |
| 1774 | // We can generate a CMOV for this Select. |
| 1775 | return true; |
| 1776 | } |
| 1777 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1778 | void LocationsBuilderX86::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1779 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1780 | if (DataType::IsFloatingPointType(select->GetType())) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1781 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1782 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1783 | } else { |
| 1784 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1785 | if (SelectCanUseCMOV(select)) { |
| 1786 | if (select->InputAt(1)->IsConstant()) { |
| 1787 | // Cmov can't handle a constant value. |
| 1788 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1789 | } else { |
| 1790 | locations->SetInAt(1, Location::Any()); |
| 1791 | } |
| 1792 | } else { |
| 1793 | locations->SetInAt(1, Location::Any()); |
| 1794 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1795 | } |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1796 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1797 | locations->SetInAt(2, Location::RequiresRegister()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1798 | } |
| 1799 | locations->SetOut(Location::SameAsFirstInput()); |
| 1800 | } |
| 1801 | |
| 1802 | void InstructionCodeGeneratorX86::VisitSelect(HSelect* select) { |
| 1803 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1804 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1805 | if (SelectCanUseCMOV(select)) { |
| 1806 | // If both the condition and the source types are integer, we can generate |
| 1807 | // a CMOV to implement Select. |
| 1808 | |
| 1809 | HInstruction* select_condition = select->GetCondition(); |
| 1810 | Condition cond = kNotEqual; |
| 1811 | |
| 1812 | // Figure out how to test the 'condition'. |
| 1813 | if (select_condition->IsCondition()) { |
| 1814 | HCondition* condition = select_condition->AsCondition(); |
| 1815 | if (!condition->IsEmittedAtUseSite()) { |
| 1816 | // This was a previously materialized condition. |
| 1817 | // Can we use the existing condition code? |
| 1818 | if (AreEflagsSetFrom(condition, select)) { |
| 1819 | // Materialization was the previous instruction. Condition codes are right. |
| 1820 | cond = X86Condition(condition->GetCondition()); |
| 1821 | } else { |
| 1822 | // No, we have to recreate the condition code. |
| 1823 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1824 | __ testl(cond_reg, cond_reg); |
| 1825 | } |
| 1826 | } else { |
| 1827 | // We can't handle FP or long here. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1828 | DCHECK_NE(condition->InputAt(0)->GetType(), DataType::Type::kInt64); |
| 1829 | DCHECK(!DataType::IsFloatingPointType(condition->InputAt(0)->GetType())); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1830 | LocationSummary* cond_locations = condition->GetLocations(); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1831 | codegen_->GenerateIntCompare(cond_locations->InAt(0), cond_locations->InAt(1)); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1832 | cond = X86Condition(condition->GetCondition()); |
| 1833 | } |
| 1834 | } else { |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 1835 | // Must be a Boolean condition, which needs to be compared to 0. |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1836 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1837 | __ testl(cond_reg, cond_reg); |
| 1838 | } |
| 1839 | |
| 1840 | // If the condition is true, overwrite the output, which already contains false. |
| 1841 | Location false_loc = locations->InAt(0); |
| 1842 | Location true_loc = locations->InAt(1); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1843 | if (select->GetType() == DataType::Type::kInt64) { |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1844 | // 64 bit conditional move. |
| 1845 | Register false_high = false_loc.AsRegisterPairHigh<Register>(); |
| 1846 | Register false_low = false_loc.AsRegisterPairLow<Register>(); |
| 1847 | if (true_loc.IsRegisterPair()) { |
| 1848 | __ cmovl(cond, false_high, true_loc.AsRegisterPairHigh<Register>()); |
| 1849 | __ cmovl(cond, false_low, true_loc.AsRegisterPairLow<Register>()); |
| 1850 | } else { |
| 1851 | __ cmovl(cond, false_high, Address(ESP, true_loc.GetHighStackIndex(kX86WordSize))); |
| 1852 | __ cmovl(cond, false_low, Address(ESP, true_loc.GetStackIndex())); |
| 1853 | } |
| 1854 | } else { |
| 1855 | // 32 bit conditional move. |
| 1856 | Register false_reg = false_loc.AsRegister<Register>(); |
| 1857 | if (true_loc.IsRegister()) { |
| 1858 | __ cmovl(cond, false_reg, true_loc.AsRegister<Register>()); |
| 1859 | } else { |
| 1860 | __ cmovl(cond, false_reg, Address(ESP, true_loc.GetStackIndex())); |
| 1861 | } |
| 1862 | } |
| 1863 | } else { |
| 1864 | NearLabel false_target; |
| 1865 | GenerateTestAndBranch<NearLabel>( |
| 1866 | select, /* condition_input_index */ 2, /* true_target */ nullptr, &false_target); |
| 1867 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1868 | __ Bind(&false_target); |
| 1869 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1870 | } |
| 1871 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1872 | void LocationsBuilderX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1873 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1874 | } |
| 1875 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1876 | void InstructionCodeGeneratorX86::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1877 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1878 | } |
| 1879 | |
| 1880 | void CodeGeneratorX86::GenerateNop() { |
| 1881 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1882 | } |
| 1883 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1884 | void LocationsBuilderX86::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1885 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1886 | new (GetGraph()->GetAllocator()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1887 | // Handle the long/FP comparisons made in instruction simplification. |
| 1888 | switch (cond->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1889 | case DataType::Type::kInt64: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1890 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1891 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1892 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1893 | locations->SetOut(Location::RequiresRegister()); |
| 1894 | } |
| 1895 | break; |
| 1896 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1897 | case DataType::Type::kFloat32: |
| 1898 | case DataType::Type::kFloat64: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1899 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1900 | if (cond->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 1901 | DCHECK(cond->InputAt(1)->IsEmittedAtUseSite()); |
| 1902 | } else if (cond->InputAt(1)->IsConstant()) { |
| 1903 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1904 | } else { |
| 1905 | locations->SetInAt(1, Location::Any()); |
| 1906 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1907 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1908 | locations->SetOut(Location::RequiresRegister()); |
| 1909 | } |
| 1910 | break; |
| 1911 | } |
| 1912 | default: |
| 1913 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1914 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1915 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1916 | // We need a byte register. |
| 1917 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1918 | } |
| 1919 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1920 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1921 | } |
| 1922 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1923 | void InstructionCodeGeneratorX86::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1924 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1925 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1926 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1927 | |
| 1928 | LocationSummary* locations = cond->GetLocations(); |
| 1929 | Location lhs = locations->InAt(0); |
| 1930 | Location rhs = locations->InAt(1); |
| 1931 | Register reg = locations->Out().AsRegister<Register>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1932 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1933 | |
| 1934 | switch (cond->InputAt(0)->GetType()) { |
| 1935 | default: { |
| 1936 | // Integer case. |
| 1937 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 1938 | // Clear output register: setb only sets the low byte. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1939 | __ xorl(reg, reg); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1940 | codegen_->GenerateIntCompare(lhs, rhs); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1941 | __ setb(X86Condition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1942 | return; |
| 1943 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1944 | case DataType::Type::kInt64: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1945 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1946 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1947 | case DataType::Type::kFloat32: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1948 | GenerateFPCompare(lhs, rhs, cond, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1949 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1950 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1951 | case DataType::Type::kFloat64: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1952 | GenerateFPCompare(lhs, rhs, cond, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1953 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1954 | break; |
| 1955 | } |
| 1956 | |
| 1957 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1958 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1959 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1960 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1961 | __ Bind(&false_label); |
| 1962 | __ xorl(reg, reg); |
| 1963 | __ jmp(&done_label); |
| 1964 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1965 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1966 | __ Bind(&true_label); |
| 1967 | __ movl(reg, Immediate(1)); |
| 1968 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1969 | } |
| 1970 | |
| 1971 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1972 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1973 | } |
| 1974 | |
| 1975 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1976 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1977 | } |
| 1978 | |
| 1979 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1980 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1981 | } |
| 1982 | |
| 1983 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1984 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1985 | } |
| 1986 | |
| 1987 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1988 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1989 | } |
| 1990 | |
| 1991 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1992 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1993 | } |
| 1994 | |
| 1995 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1996 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1997 | } |
| 1998 | |
| 1999 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2000 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2001 | } |
| 2002 | |
| 2003 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2004 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2005 | } |
| 2006 | |
| 2007 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2008 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2009 | } |
| 2010 | |
| 2011 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2012 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2013 | } |
| 2014 | |
| 2015 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2016 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2017 | } |
| 2018 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2019 | void LocationsBuilderX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2020 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2021 | } |
| 2022 | |
| 2023 | void InstructionCodeGeneratorX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2024 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2025 | } |
| 2026 | |
| 2027 | void LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2028 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2029 | } |
| 2030 | |
| 2031 | void InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2032 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2033 | } |
| 2034 | |
| 2035 | void LocationsBuilderX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2036 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2037 | } |
| 2038 | |
| 2039 | void InstructionCodeGeneratorX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2040 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2041 | } |
| 2042 | |
| 2043 | void LocationsBuilderX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2044 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2045 | } |
| 2046 | |
| 2047 | void InstructionCodeGeneratorX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2048 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2049 | } |
| 2050 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2051 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2052 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2053 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2054 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2055 | } |
| 2056 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2057 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2058 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2059 | } |
| 2060 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2061 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 2062 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2063 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2064 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2065 | } |
| 2066 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2067 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2068 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2069 | } |
| 2070 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2071 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2072 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2073 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2074 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2075 | } |
| 2076 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2077 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2078 | // Will be generated at use site. |
| 2079 | } |
| 2080 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2081 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 2082 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2083 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2084 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2085 | } |
| 2086 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2087 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2088 | // Will be generated at use site. |
| 2089 | } |
| 2090 | |
| 2091 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2092 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2093 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2094 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2095 | } |
| 2096 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2097 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2098 | // Will be generated at use site. |
| 2099 | } |
| 2100 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2101 | void LocationsBuilderX86::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 2102 | constructor_fence->SetLocations(nullptr); |
| 2103 | } |
| 2104 | |
| 2105 | void InstructionCodeGeneratorX86::VisitConstructorFence( |
| 2106 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 2107 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 2108 | } |
| 2109 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2110 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2111 | memory_barrier->SetLocations(nullptr); |
| 2112 | } |
| 2113 | |
| 2114 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 2115 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2116 | } |
| 2117 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2118 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2119 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2120 | } |
| 2121 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2122 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2123 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2124 | } |
| 2125 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2126 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2127 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2128 | new (GetGraph()->GetAllocator()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2129 | switch (ret->InputAt(0)->GetType()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2130 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2131 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2132 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2133 | case DataType::Type::kInt8: |
| 2134 | case DataType::Type::kUint16: |
| 2135 | case DataType::Type::kInt16: |
| 2136 | case DataType::Type::kInt32: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2137 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2138 | break; |
| 2139 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2140 | case DataType::Type::kInt64: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2141 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2142 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2143 | break; |
| 2144 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2145 | case DataType::Type::kFloat32: |
| 2146 | case DataType::Type::kFloat64: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2147 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2148 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2149 | break; |
| 2150 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2151 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2152 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2153 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2154 | } |
| 2155 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2156 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2157 | if (kIsDebugBuild) { |
| 2158 | switch (ret->InputAt(0)->GetType()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2159 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2160 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2161 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2162 | case DataType::Type::kInt8: |
| 2163 | case DataType::Type::kUint16: |
| 2164 | case DataType::Type::kInt16: |
| 2165 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2166 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2167 | break; |
| 2168 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2169 | case DataType::Type::kInt64: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2170 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 2171 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2172 | break; |
| 2173 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2174 | case DataType::Type::kFloat32: |
| 2175 | case DataType::Type::kFloat64: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2176 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2177 | break; |
| 2178 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2179 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2180 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2181 | } |
| 2182 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2183 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2184 | } |
| 2185 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2186 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2187 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2188 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2189 | // the method_idx. |
| 2190 | HandleInvoke(invoke); |
| 2191 | } |
| 2192 | |
| 2193 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2194 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2195 | } |
| 2196 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2197 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2198 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2199 | // art::PrepareForRegisterAllocation. |
| 2200 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2201 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2202 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2203 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 2204 | if (invoke->GetLocations()->CanCall() && |
| 2205 | invoke->HasPcRelativeMethodLoadKind() && |
| 2206 | invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()).IsInvalid()) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 2207 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2208 | } |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2209 | return; |
| 2210 | } |
| 2211 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2212 | HandleInvoke(invoke); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2213 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2214 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 2215 | if (invoke->HasPcRelativeMethodLoadKind()) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2216 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2217 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2218 | } |
| 2219 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2220 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 2221 | if (invoke->GetLocations()->Intrinsified()) { |
| 2222 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 2223 | intrinsic.Dispatch(invoke); |
| 2224 | return true; |
| 2225 | } |
| 2226 | return false; |
| 2227 | } |
| 2228 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2229 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2230 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2231 | // art::PrepareForRegisterAllocation. |
| 2232 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2233 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2234 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2235 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2236 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2237 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2238 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2239 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2240 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2241 | } |
| 2242 | |
| 2243 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 2244 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 2245 | if (intrinsic.TryDispatch(invoke)) { |
| 2246 | return; |
| 2247 | } |
| 2248 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2249 | HandleInvoke(invoke); |
| 2250 | } |
| 2251 | |
| 2252 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2253 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2254 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2255 | } |
| 2256 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2257 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2258 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2259 | return; |
| 2260 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2261 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2262 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2263 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2264 | } |
| 2265 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2266 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2267 | // This call to HandleInvoke allocates a temporary (core) register |
| 2268 | // which is also used to transfer the hidden argument from FP to |
| 2269 | // core register. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2270 | HandleInvoke(invoke); |
| 2271 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2272 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2273 | } |
| 2274 | |
| 2275 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2276 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2277 | LocationSummary* locations = invoke->GetLocations(); |
| 2278 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2279 | XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2280 | Location receiver = locations->InAt(0); |
| 2281 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2282 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2283 | // Set the hidden argument. This is safe to do this here, as XMM7 |
| 2284 | // won't be modified thereafter, before the `call` instruction. |
| 2285 | DCHECK_EQ(XMM7, hidden_reg); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2286 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2287 | __ movd(hidden_reg, temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2288 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2289 | if (receiver.IsStackSlot()) { |
| 2290 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2291 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2292 | __ movl(temp, Address(temp, class_offset)); |
| 2293 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2294 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2295 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2296 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2297 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2298 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2299 | // emit a read barrier for the previous class reference load. |
| 2300 | // However this is not required in practice, as this is an |
| 2301 | // intermediate/temporary reference and because the current |
| 2302 | // concurrent copying collector keeps the from-space memory |
| 2303 | // intact/accessible until the end of the marking phase (the |
| 2304 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2305 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2306 | // temp = temp->GetAddressOfIMT() |
| 2307 | __ movl(temp, |
| 2308 | Address(temp, mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2309 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2310 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2311 | invoke->GetImtIndex(), kX86PointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2312 | __ movl(temp, Address(temp, method_offset)); |
| 2313 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2314 | __ call(Address(temp, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2315 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2316 | |
| 2317 | DCHECK(!codegen_->IsLeafMethod()); |
| 2318 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2319 | } |
| 2320 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2321 | void LocationsBuilderX86::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2322 | HandleInvoke(invoke); |
| 2323 | } |
| 2324 | |
| 2325 | void InstructionCodeGeneratorX86::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2326 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 2327 | } |
| 2328 | |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 2329 | void LocationsBuilderX86::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 2330 | HandleInvoke(invoke); |
| 2331 | } |
| 2332 | |
| 2333 | void InstructionCodeGeneratorX86::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 2334 | codegen_->GenerateInvokeCustomCall(invoke); |
| 2335 | } |
| 2336 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2337 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 2338 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2339 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2340 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2341 | case DataType::Type::kInt32: |
| 2342 | case DataType::Type::kInt64: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2343 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2344 | locations->SetOut(Location::SameAsFirstInput()); |
| 2345 | break; |
| 2346 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2347 | case DataType::Type::kFloat32: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2348 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2349 | locations->SetOut(Location::SameAsFirstInput()); |
| 2350 | locations->AddTemp(Location::RequiresRegister()); |
| 2351 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2352 | break; |
| 2353 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2354 | case DataType::Type::kFloat64: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2355 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2356 | locations->SetOut(Location::SameAsFirstInput()); |
| 2357 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2358 | break; |
| 2359 | |
| 2360 | default: |
| 2361 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2362 | } |
| 2363 | } |
| 2364 | |
| 2365 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 2366 | LocationSummary* locations = neg->GetLocations(); |
| 2367 | Location out = locations->Out(); |
| 2368 | Location in = locations->InAt(0); |
| 2369 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2370 | case DataType::Type::kInt32: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2371 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2372 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2373 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2374 | break; |
| 2375 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2376 | case DataType::Type::kInt64: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2377 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2378 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2379 | __ negl(out.AsRegisterPairLow<Register>()); |
| 2380 | // Negation is similar to subtraction from zero. The least |
| 2381 | // significant byte triggers a borrow when it is different from |
| 2382 | // zero; to take it into account, add 1 to the most significant |
| 2383 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 2384 | // operation. |
| 2385 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2386 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 2387 | break; |
| 2388 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2389 | case DataType::Type::kFloat32: { |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2390 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2391 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 2392 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2393 | // Implement float negation with an exclusive or with value |
| 2394 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2395 | // single-precision floating-point number). |
| 2396 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 2397 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2398 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2399 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2400 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2401 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2402 | case DataType::Type::kFloat64: { |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2403 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2404 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2405 | // Implement double negation with an exclusive or with value |
| 2406 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 2407 | // a double-precision floating-point number). |
| 2408 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2409 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2410 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2411 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2412 | |
| 2413 | default: |
| 2414 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2415 | } |
| 2416 | } |
| 2417 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2418 | void LocationsBuilderX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2419 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2420 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2421 | DCHECK(DataType::IsFloatingPointType(neg->GetType())); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2422 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2423 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2424 | locations->SetOut(Location::SameAsFirstInput()); |
| 2425 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2426 | } |
| 2427 | |
| 2428 | void InstructionCodeGeneratorX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2429 | LocationSummary* locations = neg->GetLocations(); |
| 2430 | Location out = locations->Out(); |
| 2431 | DCHECK(locations->InAt(0).Equals(out)); |
| 2432 | |
| 2433 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 2434 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2435 | if (neg->GetType() == DataType::Type::kFloat32) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 2436 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x80000000), |
| 2437 | neg->GetBaseMethodAddress(), |
| 2438 | constant_area)); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2439 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| 2440 | } else { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 2441 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000), |
| 2442 | neg->GetBaseMethodAddress(), |
| 2443 | constant_area)); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2444 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| 2445 | } |
| 2446 | } |
| 2447 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2448 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2449 | DataType::Type result_type = conversion->GetResultType(); |
| 2450 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2451 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 2452 | << input_type << " -> " << result_type; |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2453 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2454 | // The float-to-long and double-to-long type conversions rely on a |
| 2455 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2456 | LocationSummary::CallKind call_kind = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2457 | ((input_type == DataType::Type::kFloat32 || input_type == DataType::Type::kFloat64) |
| 2458 | && result_type == DataType::Type::kInt64) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2459 | ? LocationSummary::kCallOnMainOnly |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2460 | : LocationSummary::kNoCall; |
| 2461 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2462 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, call_kind); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2463 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2464 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2465 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2466 | case DataType::Type::kInt8: |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2467 | switch (input_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2468 | case DataType::Type::kUint8: |
| 2469 | case DataType::Type::kInt8: |
| 2470 | case DataType::Type::kUint16: |
| 2471 | case DataType::Type::kInt16: |
| 2472 | case DataType::Type::kInt32: |
| 2473 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 2474 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2475 | // the validation of the linear scan implementation |
| 2476 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2477 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2478 | case DataType::Type::kInt64: { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2479 | HInstruction* input = conversion->InputAt(0); |
| 2480 | Location input_location = input->IsConstant() |
| 2481 | ? Location::ConstantLocation(input->AsConstant()) |
| 2482 | : Location::RegisterPairLocation(EAX, EDX); |
| 2483 | locations->SetInAt(0, input_location); |
| 2484 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2485 | // the validation of the linear scan implementation |
| 2486 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2487 | break; |
| 2488 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2489 | |
| 2490 | default: |
| 2491 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2492 | << " to " << result_type; |
| 2493 | } |
| 2494 | break; |
| 2495 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2496 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2497 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2498 | DCHECK(DataType::IsIntegralType(input_type)) << input_type; |
| 2499 | locations->SetInAt(0, Location::Any()); |
| 2500 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2501 | break; |
| 2502 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2503 | case DataType::Type::kInt32: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2504 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2505 | case DataType::Type::kInt64: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2506 | locations->SetInAt(0, Location::Any()); |
| 2507 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2508 | break; |
| 2509 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2510 | case DataType::Type::kFloat32: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2511 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2512 | locations->SetOut(Location::RequiresRegister()); |
| 2513 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2514 | break; |
| 2515 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2516 | case DataType::Type::kFloat64: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2517 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2518 | locations->SetOut(Location::RequiresRegister()); |
| 2519 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2520 | break; |
| 2521 | |
| 2522 | default: |
| 2523 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2524 | << " to " << result_type; |
| 2525 | } |
| 2526 | break; |
| 2527 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2528 | case DataType::Type::kInt64: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2529 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2530 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2531 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2532 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2533 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2534 | case DataType::Type::kInt16: |
| 2535 | case DataType::Type::kInt32: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2536 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 2537 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2538 | break; |
| 2539 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2540 | case DataType::Type::kFloat32: |
| 2541 | case DataType::Type::kFloat64: { |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2542 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2543 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 2544 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 2545 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2546 | // The runtime helper puts the result in EAX, EDX. |
| 2547 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2548 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2549 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2550 | |
| 2551 | default: |
| 2552 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2553 | << " to " << result_type; |
| 2554 | } |
| 2555 | break; |
| 2556 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2557 | case DataType::Type::kFloat32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2558 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2559 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2560 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2561 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2562 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2563 | case DataType::Type::kInt16: |
| 2564 | case DataType::Type::kInt32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2565 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2566 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2567 | break; |
| 2568 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2569 | case DataType::Type::kInt64: |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2570 | locations->SetInAt(0, Location::Any()); |
| 2571 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2572 | break; |
| 2573 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2574 | case DataType::Type::kFloat64: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2575 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2576 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2577 | break; |
| 2578 | |
| 2579 | default: |
| 2580 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2581 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 2582 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2583 | break; |
| 2584 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2585 | case DataType::Type::kFloat64: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2586 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2587 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2588 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2589 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2590 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2591 | case DataType::Type::kInt16: |
| 2592 | case DataType::Type::kInt32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2593 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2594 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2595 | break; |
| 2596 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2597 | case DataType::Type::kInt64: |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2598 | locations->SetInAt(0, Location::Any()); |
| 2599 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2600 | break; |
| 2601 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2602 | case DataType::Type::kFloat32: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2603 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2604 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2605 | break; |
| 2606 | |
| 2607 | default: |
| 2608 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2609 | << " to " << result_type; |
| 2610 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2611 | break; |
| 2612 | |
| 2613 | default: |
| 2614 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2615 | << " to " << result_type; |
| 2616 | } |
| 2617 | } |
| 2618 | |
| 2619 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 2620 | LocationSummary* locations = conversion->GetLocations(); |
| 2621 | Location out = locations->Out(); |
| 2622 | Location in = locations->InAt(0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2623 | DataType::Type result_type = conversion->GetResultType(); |
| 2624 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2625 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 2626 | << input_type << " -> " << result_type; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2627 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2628 | case DataType::Type::kUint8: |
| 2629 | switch (input_type) { |
| 2630 | case DataType::Type::kInt8: |
| 2631 | case DataType::Type::kUint16: |
| 2632 | case DataType::Type::kInt16: |
| 2633 | case DataType::Type::kInt32: |
| 2634 | if (in.IsRegister()) { |
| 2635 | __ movzxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
| 2636 | } else { |
| 2637 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2638 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2639 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint8_t>(value))); |
| 2640 | } |
| 2641 | break; |
| 2642 | case DataType::Type::kInt64: |
| 2643 | if (in.IsRegisterPair()) { |
| 2644 | __ movzxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 2645 | } else { |
| 2646 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2647 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2648 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint8_t>(value))); |
| 2649 | } |
| 2650 | break; |
| 2651 | |
| 2652 | default: |
| 2653 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2654 | << " to " << result_type; |
| 2655 | } |
| 2656 | break; |
| 2657 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2658 | case DataType::Type::kInt8: |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2659 | switch (input_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2660 | case DataType::Type::kUint8: |
| 2661 | case DataType::Type::kUint16: |
| 2662 | case DataType::Type::kInt16: |
| 2663 | case DataType::Type::kInt32: |
| 2664 | if (in.IsRegister()) { |
| 2665 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
| 2666 | } else { |
| 2667 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2668 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2669 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2670 | } |
| 2671 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2672 | case DataType::Type::kInt64: |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2673 | if (in.IsRegisterPair()) { |
| 2674 | __ movsxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 2675 | } else { |
| 2676 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2677 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2678 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2679 | } |
| 2680 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2681 | |
| 2682 | default: |
| 2683 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2684 | << " to " << result_type; |
| 2685 | } |
| 2686 | break; |
| 2687 | |
| 2688 | case DataType::Type::kUint16: |
| 2689 | switch (input_type) { |
| 2690 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2691 | case DataType::Type::kInt16: |
| 2692 | case DataType::Type::kInt32: |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2693 | if (in.IsRegister()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2694 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
| 2695 | } else if (in.IsStackSlot()) { |
| 2696 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2697 | } else { |
| 2698 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2699 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2700 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
| 2701 | } |
| 2702 | break; |
| 2703 | case DataType::Type::kInt64: |
| 2704 | if (in.IsRegisterPair()) { |
| 2705 | __ movzxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2706 | } else if (in.IsDoubleStackSlot()) { |
| 2707 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2708 | } else { |
| 2709 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2710 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2711 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2712 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2713 | break; |
| 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::kInt16: |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2722 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2723 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2724 | case DataType::Type::kInt32: |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2725 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2726 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2727 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2728 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2729 | } else { |
| 2730 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2731 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2732 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2733 | } |
| 2734 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2735 | case DataType::Type::kInt64: |
| 2736 | if (in.IsRegisterPair()) { |
| 2737 | __ movsxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2738 | } else if (in.IsDoubleStackSlot()) { |
| 2739 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2740 | } else { |
| 2741 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2742 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2743 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
| 2744 | } |
| 2745 | break; |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2746 | |
| 2747 | default: |
| 2748 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2749 | << " to " << result_type; |
| 2750 | } |
| 2751 | break; |
| 2752 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2753 | case DataType::Type::kInt32: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2754 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2755 | case DataType::Type::kInt64: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2756 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2757 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2758 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2759 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2760 | } else { |
| 2761 | DCHECK(in.IsConstant()); |
| 2762 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2763 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2764 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2765 | } |
| 2766 | break; |
| 2767 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2768 | case DataType::Type::kFloat32: { |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2769 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2770 | Register output = out.AsRegister<Register>(); |
| 2771 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2772 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2773 | |
| 2774 | __ movl(output, Immediate(kPrimIntMax)); |
| 2775 | // temp = int-to-float(output) |
| 2776 | __ cvtsi2ss(temp, output); |
| 2777 | // if input >= temp goto done |
| 2778 | __ comiss(input, temp); |
| 2779 | __ j(kAboveEqual, &done); |
| 2780 | // if input == NaN goto nan |
| 2781 | __ j(kUnordered, &nan); |
| 2782 | // output = float-to-int-truncate(input) |
| 2783 | __ cvttss2si(output, input); |
| 2784 | __ jmp(&done); |
| 2785 | __ Bind(&nan); |
| 2786 | // output = 0 |
| 2787 | __ xorl(output, output); |
| 2788 | __ Bind(&done); |
| 2789 | break; |
| 2790 | } |
| 2791 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2792 | case DataType::Type::kFloat64: { |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2793 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2794 | Register output = out.AsRegister<Register>(); |
| 2795 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2796 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2797 | |
| 2798 | __ movl(output, Immediate(kPrimIntMax)); |
| 2799 | // temp = int-to-double(output) |
| 2800 | __ cvtsi2sd(temp, output); |
| 2801 | // if input >= temp goto done |
| 2802 | __ comisd(input, temp); |
| 2803 | __ j(kAboveEqual, &done); |
| 2804 | // if input == NaN goto nan |
| 2805 | __ j(kUnordered, &nan); |
| 2806 | // output = double-to-int-truncate(input) |
| 2807 | __ cvttsd2si(output, input); |
| 2808 | __ jmp(&done); |
| 2809 | __ Bind(&nan); |
| 2810 | // output = 0 |
| 2811 | __ xorl(output, output); |
| 2812 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2813 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2814 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 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::kInt64: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2823 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2824 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2825 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2826 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2827 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2828 | case DataType::Type::kInt16: |
| 2829 | case DataType::Type::kInt32: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2830 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2831 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2832 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2833 | __ cdq(); |
| 2834 | break; |
| 2835 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2836 | case DataType::Type::kFloat32: |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2837 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2838 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2839 | break; |
| 2840 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2841 | case DataType::Type::kFloat64: |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2842 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2843 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2844 | break; |
| 2845 | |
| 2846 | default: |
| 2847 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2848 | << " to " << result_type; |
| 2849 | } |
| 2850 | break; |
| 2851 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2852 | case DataType::Type::kFloat32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2853 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2854 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2855 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2856 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2857 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2858 | case DataType::Type::kInt16: |
| 2859 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2860 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2861 | break; |
| 2862 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2863 | case DataType::Type::kInt64: { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2864 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2865 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2866 | // Create stack space for the call to |
| 2867 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2868 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2869 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2870 | adjustment = DataType::Size(DataType::Type::kInt64); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2871 | __ subl(ESP, Immediate(adjustment)); |
| 2872 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2873 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2874 | // Load the value to the FP stack, using temporaries if needed. |
| 2875 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2876 | |
| 2877 | if (out.IsStackSlot()) { |
| 2878 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2879 | } else { |
| 2880 | __ fstps(Address(ESP, 0)); |
| 2881 | Location stack_temp = Location::StackSlot(0); |
| 2882 | codegen_->Move32(out, stack_temp); |
| 2883 | } |
| 2884 | |
| 2885 | // Remove the temporary stack space we allocated. |
| 2886 | if (adjustment != 0) { |
| 2887 | __ addl(ESP, Immediate(adjustment)); |
| 2888 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2889 | break; |
| 2890 | } |
| 2891 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2892 | case DataType::Type::kFloat64: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2893 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2894 | break; |
| 2895 | |
| 2896 | default: |
| 2897 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2898 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 2899 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2900 | break; |
| 2901 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2902 | case DataType::Type::kFloat64: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2903 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2904 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2905 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2906 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2907 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2908 | case DataType::Type::kInt16: |
| 2909 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2910 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2911 | break; |
| 2912 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2913 | case DataType::Type::kInt64: { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2914 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2915 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2916 | // Create stack space for the call to |
| 2917 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2918 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2919 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2920 | adjustment = DataType::Size(DataType::Type::kInt64); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2921 | __ subl(ESP, Immediate(adjustment)); |
| 2922 | } |
| 2923 | |
| 2924 | // Load the value to the FP stack, using temporaries if needed. |
| 2925 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2926 | |
| 2927 | if (out.IsDoubleStackSlot()) { |
| 2928 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2929 | } else { |
| 2930 | __ fstpl(Address(ESP, 0)); |
| 2931 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2932 | codegen_->Move64(out, stack_temp); |
| 2933 | } |
| 2934 | |
| 2935 | // Remove the temporary stack space we allocated. |
| 2936 | if (adjustment != 0) { |
| 2937 | __ addl(ESP, Immediate(adjustment)); |
| 2938 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2939 | break; |
| 2940 | } |
| 2941 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2942 | case DataType::Type::kFloat32: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2943 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2944 | break; |
| 2945 | |
| 2946 | default: |
| 2947 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2948 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 2949 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2950 | break; |
| 2951 | |
| 2952 | default: |
| 2953 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2954 | << " to " << result_type; |
| 2955 | } |
| 2956 | } |
| 2957 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2958 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2959 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2960 | new (GetGraph()->GetAllocator()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2961 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2962 | case DataType::Type::kInt32: { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2963 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2964 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2965 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2966 | break; |
| 2967 | } |
| 2968 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2969 | case DataType::Type::kInt64: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2970 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2971 | locations->SetInAt(1, Location::Any()); |
| 2972 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2973 | break; |
| 2974 | } |
| 2975 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2976 | case DataType::Type::kFloat32: |
| 2977 | case DataType::Type::kFloat64: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2978 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2979 | if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2980 | DCHECK(add->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2981 | } else if (add->InputAt(1)->IsConstant()) { |
| 2982 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2983 | } else { |
| 2984 | locations->SetInAt(1, Location::Any()); |
| 2985 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2986 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2987 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2988 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2989 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2990 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2991 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2992 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2993 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2994 | } |
| 2995 | |
| 2996 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 2997 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2998 | Location first = locations->InAt(0); |
| 2999 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3000 | Location out = locations->Out(); |
| 3001 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3002 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3003 | case DataType::Type::kInt32: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3004 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3005 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3006 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 3007 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 3008 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3009 | } else { |
| 3010 | __ leal(out.AsRegister<Register>(), Address( |
| 3011 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 3012 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3013 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3014 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3015 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3016 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 3017 | } else { |
| 3018 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 3019 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3020 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3021 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3022 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3023 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3024 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3025 | } |
| 3026 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3027 | case DataType::Type::kInt64: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3028 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3029 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3030 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3031 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3032 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 3033 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3034 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3035 | } else { |
| 3036 | DCHECK(second.IsConstant()) << second; |
| 3037 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3038 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 3039 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3040 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3041 | break; |
| 3042 | } |
| 3043 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3044 | case DataType::Type::kFloat32: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3045 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3046 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3047 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3048 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3049 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3050 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 3051 | codegen_->LiteralFloatAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3052 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3053 | const_area->GetBaseMethodAddress(), |
| 3054 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3055 | } else { |
| 3056 | DCHECK(second.IsStackSlot()); |
| 3057 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3058 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3059 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3060 | } |
| 3061 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3062 | case DataType::Type::kFloat64: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3063 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3064 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3065 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3066 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3067 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3068 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 3069 | codegen_->LiteralDoubleAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3070 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3071 | const_area->GetBaseMethodAddress(), |
| 3072 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3073 | } else { |
| 3074 | DCHECK(second.IsDoubleStackSlot()); |
| 3075 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3076 | } |
| 3077 | break; |
| 3078 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3079 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3080 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3081 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3082 | } |
| 3083 | } |
| 3084 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3085 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3086 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3087 | new (GetGraph()->GetAllocator()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3088 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3089 | case DataType::Type::kInt32: |
| 3090 | case DataType::Type::kInt64: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3091 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3092 | locations->SetInAt(1, Location::Any()); |
| 3093 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3094 | break; |
| 3095 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3096 | case DataType::Type::kFloat32: |
| 3097 | case DataType::Type::kFloat64: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3098 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3099 | if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3100 | DCHECK(sub->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3101 | } else if (sub->InputAt(1)->IsConstant()) { |
| 3102 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3103 | } else { |
| 3104 | locations->SetInAt(1, Location::Any()); |
| 3105 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3106 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3107 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3108 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3109 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3110 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3111 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3112 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3113 | } |
| 3114 | |
| 3115 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 3116 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3117 | Location first = locations->InAt(0); |
| 3118 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3119 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3120 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3121 | case DataType::Type::kInt32: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3122 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3123 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3124 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3125 | __ subl(first.AsRegister<Register>(), |
| 3126 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3127 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3128 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3129 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3130 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3131 | } |
| 3132 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3133 | case DataType::Type::kInt64: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3134 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3135 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3136 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3137 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3138 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3139 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 3140 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3141 | } else { |
| 3142 | DCHECK(second.IsConstant()) << second; |
| 3143 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3144 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 3145 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3146 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3147 | break; |
| 3148 | } |
| 3149 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3150 | case DataType::Type::kFloat32: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3151 | if (second.IsFpuRegister()) { |
| 3152 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3153 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3154 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3155 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3156 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3157 | codegen_->LiteralFloatAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3158 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3159 | const_area->GetBaseMethodAddress(), |
| 3160 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3161 | } else { |
| 3162 | DCHECK(second.IsStackSlot()); |
| 3163 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3164 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3165 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3166 | } |
| 3167 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3168 | case DataType::Type::kFloat64: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3169 | if (second.IsFpuRegister()) { |
| 3170 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3171 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3172 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3173 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3174 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3175 | codegen_->LiteralDoubleAddress( |
| 3176 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3177 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3178 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3179 | } else { |
| 3180 | DCHECK(second.IsDoubleStackSlot()); |
| 3181 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3182 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3183 | break; |
| 3184 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3185 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3186 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3187 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3188 | } |
| 3189 | } |
| 3190 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3191 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 3192 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3193 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3194 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3195 | case DataType::Type::kInt32: |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3196 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3197 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3198 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3199 | // Can use 3 operand multiply. |
| 3200 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3201 | } else { |
| 3202 | locations->SetOut(Location::SameAsFirstInput()); |
| 3203 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3204 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3205 | case DataType::Type::kInt64: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3206 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3207 | locations->SetInAt(1, Location::Any()); |
| 3208 | locations->SetOut(Location::SameAsFirstInput()); |
| 3209 | // Needed for imul on 32bits with 64bits output. |
| 3210 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 3211 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 3212 | break; |
| 3213 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3214 | case DataType::Type::kFloat32: |
| 3215 | case DataType::Type::kFloat64: { |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3216 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3217 | if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3218 | DCHECK(mul->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3219 | } else if (mul->InputAt(1)->IsConstant()) { |
| 3220 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3221 | } else { |
| 3222 | locations->SetInAt(1, Location::Any()); |
| 3223 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3224 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3225 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3226 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3227 | |
| 3228 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3229 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3230 | } |
| 3231 | } |
| 3232 | |
| 3233 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 3234 | LocationSummary* locations = mul->GetLocations(); |
| 3235 | Location first = locations->InAt(0); |
| 3236 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3237 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3238 | |
| 3239 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3240 | case DataType::Type::kInt32: |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3241 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3242 | // problems where the output may not be the same as the first operand. |
| 3243 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3244 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3245 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 3246 | } else if (second.IsRegister()) { |
| 3247 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3248 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3249 | } else { |
| 3250 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3251 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3252 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3253 | } |
| 3254 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3255 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3256 | case DataType::Type::kInt64: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3257 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 3258 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3259 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 3260 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3261 | |
| 3262 | DCHECK_EQ(EAX, eax); |
| 3263 | DCHECK_EQ(EDX, edx); |
| 3264 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3265 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3266 | // output: in1 |
| 3267 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3268 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3269 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3270 | if (second.IsConstant()) { |
| 3271 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3272 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3273 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3274 | int32_t low_value = Low32Bits(value); |
| 3275 | int32_t high_value = High32Bits(value); |
| 3276 | Immediate low(low_value); |
| 3277 | Immediate high(high_value); |
| 3278 | |
| 3279 | __ movl(eax, high); |
| 3280 | // eax <- in1.lo * in2.hi |
| 3281 | __ imull(eax, in1_lo); |
| 3282 | // in1.hi <- in1.hi * in2.lo |
| 3283 | __ imull(in1_hi, low); |
| 3284 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3285 | __ addl(in1_hi, eax); |
| 3286 | // move in2_lo to eax to prepare for double precision |
| 3287 | __ movl(eax, low); |
| 3288 | // edx:eax <- in1.lo * in2.lo |
| 3289 | __ mull(in1_lo); |
| 3290 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3291 | __ addl(in1_hi, edx); |
| 3292 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3293 | __ movl(in1_lo, eax); |
| 3294 | } else if (second.IsRegisterPair()) { |
| 3295 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3296 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3297 | |
| 3298 | __ movl(eax, in2_hi); |
| 3299 | // eax <- in1.lo * in2.hi |
| 3300 | __ imull(eax, in1_lo); |
| 3301 | // in1.hi <- in1.hi * in2.lo |
| 3302 | __ imull(in1_hi, in2_lo); |
| 3303 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3304 | __ addl(in1_hi, eax); |
| 3305 | // move in1_lo to eax to prepare for double precision |
| 3306 | __ movl(eax, in1_lo); |
| 3307 | // edx:eax <- in1.lo * in2.lo |
| 3308 | __ mull(in2_lo); |
| 3309 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3310 | __ addl(in1_hi, edx); |
| 3311 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3312 | __ movl(in1_lo, eax); |
| 3313 | } else { |
| 3314 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 3315 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 3316 | Address in2_lo(ESP, second.GetStackIndex()); |
| 3317 | |
| 3318 | __ movl(eax, in2_hi); |
| 3319 | // eax <- in1.lo * in2.hi |
| 3320 | __ imull(eax, in1_lo); |
| 3321 | // in1.hi <- in1.hi * in2.lo |
| 3322 | __ imull(in1_hi, in2_lo); |
| 3323 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3324 | __ addl(in1_hi, eax); |
| 3325 | // move in1_lo to eax to prepare for double precision |
| 3326 | __ movl(eax, in1_lo); |
| 3327 | // edx:eax <- in1.lo * in2.lo |
| 3328 | __ mull(in2_lo); |
| 3329 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3330 | __ addl(in1_hi, edx); |
| 3331 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3332 | __ movl(in1_lo, eax); |
| 3333 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3334 | |
| 3335 | break; |
| 3336 | } |
| 3337 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3338 | case DataType::Type::kFloat32: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3339 | DCHECK(first.Equals(locations->Out())); |
| 3340 | if (second.IsFpuRegister()) { |
| 3341 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3342 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3343 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3344 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3345 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3346 | codegen_->LiteralFloatAddress( |
| 3347 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3348 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3349 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3350 | } else { |
| 3351 | DCHECK(second.IsStackSlot()); |
| 3352 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3353 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3354 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3355 | } |
| 3356 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3357 | case DataType::Type::kFloat64: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3358 | DCHECK(first.Equals(locations->Out())); |
| 3359 | if (second.IsFpuRegister()) { |
| 3360 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3361 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3362 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3363 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3364 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3365 | codegen_->LiteralDoubleAddress( |
| 3366 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3367 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3368 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3369 | } else { |
| 3370 | DCHECK(second.IsDoubleStackSlot()); |
| 3371 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3372 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3373 | break; |
| 3374 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3375 | |
| 3376 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3377 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3378 | } |
| 3379 | } |
| 3380 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3381 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 3382 | uint32_t temp_offset, |
| 3383 | uint32_t stack_adjustment, |
| 3384 | bool is_fp, |
| 3385 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3386 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3387 | DCHECK(!is_wide); |
| 3388 | if (is_fp) { |
| 3389 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3390 | } else { |
| 3391 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3392 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3393 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3394 | DCHECK(is_wide); |
| 3395 | if (is_fp) { |
| 3396 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3397 | } else { |
| 3398 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3399 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3400 | } else { |
| 3401 | // 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] | 3402 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3403 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3404 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3405 | if (is_fp) { |
| 3406 | __ flds(Address(ESP, temp_offset)); |
| 3407 | } else { |
| 3408 | __ filds(Address(ESP, temp_offset)); |
| 3409 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3410 | } else { |
| 3411 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3412 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3413 | if (is_fp) { |
| 3414 | __ fldl(Address(ESP, temp_offset)); |
| 3415 | } else { |
| 3416 | __ fildl(Address(ESP, temp_offset)); |
| 3417 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3418 | } |
| 3419 | } |
| 3420 | } |
| 3421 | |
| 3422 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3423 | DataType::Type type = rem->GetResultType(); |
| 3424 | bool is_float = type == DataType::Type::kFloat32; |
| 3425 | size_t elem_size = DataType::Size(type); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3426 | LocationSummary* locations = rem->GetLocations(); |
| 3427 | Location first = locations->InAt(0); |
| 3428 | Location second = locations->InAt(1); |
| 3429 | Location out = locations->Out(); |
| 3430 | |
| 3431 | // Create stack space for 2 elements. |
| 3432 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3433 | __ subl(ESP, Immediate(2 * elem_size)); |
| 3434 | |
| 3435 | // 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] | 3436 | const bool is_wide = !is_float; |
| 3437 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); |
| 3438 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3439 | |
| 3440 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3441 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3442 | __ Bind(&retry); |
| 3443 | __ fprem(); |
| 3444 | |
| 3445 | // Move FP status to AX. |
| 3446 | __ fstsw(); |
| 3447 | |
| 3448 | // And see if the argument reduction is complete. This is signaled by the |
| 3449 | // C2 FPU flag bit set to 0. |
| 3450 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 3451 | __ j(kNotEqual, &retry); |
| 3452 | |
| 3453 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3454 | // Store FP top of stack to real stack. |
| 3455 | if (is_float) { |
| 3456 | __ fsts(Address(ESP, 0)); |
| 3457 | } else { |
| 3458 | __ fstl(Address(ESP, 0)); |
| 3459 | } |
| 3460 | |
| 3461 | // Pop the 2 items from the FP stack. |
| 3462 | __ fucompp(); |
| 3463 | |
| 3464 | // Load the value from the stack into an XMM register. |
| 3465 | DCHECK(out.IsFpuRegister()) << out; |
| 3466 | if (is_float) { |
| 3467 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3468 | } else { |
| 3469 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3470 | } |
| 3471 | |
| 3472 | // And remove the temporary stack space we allocated. |
| 3473 | __ addl(ESP, Immediate(2 * elem_size)); |
| 3474 | } |
| 3475 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3476 | |
| 3477 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3478 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3479 | |
| 3480 | LocationSummary* locations = instruction->GetLocations(); |
| 3481 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3482 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3483 | |
| 3484 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3485 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3486 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3487 | |
| 3488 | DCHECK(imm == 1 || imm == -1); |
| 3489 | |
| 3490 | if (instruction->IsRem()) { |
| 3491 | __ xorl(out_register, out_register); |
| 3492 | } else { |
| 3493 | __ movl(out_register, input_register); |
| 3494 | if (imm == -1) { |
| 3495 | __ negl(out_register); |
| 3496 | } |
| 3497 | } |
| 3498 | } |
| 3499 | |
| 3500 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3501 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3502 | LocationSummary* locations = instruction->GetLocations(); |
| 3503 | |
| 3504 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3505 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3506 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3507 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3508 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3509 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3510 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 3511 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3512 | __ leal(num, Address(input_register, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3513 | __ testl(input_register, input_register); |
| 3514 | __ cmovl(kGreaterEqual, num, input_register); |
| 3515 | int shift = CTZ(imm); |
| 3516 | __ sarl(num, Immediate(shift)); |
| 3517 | |
| 3518 | if (imm < 0) { |
| 3519 | __ negl(num); |
| 3520 | } |
| 3521 | |
| 3522 | __ movl(out_register, num); |
| 3523 | } |
| 3524 | |
| 3525 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3526 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3527 | |
| 3528 | LocationSummary* locations = instruction->GetLocations(); |
| 3529 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 3530 | |
| 3531 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 3532 | Register out = locations->Out().AsRegister<Register>(); |
| 3533 | Register num; |
| 3534 | Register edx; |
| 3535 | |
| 3536 | if (instruction->IsDiv()) { |
| 3537 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 3538 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 3539 | } else { |
| 3540 | edx = locations->Out().AsRegister<Register>(); |
| 3541 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 3542 | } |
| 3543 | |
| 3544 | DCHECK_EQ(EAX, eax); |
| 3545 | DCHECK_EQ(EDX, edx); |
| 3546 | if (instruction->IsDiv()) { |
| 3547 | DCHECK_EQ(EAX, out); |
| 3548 | } else { |
| 3549 | DCHECK_EQ(EDX, out); |
| 3550 | } |
| 3551 | |
| 3552 | int64_t magic; |
| 3553 | int shift; |
| 3554 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3555 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3556 | // Save the numerator. |
| 3557 | __ movl(num, eax); |
| 3558 | |
| 3559 | // EAX = magic |
| 3560 | __ movl(eax, Immediate(magic)); |
| 3561 | |
| 3562 | // EDX:EAX = magic * numerator |
| 3563 | __ imull(num); |
| 3564 | |
| 3565 | if (imm > 0 && magic < 0) { |
| 3566 | // EDX += num |
| 3567 | __ addl(edx, num); |
| 3568 | } else if (imm < 0 && magic > 0) { |
| 3569 | __ subl(edx, num); |
| 3570 | } |
| 3571 | |
| 3572 | // Shift if needed. |
| 3573 | if (shift != 0) { |
| 3574 | __ sarl(edx, Immediate(shift)); |
| 3575 | } |
| 3576 | |
| 3577 | // EDX += 1 if EDX < 0 |
| 3578 | __ movl(eax, edx); |
| 3579 | __ shrl(edx, Immediate(31)); |
| 3580 | __ addl(edx, eax); |
| 3581 | |
| 3582 | if (instruction->IsRem()) { |
| 3583 | __ movl(eax, num); |
| 3584 | __ imull(edx, Immediate(imm)); |
| 3585 | __ subl(eax, edx); |
| 3586 | __ movl(edx, eax); |
| 3587 | } else { |
| 3588 | __ movl(eax, edx); |
| 3589 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3590 | } |
| 3591 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3592 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3593 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3594 | |
| 3595 | LocationSummary* locations = instruction->GetLocations(); |
| 3596 | Location out = locations->Out(); |
| 3597 | Location first = locations->InAt(0); |
| 3598 | Location second = locations->InAt(1); |
| 3599 | bool is_div = instruction->IsDiv(); |
| 3600 | |
| 3601 | switch (instruction->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3602 | case DataType::Type::kInt32: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3603 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 3604 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3605 | |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3606 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3607 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3608 | |
| 3609 | if (imm == 0) { |
| 3610 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 3611 | } else if (imm == 1 || imm == -1) { |
| 3612 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3613 | } else if (is_div && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3614 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3615 | } else { |
| 3616 | DCHECK(imm <= -2 || imm >= 2); |
| 3617 | GenerateDivRemWithAnyConstant(instruction); |
| 3618 | } |
| 3619 | } else { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3620 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) DivRemMinusOneSlowPathX86( |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3621 | instruction, out.AsRegister<Register>(), is_div); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3622 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3623 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3624 | Register second_reg = second.AsRegister<Register>(); |
| 3625 | // 0x80000000/-1 triggers an arithmetic exception! |
| 3626 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 3627 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3628 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3629 | __ cmpl(second_reg, Immediate(-1)); |
| 3630 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3631 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3632 | // edx:eax <- sign-extended of eax |
| 3633 | __ cdq(); |
| 3634 | // eax = quotient, edx = remainder |
| 3635 | __ idivl(second_reg); |
| 3636 | __ Bind(slow_path->GetExitLabel()); |
| 3637 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3638 | break; |
| 3639 | } |
| 3640 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3641 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3642 | InvokeRuntimeCallingConvention calling_convention; |
| 3643 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3644 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3645 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3646 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3647 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 3648 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 3649 | |
| 3650 | if (is_div) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3651 | codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3652 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3653 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3654 | codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3655 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3656 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3657 | break; |
| 3658 | } |
| 3659 | |
| 3660 | default: |
| 3661 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 3662 | } |
| 3663 | } |
| 3664 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3665 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3666 | LocationSummary::CallKind call_kind = (div->GetResultType() == DataType::Type::kInt64) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3667 | ? LocationSummary::kCallOnMainOnly |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3668 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3669 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(div, call_kind); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3670 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3671 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3672 | case DataType::Type::kInt32: { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3673 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3674 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3675 | locations->SetOut(Location::SameAsFirstInput()); |
| 3676 | // Intel uses edx:eax as the dividend. |
| 3677 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3678 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3679 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 3680 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3681 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3682 | locations->AddTemp(Location::RequiresRegister()); |
| 3683 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3684 | break; |
| 3685 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3686 | case DataType::Type::kInt64: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3687 | InvokeRuntimeCallingConvention calling_convention; |
| 3688 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3689 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3690 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3691 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3692 | // Runtime helper puts the result in EAX, EDX. |
| 3693 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3694 | break; |
| 3695 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3696 | case DataType::Type::kFloat32: |
| 3697 | case DataType::Type::kFloat64: { |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3698 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3699 | if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3700 | DCHECK(div->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3701 | } else if (div->InputAt(1)->IsConstant()) { |
| 3702 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3703 | } else { |
| 3704 | locations->SetInAt(1, Location::Any()); |
| 3705 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3706 | locations->SetOut(Location::SameAsFirstInput()); |
| 3707 | break; |
| 3708 | } |
| 3709 | |
| 3710 | default: |
| 3711 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3712 | } |
| 3713 | } |
| 3714 | |
| 3715 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 3716 | LocationSummary* locations = div->GetLocations(); |
| 3717 | Location first = locations->InAt(0); |
| 3718 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3719 | |
| 3720 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3721 | case DataType::Type::kInt32: |
| 3722 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3723 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3724 | break; |
| 3725 | } |
| 3726 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3727 | case DataType::Type::kFloat32: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3728 | if (second.IsFpuRegister()) { |
| 3729 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3730 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3731 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3732 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3733 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3734 | codegen_->LiteralFloatAddress( |
| 3735 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3736 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3737 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3738 | } else { |
| 3739 | DCHECK(second.IsStackSlot()); |
| 3740 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3741 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3742 | break; |
| 3743 | } |
| 3744 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3745 | case DataType::Type::kFloat64: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3746 | if (second.IsFpuRegister()) { |
| 3747 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3748 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3749 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3750 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3751 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3752 | codegen_->LiteralDoubleAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3753 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3754 | const_area->GetBaseMethodAddress(), |
| 3755 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3756 | } else { |
| 3757 | DCHECK(second.IsDoubleStackSlot()); |
| 3758 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3759 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3760 | break; |
| 3761 | } |
| 3762 | |
| 3763 | default: |
| 3764 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3765 | } |
| 3766 | } |
| 3767 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3768 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3769 | DataType::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3770 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3771 | LocationSummary::CallKind call_kind = (rem->GetResultType() == DataType::Type::kInt64) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3772 | ? LocationSummary::kCallOnMainOnly |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3773 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3774 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3775 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3776 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3777 | case DataType::Type::kInt32: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3778 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3779 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3780 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3781 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3782 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 3783 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3784 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3785 | locations->AddTemp(Location::RequiresRegister()); |
| 3786 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3787 | break; |
| 3788 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3789 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3790 | InvokeRuntimeCallingConvention calling_convention; |
| 3791 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3792 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3793 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3794 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3795 | // Runtime helper puts the result in EAX, EDX. |
| 3796 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3797 | break; |
| 3798 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3799 | case DataType::Type::kFloat64: |
| 3800 | case DataType::Type::kFloat32: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3801 | locations->SetInAt(0, Location::Any()); |
| 3802 | locations->SetInAt(1, Location::Any()); |
| 3803 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3804 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3805 | break; |
| 3806 | } |
| 3807 | |
| 3808 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3809 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3810 | } |
| 3811 | } |
| 3812 | |
| 3813 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3814 | DataType::Type type = rem->GetResultType(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3815 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3816 | case DataType::Type::kInt32: |
| 3817 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3818 | GenerateDivRemIntegral(rem); |
| 3819 | break; |
| 3820 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3821 | case DataType::Type::kFloat32: |
| 3822 | case DataType::Type::kFloat64: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3823 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3824 | break; |
| 3825 | } |
| 3826 | default: |
| 3827 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3828 | } |
| 3829 | } |
| 3830 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 3831 | static void CreateMinMaxLocations(ArenaAllocator* allocator, HBinaryOperation* minmax) { |
| 3832 | LocationSummary* locations = new (allocator) LocationSummary(minmax); |
| 3833 | switch (minmax->GetResultType()) { |
| 3834 | case DataType::Type::kInt32: |
| 3835 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3836 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3837 | locations->SetOut(Location::SameAsFirstInput()); |
| 3838 | break; |
| 3839 | case DataType::Type::kInt64: |
| 3840 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3841 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3842 | locations->SetOut(Location::SameAsFirstInput()); |
| 3843 | // Register to use to perform a long subtract to set cc. |
| 3844 | locations->AddTemp(Location::RequiresRegister()); |
| 3845 | break; |
| 3846 | case DataType::Type::kFloat32: |
| 3847 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3848 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3849 | locations->SetOut(Location::SameAsFirstInput()); |
| 3850 | locations->AddTemp(Location::RequiresRegister()); |
| 3851 | break; |
| 3852 | case DataType::Type::kFloat64: |
| 3853 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3854 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3855 | locations->SetOut(Location::SameAsFirstInput()); |
| 3856 | break; |
| 3857 | default: |
| 3858 | LOG(FATAL) << "Unexpected type for HMinMax " << minmax->GetResultType(); |
| 3859 | } |
| 3860 | } |
| 3861 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 3862 | void InstructionCodeGeneratorX86::GenerateMinMaxInt(LocationSummary* locations, |
| 3863 | bool is_min, |
| 3864 | DataType::Type type) { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 3865 | Location op1_loc = locations->InAt(0); |
| 3866 | Location op2_loc = locations->InAt(1); |
| 3867 | |
| 3868 | // Shortcut for same input locations. |
| 3869 | if (op1_loc.Equals(op2_loc)) { |
| 3870 | // Can return immediately, as op1_loc == out_loc. |
| 3871 | // Note: if we ever support separate registers, e.g., output into memory, we need to check for |
| 3872 | // a copy here. |
| 3873 | DCHECK(locations->Out().Equals(op1_loc)); |
| 3874 | return; |
| 3875 | } |
| 3876 | |
| 3877 | if (type == DataType::Type::kInt64) { |
| 3878 | // Need to perform a subtract to get the sign right. |
| 3879 | // op1 is already in the same location as the output. |
| 3880 | Location output = locations->Out(); |
| 3881 | Register output_lo = output.AsRegisterPairLow<Register>(); |
| 3882 | Register output_hi = output.AsRegisterPairHigh<Register>(); |
| 3883 | |
| 3884 | Register op2_lo = op2_loc.AsRegisterPairLow<Register>(); |
| 3885 | Register op2_hi = op2_loc.AsRegisterPairHigh<Register>(); |
| 3886 | |
| 3887 | // The comparison is performed by subtracting the second operand from |
| 3888 | // the first operand and then setting the status flags in the same |
| 3889 | // manner as the SUB instruction." |
| 3890 | __ cmpl(output_lo, op2_lo); |
| 3891 | |
| 3892 | // Now use a temp and the borrow to finish the subtraction of op2_hi. |
| 3893 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3894 | __ movl(temp, output_hi); |
| 3895 | __ sbbl(temp, op2_hi); |
| 3896 | |
| 3897 | // Now the condition code is correct. |
| 3898 | Condition cond = is_min ? Condition::kGreaterEqual : Condition::kLess; |
| 3899 | __ cmovl(cond, output_lo, op2_lo); |
| 3900 | __ cmovl(cond, output_hi, op2_hi); |
| 3901 | } else { |
| 3902 | DCHECK_EQ(type, DataType::Type::kInt32); |
| 3903 | Register out = locations->Out().AsRegister<Register>(); |
| 3904 | Register op2 = op2_loc.AsRegister<Register>(); |
| 3905 | |
| 3906 | // (out := op1) |
| 3907 | // out <=? op2 |
| 3908 | // if out is min jmp done |
| 3909 | // out := op2 |
| 3910 | // done: |
| 3911 | |
| 3912 | __ cmpl(out, op2); |
| 3913 | Condition cond = is_min ? Condition::kGreater : Condition::kLess; |
| 3914 | __ cmovl(cond, out, op2); |
| 3915 | } |
| 3916 | } |
| 3917 | |
| 3918 | void InstructionCodeGeneratorX86::GenerateMinMaxFP(LocationSummary* locations, |
| 3919 | bool is_min, |
| 3920 | DataType::Type type) { |
| 3921 | Location op1_loc = locations->InAt(0); |
| 3922 | Location op2_loc = locations->InAt(1); |
| 3923 | Location out_loc = locations->Out(); |
| 3924 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
| 3925 | |
| 3926 | // Shortcut for same input locations. |
| 3927 | if (op1_loc.Equals(op2_loc)) { |
| 3928 | DCHECK(out_loc.Equals(op1_loc)); |
| 3929 | return; |
| 3930 | } |
| 3931 | |
| 3932 | // (out := op1) |
| 3933 | // out <=? op2 |
| 3934 | // if Nan jmp Nan_label |
| 3935 | // if out is min jmp done |
| 3936 | // if op2 is min jmp op2_label |
| 3937 | // handle -0/+0 |
| 3938 | // jmp done |
| 3939 | // Nan_label: |
| 3940 | // out := NaN |
| 3941 | // op2_label: |
| 3942 | // out := op2 |
| 3943 | // done: |
| 3944 | // |
| 3945 | // This removes one jmp, but needs to copy one input (op1) to out. |
| 3946 | // |
| 3947 | // TODO: This is straight from Quick (except literal pool). Make NaN an out-of-line slowpath? |
| 3948 | |
| 3949 | XmmRegister op2 = op2_loc.AsFpuRegister<XmmRegister>(); |
| 3950 | |
| 3951 | NearLabel nan, done, op2_label; |
| 3952 | if (type == DataType::Type::kFloat64) { |
| 3953 | __ ucomisd(out, op2); |
| 3954 | } else { |
| 3955 | DCHECK_EQ(type, DataType::Type::kFloat32); |
| 3956 | __ ucomiss(out, op2); |
| 3957 | } |
| 3958 | |
| 3959 | __ j(Condition::kParityEven, &nan); |
| 3960 | |
| 3961 | __ j(is_min ? Condition::kAbove : Condition::kBelow, &op2_label); |
| 3962 | __ j(is_min ? Condition::kBelow : Condition::kAbove, &done); |
| 3963 | |
| 3964 | // Handle 0.0/-0.0. |
| 3965 | if (is_min) { |
| 3966 | if (type == DataType::Type::kFloat64) { |
| 3967 | __ orpd(out, op2); |
| 3968 | } else { |
| 3969 | __ orps(out, op2); |
| 3970 | } |
| 3971 | } else { |
| 3972 | if (type == DataType::Type::kFloat64) { |
| 3973 | __ andpd(out, op2); |
| 3974 | } else { |
| 3975 | __ andps(out, op2); |
| 3976 | } |
| 3977 | } |
| 3978 | __ jmp(&done); |
| 3979 | |
| 3980 | // NaN handling. |
| 3981 | __ Bind(&nan); |
| 3982 | if (type == DataType::Type::kFloat64) { |
| 3983 | // TODO: Use a constant from the constant table (requires extra input). |
| 3984 | __ LoadLongConstant(out, kDoubleNaN); |
| 3985 | } else { |
| 3986 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 3987 | __ movl(constant, Immediate(kFloatNaN)); |
| 3988 | __ movd(out, constant); |
| 3989 | } |
| 3990 | __ jmp(&done); |
| 3991 | |
| 3992 | // out := op2; |
| 3993 | __ Bind(&op2_label); |
| 3994 | if (type == DataType::Type::kFloat64) { |
| 3995 | __ movsd(out, op2); |
| 3996 | } else { |
| 3997 | __ movss(out, op2); |
| 3998 | } |
| 3999 | |
| 4000 | // Done. |
| 4001 | __ Bind(&done); |
| 4002 | } |
| 4003 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4004 | void InstructionCodeGeneratorX86::GenerateMinMax(HBinaryOperation* minmax, bool is_min) { |
| 4005 | DataType::Type type = minmax->GetResultType(); |
| 4006 | switch (type) { |
| 4007 | case DataType::Type::kInt32: |
| 4008 | case DataType::Type::kInt64: |
| 4009 | GenerateMinMaxInt(minmax->GetLocations(), is_min, type); |
| 4010 | break; |
| 4011 | case DataType::Type::kFloat32: |
| 4012 | case DataType::Type::kFloat64: |
| 4013 | GenerateMinMaxFP(minmax->GetLocations(), is_min, type); |
| 4014 | break; |
| 4015 | default: |
| 4016 | LOG(FATAL) << "Unexpected type for HMinMax " << type; |
| 4017 | } |
| 4018 | } |
| 4019 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4020 | void LocationsBuilderX86::VisitMin(HMin* min) { |
| 4021 | CreateMinMaxLocations(GetGraph()->GetAllocator(), min); |
| 4022 | } |
| 4023 | |
| 4024 | void InstructionCodeGeneratorX86::VisitMin(HMin* min) { |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4025 | GenerateMinMax(min, /*is_min*/ true); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4026 | } |
| 4027 | |
| 4028 | void LocationsBuilderX86::VisitMax(HMax* max) { |
| 4029 | CreateMinMaxLocations(GetGraph()->GetAllocator(), max); |
| 4030 | } |
| 4031 | |
| 4032 | void InstructionCodeGeneratorX86::VisitMax(HMax* max) { |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4033 | GenerateMinMax(max, /*is_min*/ false); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4034 | } |
| 4035 | |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 4036 | void LocationsBuilderX86::VisitAbs(HAbs* abs) { |
| 4037 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 4038 | switch (abs->GetResultType()) { |
| 4039 | case DataType::Type::kInt32: |
| 4040 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 4041 | locations->SetOut(Location::SameAsFirstInput()); |
| 4042 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 4043 | break; |
| 4044 | case DataType::Type::kInt64: |
| 4045 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4046 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4047 | locations->AddTemp(Location::RequiresRegister()); |
| 4048 | break; |
| 4049 | case DataType::Type::kFloat32: |
| 4050 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4051 | locations->SetOut(Location::SameAsFirstInput()); |
| 4052 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4053 | locations->AddTemp(Location::RequiresRegister()); |
| 4054 | break; |
| 4055 | case DataType::Type::kFloat64: |
| 4056 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4057 | locations->SetOut(Location::SameAsFirstInput()); |
| 4058 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4059 | break; |
| 4060 | default: |
| 4061 | LOG(FATAL) << "Unexpected type for HAbs " << abs->GetResultType(); |
| 4062 | } |
| 4063 | } |
| 4064 | |
| 4065 | void InstructionCodeGeneratorX86::VisitAbs(HAbs* abs) { |
| 4066 | LocationSummary* locations = abs->GetLocations(); |
| 4067 | switch (abs->GetResultType()) { |
| 4068 | case DataType::Type::kInt32: { |
| 4069 | Register out = locations->Out().AsRegister<Register>(); |
| 4070 | DCHECK_EQ(out, EAX); |
| 4071 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4072 | DCHECK_EQ(temp, EDX); |
| 4073 | // Sign extend EAX into EDX. |
| 4074 | __ cdq(); |
| 4075 | // XOR EAX with sign. |
| 4076 | __ xorl(EAX, EDX); |
| 4077 | // Subtract out sign to correct. |
| 4078 | __ subl(EAX, EDX); |
| 4079 | // The result is in EAX. |
| 4080 | break; |
| 4081 | } |
| 4082 | case DataType::Type::kInt64: { |
| 4083 | Location input = locations->InAt(0); |
| 4084 | Register input_lo = input.AsRegisterPairLow<Register>(); |
| 4085 | Register input_hi = input.AsRegisterPairHigh<Register>(); |
| 4086 | Location output = locations->Out(); |
| 4087 | Register output_lo = output.AsRegisterPairLow<Register>(); |
| 4088 | Register output_hi = output.AsRegisterPairHigh<Register>(); |
| 4089 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4090 | // Compute the sign into the temporary. |
| 4091 | __ movl(temp, input_hi); |
| 4092 | __ sarl(temp, Immediate(31)); |
| 4093 | // Store the sign into the output. |
| 4094 | __ movl(output_lo, temp); |
| 4095 | __ movl(output_hi, temp); |
| 4096 | // XOR the input to the output. |
| 4097 | __ xorl(output_lo, input_lo); |
| 4098 | __ xorl(output_hi, input_hi); |
| 4099 | // Subtract the sign. |
| 4100 | __ subl(output_lo, temp); |
| 4101 | __ sbbl(output_hi, temp); |
| 4102 | break; |
| 4103 | } |
| 4104 | case DataType::Type::kFloat32: { |
| 4105 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4106 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4107 | Register constant = locations->GetTemp(1).AsRegister<Register>(); |
| 4108 | __ movl(constant, Immediate(INT32_C(0x7FFFFFFF))); |
| 4109 | __ movd(temp, constant); |
| 4110 | __ andps(out, temp); |
| 4111 | break; |
| 4112 | } |
| 4113 | case DataType::Type::kFloat64: { |
| 4114 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4115 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4116 | // TODO: Use a constant from the constant table (requires extra input). |
| 4117 | __ LoadLongConstant(temp, INT64_C(0x7FFFFFFFFFFFFFFF)); |
| 4118 | __ andpd(out, temp); |
| 4119 | break; |
| 4120 | } |
| 4121 | default: |
| 4122 | LOG(FATAL) << "Unexpected type for HAbs " << abs->GetResultType(); |
| 4123 | } |
| 4124 | } |
| 4125 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4126 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4127 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4128 | switch (instruction->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4129 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4130 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4131 | case DataType::Type::kInt8: |
| 4132 | case DataType::Type::kUint16: |
| 4133 | case DataType::Type::kInt16: |
| 4134 | case DataType::Type::kInt32: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4135 | locations->SetInAt(0, Location::Any()); |
| 4136 | break; |
| 4137 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4138 | case DataType::Type::kInt64: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4139 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 4140 | if (!instruction->IsConstant()) { |
| 4141 | locations->AddTemp(Location::RequiresRegister()); |
| 4142 | } |
| 4143 | break; |
| 4144 | } |
| 4145 | default: |
| 4146 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 4147 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4148 | } |
| 4149 | |
| 4150 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4151 | SlowPathCode* slow_path = |
| 4152 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathX86(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4153 | codegen_->AddSlowPath(slow_path); |
| 4154 | |
| 4155 | LocationSummary* locations = instruction->GetLocations(); |
| 4156 | Location value = locations->InAt(0); |
| 4157 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4158 | switch (instruction->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4159 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4160 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4161 | case DataType::Type::kInt8: |
| 4162 | case DataType::Type::kUint16: |
| 4163 | case DataType::Type::kInt16: |
| 4164 | case DataType::Type::kInt32: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4165 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4166 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4167 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4168 | } else if (value.IsStackSlot()) { |
| 4169 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 4170 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4171 | } else { |
| 4172 | DCHECK(value.IsConstant()) << value; |
| 4173 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4174 | __ jmp(slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4175 | } |
| 4176 | } |
| 4177 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4178 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4179 | case DataType::Type::kInt64: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4180 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4181 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4182 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 4183 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 4184 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4185 | } else { |
| 4186 | DCHECK(value.IsConstant()) << value; |
| 4187 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 4188 | __ jmp(slow_path->GetEntryLabel()); |
| 4189 | } |
| 4190 | } |
| 4191 | break; |
| 4192 | } |
| 4193 | default: |
| 4194 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4195 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4196 | } |
| 4197 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4198 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 4199 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4200 | |
| 4201 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4202 | new (GetGraph()->GetAllocator()) LocationSummary(op, LocationSummary::kNoCall); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4203 | |
| 4204 | switch (op->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4205 | case DataType::Type::kInt32: |
| 4206 | case DataType::Type::kInt64: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4207 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4208 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4209 | // The shift count needs to be in CL or a constant. |
| 4210 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4211 | locations->SetOut(Location::SameAsFirstInput()); |
| 4212 | break; |
| 4213 | } |
| 4214 | default: |
| 4215 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 4216 | } |
| 4217 | } |
| 4218 | |
| 4219 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 4220 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4221 | |
| 4222 | LocationSummary* locations = op->GetLocations(); |
| 4223 | Location first = locations->InAt(0); |
| 4224 | Location second = locations->InAt(1); |
| 4225 | DCHECK(first.Equals(locations->Out())); |
| 4226 | |
| 4227 | switch (op->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4228 | case DataType::Type::kInt32: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4229 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4230 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4231 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4232 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4233 | DCHECK_EQ(ECX, second_reg); |
| 4234 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4235 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4236 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4237 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4238 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4239 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4240 | } |
| 4241 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4242 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4243 | if (shift == 0) { |
| 4244 | return; |
| 4245 | } |
| 4246 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4247 | if (op->IsShl()) { |
| 4248 | __ shll(first_reg, imm); |
| 4249 | } else if (op->IsShr()) { |
| 4250 | __ sarl(first_reg, imm); |
| 4251 | } else { |
| 4252 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4253 | } |
| 4254 | } |
| 4255 | break; |
| 4256 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4257 | case DataType::Type::kInt64: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4258 | if (second.IsRegister()) { |
| 4259 | Register second_reg = second.AsRegister<Register>(); |
| 4260 | DCHECK_EQ(ECX, second_reg); |
| 4261 | if (op->IsShl()) { |
| 4262 | GenerateShlLong(first, second_reg); |
| 4263 | } else if (op->IsShr()) { |
| 4264 | GenerateShrLong(first, second_reg); |
| 4265 | } else { |
| 4266 | GenerateUShrLong(first, second_reg); |
| 4267 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4268 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4269 | // Shift by a constant. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4270 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4271 | // Nothing to do if the shift is 0, as the input is already the output. |
| 4272 | if (shift != 0) { |
| 4273 | if (op->IsShl()) { |
| 4274 | GenerateShlLong(first, shift); |
| 4275 | } else if (op->IsShr()) { |
| 4276 | GenerateShrLong(first, shift); |
| 4277 | } else { |
| 4278 | GenerateUShrLong(first, shift); |
| 4279 | } |
| 4280 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4281 | } |
| 4282 | break; |
| 4283 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4284 | default: |
| 4285 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 4286 | } |
| 4287 | } |
| 4288 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4289 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 4290 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4291 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 4292 | if (shift == 1) { |
| 4293 | // This is just an addition. |
| 4294 | __ addl(low, low); |
| 4295 | __ adcl(high, high); |
| 4296 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4297 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 4298 | codegen_->EmitParallelMoves( |
| 4299 | loc.ToLow(), |
| 4300 | loc.ToHigh(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4301 | DataType::Type::kInt32, |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4302 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 4303 | loc.ToLow(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4304 | DataType::Type::kInt32); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4305 | } else if (shift > 32) { |
| 4306 | // Low part becomes 0. High part is low part << (shift-32). |
| 4307 | __ movl(high, low); |
| 4308 | __ shll(high, Immediate(shift - 32)); |
| 4309 | __ xorl(low, low); |
| 4310 | } else { |
| 4311 | // Between 1 and 31. |
| 4312 | __ shld(high, low, Immediate(shift)); |
| 4313 | __ shll(low, Immediate(shift)); |
| 4314 | } |
| 4315 | } |
| 4316 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4317 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4318 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4319 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 4320 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 4321 | __ testl(shifter, Immediate(32)); |
| 4322 | __ j(kEqual, &done); |
| 4323 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 4324 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 4325 | __ Bind(&done); |
| 4326 | } |
| 4327 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4328 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 4329 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4330 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 4331 | if (shift == 32) { |
| 4332 | // Need to copy the sign. |
| 4333 | DCHECK_NE(low, high); |
| 4334 | __ movl(low, high); |
| 4335 | __ sarl(high, Immediate(31)); |
| 4336 | } else if (shift > 32) { |
| 4337 | DCHECK_NE(low, high); |
| 4338 | // High part becomes sign. Low part is shifted by shift - 32. |
| 4339 | __ movl(low, high); |
| 4340 | __ sarl(high, Immediate(31)); |
| 4341 | __ sarl(low, Immediate(shift - 32)); |
| 4342 | } else { |
| 4343 | // Between 1 and 31. |
| 4344 | __ shrd(low, high, Immediate(shift)); |
| 4345 | __ sarl(high, Immediate(shift)); |
| 4346 | } |
| 4347 | } |
| 4348 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4349 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4350 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4351 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4352 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4353 | __ testl(shifter, Immediate(32)); |
| 4354 | __ j(kEqual, &done); |
| 4355 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4356 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 4357 | __ Bind(&done); |
| 4358 | } |
| 4359 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4360 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 4361 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4362 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 4363 | if (shift == 32) { |
| 4364 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 4365 | codegen_->EmitParallelMoves( |
| 4366 | loc.ToHigh(), |
| 4367 | loc.ToLow(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4368 | DataType::Type::kInt32, |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4369 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 4370 | loc.ToHigh(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4371 | DataType::Type::kInt32); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4372 | } else if (shift > 32) { |
| 4373 | // Low part is high >> (shift - 32). High part becomes 0. |
| 4374 | __ movl(low, high); |
| 4375 | __ shrl(low, Immediate(shift - 32)); |
| 4376 | __ xorl(high, high); |
| 4377 | } else { |
| 4378 | // Between 1 and 31. |
| 4379 | __ shrd(low, high, Immediate(shift)); |
| 4380 | __ shrl(high, Immediate(shift)); |
| 4381 | } |
| 4382 | } |
| 4383 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4384 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4385 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4386 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4387 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4388 | __ testl(shifter, Immediate(32)); |
| 4389 | __ j(kEqual, &done); |
| 4390 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4391 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 4392 | __ Bind(&done); |
| 4393 | } |
| 4394 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4395 | void LocationsBuilderX86::VisitRor(HRor* ror) { |
| 4396 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4397 | new (GetGraph()->GetAllocator()) LocationSummary(ror, LocationSummary::kNoCall); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4398 | |
| 4399 | switch (ror->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4400 | case DataType::Type::kInt64: |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4401 | // Add the temporary needed. |
| 4402 | locations->AddTemp(Location::RequiresRegister()); |
| 4403 | FALLTHROUGH_INTENDED; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4404 | case DataType::Type::kInt32: |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4405 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4406 | // The shift count needs to be in CL (unless it is a constant). |
| 4407 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); |
| 4408 | locations->SetOut(Location::SameAsFirstInput()); |
| 4409 | break; |
| 4410 | default: |
| 4411 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4412 | UNREACHABLE(); |
| 4413 | } |
| 4414 | } |
| 4415 | |
| 4416 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { |
| 4417 | LocationSummary* locations = ror->GetLocations(); |
| 4418 | Location first = locations->InAt(0); |
| 4419 | Location second = locations->InAt(1); |
| 4420 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4421 | if (ror->GetResultType() == DataType::Type::kInt32) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4422 | Register first_reg = first.AsRegister<Register>(); |
| 4423 | if (second.IsRegister()) { |
| 4424 | Register second_reg = second.AsRegister<Register>(); |
| 4425 | __ rorl(first_reg, second_reg); |
| 4426 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4427 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4428 | __ rorl(first_reg, imm); |
| 4429 | } |
| 4430 | return; |
| 4431 | } |
| 4432 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4433 | DCHECK_EQ(ror->GetResultType(), DataType::Type::kInt64); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4434 | Register first_reg_lo = first.AsRegisterPairLow<Register>(); |
| 4435 | Register first_reg_hi = first.AsRegisterPairHigh<Register>(); |
| 4436 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 4437 | if (second.IsRegister()) { |
| 4438 | Register second_reg = second.AsRegister<Register>(); |
| 4439 | DCHECK_EQ(second_reg, ECX); |
| 4440 | __ movl(temp_reg, first_reg_hi); |
| 4441 | __ shrd(first_reg_hi, first_reg_lo, second_reg); |
| 4442 | __ shrd(first_reg_lo, temp_reg, second_reg); |
| 4443 | __ movl(temp_reg, first_reg_hi); |
| 4444 | __ testl(second_reg, Immediate(32)); |
| 4445 | __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); |
| 4446 | __ cmovl(kNotEqual, first_reg_lo, temp_reg); |
| 4447 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4448 | int32_t shift_amt = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4449 | if (shift_amt == 0) { |
| 4450 | // Already fine. |
| 4451 | return; |
| 4452 | } |
| 4453 | if (shift_amt == 32) { |
| 4454 | // Just swap. |
| 4455 | __ movl(temp_reg, first_reg_lo); |
| 4456 | __ movl(first_reg_lo, first_reg_hi); |
| 4457 | __ movl(first_reg_hi, temp_reg); |
| 4458 | return; |
| 4459 | } |
| 4460 | |
| 4461 | Immediate imm(shift_amt); |
| 4462 | // Save the constents of the low value. |
| 4463 | __ movl(temp_reg, first_reg_lo); |
| 4464 | |
| 4465 | // Shift right into low, feeding bits from high. |
| 4466 | __ shrd(first_reg_lo, first_reg_hi, imm); |
| 4467 | |
| 4468 | // Shift right into high, feeding bits from the original low. |
| 4469 | __ shrd(first_reg_hi, temp_reg, imm); |
| 4470 | |
| 4471 | // Swap if needed. |
| 4472 | if (shift_amt > 32) { |
| 4473 | __ movl(temp_reg, first_reg_lo); |
| 4474 | __ movl(first_reg_lo, first_reg_hi); |
| 4475 | __ movl(first_reg_hi, temp_reg); |
| 4476 | } |
| 4477 | } |
| 4478 | } |
| 4479 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4480 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 4481 | HandleShift(shl); |
| 4482 | } |
| 4483 | |
| 4484 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 4485 | HandleShift(shl); |
| 4486 | } |
| 4487 | |
| 4488 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 4489 | HandleShift(shr); |
| 4490 | } |
| 4491 | |
| 4492 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 4493 | HandleShift(shr); |
| 4494 | } |
| 4495 | |
| 4496 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 4497 | HandleShift(ushr); |
| 4498 | } |
| 4499 | |
| 4500 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 4501 | HandleShift(ushr); |
| 4502 | } |
| 4503 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4504 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4505 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4506 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4507 | locations->SetOut(Location::RegisterLocation(EAX)); |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 4508 | InvokeRuntimeCallingConvention calling_convention; |
| 4509 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4510 | } |
| 4511 | |
| 4512 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 4513 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
| 4514 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| 4515 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4516 | } |
| 4517 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4518 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4519 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4520 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4521 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 4522 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4523 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4524 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4525 | } |
| 4526 | |
| 4527 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4528 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4529 | // of poisoning the reference. |
Nicolas Geoffray | d095844 | 2017-01-30 14:57:16 +0000 | [diff] [blame] | 4530 | QuickEntrypointEnum entrypoint = |
| 4531 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 4532 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4533 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4534 | DCHECK(!codegen_->IsLeafMethod()); |
| 4535 | } |
| 4536 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4537 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4538 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4539 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4540 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4541 | if (location.IsStackSlot()) { |
| 4542 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4543 | } else if (location.IsDoubleStackSlot()) { |
| 4544 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4545 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4546 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4547 | } |
| 4548 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4549 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 4550 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 4551 | } |
| 4552 | |
| 4553 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4554 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4555 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4556 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4557 | } |
| 4558 | |
| 4559 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4560 | } |
| 4561 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4562 | void LocationsBuilderX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4563 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4564 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4565 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4566 | locations->SetOut(Location::RequiresRegister()); |
| 4567 | } |
| 4568 | |
| 4569 | void InstructionCodeGeneratorX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4570 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4571 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4572 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4573 | instruction->GetIndex(), kX86PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4574 | __ movl(locations->Out().AsRegister<Register>(), |
| 4575 | Address(locations->InAt(0).AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4576 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4577 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4578 | instruction->GetIndex(), kX86PointerSize)); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4579 | __ movl(locations->Out().AsRegister<Register>(), |
| 4580 | Address(locations->InAt(0).AsRegister<Register>(), |
| 4581 | mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
| 4582 | // temp = temp->GetImtEntryAt(method_offset); |
| 4583 | __ movl(locations->Out().AsRegister<Register>(), |
| 4584 | Address(locations->Out().AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4585 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4586 | } |
| 4587 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4588 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4589 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4590 | new (GetGraph()->GetAllocator()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4591 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4592 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4593 | } |
| 4594 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4595 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 4596 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4597 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4598 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4599 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4600 | switch (not_->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4601 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4602 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4603 | break; |
| 4604 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4605 | case DataType::Type::kInt64: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4606 | __ notl(out.AsRegisterPairLow<Register>()); |
| 4607 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4608 | break; |
| 4609 | |
| 4610 | default: |
| 4611 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4612 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4613 | } |
| 4614 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4615 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4616 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4617 | new (GetGraph()->GetAllocator()) LocationSummary(bool_not, LocationSummary::kNoCall); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4618 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4619 | locations->SetOut(Location::SameAsFirstInput()); |
| 4620 | } |
| 4621 | |
| 4622 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4623 | LocationSummary* locations = bool_not->GetLocations(); |
| 4624 | Location in = locations->InAt(0); |
| 4625 | Location out = locations->Out(); |
| 4626 | DCHECK(in.Equals(out)); |
| 4627 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 4628 | } |
| 4629 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4630 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4631 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4632 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4633 | switch (compare->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4634 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4635 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4636 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4637 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4638 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4639 | case DataType::Type::kInt32: |
| 4640 | case DataType::Type::kInt64: { |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4641 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4642 | locations->SetInAt(1, Location::Any()); |
| 4643 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4644 | break; |
| 4645 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4646 | case DataType::Type::kFloat32: |
| 4647 | case DataType::Type::kFloat64: { |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4648 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4649 | if (compare->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4650 | DCHECK(compare->InputAt(1)->IsEmittedAtUseSite()); |
| 4651 | } else if (compare->InputAt(1)->IsConstant()) { |
| 4652 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4653 | } else { |
| 4654 | locations->SetInAt(1, Location::Any()); |
| 4655 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4656 | locations->SetOut(Location::RequiresRegister()); |
| 4657 | break; |
| 4658 | } |
| 4659 | default: |
| 4660 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4661 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4662 | } |
| 4663 | |
| 4664 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4665 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4666 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4667 | Location left = locations->InAt(0); |
| 4668 | Location right = locations->InAt(1); |
| 4669 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4670 | NearLabel less, greater, done; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4671 | Condition less_cond = kLess; |
| 4672 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4673 | switch (compare->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4674 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4675 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4676 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4677 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4678 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4679 | case DataType::Type::kInt32: { |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 4680 | codegen_->GenerateIntCompare(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4681 | break; |
| 4682 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4683 | case DataType::Type::kInt64: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4684 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 4685 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 4686 | int32_t val_low = 0; |
| 4687 | int32_t val_high = 0; |
| 4688 | bool right_is_const = false; |
| 4689 | |
| 4690 | if (right.IsConstant()) { |
| 4691 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 4692 | right_is_const = true; |
| 4693 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 4694 | val_low = Low32Bits(val); |
| 4695 | val_high = High32Bits(val); |
| 4696 | } |
| 4697 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4698 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4699 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4700 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4701 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4702 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4703 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4704 | codegen_->Compare32BitValue(left_high, val_high); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4705 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4706 | __ j(kLess, &less); // Signed compare. |
| 4707 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4708 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4709 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4710 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4711 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4712 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4713 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4714 | codegen_->Compare32BitValue(left_low, val_low); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4715 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4716 | less_cond = kBelow; // for CF (unsigned). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4717 | break; |
| 4718 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4719 | case DataType::Type::kFloat32: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4720 | GenerateFPCompare(left, right, compare, false); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4721 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4722 | less_cond = kBelow; // for CF (floats). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4723 | break; |
| 4724 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4725 | case DataType::Type::kFloat64: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4726 | GenerateFPCompare(left, right, compare, true); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4727 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4728 | less_cond = kBelow; // for CF (floats). |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4729 | break; |
| 4730 | } |
| 4731 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4732 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4733 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4734 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4735 | __ movl(out, Immediate(0)); |
| 4736 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4737 | __ j(less_cond, &less); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4738 | |
| 4739 | __ Bind(&greater); |
| 4740 | __ movl(out, Immediate(1)); |
| 4741 | __ jmp(&done); |
| 4742 | |
| 4743 | __ Bind(&less); |
| 4744 | __ movl(out, Immediate(-1)); |
| 4745 | |
| 4746 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4747 | } |
| 4748 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4749 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4750 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4751 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4752 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4753 | locations->SetInAt(i, Location::Any()); |
| 4754 | } |
| 4755 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4756 | } |
| 4757 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4758 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4759 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4760 | } |
| 4761 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4762 | void CodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4763 | /* |
| 4764 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 4765 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 4766 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4767 | */ |
| 4768 | switch (kind) { |
| 4769 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4770 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4771 | break; |
| 4772 | } |
| 4773 | case MemBarrierKind::kAnyStore: |
| 4774 | case MemBarrierKind::kLoadAny: |
| 4775 | case MemBarrierKind::kStoreStore: { |
| 4776 | // nop |
| 4777 | break; |
| 4778 | } |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4779 | case MemBarrierKind::kNTStoreStore: |
| 4780 | // Non-Temporal Store/Store needs an explicit fence. |
| 4781 | MemoryFence(/* non-temporal */ true); |
| 4782 | break; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4783 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4784 | } |
| 4785 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4786 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( |
| 4787 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | bdb2ecc | 2018-09-18 14:33:55 +0100 | [diff] [blame] | 4788 | ArtMethod* method ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4789 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4790 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4791 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4792 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 4793 | Register temp) { |
| 4794 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4795 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4796 | if (!invoke->GetLocations()->Intrinsified()) { |
| 4797 | return location.AsRegister<Register>(); |
| 4798 | } |
| 4799 | // For intrinsics we allow any location, so it may be on the stack. |
| 4800 | if (!location.IsRegister()) { |
| 4801 | __ movl(temp, Address(ESP, location.GetStackIndex())); |
| 4802 | return temp; |
| 4803 | } |
| 4804 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 4805 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 4806 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 4807 | // simple and more robust approach rather that trying to determine if that's the case. |
| 4808 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
Vladimir Marko | 4ee8e29 | 2017-06-02 15:39:30 +0000 | [diff] [blame] | 4809 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 4810 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 4811 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 4812 | __ movl(temp, Address(ESP, stack_offset)); |
| 4813 | return temp; |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4814 | } |
| 4815 | return location.AsRegister<Register>(); |
| 4816 | } |
| 4817 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4818 | void CodeGeneratorX86::GenerateStaticOrDirectCall( |
| 4819 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4820 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4821 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4822 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4823 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4824 | uint32_t offset = |
| 4825 | GetThreadOffset<kX86PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 4826 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4827 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4828 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4829 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4830 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4831 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4832 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 4833 | DCHECK(GetCompilerOptions().IsBootImage()); |
| 4834 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4835 | temp.AsRegister<Register>()); |
| 4836 | __ leal(temp.AsRegister<Register>(), Address(base_reg, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4837 | RecordBootImageMethodPatch(invoke); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4838 | break; |
| 4839 | } |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4840 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageRelRo: { |
| 4841 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4842 | temp.AsRegister<Register>()); |
| 4843 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
| 4844 | RecordBootImageRelRoPatch( |
| 4845 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(), |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4846 | GetBootImageOffset(invoke)); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4847 | break; |
| 4848 | } |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4849 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4850 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4851 | temp.AsRegister<Register>()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4852 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4853 | RecordMethodBssEntryPatch(invoke); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4854 | break; |
| 4855 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4856 | case HInvokeStaticOrDirect::MethodLoadKind::kJitDirectAddress: |
| 4857 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 4858 | break; |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4859 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 4860 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 4861 | return; // No code pointer retrieval; the runtime performs the call directly. |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4862 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4863 | } |
| 4864 | |
| 4865 | switch (invoke->GetCodePtrLocation()) { |
| 4866 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 4867 | __ call(GetFrameEntryLabel()); |
| 4868 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4869 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4870 | // (callee_method + offset_of_quick_compiled_code)() |
| 4871 | __ call(Address(callee_method.AsRegister<Register>(), |
| 4872 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4873 | kX86PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4874 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4875 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4876 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4877 | |
| 4878 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4879 | } |
| 4880 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4881 | void CodeGeneratorX86::GenerateVirtualCall( |
| 4882 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4883 | Register temp = temp_in.AsRegister<Register>(); |
| 4884 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4885 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4886 | |
| 4887 | // Use the calling convention instead of the location of the receiver, as |
| 4888 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4889 | // slow path, the arguments have been moved to the right place, so here we are |
| 4890 | // guaranteed that the receiver is the first register of the calling convention. |
| 4891 | InvokeDexCallingConvention calling_convention; |
| 4892 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4893 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4894 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4895 | __ movl(temp, Address(receiver, class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4896 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4897 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4898 | // emit a read barrier for the previous class reference load. |
| 4899 | // However this is not required in practice, as this is an |
| 4900 | // intermediate/temporary reference and because the current |
| 4901 | // concurrent copying collector keeps the from-space memory |
| 4902 | // intact/accessible until the end of the marking phase (the |
| 4903 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4904 | __ MaybeUnpoisonHeapReference(temp); |
| 4905 | // temp = temp->GetMethodAt(method_offset); |
| 4906 | __ movl(temp, Address(temp, method_offset)); |
| 4907 | // call temp->GetEntryPoint(); |
| 4908 | __ call(Address( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4909 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4910 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4911 | } |
| 4912 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4913 | void CodeGeneratorX86::RecordBootImageIntrinsicPatch(HX86ComputeBaseMethodAddress* method_address, |
| 4914 | uint32_t intrinsic_data) { |
| 4915 | boot_image_intrinsic_patches_.emplace_back( |
| 4916 | method_address, /* target_dex_file */ nullptr, intrinsic_data); |
| 4917 | __ Bind(&boot_image_intrinsic_patches_.back().label); |
| 4918 | } |
| 4919 | |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4920 | void CodeGeneratorX86::RecordBootImageRelRoPatch(HX86ComputeBaseMethodAddress* method_address, |
| 4921 | uint32_t boot_image_offset) { |
| 4922 | boot_image_method_patches_.emplace_back( |
| 4923 | method_address, /* target_dex_file */ nullptr, boot_image_offset); |
| 4924 | __ Bind(&boot_image_method_patches_.back().label); |
| 4925 | } |
| 4926 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4927 | void CodeGeneratorX86::RecordBootImageMethodPatch(HInvokeStaticOrDirect* invoke) { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4928 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4929 | HX86ComputeBaseMethodAddress* method_address = |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4930 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4931 | boot_image_method_patches_.emplace_back( |
| 4932 | method_address, invoke->GetTargetMethod().dex_file, invoke->GetTargetMethod().index); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4933 | __ Bind(&boot_image_method_patches_.back().label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4934 | } |
| 4935 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4936 | void CodeGeneratorX86::RecordMethodBssEntryPatch(HInvokeStaticOrDirect* invoke) { |
| 4937 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 4938 | HX86ComputeBaseMethodAddress* method_address = |
| 4939 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4940 | // 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] | 4941 | method_bss_entry_patches_.emplace_back( |
| 4942 | method_address, &GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()); |
| 4943 | __ Bind(&method_bss_entry_patches_.back().label); |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4944 | } |
| 4945 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4946 | void CodeGeneratorX86::RecordBootImageTypePatch(HLoadClass* load_class) { |
| 4947 | HX86ComputeBaseMethodAddress* method_address = |
| 4948 | load_class->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 4949 | boot_image_type_patches_.emplace_back( |
| 4950 | method_address, &load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4951 | __ Bind(&boot_image_type_patches_.back().label); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4952 | } |
| 4953 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4954 | Label* CodeGeneratorX86::NewTypeBssEntryPatch(HLoadClass* load_class) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4955 | HX86ComputeBaseMethodAddress* method_address = |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4956 | load_class->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 4957 | type_bss_entry_patches_.emplace_back( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4958 | method_address, &load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4959 | return &type_bss_entry_patches_.back().label; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4960 | } |
| 4961 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4962 | void CodeGeneratorX86::RecordBootImageStringPatch(HLoadString* load_string) { |
| 4963 | HX86ComputeBaseMethodAddress* method_address = |
| 4964 | load_string->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 4965 | boot_image_string_patches_.emplace_back( |
| 4966 | method_address, &load_string->GetDexFile(), load_string->GetStringIndex().index_); |
| 4967 | __ Bind(&boot_image_string_patches_.back().label); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4968 | } |
| 4969 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4970 | Label* CodeGeneratorX86::NewStringBssEntryPatch(HLoadString* load_string) { |
| 4971 | DCHECK(!GetCompilerOptions().IsBootImage()); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4972 | HX86ComputeBaseMethodAddress* method_address = |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4973 | load_string->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4974 | string_bss_entry_patches_.emplace_back( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4975 | method_address, &load_string->GetDexFile(), load_string->GetStringIndex().index_); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4976 | return &string_bss_entry_patches_.back().label; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4977 | } |
| 4978 | |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4979 | void CodeGeneratorX86::LoadBootImageAddress(Register reg, |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4980 | uint32_t boot_image_reference, |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4981 | HInvokeStaticOrDirect* invoke) { |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4982 | if (GetCompilerOptions().IsBootImage()) { |
| 4983 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 4984 | HX86ComputeBaseMethodAddress* method_address = |
| 4985 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
| 4986 | DCHECK(method_address != nullptr); |
| 4987 | Register method_address_reg = |
| 4988 | invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()).AsRegister<Register>(); |
| 4989 | __ leal(reg, Address(method_address_reg, CodeGeneratorX86::kDummy32BitOffset)); |
| 4990 | RecordBootImageIntrinsicPatch(method_address, boot_image_reference); |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4991 | } else if (Runtime::Current()->IsAotCompiler()) { |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4992 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 4993 | HX86ComputeBaseMethodAddress* method_address = |
| 4994 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
| 4995 | DCHECK(method_address != nullptr); |
| 4996 | Register method_address_reg = |
| 4997 | invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()).AsRegister<Register>(); |
| 4998 | __ movl(reg, Address(method_address_reg, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4999 | RecordBootImageRelRoPatch(method_address, boot_image_reference); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5000 | } else { |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5001 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5002 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 5003 | DCHECK(!heap->GetBootImageSpaces().empty()); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5004 | const uint8_t* address = heap->GetBootImageSpaces()[0]->Begin() + boot_image_reference; |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5005 | __ movl(reg, Immediate(dchecked_integral_cast<uint32_t>(reinterpret_cast<uintptr_t>(address)))); |
| 5006 | } |
| 5007 | } |
| 5008 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5009 | void CodeGeneratorX86::AllocateInstanceForIntrinsic(HInvokeStaticOrDirect* invoke, |
| 5010 | uint32_t boot_image_offset) { |
| 5011 | DCHECK(invoke->IsStatic()); |
| 5012 | InvokeRuntimeCallingConvention calling_convention; |
| 5013 | Register argument = calling_convention.GetRegisterAt(0); |
| 5014 | if (GetCompilerOptions().IsBootImage()) { |
| 5015 | DCHECK_EQ(boot_image_offset, IntrinsicVisitor::IntegerValueOfInfo::kInvalidReference); |
| 5016 | // Load the class the same way as for HLoadClass::LoadKind::kBootImageLinkTimePcRelative. |
| 5017 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 5018 | HX86ComputeBaseMethodAddress* method_address = |
| 5019 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
| 5020 | DCHECK(method_address != nullptr); |
| 5021 | Register method_address_reg = |
| 5022 | invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()).AsRegister<Register>(); |
| 5023 | __ leal(argument, Address(method_address_reg, CodeGeneratorX86::kDummy32BitOffset)); |
| 5024 | MethodReference target_method = invoke->GetTargetMethod(); |
| 5025 | dex::TypeIndex type_idx = target_method.dex_file->GetMethodId(target_method.index).class_idx_; |
| 5026 | boot_image_type_patches_.emplace_back(method_address, target_method.dex_file, type_idx.index_); |
| 5027 | __ Bind(&boot_image_type_patches_.back().label); |
| 5028 | } else { |
| 5029 | LoadBootImageAddress(argument, boot_image_offset, invoke); |
| 5030 | } |
| 5031 | InvokeRuntime(kQuickAllocObjectInitialized, invoke, invoke->GetDexPc()); |
| 5032 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| 5033 | } |
| 5034 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5035 | // The label points to the end of the "movl" or another instruction but the literal offset |
| 5036 | // for method patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 5037 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
| 5038 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5039 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5040 | inline void CodeGeneratorX86::EmitPcRelativeLinkerPatches( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 5041 | const ArenaDeque<X86PcRelativePatchInfo>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5042 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 5043 | for (const X86PcRelativePatchInfo& info : infos) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5044 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5045 | linker_patches->push_back(Factory(literal_offset, |
| 5046 | info.target_dex_file, |
| 5047 | GetMethodAddressOffset(info.method_address), |
| 5048 | info.offset_or_index)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5049 | } |
| 5050 | } |
| 5051 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5052 | template <linker::LinkerPatch (*Factory)(size_t, uint32_t, uint32_t)> |
| 5053 | linker::LinkerPatch NoDexFileAdapter(size_t literal_offset, |
| 5054 | const DexFile* target_dex_file, |
| 5055 | uint32_t pc_insn_offset, |
| 5056 | uint32_t boot_image_offset) { |
| 5057 | DCHECK(target_dex_file == nullptr); // Unused for these patches, should be null. |
| 5058 | return Factory(literal_offset, pc_insn_offset, boot_image_offset); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 5059 | } |
| 5060 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5061 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5062 | DCHECK(linker_patches->empty()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 5063 | size_t size = |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5064 | boot_image_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5065 | method_bss_entry_patches_.size() + |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5066 | boot_image_type_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5067 | type_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5068 | boot_image_string_patches_.size() + |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5069 | string_bss_entry_patches_.size() + |
| 5070 | boot_image_intrinsic_patches_.size(); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 5071 | linker_patches->reserve(size); |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 5072 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5073 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
| 5074 | boot_image_method_patches_, linker_patches); |
| 5075 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
| 5076 | boot_image_type_patches_, linker_patches); |
| 5077 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5078 | boot_image_string_patches_, linker_patches); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5079 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::IntrinsicReferencePatch>>( |
| 5080 | boot_image_intrinsic_patches_, linker_patches); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5081 | } else { |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5082 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::DataBimgRelRoPatch>>( |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 5083 | boot_image_method_patches_, linker_patches); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5084 | DCHECK(boot_image_type_patches_.empty()); |
| 5085 | DCHECK(boot_image_string_patches_.empty()); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5086 | DCHECK(boot_image_intrinsic_patches_.empty()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5087 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5088 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 5089 | method_bss_entry_patches_, linker_patches); |
| 5090 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 5091 | type_bss_entry_patches_, linker_patches); |
| 5092 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 5093 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5094 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5095 | } |
| 5096 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5097 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 5098 | Register card, |
| 5099 | Register object, |
| 5100 | Register value, |
| 5101 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 5102 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5103 | if (value_can_be_null) { |
| 5104 | __ testl(value, value); |
| 5105 | __ j(kEqual, &is_null); |
| 5106 | } |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5107 | // Load the address of the card table into `card`. |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5108 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86PointerSize>().Int32Value())); |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5109 | // Calculate the offset (in the card table) of the card corresponding to |
| 5110 | // `object`. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5111 | __ movl(temp, object); |
| 5112 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5113 | // Write the `art::gc::accounting::CardTable::kCardDirty` value into the |
| 5114 | // `object`'s card. |
| 5115 | // |
| 5116 | // Register `card` contains the address of the card table. Note that the card |
| 5117 | // table's base is biased during its creation so that it always starts at an |
| 5118 | // address whose least-significant byte is equal to `kCardDirty` (see |
| 5119 | // art::gc::accounting::CardTable::Create). Therefore the MOVB instruction |
| 5120 | // below writes the `kCardDirty` (byte) value into the `object`'s card |
| 5121 | // (located at `card + object >> kCardShift`). |
| 5122 | // |
| 5123 | // This dual use of the value in register `card` (1. to calculate the location |
| 5124 | // of the card to mark; and 2. to load the `kCardDirty` value) saves a load |
| 5125 | // (no need to explicitly load `kCardDirty` as an immediate value). |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 5126 | __ movb(Address(temp, card, TIMES_1, 0), |
| 5127 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5128 | if (value_can_be_null) { |
| 5129 | __ Bind(&is_null); |
| 5130 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5131 | } |
| 5132 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5133 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 5134 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5135 | |
| 5136 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5137 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5138 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5139 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 5140 | kEmitCompilerReadBarrier |
| 5141 | ? LocationSummary::kCallOnSlowPath |
| 5142 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5143 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5144 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5145 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5146 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5147 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5148 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5149 | locations->SetOut(Location::RequiresFpuRegister()); |
| 5150 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5151 | // The output overlaps in case of long: we don't want the low move |
| 5152 | // to overwrite the object's location. Likewise, in the case of |
| 5153 | // an object field get with read barriers enabled, we do not want |
| 5154 | // the move to overwrite the object's location, as we need it to emit |
| 5155 | // the read barrier. |
| 5156 | locations->SetOut( |
| 5157 | Location::RequiresRegister(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5158 | (object_field_get_with_read_barrier || instruction->GetType() == DataType::Type::kInt64) ? |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5159 | Location::kOutputOverlap : |
| 5160 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5161 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5162 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5163 | if (field_info.IsVolatile() && (field_info.GetFieldType() == DataType::Type::kInt64)) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5164 | // Long values can be loaded atomically into an XMM using movsd. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5165 | // So we use an XMM register as a temp to achieve atomicity (first |
| 5166 | // load the temp into the XMM and then copy the XMM into the |
| 5167 | // output, 32 bits at a time). |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5168 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 5169 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5170 | } |
| 5171 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5172 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 5173 | const FieldInfo& field_info) { |
| 5174 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5175 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5176 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5177 | Location base_loc = locations->InAt(0); |
| 5178 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5179 | Location out = locations->Out(); |
| 5180 | bool is_volatile = field_info.IsVolatile(); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5181 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 5182 | DataType::Type load_type = instruction->GetType(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5183 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5184 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5185 | switch (load_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5186 | case DataType::Type::kBool: |
| 5187 | case DataType::Type::kUint8: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5188 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5189 | break; |
| 5190 | } |
| 5191 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5192 | case DataType::Type::kInt8: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5193 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5194 | break; |
| 5195 | } |
| 5196 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5197 | case DataType::Type::kUint16: { |
| 5198 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5199 | break; |
| 5200 | } |
| 5201 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5202 | case DataType::Type::kInt16: { |
| 5203 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5204 | break; |
| 5205 | } |
| 5206 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5207 | case DataType::Type::kInt32: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5208 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5209 | break; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5210 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5211 | case DataType::Type::kReference: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5212 | // /* HeapReference<Object> */ out = *(base + offset) |
| 5213 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5214 | // Note that a potential implicit null check is handled in this |
| 5215 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 5216 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5217 | instruction, out, base, offset, /* needs_null_check */ true); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5218 | if (is_volatile) { |
| 5219 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5220 | } |
| 5221 | } else { |
| 5222 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| 5223 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5224 | if (is_volatile) { |
| 5225 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5226 | } |
| 5227 | // If read barriers are enabled, emit read barriers other than |
| 5228 | // Baker's using a slow path (and also unpoison the loaded |
| 5229 | // reference, if heap poisoning is enabled). |
| 5230 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 5231 | } |
| 5232 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5233 | } |
| 5234 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5235 | case DataType::Type::kInt64: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5236 | if (is_volatile) { |
| 5237 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 5238 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5239 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5240 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 5241 | __ psrlq(temp, Immediate(32)); |
| 5242 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 5243 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5244 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5245 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5246 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5247 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 5248 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5249 | break; |
| 5250 | } |
| 5251 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5252 | case DataType::Type::kFloat32: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5253 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5254 | break; |
| 5255 | } |
| 5256 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5257 | case DataType::Type::kFloat64: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5258 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5259 | break; |
| 5260 | } |
| 5261 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5262 | case DataType::Type::kUint32: |
| 5263 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5264 | case DataType::Type::kVoid: |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5265 | LOG(FATAL) << "Unreachable type " << load_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5266 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5267 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5268 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5269 | if (load_type == DataType::Type::kReference || load_type == DataType::Type::kInt64) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5270 | // Potential implicit null checks, in the case of reference or |
| 5271 | // long fields, are handled in the previous switch statement. |
| 5272 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5273 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5274 | } |
| 5275 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5276 | if (is_volatile) { |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5277 | if (load_type == DataType::Type::kReference) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5278 | // Memory barriers, in the case of references, are also handled |
| 5279 | // in the previous switch statement. |
| 5280 | } else { |
| 5281 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5282 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5283 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5284 | } |
| 5285 | |
| 5286 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 5287 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5288 | |
| 5289 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5290 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5291 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5292 | bool is_volatile = field_info.IsVolatile(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5293 | DataType::Type field_type = field_info.GetFieldType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5294 | bool is_byte_type = DataType::Size(field_type) == 1u; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5295 | |
| 5296 | // The register allocator does not support multiple |
| 5297 | // inputs that die at entry with one in a specific register. |
| 5298 | if (is_byte_type) { |
| 5299 | // Ensure the value is in a byte register. |
| 5300 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5301 | } else if (DataType::IsFloatingPointType(field_type)) { |
| 5302 | if (is_volatile && field_type == DataType::Type::kFloat64) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5303 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 5304 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 5305 | } else { |
| 5306 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 5307 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5308 | } else if (is_volatile && field_type == DataType::Type::kInt64) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5309 | // 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] | 5310 | locations->SetInAt(1, Location::RequiresRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5311 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5312 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 5313 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 5314 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 5315 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 5316 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 5317 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 5318 | locations->AddTemp(Location::RequiresFpuRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5319 | } else { |
| 5320 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5321 | |
| 5322 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 5323 | // Temporary registers for the write barrier. |
| 5324 | locations->AddTemp(Location::RequiresRegister()); // May be used for reference poisoning too. |
| 5325 | // Ensure the card is in a byte register. |
| 5326 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 5327 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5328 | } |
| 5329 | } |
| 5330 | |
| 5331 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5332 | const FieldInfo& field_info, |
| 5333 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5334 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5335 | |
| 5336 | LocationSummary* locations = instruction->GetLocations(); |
| 5337 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 5338 | Location value = locations->InAt(1); |
| 5339 | bool is_volatile = field_info.IsVolatile(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5340 | DataType::Type field_type = field_info.GetFieldType(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5341 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5342 | bool needs_write_barrier = |
| 5343 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5344 | |
| 5345 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5346 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5347 | } |
| 5348 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5349 | bool maybe_record_implicit_null_check_done = false; |
| 5350 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5351 | switch (field_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5352 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5353 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5354 | case DataType::Type::kInt8: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5355 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 5356 | break; |
| 5357 | } |
| 5358 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5359 | case DataType::Type::kUint16: |
| 5360 | case DataType::Type::kInt16: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5361 | if (value.IsConstant()) { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5362 | __ movw(Address(base, offset), |
| 5363 | Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5364 | } else { |
| 5365 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 5366 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5367 | break; |
| 5368 | } |
| 5369 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5370 | case DataType::Type::kInt32: |
| 5371 | case DataType::Type::kReference: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5372 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 5373 | // Note that in the case where `value` is a null reference, |
| 5374 | // we do not enter this block, as the reference does not |
| 5375 | // need poisoning. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5376 | DCHECK_EQ(field_type, DataType::Type::kReference); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5377 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5378 | __ movl(temp, value.AsRegister<Register>()); |
| 5379 | __ PoisonHeapReference(temp); |
| 5380 | __ movl(Address(base, offset), temp); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5381 | } else if (value.IsConstant()) { |
| 5382 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5383 | __ movl(Address(base, offset), Immediate(v)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5384 | } else { |
Nicolas Geoffray | 0397163 | 2016-03-17 10:44:24 +0000 | [diff] [blame] | 5385 | DCHECK(value.IsRegister()) << value; |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5386 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 5387 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5388 | break; |
| 5389 | } |
| 5390 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5391 | case DataType::Type::kInt64: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5392 | if (is_volatile) { |
| 5393 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 5394 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 5395 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 5396 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 5397 | __ punpckldq(temp1, temp2); |
| 5398 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5399 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5400 | } else if (value.IsConstant()) { |
| 5401 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 5402 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 5403 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5404 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5405 | } else { |
| 5406 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5407 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5408 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 5409 | } |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5410 | maybe_record_implicit_null_check_done = true; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5411 | break; |
| 5412 | } |
| 5413 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5414 | case DataType::Type::kFloat32: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5415 | if (value.IsConstant()) { |
| 5416 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5417 | __ movl(Address(base, offset), Immediate(v)); |
| 5418 | } else { |
| 5419 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 5420 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5421 | break; |
| 5422 | } |
| 5423 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5424 | case DataType::Type::kFloat64: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5425 | if (value.IsConstant()) { |
| 5426 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 5427 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 5428 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5429 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
| 5430 | maybe_record_implicit_null_check_done = true; |
| 5431 | } else { |
| 5432 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 5433 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5434 | break; |
| 5435 | } |
| 5436 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5437 | case DataType::Type::kUint32: |
| 5438 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5439 | case DataType::Type::kVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5440 | LOG(FATAL) << "Unreachable type " << field_type; |
| 5441 | UNREACHABLE(); |
| 5442 | } |
| 5443 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5444 | if (!maybe_record_implicit_null_check_done) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5445 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5446 | } |
| 5447 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5448 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5449 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5450 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5451 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5452 | } |
| 5453 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5454 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5455 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5456 | } |
| 5457 | } |
| 5458 | |
| 5459 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5460 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5461 | } |
| 5462 | |
| 5463 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5464 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5465 | } |
| 5466 | |
| 5467 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 5468 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5469 | } |
| 5470 | |
| 5471 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5472 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5473 | } |
| 5474 | |
| 5475 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5476 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5477 | } |
| 5478 | |
| 5479 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5480 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5481 | } |
| 5482 | |
| 5483 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5484 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5485 | } |
| 5486 | |
| 5487 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5488 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5489 | } |
| 5490 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5491 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 5492 | HUnresolvedInstanceFieldGet* instruction) { |
| 5493 | FieldAccessCallingConventionX86 calling_convention; |
| 5494 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5495 | instruction, instruction->GetFieldType(), calling_convention); |
| 5496 | } |
| 5497 | |
| 5498 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 5499 | HUnresolvedInstanceFieldGet* instruction) { |
| 5500 | FieldAccessCallingConventionX86 calling_convention; |
| 5501 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5502 | instruction->GetFieldType(), |
| 5503 | instruction->GetFieldIndex(), |
| 5504 | instruction->GetDexPc(), |
| 5505 | calling_convention); |
| 5506 | } |
| 5507 | |
| 5508 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 5509 | HUnresolvedInstanceFieldSet* instruction) { |
| 5510 | FieldAccessCallingConventionX86 calling_convention; |
| 5511 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5512 | instruction, instruction->GetFieldType(), calling_convention); |
| 5513 | } |
| 5514 | |
| 5515 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 5516 | HUnresolvedInstanceFieldSet* instruction) { |
| 5517 | FieldAccessCallingConventionX86 calling_convention; |
| 5518 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5519 | instruction->GetFieldType(), |
| 5520 | instruction->GetFieldIndex(), |
| 5521 | instruction->GetDexPc(), |
| 5522 | calling_convention); |
| 5523 | } |
| 5524 | |
| 5525 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 5526 | HUnresolvedStaticFieldGet* instruction) { |
| 5527 | FieldAccessCallingConventionX86 calling_convention; |
| 5528 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5529 | instruction, instruction->GetFieldType(), calling_convention); |
| 5530 | } |
| 5531 | |
| 5532 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 5533 | HUnresolvedStaticFieldGet* instruction) { |
| 5534 | FieldAccessCallingConventionX86 calling_convention; |
| 5535 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5536 | instruction->GetFieldType(), |
| 5537 | instruction->GetFieldIndex(), |
| 5538 | instruction->GetDexPc(), |
| 5539 | calling_convention); |
| 5540 | } |
| 5541 | |
| 5542 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 5543 | HUnresolvedStaticFieldSet* instruction) { |
| 5544 | FieldAccessCallingConventionX86 calling_convention; |
| 5545 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5546 | instruction, instruction->GetFieldType(), calling_convention); |
| 5547 | } |
| 5548 | |
| 5549 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 5550 | HUnresolvedStaticFieldSet* instruction) { |
| 5551 | FieldAccessCallingConventionX86 calling_convention; |
| 5552 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5553 | instruction->GetFieldType(), |
| 5554 | instruction->GetFieldIndex(), |
| 5555 | instruction->GetDexPc(), |
| 5556 | calling_convention); |
| 5557 | } |
| 5558 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5559 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5560 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5561 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 5562 | ? Location::RequiresRegister() |
| 5563 | : Location::Any(); |
| 5564 | locations->SetInAt(0, loc); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5565 | } |
| 5566 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5567 | void CodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5568 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5569 | return; |
| 5570 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5571 | LocationSummary* locations = instruction->GetLocations(); |
| 5572 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5573 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5574 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5575 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5576 | } |
| 5577 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5578 | void CodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5579 | SlowPathCode* slow_path = new (GetScopedAllocator()) NullCheckSlowPathX86(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5580 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5581 | |
| 5582 | LocationSummary* locations = instruction->GetLocations(); |
| 5583 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5584 | |
| 5585 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 5586 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5587 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5588 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5589 | } else { |
| 5590 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5591 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5592 | __ jmp(slow_path->GetEntryLabel()); |
| 5593 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5594 | } |
| 5595 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5596 | } |
| 5597 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5598 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5599 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5600 | } |
| 5601 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5602 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5603 | bool object_array_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5604 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5605 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5606 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 5607 | object_array_get_with_read_barrier |
| 5608 | ? LocationSummary::kCallOnSlowPath |
| 5609 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5610 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5611 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5612 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5613 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5614 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5615 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5616 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5617 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5618 | // The output overlaps in case of long: we don't want the low move |
| 5619 | // to overwrite the array's location. Likewise, in the case of an |
| 5620 | // object array get with read barriers enabled, we do not want the |
| 5621 | // move to overwrite the array's location, as we need it to emit |
| 5622 | // the read barrier. |
| 5623 | locations->SetOut( |
| 5624 | Location::RequiresRegister(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5625 | (instruction->GetType() == DataType::Type::kInt64 || object_array_get_with_read_barrier) |
| 5626 | ? Location::kOutputOverlap |
| 5627 | : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5628 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5629 | } |
| 5630 | |
| 5631 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 5632 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5633 | Location obj_loc = locations->InAt(0); |
| 5634 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5635 | Location index = locations->InAt(1); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5636 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5637 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5638 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5639 | DataType::Type type = instruction->GetType(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5640 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5641 | case DataType::Type::kBool: |
| 5642 | case DataType::Type::kUint8: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5643 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5644 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5645 | break; |
| 5646 | } |
| 5647 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5648 | case DataType::Type::kInt8: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5649 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5650 | __ movsxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5651 | break; |
| 5652 | } |
| 5653 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5654 | case DataType::Type::kUint16: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5655 | Register out = out_loc.AsRegister<Register>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5656 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5657 | // Branch cases into compressed and uncompressed for each index's type. |
| 5658 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 5659 | NearLabel done, not_compressed; |
Vladimir Marko | 3c89d42 | 2017-02-17 11:30:23 +0000 | [diff] [blame] | 5660 | __ testb(Address(obj, count_offset), Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5661 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5662 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 5663 | "Expecting 0=compressed, 1=uncompressed"); |
| 5664 | __ j(kNotZero, ¬_compressed); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5665 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| 5666 | __ jmp(&done); |
| 5667 | __ Bind(¬_compressed); |
| 5668 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5669 | __ Bind(&done); |
| 5670 | } else { |
| 5671 | // Common case for charAt of array of char or when string compression's |
| 5672 | // feature is turned off. |
| 5673 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5674 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5675 | break; |
| 5676 | } |
| 5677 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5678 | case DataType::Type::kInt16: { |
| 5679 | Register out = out_loc.AsRegister<Register>(); |
| 5680 | __ movsxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5681 | break; |
| 5682 | } |
| 5683 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5684 | case DataType::Type::kInt32: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5685 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5686 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5687 | break; |
| 5688 | } |
| 5689 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5690 | case DataType::Type::kReference: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5691 | static_assert( |
| 5692 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5693 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5694 | // /* HeapReference<Object> */ out = |
| 5695 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5696 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5697 | // Note that a potential implicit null check is handled in this |
| 5698 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 5699 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5700 | instruction, out_loc, obj, data_offset, index, /* needs_null_check */ true); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5701 | } else { |
| 5702 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5703 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| 5704 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5705 | // If read barriers are enabled, emit read barriers other than |
| 5706 | // Baker's using a slow path (and also unpoison the loaded |
| 5707 | // reference, if heap poisoning is enabled). |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5708 | if (index.IsConstant()) { |
| 5709 | uint32_t offset = |
| 5710 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5711 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5712 | } else { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5713 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5714 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5715 | } |
| 5716 | } |
| 5717 | break; |
| 5718 | } |
| 5719 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5720 | case DataType::Type::kInt64: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5721 | DCHECK_NE(obj, out_loc.AsRegisterPairLow<Register>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5722 | __ movl(out_loc.AsRegisterPairLow<Register>(), |
| 5723 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
| 5724 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5725 | __ movl(out_loc.AsRegisterPairHigh<Register>(), |
| 5726 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5727 | break; |
| 5728 | } |
| 5729 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5730 | case DataType::Type::kFloat32: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5731 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5732 | __ movss(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5733 | break; |
| 5734 | } |
| 5735 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5736 | case DataType::Type::kFloat64: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5737 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5738 | __ movsd(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5739 | break; |
| 5740 | } |
| 5741 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5742 | case DataType::Type::kUint32: |
| 5743 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5744 | case DataType::Type::kVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5745 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5746 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5747 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5748 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5749 | if (type == DataType::Type::kReference || type == DataType::Type::kInt64) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5750 | // Potential implicit null checks, in the case of reference or |
| 5751 | // long arrays, are handled in the previous switch statement. |
| 5752 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5753 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5754 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5755 | } |
| 5756 | |
| 5757 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5758 | DataType::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5759 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5760 | bool needs_write_barrier = |
| 5761 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5762 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5763 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5764 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5765 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 5766 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5767 | LocationSummary::kCallOnSlowPath : |
| 5768 | LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5769 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5770 | bool is_byte_type = DataType::Size(value_type) == 1u; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5771 | // We need the inputs to be different than the output in case of long operation. |
| 5772 | // In case of a byte operation, the register allocator does not support multiple |
| 5773 | // inputs that die at entry with one in a specific register. |
| 5774 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5775 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5776 | if (is_byte_type) { |
| 5777 | // Ensure the value is in a byte register. |
| 5778 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5779 | } else if (DataType::IsFloatingPointType(value_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5780 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5781 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5782 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 5783 | } |
| 5784 | if (needs_write_barrier) { |
| 5785 | // Temporary registers for the write barrier. |
| 5786 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 5787 | // Ensure the card is in a byte register. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5788 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5789 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5790 | } |
| 5791 | |
| 5792 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 5793 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5794 | Location array_loc = locations->InAt(0); |
| 5795 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5796 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5797 | Location value = locations->InAt(2); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5798 | DataType::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5799 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5800 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5801 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5802 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5803 | bool needs_write_barrier = |
| 5804 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5805 | |
| 5806 | switch (value_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5807 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5808 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5809 | case DataType::Type::kInt8: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5810 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5811 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_1, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5812 | if (value.IsRegister()) { |
| 5813 | __ movb(address, value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5814 | } else { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5815 | __ movb(address, Immediate(CodeGenerator::GetInt8ValueOf(value.GetConstant()))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5816 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5817 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5818 | break; |
| 5819 | } |
| 5820 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5821 | case DataType::Type::kUint16: |
| 5822 | case DataType::Type::kInt16: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5823 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5824 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_2, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5825 | if (value.IsRegister()) { |
| 5826 | __ movw(address, value.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5827 | } else { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5828 | __ movw(address, Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5829 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5830 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5831 | break; |
| 5832 | } |
| 5833 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5834 | case DataType::Type::kReference: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5835 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5836 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5837 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5838 | if (!value.IsRegister()) { |
| 5839 | // Just setting null. |
| 5840 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5841 | DCHECK(value.IsConstant()) << value; |
| 5842 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5843 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5844 | DCHECK(!needs_write_barrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5845 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5846 | break; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5847 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5848 | |
| 5849 | DCHECK(needs_write_barrier); |
| 5850 | Register register_value = value.AsRegister<Register>(); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5851 | // We cannot use a NearLabel for `done`, as its range may be too |
| 5852 | // short when Baker read barriers are enabled. |
| 5853 | Label done; |
| 5854 | NearLabel not_null, do_put; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5855 | SlowPathCode* slow_path = nullptr; |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5856 | Location temp_loc = locations->GetTemp(0); |
| 5857 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5858 | if (may_need_runtime_call_for_type_check) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5859 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathX86(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5860 | codegen_->AddSlowPath(slow_path); |
| 5861 | if (instruction->GetValueCanBeNull()) { |
| 5862 | __ testl(register_value, register_value); |
| 5863 | __ j(kNotEqual, ¬_null); |
| 5864 | __ movl(address, Immediate(0)); |
| 5865 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5866 | __ jmp(&done); |
| 5867 | __ Bind(¬_null); |
| 5868 | } |
| 5869 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5870 | // Note that when Baker read barriers are enabled, the type |
| 5871 | // checks are performed without read barriers. This is fine, |
| 5872 | // even in the case where a class object is in the from-space |
| 5873 | // after the flip, as a comparison involving such a type would |
| 5874 | // not produce a false positive; it may of course produce a |
| 5875 | // false negative, in which case we would take the ArraySet |
| 5876 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5877 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5878 | // /* HeapReference<Class> */ temp = array->klass_ |
| 5879 | __ movl(temp, Address(array, class_offset)); |
| 5880 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5881 | __ MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5882 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5883 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5884 | __ movl(temp, Address(temp, component_offset)); |
| 5885 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 5886 | // nor the object reference in `register_value->klass`, as |
| 5887 | // we are comparing two poisoned references. |
| 5888 | __ cmpl(temp, Address(register_value, class_offset)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5889 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5890 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5891 | __ j(kEqual, &do_put); |
| 5892 | // If heap poisoning is enabled, the `temp` reference has |
| 5893 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5894 | __ MaybeUnpoisonHeapReference(temp); |
| 5895 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5896 | // If heap poisoning is enabled, no need to unpoison the |
| 5897 | // heap reference loaded below, as it is only used for a |
| 5898 | // comparison with null. |
| 5899 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 5900 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5901 | __ Bind(&do_put); |
| 5902 | } else { |
| 5903 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5904 | } |
| 5905 | } |
| 5906 | |
| 5907 | if (kPoisonHeapReferences) { |
| 5908 | __ movl(temp, register_value); |
| 5909 | __ PoisonHeapReference(temp); |
| 5910 | __ movl(address, temp); |
| 5911 | } else { |
| 5912 | __ movl(address, register_value); |
| 5913 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5914 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5915 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5916 | } |
| 5917 | |
| 5918 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 5919 | codegen_->MarkGCCard( |
| 5920 | temp, card, array, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); |
| 5921 | __ Bind(&done); |
| 5922 | |
| 5923 | if (slow_path != nullptr) { |
| 5924 | __ Bind(slow_path->GetExitLabel()); |
| 5925 | } |
| 5926 | |
| 5927 | break; |
| 5928 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5929 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5930 | case DataType::Type::kInt32: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5931 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5932 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5933 | if (value.IsRegister()) { |
| 5934 | __ movl(address, value.AsRegister<Register>()); |
| 5935 | } else { |
| 5936 | DCHECK(value.IsConstant()) << value; |
| 5937 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5938 | __ movl(address, Immediate(v)); |
| 5939 | } |
| 5940 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5941 | break; |
| 5942 | } |
| 5943 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5944 | case DataType::Type::kInt64: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5945 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5946 | if (value.IsRegisterPair()) { |
| 5947 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 5948 | value.AsRegisterPairLow<Register>()); |
| 5949 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5950 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 5951 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5952 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5953 | DCHECK(value.IsConstant()); |
| 5954 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
| 5955 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 5956 | Immediate(Low32Bits(val))); |
| 5957 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5958 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 5959 | Immediate(High32Bits(val))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5960 | } |
| 5961 | break; |
| 5962 | } |
| 5963 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5964 | case DataType::Type::kFloat32: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5965 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5966 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5967 | if (value.IsFpuRegister()) { |
| 5968 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5969 | } else { |
| 5970 | DCHECK(value.IsConstant()); |
| 5971 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 5972 | __ movl(address, Immediate(v)); |
| 5973 | } |
| 5974 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5975 | break; |
| 5976 | } |
| 5977 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5978 | case DataType::Type::kFloat64: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5979 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5980 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5981 | if (value.IsFpuRegister()) { |
| 5982 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5983 | } else { |
| 5984 | DCHECK(value.IsConstant()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5985 | Address address_hi = |
| 5986 | CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset + kX86WordSize); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5987 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 5988 | __ movl(address, Immediate(Low32Bits(v))); |
| 5989 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5990 | __ movl(address_hi, Immediate(High32Bits(v))); |
| 5991 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5992 | break; |
| 5993 | } |
| 5994 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5995 | case DataType::Type::kUint32: |
| 5996 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5997 | case DataType::Type::kVoid: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5998 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5999 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6000 | } |
| 6001 | } |
| 6002 | |
| 6003 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6004 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 6005 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6006 | if (!instruction->IsEmittedAtUseSite()) { |
| 6007 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6008 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6009 | } |
| 6010 | |
| 6011 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6012 | if (instruction->IsEmittedAtUseSite()) { |
| 6013 | return; |
| 6014 | } |
| 6015 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6016 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 6017 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6018 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 6019 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6020 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6021 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6022 | // Mask out most significant bit in case the array is String's array of char. |
| 6023 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6024 | __ shrl(out, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6025 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6026 | } |
| 6027 | |
| 6028 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6029 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6030 | InvokeRuntimeCallingConvention calling_convention; |
| 6031 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6032 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 6033 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 6034 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6035 | HInstruction* length = instruction->InputAt(1); |
| 6036 | if (!length->IsEmittedAtUseSite()) { |
| 6037 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 6038 | } |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6039 | // Need register to see array's length. |
| 6040 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 6041 | locations->AddTemp(Location::RequiresRegister()); |
| 6042 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6043 | } |
| 6044 | |
| 6045 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6046 | const bool is_string_compressed_char_at = |
| 6047 | mirror::kUseStringCompression && instruction->IsStringCharAt(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6048 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 6049 | Location index_loc = locations->InAt(0); |
| 6050 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6051 | SlowPathCode* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6052 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathX86(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6053 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 6054 | if (length_loc.IsConstant()) { |
| 6055 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 6056 | if (index_loc.IsConstant()) { |
| 6057 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 6058 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 6059 | if (index < 0 || index >= length) { |
| 6060 | codegen_->AddSlowPath(slow_path); |
| 6061 | __ jmp(slow_path->GetEntryLabel()); |
| 6062 | } else { |
| 6063 | // Some optimization after BCE may have generated this, and we should not |
| 6064 | // generate a bounds check if it is a valid range. |
| 6065 | } |
| 6066 | return; |
| 6067 | } |
| 6068 | |
| 6069 | // We have to reverse the jump condition because the length is the constant. |
| 6070 | Register index_reg = index_loc.AsRegister<Register>(); |
| 6071 | __ cmpl(index_reg, Immediate(length)); |
| 6072 | codegen_->AddSlowPath(slow_path); |
| 6073 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 6074 | } else { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6075 | HInstruction* array_length = instruction->InputAt(1); |
| 6076 | if (array_length->IsEmittedAtUseSite()) { |
| 6077 | // Address the length field in the array. |
| 6078 | DCHECK(array_length->IsArrayLength()); |
| 6079 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 6080 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 6081 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6082 | if (is_string_compressed_char_at) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6083 | // TODO: if index_loc.IsConstant(), compare twice the index (to compensate for |
| 6084 | // the string compression flag) with the in-memory length and avoid the temporary. |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6085 | Register length_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 6086 | __ movl(length_reg, array_len); |
| 6087 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6088 | __ shrl(length_reg, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6089 | codegen_->GenerateIntCompare(length_reg, index_loc); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6090 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6091 | // Checking bounds for general case: |
| 6092 | // Array of char or string's array with feature compression off. |
| 6093 | if (index_loc.IsConstant()) { |
| 6094 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 6095 | __ cmpl(array_len, Immediate(value)); |
| 6096 | } else { |
| 6097 | __ cmpl(array_len, index_loc.AsRegister<Register>()); |
| 6098 | } |
| 6099 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6100 | } |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 6101 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6102 | codegen_->GenerateIntCompare(length_loc, index_loc); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 6103 | } |
| 6104 | codegen_->AddSlowPath(slow_path); |
| 6105 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 6106 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6107 | } |
| 6108 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6109 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6110 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6111 | } |
| 6112 | |
| 6113 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 6114 | if (instruction->GetNext()->IsSuspendCheck() && |
| 6115 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 6116 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 6117 | // The back edge will generate the suspend check. |
| 6118 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 6119 | } |
| 6120 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6121 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 6122 | } |
| 6123 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6124 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6125 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6126 | instruction, LocationSummary::kCallOnSlowPath); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 6127 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 6128 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 6129 | // registers in full width (since the runtime only saves/restores lower part). |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6130 | locations->SetCustomSlowPathCallerSaves( |
| 6131 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6132 | } |
| 6133 | |
| 6134 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6135 | HBasicBlock* block = instruction->GetBlock(); |
| 6136 | if (block->GetLoopInformation() != nullptr) { |
| 6137 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 6138 | // The back edge will generate the suspend check. |
| 6139 | return; |
| 6140 | } |
| 6141 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 6142 | // The goto will generate the suspend check. |
| 6143 | return; |
| 6144 | } |
| 6145 | GenerateSuspendCheck(instruction, nullptr); |
| 6146 | } |
| 6147 | |
| 6148 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 6149 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6150 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6151 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 6152 | if (slow_path == nullptr) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6153 | slow_path = |
| 6154 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathX86(instruction, successor); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6155 | instruction->SetSlowPath(slow_path); |
| 6156 | codegen_->AddSlowPath(slow_path); |
| 6157 | if (successor != nullptr) { |
| 6158 | DCHECK(successor->IsLoopHeader()); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6159 | } |
| 6160 | } else { |
| 6161 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 6162 | } |
| 6163 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6164 | __ fs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86PointerSize>().Int32Value()), |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6165 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6166 | if (successor == nullptr) { |
| 6167 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6168 | __ Bind(slow_path->GetReturnLabel()); |
| 6169 | } else { |
| 6170 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 6171 | __ jmp(slow_path->GetEntryLabel()); |
| 6172 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6173 | } |
| 6174 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6175 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 6176 | return codegen_->GetAssembler(); |
| 6177 | } |
| 6178 | |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6179 | void ParallelMoveResolverX86::MoveMemoryToMemory(int dst, int src, int number_of_words) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6180 | ScratchRegisterScope ensure_scratch( |
| 6181 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 6182 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 6183 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6184 | |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6185 | // Now that temp register is available (possibly spilled), move blocks of memory. |
| 6186 | for (int i = 0; i < number_of_words; i++) { |
| 6187 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 6188 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 6189 | stack_offset += kX86WordSize; |
| 6190 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6191 | } |
| 6192 | |
| 6193 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6194 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6195 | Location source = move->GetSource(); |
| 6196 | Location destination = move->GetDestination(); |
| 6197 | |
| 6198 | if (source.IsRegister()) { |
| 6199 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6200 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6201 | } else if (destination.IsFpuRegister()) { |
| 6202 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6203 | } else { |
| 6204 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6205 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6206 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6207 | } else if (source.IsRegisterPair()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6208 | size_t elem_size = DataType::Size(DataType::Type::kInt32); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6209 | // Create stack space for 2 elements. |
| 6210 | __ subl(ESP, Immediate(2 * elem_size)); |
| 6211 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 6212 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 6213 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 6214 | // And remove the temporary stack space we allocated. |
| 6215 | __ addl(ESP, Immediate(2 * elem_size)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6216 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6217 | if (destination.IsRegister()) { |
| 6218 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
| 6219 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6220 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6221 | } else if (destination.IsRegisterPair()) { |
| 6222 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 6223 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 6224 | __ psrlq(src_reg, Immediate(32)); |
| 6225 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6226 | } else if (destination.IsStackSlot()) { |
| 6227 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6228 | } else if (destination.IsDoubleStackSlot()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6229 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6230 | } else { |
| 6231 | DCHECK(destination.IsSIMDStackSlot()); |
| 6232 | __ movups(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6233 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6234 | } else if (source.IsStackSlot()) { |
| 6235 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6236 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6237 | } else if (destination.IsFpuRegister()) { |
| 6238 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6239 | } else { |
| 6240 | DCHECK(destination.IsStackSlot()); |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6241 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 1); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6242 | } |
| 6243 | } else if (source.IsDoubleStackSlot()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6244 | if (destination.IsRegisterPair()) { |
| 6245 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 6246 | __ movl(destination.AsRegisterPairHigh<Register>(), |
| 6247 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 6248 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6249 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 6250 | } else { |
| 6251 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6252 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 2); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6253 | } |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6254 | } else if (source.IsSIMDStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6255 | if (destination.IsFpuRegister()) { |
| 6256 | __ movups(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 6257 | } else { |
| 6258 | DCHECK(destination.IsSIMDStackSlot()); |
| 6259 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 4); |
| 6260 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 6261 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6262 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 6263 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 6264 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6265 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 6266 | if (value == 0) { |
| 6267 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 6268 | } else { |
| 6269 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 6270 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6271 | } else { |
| 6272 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 6273 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6274 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6275 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6276 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 6277 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6278 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6279 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6280 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 6281 | if (value == 0) { |
| 6282 | // Easy handling of 0.0. |
| 6283 | __ xorps(dest, dest); |
| 6284 | } else { |
| 6285 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6286 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 6287 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 6288 | __ movl(temp, Immediate(value)); |
| 6289 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6290 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6291 | } else { |
| 6292 | DCHECK(destination.IsStackSlot()) << destination; |
| 6293 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 6294 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6295 | } else if (constant->IsLongConstant()) { |
| 6296 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 6297 | int32_t low_value = Low32Bits(value); |
| 6298 | int32_t high_value = High32Bits(value); |
| 6299 | Immediate low(low_value); |
| 6300 | Immediate high(high_value); |
| 6301 | if (destination.IsDoubleStackSlot()) { |
| 6302 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 6303 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 6304 | } else { |
| 6305 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 6306 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 6307 | } |
| 6308 | } else { |
| 6309 | DCHECK(constant->IsDoubleConstant()); |
| 6310 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 6311 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6312 | int32_t low_value = Low32Bits(value); |
| 6313 | int32_t high_value = High32Bits(value); |
| 6314 | Immediate low(low_value); |
| 6315 | Immediate high(high_value); |
| 6316 | if (destination.IsFpuRegister()) { |
| 6317 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 6318 | if (value == 0) { |
| 6319 | // Easy handling of 0.0. |
| 6320 | __ xorpd(dest, dest); |
| 6321 | } else { |
| 6322 | __ pushl(high); |
| 6323 | __ pushl(low); |
| 6324 | __ movsd(dest, Address(ESP, 0)); |
| 6325 | __ addl(ESP, Immediate(8)); |
| 6326 | } |
| 6327 | } else { |
| 6328 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6329 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 6330 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 6331 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 6332 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6333 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 6334 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6335 | } |
| 6336 | } |
| 6337 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 6338 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6339 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 6340 | ScratchRegisterScope ensure_scratch( |
| 6341 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 6342 | |
| 6343 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 6344 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 6345 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 6346 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6347 | } |
| 6348 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6349 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6350 | ScratchRegisterScope ensure_scratch( |
| 6351 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 6352 | |
| 6353 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 6354 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 6355 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 6356 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 6357 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6358 | } |
| 6359 | |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6360 | void ParallelMoveResolverX86::Exchange128(XmmRegister reg, int mem) { |
| 6361 | size_t extra_slot = 4 * kX86WordSize; |
| 6362 | __ subl(ESP, Immediate(extra_slot)); |
| 6363 | __ movups(Address(ESP, 0), XmmRegister(reg)); |
| 6364 | ExchangeMemory(0, mem + extra_slot, 4); |
| 6365 | __ movups(XmmRegister(reg), Address(ESP, 0)); |
| 6366 | __ addl(ESP, Immediate(extra_slot)); |
| 6367 | } |
| 6368 | |
| 6369 | void ParallelMoveResolverX86::ExchangeMemory(int mem1, int mem2, int number_of_words) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6370 | ScratchRegisterScope ensure_scratch1( |
| 6371 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6372 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6373 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 6374 | ScratchRegisterScope ensure_scratch2( |
| 6375 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6376 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6377 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 6378 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6379 | |
| 6380 | // Now that temp registers are available (possibly spilled), exchange blocks of memory. |
| 6381 | for (int i = 0; i < number_of_words; i++) { |
| 6382 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 6383 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 6384 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 6385 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
| 6386 | stack_offset += kX86WordSize; |
| 6387 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6388 | } |
| 6389 | |
| 6390 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6391 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6392 | Location source = move->GetSource(); |
| 6393 | Location destination = move->GetDestination(); |
| 6394 | |
| 6395 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 6396 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 6397 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 6398 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 6399 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 6400 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6401 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6402 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6403 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6404 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6405 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6406 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 1); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6407 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 6408 | // Use XOR Swap algorithm to avoid a temporary. |
| 6409 | DCHECK_NE(source.reg(), destination.reg()); |
| 6410 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 6411 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 6412 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 6413 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 6414 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 6415 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 6416 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6417 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 6418 | // Take advantage of the 16 bytes in the XMM register. |
| 6419 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 6420 | Address stack(ESP, destination.GetStackIndex()); |
| 6421 | // Load the double into the high doubleword. |
| 6422 | __ movhpd(reg, stack); |
| 6423 | |
| 6424 | // Store the low double into the destination. |
| 6425 | __ movsd(stack, reg); |
| 6426 | |
| 6427 | // Move the high double to the low double. |
| 6428 | __ psrldq(reg, Immediate(8)); |
| 6429 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 6430 | // Take advantage of the 16 bytes in the XMM register. |
| 6431 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 6432 | Address stack(ESP, source.GetStackIndex()); |
| 6433 | // Load the double into the high doubleword. |
| 6434 | __ movhpd(reg, stack); |
| 6435 | |
| 6436 | // Store the low double into the destination. |
| 6437 | __ movsd(stack, reg); |
| 6438 | |
| 6439 | // Move the high double to the low double. |
| 6440 | __ psrldq(reg, Immediate(8)); |
| 6441 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6442 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 2); |
| 6443 | } else if (source.IsSIMDStackSlot() && destination.IsSIMDStackSlot()) { |
| 6444 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 4); |
| 6445 | } else if (source.IsFpuRegister() && destination.IsSIMDStackSlot()) { |
| 6446 | Exchange128(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 6447 | } else if (destination.IsFpuRegister() && source.IsSIMDStackSlot()) { |
| 6448 | Exchange128(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6449 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6450 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6451 | } |
| 6452 | } |
| 6453 | |
| 6454 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 6455 | __ pushl(static_cast<Register>(reg)); |
| 6456 | } |
| 6457 | |
| 6458 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 6459 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6460 | } |
| 6461 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6462 | HLoadClass::LoadKind CodeGeneratorX86::GetSupportedLoadClassKind( |
| 6463 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6464 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6465 | case HLoadClass::LoadKind::kInvalid: |
| 6466 | LOG(FATAL) << "UNREACHABLE"; |
| 6467 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6468 | case HLoadClass::LoadKind::kReferrersClass: |
| 6469 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6470 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6471 | case HLoadClass::LoadKind::kBootImageRelRo: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6472 | case HLoadClass::LoadKind::kBssEntry: |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6473 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6474 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6475 | case HLoadClass::LoadKind::kJitBootImageAddress: |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6476 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6477 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6478 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6479 | case HLoadClass::LoadKind::kRuntimeCall: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6480 | break; |
| 6481 | } |
| 6482 | return desired_class_load_kind; |
| 6483 | } |
| 6484 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6485 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6486 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6487 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6488 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6489 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6490 | cls, |
| 6491 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6492 | Location::RegisterLocation(EAX)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6493 | DCHECK_EQ(calling_convention.GetRegisterAt(0), EAX); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6494 | return; |
| 6495 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6496 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6497 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6498 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 6499 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6500 | ? LocationSummary::kCallOnSlowPath |
| 6501 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6502 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6503 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6504 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6505 | } |
| 6506 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6507 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6508 | load_kind == HLoadClass::LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6509 | load_kind == HLoadClass::LoadKind::kBootImageRelRo || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6510 | load_kind == HLoadClass::LoadKind::kBssEntry) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6511 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6512 | } |
| 6513 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6514 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 6515 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 6516 | // Rely on the type resolution and/or initialization to save everything. |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 6517 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6518 | } else { |
| 6519 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6520 | } |
| 6521 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6522 | } |
| 6523 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6524 | Label* CodeGeneratorX86::NewJitRootClassPatch(const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6525 | dex::TypeIndex type_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6526 | Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6527 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6528 | // Add a patch entry and return the label. |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6529 | jit_class_patches_.emplace_back(&dex_file, type_index.index_); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6530 | PatchInfo<Label>* info = &jit_class_patches_.back(); |
| 6531 | return &info->label; |
| 6532 | } |
| 6533 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6534 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6535 | // move. |
| 6536 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6537 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6538 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6539 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6540 | return; |
| 6541 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6542 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6543 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6544 | LocationSummary* locations = cls->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6545 | Location out_loc = locations->Out(); |
| 6546 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6547 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6548 | bool generate_null_check = false; |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6549 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 6550 | ? kWithoutReadBarrier |
| 6551 | : kCompilerReadBarrierOption; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6552 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6553 | case HLoadClass::LoadKind::kReferrersClass: { |
| 6554 | DCHECK(!cls->CanCallRuntime()); |
| 6555 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 6556 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6557 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 6558 | GenerateGcRootFieldLoad( |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6559 | cls, |
| 6560 | out_loc, |
| 6561 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 6562 | /* fixup_label */ nullptr, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6563 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6564 | break; |
| 6565 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6566 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6567 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6568 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6569 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6570 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6571 | codegen_->RecordBootImageTypePatch(cls); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6572 | break; |
| 6573 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6574 | case HLoadClass::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6575 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 6576 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6577 | __ movl(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6578 | codegen_->RecordBootImageRelRoPatch(cls->InputAt(0)->AsX86ComputeBaseMethodAddress(), |
| 6579 | codegen_->GetBootImageOffset(cls)); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6580 | break; |
| 6581 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6582 | case HLoadClass::LoadKind::kBssEntry: { |
| 6583 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6584 | Address address(method_address, CodeGeneratorX86::kDummy32BitOffset); |
| 6585 | Label* fixup_label = codegen_->NewTypeBssEntryPatch(cls); |
| 6586 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
| 6587 | generate_null_check = true; |
| 6588 | break; |
| 6589 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6590 | case HLoadClass::LoadKind::kJitBootImageAddress: { |
| 6591 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 6592 | uint32_t address = reinterpret_cast32<uint32_t>(cls->GetClass().Get()); |
| 6593 | DCHECK_NE(address, 0u); |
| 6594 | __ movl(out, Immediate(address)); |
| 6595 | break; |
| 6596 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6597 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 6598 | Address address = Address::Absolute(CodeGeneratorX86::kDummy32BitOffset); |
| 6599 | Label* fixup_label = codegen_->NewJitRootClassPatch( |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6600 | cls->GetDexFile(), cls->GetTypeIndex(), cls->GetClass()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6601 | // /* GcRoot<mirror::Class> */ out = *address |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6602 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6603 | break; |
| 6604 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6605 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6606 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6607 | LOG(FATAL) << "UNREACHABLE"; |
| 6608 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6609 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6610 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6611 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6612 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 6613 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86(cls, cls); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6614 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6615 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6616 | if (generate_null_check) { |
| 6617 | __ testl(out, out); |
| 6618 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6619 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6620 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6621 | if (cls->MustGenerateClinitCheck()) { |
| 6622 | GenerateClassInitializationCheck(slow_path, out); |
| 6623 | } else { |
| 6624 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6625 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6626 | } |
| 6627 | } |
| 6628 | |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 6629 | void LocationsBuilderX86::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 6630 | InvokeRuntimeCallingConvention calling_convention; |
| 6631 | Location location = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 6632 | CodeGenerator::CreateLoadMethodHandleRuntimeCallLocationSummary(load, location, location); |
| 6633 | } |
| 6634 | |
| 6635 | void InstructionCodeGeneratorX86::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 6636 | codegen_->GenerateLoadMethodHandleRuntimeCall(load); |
| 6637 | } |
| 6638 | |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6639 | void LocationsBuilderX86::VisitLoadMethodType(HLoadMethodType* load) { |
| 6640 | InvokeRuntimeCallingConvention calling_convention; |
| 6641 | Location location = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); |
| 6642 | CodeGenerator::CreateLoadMethodTypeRuntimeCallLocationSummary(load, location, location); |
| 6643 | } |
| 6644 | |
| 6645 | void InstructionCodeGeneratorX86::VisitLoadMethodType(HLoadMethodType* load) { |
| 6646 | codegen_->GenerateLoadMethodTypeRuntimeCall(load); |
| 6647 | } |
| 6648 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6649 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 6650 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6651 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6652 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6653 | if (check->HasUses()) { |
| 6654 | locations->SetOut(Location::SameAsFirstInput()); |
| 6655 | } |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 6656 | // Rely on the type initialization to save everything we need. |
| 6657 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6658 | } |
| 6659 | |
| 6660 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6661 | // We assume the class to not be null. |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 6662 | SlowPathCode* slow_path = |
| 6663 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86(check->GetLoadClass(), check); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6664 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6665 | GenerateClassInitializationCheck(slow_path, |
| 6666 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6667 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6668 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6669 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6670 | SlowPathCode* slow_path, Register class_reg) { |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 6671 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
| 6672 | const size_t status_byte_offset = |
| 6673 | mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte); |
| 6674 | constexpr uint32_t shifted_initialized_value = |
| 6675 | enum_cast<uint32_t>(ClassStatus::kInitialized) << (status_lsb_position % kBitsPerByte); |
| 6676 | |
| 6677 | __ cmpb(Address(class_reg, status_byte_offset), Immediate(shifted_initialized_value)); |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 6678 | __ j(kBelow, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6679 | __ Bind(slow_path->GetExitLabel()); |
| 6680 | // No need for memory fence, thanks to the X86 memory model. |
| 6681 | } |
| 6682 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6683 | void InstructionCodeGeneratorX86::GenerateBitstringTypeCheckCompare(HTypeCheckInstruction* check, |
| 6684 | Register temp) { |
| 6685 | uint32_t path_to_root = check->GetBitstringPathToRoot(); |
| 6686 | uint32_t mask = check->GetBitstringMask(); |
| 6687 | DCHECK(IsPowerOfTwo(mask + 1)); |
| 6688 | size_t mask_bits = WhichPowerOf2(mask + 1); |
| 6689 | |
| 6690 | if (mask_bits == 16u) { |
| 6691 | // Compare the bitstring in memory. |
| 6692 | __ cmpw(Address(temp, mirror::Class::StatusOffset()), Immediate(path_to_root)); |
| 6693 | } else { |
| 6694 | // /* uint32_t */ temp = temp->status_ |
| 6695 | __ movl(temp, Address(temp, mirror::Class::StatusOffset())); |
| 6696 | // Compare the bitstring bits using SUB. |
| 6697 | __ subl(temp, Immediate(path_to_root)); |
| 6698 | // Shift out bits that do not contribute to the comparison. |
| 6699 | __ shll(temp, Immediate(32u - mask_bits)); |
| 6700 | } |
| 6701 | } |
| 6702 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6703 | HLoadString::LoadKind CodeGeneratorX86::GetSupportedLoadStringKind( |
| 6704 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6705 | switch (desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6706 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6707 | case HLoadString::LoadKind::kBootImageRelRo: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6708 | case HLoadString::LoadKind::kBssEntry: |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6709 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6710 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6711 | case HLoadString::LoadKind::kJitBootImageAddress: |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6712 | case HLoadString::LoadKind::kJitTableAddress: |
| 6713 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6714 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6715 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6716 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6717 | } |
| 6718 | return desired_string_load_kind; |
| 6719 | } |
| 6720 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6721 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6722 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6723 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6724 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6725 | if (load_kind == HLoadString::LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6726 | load_kind == HLoadString::LoadKind::kBootImageRelRo || |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6727 | load_kind == HLoadString::LoadKind::kBssEntry) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6728 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6729 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6730 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6731 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 6732 | } else { |
| 6733 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6734 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 6735 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6736 | // Rely on the pResolveString to save everything. |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 6737 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6738 | } else { |
| 6739 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6740 | } |
| 6741 | } |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6742 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6743 | } |
| 6744 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6745 | Label* CodeGeneratorX86::NewJitRootStringPatch(const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6746 | dex::StringIndex string_index, |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6747 | Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6748 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6749 | // Add a patch entry and return the label. |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6750 | jit_string_patches_.emplace_back(&dex_file, string_index.index_); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6751 | PatchInfo<Label>* info = &jit_string_patches_.back(); |
| 6752 | return &info->label; |
| 6753 | } |
| 6754 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6755 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6756 | // move. |
| 6757 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6758 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6759 | Location out_loc = locations->Out(); |
| 6760 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6761 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6762 | switch (load->GetLoadKind()) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6763 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6764 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6765 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6766 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6767 | codegen_->RecordBootImageStringPatch(load); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6768 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6769 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6770 | case HLoadString::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6771 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 6772 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6773 | __ movl(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6774 | codegen_->RecordBootImageRelRoPatch(load->InputAt(0)->AsX86ComputeBaseMethodAddress(), |
| 6775 | codegen_->GetBootImageOffset(load)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6776 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6777 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6778 | case HLoadString::LoadKind::kBssEntry: { |
| 6779 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6780 | Address address = Address(method_address, CodeGeneratorX86::kDummy32BitOffset); |
| 6781 | Label* fixup_label = codegen_->NewStringBssEntryPatch(load); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6782 | // /* GcRoot<mirror::String> */ out = *address /* PC-relative */ |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6783 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6784 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadStringSlowPathX86(load); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6785 | codegen_->AddSlowPath(slow_path); |
| 6786 | __ testl(out, out); |
| 6787 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6788 | __ Bind(slow_path->GetExitLabel()); |
| 6789 | return; |
| 6790 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6791 | case HLoadString::LoadKind::kJitBootImageAddress: { |
| 6792 | uint32_t address = reinterpret_cast32<uint32_t>(load->GetString().Get()); |
| 6793 | DCHECK_NE(address, 0u); |
| 6794 | __ movl(out, Immediate(address)); |
| 6795 | return; |
| 6796 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6797 | case HLoadString::LoadKind::kJitTableAddress: { |
| 6798 | Address address = Address::Absolute(CodeGeneratorX86::kDummy32BitOffset); |
| 6799 | Label* fixup_label = codegen_->NewJitRootStringPatch( |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6800 | load->GetDexFile(), load->GetStringIndex(), load->GetString()); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6801 | // /* GcRoot<mirror::String> */ out = *address |
| 6802 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
| 6803 | return; |
| 6804 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6805 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6806 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6807 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6808 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6809 | // 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] | 6810 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6811 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6812 | __ movl(calling_convention.GetRegisterAt(0), Immediate(load->GetStringIndex().index_)); |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6813 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 6814 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6815 | } |
| 6816 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6817 | static Address GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6818 | return Address::Absolute(Thread::ExceptionOffset<kX86PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6819 | } |
| 6820 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6821 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 6822 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6823 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6824 | locations->SetOut(Location::RequiresRegister()); |
| 6825 | } |
| 6826 | |
| 6827 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6828 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 6829 | } |
| 6830 | |
| 6831 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6832 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6833 | } |
| 6834 | |
| 6835 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6836 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6837 | } |
| 6838 | |
| 6839 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6840 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6841 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6842 | InvokeRuntimeCallingConvention calling_convention; |
| 6843 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6844 | } |
| 6845 | |
| 6846 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6847 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6848 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6849 | } |
| 6850 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6851 | // Temp is used for read barrier. |
| 6852 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 6853 | if (kEmitCompilerReadBarrier && |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6854 | !kUseBakerReadBarrier && |
| 6855 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6856 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6857 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 6858 | return 1; |
| 6859 | } |
| 6860 | return 0; |
| 6861 | } |
| 6862 | |
Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6863 | // Interface case has 2 temps, one for holding the number of interfaces, one for the current |
| 6864 | // interface pointer, the current interface is compared in memory. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6865 | // The other checks have one temp for loading the object's class. |
| 6866 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 6867 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6868 | return 2; |
| 6869 | } |
| 6870 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6871 | } |
| 6872 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6873 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6874 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6875 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6876 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6877 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6878 | case TypeCheckKind::kExactCheck: |
| 6879 | case TypeCheckKind::kAbstractClassCheck: |
| 6880 | case TypeCheckKind::kClassHierarchyCheck: |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6881 | case TypeCheckKind::kArrayObjectCheck: { |
| 6882 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 6883 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 6884 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6885 | break; |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6886 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6887 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6888 | case TypeCheckKind::kUnresolvedCheck: |
| 6889 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6890 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6891 | break; |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6892 | case TypeCheckKind::kBitstringCheck: |
| 6893 | break; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6894 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6895 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6896 | LocationSummary* locations = |
| 6897 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6898 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6899 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6900 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6901 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6902 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 6903 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 6904 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 6905 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 6906 | } else { |
| 6907 | locations->SetInAt(1, Location::Any()); |
| 6908 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6909 | // Note that TypeCheckSlowPathX86 uses this "out" register too. |
| 6910 | locations->SetOut(Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6911 | // When read barriers are enabled, we need a temporary register for some cases. |
| 6912 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6913 | } |
| 6914 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6915 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6916 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6917 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6918 | Location obj_loc = locations->InAt(0); |
| 6919 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6920 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6921 | Location out_loc = locations->Out(); |
| 6922 | Register out = out_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6923 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 6924 | DCHECK_LE(num_temps, 1u); |
| 6925 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6926 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6927 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6928 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6929 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6930 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6931 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6932 | |
| 6933 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6934 | // Avoid null check if we know obj is not null. |
| 6935 | if (instruction->MustDoNullCheck()) { |
| 6936 | __ testl(obj, obj); |
| 6937 | __ j(kEqual, &zero); |
| 6938 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6939 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6940 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6941 | case TypeCheckKind::kExactCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6942 | ReadBarrierOption read_barrier_option = |
| 6943 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6944 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6945 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6946 | out_loc, |
| 6947 | obj_loc, |
| 6948 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6949 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6950 | if (cls.IsRegister()) { |
| 6951 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6952 | } else { |
| 6953 | DCHECK(cls.IsStackSlot()) << cls; |
| 6954 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6955 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6956 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6957 | // Classes must be equal for the instanceof to succeed. |
| 6958 | __ j(kNotEqual, &zero); |
| 6959 | __ movl(out, Immediate(1)); |
| 6960 | __ jmp(&done); |
| 6961 | break; |
| 6962 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6963 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6964 | case TypeCheckKind::kAbstractClassCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6965 | ReadBarrierOption read_barrier_option = |
| 6966 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6967 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6968 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6969 | out_loc, |
| 6970 | obj_loc, |
| 6971 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6972 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6973 | // If the class is abstract, we eagerly fetch the super class of the |
| 6974 | // object to avoid doing a comparison we know will fail. |
| 6975 | NearLabel loop; |
| 6976 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6977 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6978 | GenerateReferenceLoadOneRegister(instruction, |
| 6979 | out_loc, |
| 6980 | super_offset, |
| 6981 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6982 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6983 | __ testl(out, out); |
| 6984 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6985 | __ j(kEqual, &done); |
| 6986 | if (cls.IsRegister()) { |
| 6987 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6988 | } else { |
| 6989 | DCHECK(cls.IsStackSlot()) << cls; |
| 6990 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6991 | } |
| 6992 | __ j(kNotEqual, &loop); |
| 6993 | __ movl(out, Immediate(1)); |
| 6994 | if (zero.IsLinked()) { |
| 6995 | __ jmp(&done); |
| 6996 | } |
| 6997 | break; |
| 6998 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6999 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7000 | case TypeCheckKind::kClassHierarchyCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7001 | ReadBarrierOption read_barrier_option = |
| 7002 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7003 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7004 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7005 | out_loc, |
| 7006 | obj_loc, |
| 7007 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7008 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7009 | // Walk over the class hierarchy to find a match. |
| 7010 | NearLabel loop, success; |
| 7011 | __ Bind(&loop); |
| 7012 | if (cls.IsRegister()) { |
| 7013 | __ cmpl(out, cls.AsRegister<Register>()); |
| 7014 | } else { |
| 7015 | DCHECK(cls.IsStackSlot()) << cls; |
| 7016 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 7017 | } |
| 7018 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7019 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7020 | GenerateReferenceLoadOneRegister(instruction, |
| 7021 | out_loc, |
| 7022 | super_offset, |
| 7023 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7024 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7025 | __ testl(out, out); |
| 7026 | __ j(kNotEqual, &loop); |
| 7027 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7028 | __ jmp(&done); |
| 7029 | __ Bind(&success); |
| 7030 | __ movl(out, Immediate(1)); |
| 7031 | if (zero.IsLinked()) { |
| 7032 | __ jmp(&done); |
| 7033 | } |
| 7034 | break; |
| 7035 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7036 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7037 | case TypeCheckKind::kArrayObjectCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7038 | ReadBarrierOption read_barrier_option = |
| 7039 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7040 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7041 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7042 | out_loc, |
| 7043 | obj_loc, |
| 7044 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7045 | read_barrier_option); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7046 | // Do an exact check. |
| 7047 | NearLabel exact_check; |
| 7048 | if (cls.IsRegister()) { |
| 7049 | __ cmpl(out, cls.AsRegister<Register>()); |
| 7050 | } else { |
| 7051 | DCHECK(cls.IsStackSlot()) << cls; |
| 7052 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 7053 | } |
| 7054 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7055 | // 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] | 7056 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7057 | GenerateReferenceLoadOneRegister(instruction, |
| 7058 | out_loc, |
| 7059 | component_offset, |
| 7060 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7061 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7062 | __ testl(out, out); |
| 7063 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7064 | __ j(kEqual, &done); |
| 7065 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 7066 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7067 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7068 | __ movl(out, Immediate(1)); |
| 7069 | __ jmp(&done); |
| 7070 | break; |
| 7071 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7072 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7073 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7074 | // No read barrier since the slow path will retry upon failure. |
| 7075 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7076 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7077 | out_loc, |
| 7078 | obj_loc, |
| 7079 | class_offset, |
| 7080 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7081 | if (cls.IsRegister()) { |
| 7082 | __ cmpl(out, cls.AsRegister<Register>()); |
| 7083 | } else { |
| 7084 | DCHECK(cls.IsStackSlot()) << cls; |
| 7085 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 7086 | } |
| 7087 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7088 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
| 7089 | instruction, /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7090 | codegen_->AddSlowPath(slow_path); |
| 7091 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 7092 | __ movl(out, Immediate(1)); |
| 7093 | if (zero.IsLinked()) { |
| 7094 | __ jmp(&done); |
| 7095 | } |
| 7096 | break; |
| 7097 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7098 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 7099 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7100 | case TypeCheckKind::kInterfaceCheck: { |
| 7101 | // 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] | 7102 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7103 | // cases. |
| 7104 | // |
| 7105 | // We cannot directly call the InstanceofNonTrivial runtime |
| 7106 | // entry point without resorting to a type checking slow path |
| 7107 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 7108 | // require to assign fixed registers for the inputs of this |
| 7109 | // HInstanceOf instruction (following the runtime calling |
| 7110 | // convention), which might be cluttered by the potential first |
| 7111 | // read barrier emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7112 | // |
| 7113 | // TODO: Introduce a new runtime entry point taking the object |
| 7114 | // to test (instead of its class) as argument, and let it deal |
| 7115 | // with the read barrier issues. This will let us refactor this |
| 7116 | // case of the `switch` code as it was previously (with a direct |
| 7117 | // call to the runtime not using a type checking slow path). |
| 7118 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7119 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7120 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
| 7121 | instruction, /* is_fatal */ false); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7122 | codegen_->AddSlowPath(slow_path); |
| 7123 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7124 | if (zero.IsLinked()) { |
| 7125 | __ jmp(&done); |
| 7126 | } |
| 7127 | break; |
| 7128 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7129 | |
| 7130 | case TypeCheckKind::kBitstringCheck: { |
| 7131 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7132 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7133 | out_loc, |
| 7134 | obj_loc, |
| 7135 | class_offset, |
| 7136 | kWithoutReadBarrier); |
| 7137 | |
| 7138 | GenerateBitstringTypeCheckCompare(instruction, out); |
| 7139 | __ j(kNotEqual, &zero); |
| 7140 | __ movl(out, Immediate(1)); |
| 7141 | __ jmp(&done); |
| 7142 | break; |
| 7143 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7144 | } |
| 7145 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7146 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7147 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7148 | __ xorl(out, out); |
| 7149 | } |
| 7150 | |
| 7151 | if (done.IsLinked()) { |
| 7152 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7153 | } |
| 7154 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7155 | if (slow_path != nullptr) { |
| 7156 | __ Bind(slow_path->GetExitLabel()); |
| 7157 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7158 | } |
| 7159 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7160 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7161 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7162 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7163 | LocationSummary* locations = |
| 7164 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7165 | locations->SetInAt(0, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7166 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 7167 | // Require a register for the interface check since there is a loop that compares the class to |
| 7168 | // a memory address. |
| 7169 | locations->SetInAt(1, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7170 | } else if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 7171 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 7172 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 7173 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7174 | } else { |
| 7175 | locations->SetInAt(1, Location::Any()); |
| 7176 | } |
Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 7177 | // 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] | 7178 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
| 7179 | } |
| 7180 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7181 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7182 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7183 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7184 | Location obj_loc = locations->InAt(0); |
| 7185 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7186 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7187 | Location temp_loc = locations->GetTemp(0); |
| 7188 | Register temp = temp_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7189 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 7190 | DCHECK_GE(num_temps, 1u); |
| 7191 | DCHECK_LE(num_temps, 2u); |
| 7192 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 7193 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7194 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7195 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7196 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 7197 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 7198 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 7199 | const uint32_t object_array_data_offset = |
| 7200 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7201 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7202 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7203 | SlowPathCode* type_check_slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7204 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
| 7205 | instruction, is_type_check_slow_path_fatal); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7206 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7207 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7208 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7209 | // Avoid null check if we know obj is not null. |
| 7210 | if (instruction->MustDoNullCheck()) { |
| 7211 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7212 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7213 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7214 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7215 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7216 | case TypeCheckKind::kExactCheck: |
| 7217 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7218 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7219 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7220 | temp_loc, |
| 7221 | obj_loc, |
| 7222 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7223 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7224 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7225 | if (cls.IsRegister()) { |
| 7226 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 7227 | } else { |
| 7228 | DCHECK(cls.IsStackSlot()) << cls; |
| 7229 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 7230 | } |
| 7231 | // Jump to slow path for throwing the exception or doing a |
| 7232 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7233 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7234 | break; |
| 7235 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7236 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7237 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7238 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7239 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7240 | temp_loc, |
| 7241 | obj_loc, |
| 7242 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7243 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7244 | |
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. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7247 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7248 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7249 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7250 | GenerateReferenceLoadOneRegister(instruction, |
| 7251 | temp_loc, |
| 7252 | super_offset, |
| 7253 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7254 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7255 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7256 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 7257 | // exception. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7258 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7259 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7260 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7261 | // Otherwise, compare the classes |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7262 | if (cls.IsRegister()) { |
| 7263 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 7264 | } else { |
| 7265 | DCHECK(cls.IsStackSlot()) << cls; |
| 7266 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 7267 | } |
| 7268 | __ j(kNotEqual, &loop); |
| 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: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7273 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7274 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7275 | temp_loc, |
| 7276 | obj_loc, |
| 7277 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7278 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7279 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7280 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7281 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7282 | __ Bind(&loop); |
| 7283 | if (cls.IsRegister()) { |
| 7284 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 7285 | } else { |
| 7286 | DCHECK(cls.IsStackSlot()) << cls; |
| 7287 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 7288 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7289 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7290 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7291 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7292 | GenerateReferenceLoadOneRegister(instruction, |
| 7293 | temp_loc, |
| 7294 | super_offset, |
| 7295 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7296 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7297 | |
| 7298 | // If the class reference currently in `temp` is not null, jump |
| 7299 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7300 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7301 | __ j(kNotZero, &loop); |
| 7302 | // Otherwise, jump to the slow path to throw the exception.; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7303 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7304 | break; |
| 7305 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7306 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7307 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7308 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7309 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7310 | temp_loc, |
| 7311 | obj_loc, |
| 7312 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7313 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7314 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7315 | // Do an exact check. |
| 7316 | if (cls.IsRegister()) { |
| 7317 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 7318 | } else { |
| 7319 | DCHECK(cls.IsStackSlot()) << cls; |
| 7320 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 7321 | } |
| 7322 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7323 | |
| 7324 | // 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] | 7325 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7326 | GenerateReferenceLoadOneRegister(instruction, |
| 7327 | temp_loc, |
| 7328 | component_offset, |
| 7329 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7330 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7331 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7332 | // If the component type is null (i.e. the object not an array), jump to the slow path to |
| 7333 | // throw the exception. Otherwise proceed with the check. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7334 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7335 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7336 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7337 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7338 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7339 | break; |
| 7340 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7341 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 7342 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7343 | // 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] | 7344 | // We cannot directly call the CheckCast runtime entry point |
| 7345 | // without resorting to a type checking slow path here (i.e. by |
| 7346 | // calling InvokeRuntime directly), as it would require to |
| 7347 | // assign fixed registers for the inputs of this HInstanceOf |
| 7348 | // instruction (following the runtime calling convention), which |
| 7349 | // might be cluttered by the potential first read barrier |
| 7350 | // emission at the beginning of this method. |
| 7351 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7352 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7353 | |
| 7354 | case TypeCheckKind::kInterfaceCheck: { |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 7355 | // Fast path for the interface check. Try to avoid read barriers to improve the fast path. |
| 7356 | // We can not get false positives by doing this. |
| 7357 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7358 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7359 | temp_loc, |
| 7360 | obj_loc, |
| 7361 | class_offset, |
| 7362 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7363 | |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 7364 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 7365 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7366 | temp_loc, |
| 7367 | temp_loc, |
| 7368 | iftable_offset, |
| 7369 | kWithoutReadBarrier); |
| 7370 | // Iftable is never null. |
| 7371 | __ movl(maybe_temp2_loc.AsRegister<Register>(), Address(temp, array_length_offset)); |
| 7372 | // Maybe poison the `cls` for direct comparison with memory. |
| 7373 | __ MaybePoisonHeapReference(cls.AsRegister<Register>()); |
| 7374 | // Loop through the iftable and check if any class matches. |
| 7375 | NearLabel start_loop; |
| 7376 | __ Bind(&start_loop); |
| 7377 | // Need to subtract first to handle the empty array case. |
| 7378 | __ subl(maybe_temp2_loc.AsRegister<Register>(), Immediate(2)); |
| 7379 | __ j(kNegative, type_check_slow_path->GetEntryLabel()); |
| 7380 | // Go to next interface if the classes do not match. |
| 7381 | __ cmpl(cls.AsRegister<Register>(), |
| 7382 | CodeGeneratorX86::ArrayAddress(temp, |
| 7383 | maybe_temp2_loc, |
| 7384 | TIMES_4, |
| 7385 | object_array_data_offset)); |
| 7386 | __ j(kNotEqual, &start_loop); |
| 7387 | // If `cls` was poisoned above, unpoison it. |
| 7388 | __ MaybeUnpoisonHeapReference(cls.AsRegister<Register>()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7389 | break; |
| 7390 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7391 | |
| 7392 | case TypeCheckKind::kBitstringCheck: { |
| 7393 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7394 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7395 | temp_loc, |
| 7396 | obj_loc, |
| 7397 | class_offset, |
| 7398 | kWithoutReadBarrier); |
| 7399 | |
| 7400 | GenerateBitstringTypeCheckCompare(instruction, temp); |
| 7401 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
| 7402 | break; |
| 7403 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7404 | } |
| 7405 | __ Bind(&done); |
| 7406 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7407 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7408 | } |
| 7409 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7410 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7411 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 7412 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7413 | InvokeRuntimeCallingConvention calling_convention; |
| 7414 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 7415 | } |
| 7416 | |
| 7417 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 7418 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject |
| 7419 | : kQuickUnlockObject, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 7420 | instruction, |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 7421 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7422 | if (instruction->IsEnter()) { |
| 7423 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 7424 | } else { |
| 7425 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 7426 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7427 | } |
| 7428 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7429 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 7430 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 7431 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 7432 | |
| 7433 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 7434 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7435 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7436 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 |
| 7437 | || instruction->GetResultType() == DataType::Type::kInt64); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7438 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7439 | locations->SetInAt(1, Location::Any()); |
| 7440 | locations->SetOut(Location::SameAsFirstInput()); |
| 7441 | } |
| 7442 | |
| 7443 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 7444 | HandleBitwiseOperation(instruction); |
| 7445 | } |
| 7446 | |
| 7447 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 7448 | HandleBitwiseOperation(instruction); |
| 7449 | } |
| 7450 | |
| 7451 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 7452 | HandleBitwiseOperation(instruction); |
| 7453 | } |
| 7454 | |
| 7455 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 7456 | LocationSummary* locations = instruction->GetLocations(); |
| 7457 | Location first = locations->InAt(0); |
| 7458 | Location second = locations->InAt(1); |
| 7459 | DCHECK(first.Equals(locations->Out())); |
| 7460 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7461 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7462 | if (second.IsRegister()) { |
| 7463 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7464 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7465 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7466 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7467 | } else { |
| 7468 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7469 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7470 | } |
| 7471 | } else if (second.IsConstant()) { |
| 7472 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 7473 | __ andl(first.AsRegister<Register>(), |
| 7474 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7475 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 7476 | __ orl(first.AsRegister<Register>(), |
| 7477 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7478 | } else { |
| 7479 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 7480 | __ xorl(first.AsRegister<Register>(), |
| 7481 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7482 | } |
| 7483 | } else { |
| 7484 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7485 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7486 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7487 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7488 | } else { |
| 7489 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7490 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7491 | } |
| 7492 | } |
| 7493 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7494 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7495 | if (second.IsRegisterPair()) { |
| 7496 | if (instruction->IsAnd()) { |
| 7497 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 7498 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 7499 | } else if (instruction->IsOr()) { |
| 7500 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 7501 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 7502 | } else { |
| 7503 | DCHECK(instruction->IsXor()); |
| 7504 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 7505 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 7506 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7507 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7508 | if (instruction->IsAnd()) { |
| 7509 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7510 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 7511 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7512 | } else if (instruction->IsOr()) { |
| 7513 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7514 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 7515 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7516 | } else { |
| 7517 | DCHECK(instruction->IsXor()); |
| 7518 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7519 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 7520 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7521 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7522 | } else { |
| 7523 | DCHECK(second.IsConstant()) << second; |
| 7524 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7525 | int32_t low_value = Low32Bits(value); |
| 7526 | int32_t high_value = High32Bits(value); |
| 7527 | Immediate low(low_value); |
| 7528 | Immediate high(high_value); |
| 7529 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 7530 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7531 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7532 | if (low_value == 0) { |
| 7533 | __ xorl(first_low, first_low); |
| 7534 | } else if (low_value != -1) { |
| 7535 | __ andl(first_low, low); |
| 7536 | } |
| 7537 | if (high_value == 0) { |
| 7538 | __ xorl(first_high, first_high); |
| 7539 | } else if (high_value != -1) { |
| 7540 | __ andl(first_high, high); |
| 7541 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7542 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7543 | if (low_value != 0) { |
| 7544 | __ orl(first_low, low); |
| 7545 | } |
| 7546 | if (high_value != 0) { |
| 7547 | __ orl(first_high, high); |
| 7548 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7549 | } else { |
| 7550 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7551 | if (low_value != 0) { |
| 7552 | __ xorl(first_low, low); |
| 7553 | } |
| 7554 | if (high_value != 0) { |
| 7555 | __ xorl(first_high, high); |
| 7556 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7557 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7558 | } |
| 7559 | } |
| 7560 | } |
| 7561 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7562 | void InstructionCodeGeneratorX86::GenerateReferenceLoadOneRegister( |
| 7563 | HInstruction* instruction, |
| 7564 | Location out, |
| 7565 | uint32_t offset, |
| 7566 | Location maybe_temp, |
| 7567 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7568 | Register out_reg = out.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7569 | if (read_barrier_option == kWithReadBarrier) { |
| 7570 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7571 | if (kUseBakerReadBarrier) { |
| 7572 | // Load with fast path based Baker's read barrier. |
| 7573 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7574 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7575 | instruction, out, out_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7576 | } else { |
| 7577 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7578 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7579 | // in the following move operation, as we will need it for the |
| 7580 | // read barrier below. |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7581 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7582 | __ movl(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7583 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7584 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7585 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7586 | } |
| 7587 | } else { |
| 7588 | // Plain load with no read barrier. |
| 7589 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7590 | __ movl(out_reg, Address(out_reg, offset)); |
| 7591 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7592 | } |
| 7593 | } |
| 7594 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7595 | void InstructionCodeGeneratorX86::GenerateReferenceLoadTwoRegisters( |
| 7596 | HInstruction* instruction, |
| 7597 | Location out, |
| 7598 | Location obj, |
| 7599 | uint32_t offset, |
| 7600 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7601 | Register out_reg = out.AsRegister<Register>(); |
| 7602 | Register obj_reg = obj.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7603 | if (read_barrier_option == kWithReadBarrier) { |
| 7604 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7605 | if (kUseBakerReadBarrier) { |
| 7606 | // Load with fast path based Baker's read barrier. |
| 7607 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7608 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7609 | instruction, out, obj_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7610 | } else { |
| 7611 | // Load with slow path based read barrier. |
| 7612 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7613 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7614 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 7615 | } |
| 7616 | } else { |
| 7617 | // Plain load with no read barrier. |
| 7618 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7619 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7620 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7621 | } |
| 7622 | } |
| 7623 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7624 | void InstructionCodeGeneratorX86::GenerateGcRootFieldLoad( |
| 7625 | HInstruction* instruction, |
| 7626 | Location root, |
| 7627 | const Address& address, |
| 7628 | Label* fixup_label, |
| 7629 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7630 | Register root_reg = root.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7631 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7632 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7633 | if (kUseBakerReadBarrier) { |
| 7634 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 7635 | // Baker's read barrier are used: |
| 7636 | // |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7637 | // root = obj.field; |
| 7638 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 7639 | // if (temp != null) { |
| 7640 | // root = temp(root) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7641 | // } |
| 7642 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7643 | // /* GcRoot<mirror::Object> */ root = *address |
| 7644 | __ movl(root_reg, address); |
| 7645 | if (fixup_label != nullptr) { |
| 7646 | __ Bind(fixup_label); |
| 7647 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7648 | static_assert( |
| 7649 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 7650 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 7651 | "have different sizes."); |
| 7652 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 7653 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 7654 | "have different sizes."); |
| 7655 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7656 | // Slow path marking the GC root `root`. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7657 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathX86( |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7658 | instruction, root, /* unpoison_ref_before_marking */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7659 | codegen_->AddSlowPath(slow_path); |
| 7660 | |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7661 | // Test the entrypoint (`Thread::Current()->pReadBarrierMarkReg ## root.reg()`). |
| 7662 | const int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 7663 | Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(root.reg()); |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7664 | __ fs()->cmpl(Address::Absolute(entry_point_offset), Immediate(0)); |
| 7665 | // The entrypoint is null when the GC is not marking. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7666 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 7667 | __ Bind(slow_path->GetExitLabel()); |
| 7668 | } else { |
| 7669 | // GC root loaded through a slow path for read barriers other |
| 7670 | // than Baker's. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7671 | // /* GcRoot<mirror::Object>* */ root = address |
| 7672 | __ leal(root_reg, address); |
| 7673 | if (fixup_label != nullptr) { |
| 7674 | __ Bind(fixup_label); |
| 7675 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7676 | // /* mirror::Object* */ root = root->Read() |
| 7677 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 7678 | } |
| 7679 | } else { |
| 7680 | // Plain GC root load with no read barrier. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7681 | // /* GcRoot<mirror::Object> */ root = *address |
| 7682 | __ movl(root_reg, address); |
| 7683 | if (fixup_label != nullptr) { |
| 7684 | __ Bind(fixup_label); |
| 7685 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7686 | // Note that GC roots are not affected by heap poisoning, thus we |
| 7687 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7688 | } |
| 7689 | } |
| 7690 | |
| 7691 | void CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7692 | Location ref, |
| 7693 | Register obj, |
| 7694 | uint32_t offset, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7695 | bool needs_null_check) { |
| 7696 | DCHECK(kEmitCompilerReadBarrier); |
| 7697 | DCHECK(kUseBakerReadBarrier); |
| 7698 | |
| 7699 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7700 | Address src(obj, offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7701 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7702 | } |
| 7703 | |
| 7704 | void CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7705 | Location ref, |
| 7706 | Register obj, |
| 7707 | uint32_t data_offset, |
| 7708 | Location index, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7709 | bool needs_null_check) { |
| 7710 | DCHECK(kEmitCompilerReadBarrier); |
| 7711 | DCHECK(kUseBakerReadBarrier); |
| 7712 | |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 7713 | static_assert( |
| 7714 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 7715 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7716 | // /* HeapReference<Object> */ ref = |
| 7717 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7718 | Address src = CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7719 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7720 | } |
| 7721 | |
| 7722 | void CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7723 | Location ref, |
| 7724 | Register obj, |
| 7725 | const Address& src, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7726 | bool needs_null_check, |
| 7727 | bool always_update_field, |
| 7728 | Register* temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7729 | DCHECK(kEmitCompilerReadBarrier); |
| 7730 | DCHECK(kUseBakerReadBarrier); |
| 7731 | |
| 7732 | // In slow path based read barriers, the read barrier call is |
| 7733 | // inserted after the original load. However, in fast path based |
| 7734 | // Baker's read barriers, we need to perform the load of |
| 7735 | // mirror::Object::monitor_ *before* the original reference load. |
| 7736 | // This load-load ordering is required by the read barrier. |
| 7737 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 7738 | // |
| 7739 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7740 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7741 | // HeapReference<Object> ref = *src; // Original reference load. |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7742 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7743 | // if (is_gray) { |
| 7744 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 7745 | // } |
| 7746 | // |
| 7747 | // Note: the original implementation in ReadBarrier::Barrier is |
| 7748 | // slightly more complex as: |
| 7749 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7750 | // the high-bits of rb_state, which are expected to be all zeroes |
| 7751 | // (we use CodeGeneratorX86::GenerateMemoryBarrier instead here, |
| 7752 | // which is a no-op thanks to the x86 memory model); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7753 | // - it performs additional checks that we do not do here for |
| 7754 | // performance reasons. |
| 7755 | |
| 7756 | Register ref_reg = ref.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7757 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 7758 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7759 | // 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] | 7760 | static_assert(ReadBarrier::NonGrayState() == 0, "Expecting non-gray to have value 0"); |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7761 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7762 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 7763 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 7764 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 7765 | |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7766 | // if (rb_state == ReadBarrier::GrayState()) |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7767 | // ref = ReadBarrier::Mark(ref); |
| 7768 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 7769 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7770 | if (needs_null_check) { |
| 7771 | MaybeRecordImplicitNullCheck(instruction); |
| 7772 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7773 | |
| 7774 | // Load fence to prevent load-load reordering. |
| 7775 | // Note that this is a no-op, thanks to the x86 memory model. |
| 7776 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 7777 | |
| 7778 | // The actual reference load. |
| 7779 | // /* HeapReference<Object> */ ref = *src |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7780 | __ movl(ref_reg, src); // Flags are unaffected. |
| 7781 | |
| 7782 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 7783 | // Slow path marking the object `ref` when it is gray. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7784 | SlowPathCode* slow_path; |
| 7785 | if (always_update_field) { |
| 7786 | DCHECK(temp != nullptr); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7787 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkAndUpdateFieldSlowPathX86( |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7788 | instruction, ref, obj, src, /* unpoison_ref_before_marking */ true, *temp); |
| 7789 | } else { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7790 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkSlowPathX86( |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7791 | instruction, ref, /* unpoison_ref_before_marking */ true); |
| 7792 | } |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7793 | AddSlowPath(slow_path); |
| 7794 | |
| 7795 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 7796 | __ j(kNotZero, slow_path->GetEntryLabel()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7797 | |
| 7798 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7799 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7800 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7801 | __ Bind(slow_path->GetExitLabel()); |
| 7802 | } |
| 7803 | |
| 7804 | void CodeGeneratorX86::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7805 | Location out, |
| 7806 | Location ref, |
| 7807 | Location obj, |
| 7808 | uint32_t offset, |
| 7809 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7810 | DCHECK(kEmitCompilerReadBarrier); |
| 7811 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7812 | // Insert a slow path based read barrier *after* the reference load. |
| 7813 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7814 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7815 | // reference will be carried out by the runtime within the slow |
| 7816 | // path. |
| 7817 | // |
| 7818 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7819 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7820 | // not used by the artReadBarrierSlow entry point. |
| 7821 | // |
| 7822 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7823 | SlowPathCode* slow_path = new (GetScopedAllocator()) |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7824 | ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); |
| 7825 | AddSlowPath(slow_path); |
| 7826 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7827 | __ jmp(slow_path->GetEntryLabel()); |
| 7828 | __ Bind(slow_path->GetExitLabel()); |
| 7829 | } |
| 7830 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7831 | void CodeGeneratorX86::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 7832 | Location out, |
| 7833 | Location ref, |
| 7834 | Location obj, |
| 7835 | uint32_t offset, |
| 7836 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7837 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7838 | // Baker's read barriers shall be handled by the fast path |
| 7839 | // (CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier). |
| 7840 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7841 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7842 | // by the runtime within the slow path. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7843 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7844 | } else if (kPoisonHeapReferences) { |
| 7845 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 7846 | } |
| 7847 | } |
| 7848 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7849 | void CodeGeneratorX86::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7850 | Location out, |
| 7851 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7852 | DCHECK(kEmitCompilerReadBarrier); |
| 7853 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7854 | // Insert a slow path based read barrier *after* the GC root load. |
| 7855 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7856 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7857 | // not need to do anything special for this here. |
| 7858 | SlowPathCode* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7859 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathX86(instruction, out, root); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7860 | AddSlowPath(slow_path); |
| 7861 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7862 | __ jmp(slow_path->GetEntryLabel()); |
| 7863 | __ Bind(slow_path->GetExitLabel()); |
| 7864 | } |
| 7865 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7866 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7867 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7868 | LOG(FATAL) << "Unreachable"; |
| 7869 | } |
| 7870 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7871 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7872 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7873 | LOG(FATAL) << "Unreachable"; |
| 7874 | } |
| 7875 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7876 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7877 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7878 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7879 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7880 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7881 | } |
| 7882 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7883 | void InstructionCodeGeneratorX86::GenPackedSwitchWithCompares(Register value_reg, |
| 7884 | int32_t lower_bound, |
| 7885 | uint32_t num_entries, |
| 7886 | HBasicBlock* switch_block, |
| 7887 | HBasicBlock* default_block) { |
| 7888 | // Figure out the correct compare values and jump conditions. |
| 7889 | // Handle the first compare/branch as a special case because it might |
| 7890 | // jump to the default case. |
| 7891 | DCHECK_GT(num_entries, 2u); |
| 7892 | Condition first_condition; |
| 7893 | uint32_t index; |
| 7894 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 7895 | if (lower_bound != 0) { |
| 7896 | first_condition = kLess; |
| 7897 | __ cmpl(value_reg, Immediate(lower_bound)); |
| 7898 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 7899 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7900 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7901 | index = 1; |
| 7902 | } else { |
| 7903 | // Handle all the compare/jumps below. |
| 7904 | first_condition = kBelow; |
| 7905 | index = 0; |
| 7906 | } |
| 7907 | |
| 7908 | // Handle the rest of the compare/jumps. |
| 7909 | for (; index + 1 < num_entries; index += 2) { |
| 7910 | int32_t compare_to_value = lower_bound + index + 1; |
| 7911 | __ cmpl(value_reg, Immediate(compare_to_value)); |
| 7912 | // Jump to successors[index] if value < case_value[index]. |
| 7913 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 7914 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 7915 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 7916 | } |
| 7917 | |
| 7918 | if (index != num_entries) { |
| 7919 | // There are an odd number of entries. Handle the last one. |
| 7920 | DCHECK_EQ(index + 1, num_entries); |
| 7921 | __ cmpl(value_reg, Immediate(lower_bound + index)); |
| 7922 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7923 | } |
| 7924 | |
| 7925 | // And the default for any other value. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7926 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
| 7927 | __ jmp(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7928 | } |
| 7929 | } |
| 7930 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7931 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7932 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 7933 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 7934 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7935 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7936 | |
| 7937 | GenPackedSwitchWithCompares(value_reg, |
| 7938 | lower_bound, |
| 7939 | num_entries, |
| 7940 | switch_instr->GetBlock(), |
| 7941 | switch_instr->GetDefaultBlock()); |
| 7942 | } |
| 7943 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7944 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7945 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7946 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7947 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7948 | |
| 7949 | // Constant area pointer. |
| 7950 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7951 | |
| 7952 | // And the temporary we need. |
| 7953 | locations->AddTemp(Location::RequiresRegister()); |
| 7954 | } |
| 7955 | |
| 7956 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7957 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7958 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7959 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7960 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7961 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7962 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7963 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 7964 | GenPackedSwitchWithCompares(value_reg, |
| 7965 | lower_bound, |
| 7966 | num_entries, |
| 7967 | switch_instr->GetBlock(), |
| 7968 | default_block); |
| 7969 | return; |
| 7970 | } |
| 7971 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7972 | // Optimizing has a jump area. |
| 7973 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 7974 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 7975 | |
| 7976 | // Remove the bias, if needed. |
| 7977 | if (lower_bound != 0) { |
| 7978 | __ leal(temp_reg, Address(value_reg, -lower_bound)); |
| 7979 | value_reg = temp_reg; |
| 7980 | } |
| 7981 | |
| 7982 | // Is the value in range? |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7983 | DCHECK_GE(num_entries, 1u); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7984 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 7985 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| 7986 | |
| 7987 | // We are in the range of the table. |
| 7988 | // Load (target-constant_area) from the jump table, indexing by the value. |
| 7989 | __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); |
| 7990 | |
| 7991 | // Compute the actual target address by adding in constant_area. |
| 7992 | __ addl(temp_reg, constant_area); |
| 7993 | |
| 7994 | // And jump. |
| 7995 | __ jmp(temp_reg); |
| 7996 | } |
| 7997 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7998 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 7999 | HX86ComputeBaseMethodAddress* insn) { |
| 8000 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8001 | new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8002 | locations->SetOut(Location::RequiresRegister()); |
| 8003 | } |
| 8004 | |
| 8005 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 8006 | HX86ComputeBaseMethodAddress* insn) { |
| 8007 | LocationSummary* locations = insn->GetLocations(); |
| 8008 | Register reg = locations->Out().AsRegister<Register>(); |
| 8009 | |
| 8010 | // Generate call to next instruction. |
| 8011 | Label next_instruction; |
| 8012 | __ call(&next_instruction); |
| 8013 | __ Bind(&next_instruction); |
| 8014 | |
| 8015 | // Remember this offset for later use with constant area. |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8016 | codegen_->AddMethodAddressOffset(insn, GetAssembler()->CodeSize()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8017 | |
| 8018 | // Grab the return address off the stack. |
| 8019 | __ popl(reg); |
| 8020 | } |
| 8021 | |
| 8022 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 8023 | HX86LoadFromConstantTable* insn) { |
| 8024 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8025 | new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8026 | |
| 8027 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8028 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 8029 | |
| 8030 | // 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] | 8031 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8032 | return; |
| 8033 | } |
| 8034 | |
| 8035 | switch (insn->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8036 | case DataType::Type::kFloat32: |
| 8037 | case DataType::Type::kFloat64: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8038 | locations->SetOut(Location::RequiresFpuRegister()); |
| 8039 | break; |
| 8040 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8041 | case DataType::Type::kInt32: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8042 | locations->SetOut(Location::RequiresRegister()); |
| 8043 | break; |
| 8044 | |
| 8045 | default: |
| 8046 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 8047 | } |
| 8048 | } |
| 8049 | |
| 8050 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 8051 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8052 | return; |
| 8053 | } |
| 8054 | |
| 8055 | LocationSummary* locations = insn->GetLocations(); |
| 8056 | Location out = locations->Out(); |
| 8057 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 8058 | HConstant *value = insn->GetConstant(); |
| 8059 | |
| 8060 | switch (insn->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8061 | case DataType::Type::kFloat32: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8062 | __ movss(out.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8063 | codegen_->LiteralFloatAddress( |
| 8064 | value->AsFloatConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8065 | break; |
| 8066 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8067 | case DataType::Type::kFloat64: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8068 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8069 | codegen_->LiteralDoubleAddress( |
| 8070 | value->AsDoubleConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8071 | break; |
| 8072 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8073 | case DataType::Type::kInt32: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8074 | __ movl(out.AsRegister<Register>(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8075 | codegen_->LiteralInt32Address( |
| 8076 | value->AsIntConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8077 | break; |
| 8078 | |
| 8079 | default: |
| 8080 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 8081 | } |
| 8082 | } |
| 8083 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8084 | /** |
| 8085 | * Class to handle late fixup of offsets into constant area. |
| 8086 | */ |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 8087 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8088 | public: |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8089 | RIPFixup(CodeGeneratorX86& codegen, |
| 8090 | HX86ComputeBaseMethodAddress* base_method_address, |
| 8091 | size_t offset) |
| 8092 | : codegen_(&codegen), |
| 8093 | base_method_address_(base_method_address), |
| 8094 | offset_into_constant_area_(offset) {} |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8095 | |
| 8096 | protected: |
| 8097 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 8098 | |
| 8099 | CodeGeneratorX86* codegen_; |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8100 | HX86ComputeBaseMethodAddress* base_method_address_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8101 | |
| 8102 | private: |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8103 | void Process(const MemoryRegion& region, int pos) override { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8104 | // Patch the correct offset for the instruction. The place to patch is the |
| 8105 | // last 4 bytes of the instruction. |
| 8106 | // The value to patch is the distance from the offset in the constant area |
| 8107 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8108 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8109 | int32_t relative_position = |
| 8110 | constant_offset - codegen_->GetMethodAddressOffset(base_method_address_); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8111 | |
| 8112 | // Patch in the right value. |
| 8113 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 8114 | } |
| 8115 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8116 | // Location in constant area that the fixup refers to. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8117 | int32_t offset_into_constant_area_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8118 | }; |
| 8119 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8120 | /** |
| 8121 | * Class to handle late fixup of offsets to a jump table that will be created in the |
| 8122 | * constant area. |
| 8123 | */ |
| 8124 | class JumpTableRIPFixup : public RIPFixup { |
| 8125 | public: |
| 8126 | JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8127 | : RIPFixup(codegen, switch_instr->GetBaseMethodAddress(), static_cast<size_t>(-1)), |
| 8128 | switch_instr_(switch_instr) {} |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8129 | |
| 8130 | void CreateJumpTable() { |
| 8131 | X86Assembler* assembler = codegen_->GetAssembler(); |
| 8132 | |
| 8133 | // Ensure that the reference to the jump table has the correct offset. |
| 8134 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 8135 | SetOffset(offset_in_constant_table); |
| 8136 | |
| 8137 | // The label values in the jump table are computed relative to the |
| 8138 | // instruction addressing the constant area. |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8139 | const int32_t relative_offset = codegen_->GetMethodAddressOffset(base_method_address_); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8140 | |
| 8141 | // Populate the jump table with the correct values for the jump table. |
| 8142 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 8143 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 8144 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 8145 | // The value that we want is the target offset - the position of the table. |
| 8146 | for (int32_t i = 0; i < num_entries; i++) { |
| 8147 | HBasicBlock* b = successors[i]; |
| 8148 | Label* l = codegen_->GetLabelOf(b); |
| 8149 | DCHECK(l->IsBound()); |
| 8150 | int32_t offset_to_block = l->Position() - relative_offset; |
| 8151 | assembler->AppendInt32(offset_to_block); |
| 8152 | } |
| 8153 | } |
| 8154 | |
| 8155 | private: |
| 8156 | const HX86PackedSwitch* switch_instr_; |
| 8157 | }; |
| 8158 | |
| 8159 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 8160 | // Generate the constant area if needed. |
| 8161 | X86Assembler* assembler = GetAssembler(); |
| 8162 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 8163 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 8164 | // byte values. |
| 8165 | assembler->Align(4, 0); |
| 8166 | constant_area_start_ = assembler->CodeSize(); |
| 8167 | |
| 8168 | // Populate any jump tables. |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 8169 | for (JumpTableRIPFixup* jump_table : fixups_to_jump_tables_) { |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8170 | jump_table->CreateJumpTable(); |
| 8171 | } |
| 8172 | |
| 8173 | // And now add the constant area to the generated code. |
| 8174 | assembler->AddConstantArea(); |
| 8175 | } |
| 8176 | |
| 8177 | // And finish up. |
| 8178 | CodeGenerator::Finalize(allocator); |
| 8179 | } |
| 8180 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8181 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, |
| 8182 | HX86ComputeBaseMethodAddress* method_base, |
| 8183 | Register reg) { |
| 8184 | AssemblerFixup* fixup = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8185 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddDouble(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8186 | return Address(reg, kDummy32BitOffset, fixup); |
| 8187 | } |
| 8188 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8189 | Address CodeGeneratorX86::LiteralFloatAddress(float v, |
| 8190 | HX86ComputeBaseMethodAddress* method_base, |
| 8191 | Register reg) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8192 | AssemblerFixup* fixup = |
| 8193 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddFloat(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8194 | return Address(reg, kDummy32BitOffset, fixup); |
| 8195 | } |
| 8196 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8197 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, |
| 8198 | HX86ComputeBaseMethodAddress* method_base, |
| 8199 | Register reg) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8200 | AssemblerFixup* fixup = |
| 8201 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddInt32(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8202 | return Address(reg, kDummy32BitOffset, fixup); |
| 8203 | } |
| 8204 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8205 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, |
| 8206 | HX86ComputeBaseMethodAddress* method_base, |
| 8207 | Register reg) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8208 | AssemblerFixup* fixup = |
| 8209 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddInt64(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8210 | return Address(reg, kDummy32BitOffset, fixup); |
| 8211 | } |
| 8212 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 8213 | void CodeGeneratorX86::Load32BitValue(Register dest, int32_t value) { |
| 8214 | if (value == 0) { |
| 8215 | __ xorl(dest, dest); |
| 8216 | } else { |
| 8217 | __ movl(dest, Immediate(value)); |
| 8218 | } |
| 8219 | } |
| 8220 | |
| 8221 | void CodeGeneratorX86::Compare32BitValue(Register dest, int32_t value) { |
| 8222 | if (value == 0) { |
| 8223 | __ testl(dest, dest); |
| 8224 | } else { |
| 8225 | __ cmpl(dest, Immediate(value)); |
| 8226 | } |
| 8227 | } |
| 8228 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8229 | void CodeGeneratorX86::GenerateIntCompare(Location lhs, Location rhs) { |
| 8230 | Register lhs_reg = lhs.AsRegister<Register>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8231 | GenerateIntCompare(lhs_reg, rhs); |
| 8232 | } |
| 8233 | |
| 8234 | void CodeGeneratorX86::GenerateIntCompare(Register lhs, Location rhs) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8235 | if (rhs.IsConstant()) { |
| 8236 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8237 | Compare32BitValue(lhs, value); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8238 | } else if (rhs.IsStackSlot()) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8239 | __ cmpl(lhs, Address(ESP, rhs.GetStackIndex())); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8240 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8241 | __ cmpl(lhs, rhs.AsRegister<Register>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8242 | } |
| 8243 | } |
| 8244 | |
| 8245 | Address CodeGeneratorX86::ArrayAddress(Register obj, |
| 8246 | Location index, |
| 8247 | ScaleFactor scale, |
| 8248 | uint32_t data_offset) { |
| 8249 | return index.IsConstant() ? |
| 8250 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) : |
| 8251 | Address(obj, index.AsRegister<Register>(), scale, data_offset); |
| 8252 | } |
| 8253 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8254 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, |
| 8255 | Register reg, |
| 8256 | Register value) { |
| 8257 | // Create a fixup to be used to create and address the jump table. |
| 8258 | JumpTableRIPFixup* table_fixup = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8259 | new (GetGraph()->GetAllocator()) JumpTableRIPFixup(*this, switch_instr); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8260 | |
| 8261 | // We have to populate the jump tables. |
| 8262 | fixups_to_jump_tables_.push_back(table_fixup); |
| 8263 | |
| 8264 | // We want a scaled address, as we are extracting the correct offset from the table. |
| 8265 | return Address(reg, value, TIMES_4, kDummy32BitOffset, table_fixup); |
| 8266 | } |
| 8267 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8268 | // TODO: target as memory. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8269 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, DataType::Type type) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8270 | if (!target.IsValid()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8271 | DCHECK_EQ(type, DataType::Type::kVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8272 | return; |
| 8273 | } |
| 8274 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8275 | DCHECK_NE(type, DataType::Type::kVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8276 | |
| 8277 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 8278 | if (target.Equals(return_loc)) { |
| 8279 | return; |
| 8280 | } |
| 8281 | |
| 8282 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 8283 | // with the else branch. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8284 | if (type == DataType::Type::kInt64) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8285 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8286 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), DataType::Type::kInt32, nullptr); |
| 8287 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), DataType::Type::kInt32, nullptr); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8288 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 8289 | } else { |
| 8290 | // Let the parallel move resolver take care of all of this. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8291 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8292 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 8293 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 8294 | } |
| 8295 | } |
| 8296 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8297 | void CodeGeneratorX86::PatchJitRootUse(uint8_t* code, |
| 8298 | const uint8_t* roots_data, |
| 8299 | const PatchInfo<Label>& info, |
| 8300 | uint64_t index_in_table) const { |
| 8301 | uint32_t code_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 8302 | uintptr_t address = |
| 8303 | 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] | 8304 | using unaligned_uint32_t __attribute__((__aligned__(1))) = uint32_t; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8305 | reinterpret_cast<unaligned_uint32_t*>(code + code_offset)[0] = |
| 8306 | dchecked_integral_cast<uint32_t>(address); |
| 8307 | } |
| 8308 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 8309 | void CodeGeneratorX86::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 8310 | for (const PatchInfo<Label>& info : jit_string_patches_) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8311 | 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] | 8312 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 8313 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8314 | } |
| 8315 | |
| 8316 | for (const PatchInfo<Label>& info : jit_class_patches_) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8317 | 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] | 8318 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 8319 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 8320 | } |
| 8321 | } |
| 8322 | |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 8323 | void LocationsBuilderX86::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 8324 | ATTRIBUTE_UNUSED) { |
| 8325 | LOG(FATAL) << "Unreachable"; |
| 8326 | } |
| 8327 | |
| 8328 | void InstructionCodeGeneratorX86::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 8329 | ATTRIBUTE_UNUSED) { |
| 8330 | LOG(FATAL) << "Unreachable"; |
| 8331 | } |
| 8332 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 8333 | #undef __ |
| 8334 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 8335 | } // namespace x86 |
| 8336 | } // namespace art |