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" |
Andreas Gampe | 09659c2 | 2017-09-18 18:23:32 -0700 | [diff] [blame] | 26 | #include "heap_poisoning.h" |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 27 | #include "intrinsics.h" |
| 28 | #include "intrinsics_x86.h" |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 29 | #include "linker/linker_patch.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 30 | #include "lock_word.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 31 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 32 | #include "mirror/class-inl.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 33 | #include "thread.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 34 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 35 | #include "utils/stack_checks.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 36 | #include "utils/x86/assembler_x86.h" |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 37 | #include "utils/x86/managed_register_x86.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 38 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 39 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 40 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 41 | template<class MirrorType> |
| 42 | class GcRoot; |
| 43 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 44 | namespace x86 { |
| 45 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 46 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 47 | static constexpr Register kMethodRegisterArgument = EAX; |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 48 | static constexpr Register kCoreCalleeSaves[] = { EBP, ESI, EDI }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 49 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 50 | static constexpr int kC2ConditionMask = 0x400; |
| 51 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 52 | static constexpr int kFakeReturnRegister = Register(8); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 53 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 54 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 55 | #define __ down_cast<X86Assembler*>(codegen->GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 56 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86PointerSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 57 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 58 | class NullCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 59 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 60 | explicit NullCheckSlowPathX86(HNullCheck* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 61 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 62 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 63 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 64 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 65 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 66 | // Live registers will be restored in the catch block if caught. |
| 67 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 68 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 69 | x86_codegen->InvokeRuntime(kQuickThrowNullPointer, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 70 | instruction_, |
| 71 | instruction_->GetDexPc(), |
| 72 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 73 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 74 | } |
| 75 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 76 | bool IsFatal() const OVERRIDE { return true; } |
| 77 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 78 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86"; } |
| 79 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 80 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 81 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86); |
| 82 | }; |
| 83 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 84 | class DivZeroCheckSlowPathX86 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 85 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 86 | explicit DivZeroCheckSlowPathX86(HDivZeroCheck* instruction) : SlowPathCode(instruction) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 87 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 88 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 89 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 90 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 91 | x86_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 92 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 93 | } |
| 94 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 95 | bool IsFatal() const OVERRIDE { return true; } |
| 96 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 97 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86"; } |
| 98 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 99 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 100 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86); |
| 101 | }; |
| 102 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 103 | class DivRemMinusOneSlowPathX86 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 104 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 105 | DivRemMinusOneSlowPathX86(HInstruction* instruction, Register reg, bool is_div) |
| 106 | : SlowPathCode(instruction), reg_(reg), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 107 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 108 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 109 | __ Bind(GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 110 | if (is_div_) { |
| 111 | __ negl(reg_); |
| 112 | } else { |
| 113 | __ movl(reg_, Immediate(0)); |
| 114 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 115 | __ jmp(GetExitLabel()); |
| 116 | } |
| 117 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 118 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86"; } |
| 119 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 120 | private: |
| 121 | Register reg_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 122 | bool is_div_; |
| 123 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 124 | }; |
| 125 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 126 | class BoundsCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 127 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 128 | explicit BoundsCheckSlowPathX86(HBoundsCheck* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 129 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 130 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 131 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 132 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 133 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 134 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 135 | // move resolver. |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 136 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 137 | // Live registers will be restored in the catch block if caught. |
| 138 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 139 | } |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 140 | |
| 141 | // Are we using an array length from memory? |
| 142 | HInstruction* array_length = instruction_->InputAt(1); |
| 143 | Location length_loc = locations->InAt(1); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 144 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 145 | if (array_length->IsArrayLength() && array_length->IsEmittedAtUseSite()) { |
| 146 | // Load the array length into our temporary. |
Nicolas Geoffray | 0aff3a8 | 2017-10-13 13:12:36 +0100 | [diff] [blame] | 147 | HArrayLength* length = array_length->AsArrayLength(); |
| 148 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(length); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 149 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 150 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
| 151 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(1)); |
| 152 | // Check for conflicts with index. |
| 153 | if (length_loc.Equals(locations->InAt(0))) { |
| 154 | // We know we aren't using parameter 2. |
| 155 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(2)); |
| 156 | } |
| 157 | __ movl(length_loc.AsRegister<Register>(), array_len); |
Nicolas Geoffray | 0aff3a8 | 2017-10-13 13:12:36 +0100 | [diff] [blame] | 158 | if (mirror::kUseStringCompression && length->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 159 | __ shrl(length_loc.AsRegister<Register>(), Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 160 | } |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 161 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 162 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 163 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 164 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 165 | DataType::Type::kInt32, |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 166 | length_loc, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 167 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 168 | DataType::Type::kInt32); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 169 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 170 | ? kQuickThrowStringBounds |
| 171 | : kQuickThrowArrayBounds; |
| 172 | x86_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 173 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 174 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 175 | } |
| 176 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 177 | bool IsFatal() const OVERRIDE { return true; } |
| 178 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 179 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86"; } |
| 180 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 181 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 182 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86); |
| 183 | }; |
| 184 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 185 | class SuspendCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 186 | public: |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 187 | SuspendCheckSlowPathX86(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 188 | : SlowPathCode(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 189 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 190 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 191 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 192 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 193 | __ Bind(GetEntryLabel()); |
Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 194 | SaveLiveRegisters(codegen, locations); // Only saves full width XMM for SIMD. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 195 | x86_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 196 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 197 | RestoreLiveRegisters(codegen, locations); // Only restores full width XMM for SIMD. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 198 | if (successor_ == nullptr) { |
| 199 | __ jmp(GetReturnLabel()); |
| 200 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 201 | __ jmp(x86_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 202 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 203 | } |
| 204 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 205 | Label* GetReturnLabel() { |
| 206 | DCHECK(successor_ == nullptr); |
| 207 | return &return_label_; |
| 208 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 209 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 210 | HBasicBlock* GetSuccessor() const { |
| 211 | return successor_; |
| 212 | } |
| 213 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 214 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86"; } |
| 215 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 216 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 217 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 218 | Label return_label_; |
| 219 | |
| 220 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86); |
| 221 | }; |
| 222 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 223 | class LoadStringSlowPathX86 : public SlowPathCode { |
| 224 | public: |
| 225 | explicit LoadStringSlowPathX86(HLoadString* instruction): SlowPathCode(instruction) {} |
| 226 | |
| 227 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 228 | LocationSummary* locations = instruction_->GetLocations(); |
| 229 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 230 | |
| 231 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 232 | __ Bind(GetEntryLabel()); |
| 233 | SaveLiveRegisters(codegen, locations); |
| 234 | |
| 235 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 236 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 237 | __ movl(calling_convention.GetRegisterAt(0), Immediate(string_index.index_)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 238 | x86_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 239 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 240 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 241 | RestoreLiveRegisters(codegen, locations); |
| 242 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 243 | __ jmp(GetExitLabel()); |
| 244 | } |
| 245 | |
| 246 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86"; } |
| 247 | |
| 248 | private: |
| 249 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86); |
| 250 | }; |
| 251 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 252 | class LoadClassSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 253 | public: |
| 254 | LoadClassSlowPathX86(HLoadClass* cls, |
| 255 | HInstruction* at, |
| 256 | uint32_t dex_pc, |
| 257 | bool do_clinit) |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 258 | : SlowPathCode(at), cls_(cls), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 259 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 260 | } |
| 261 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 262 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 263 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 264 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 265 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 266 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 267 | |
| 268 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 269 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 270 | __ movl(calling_convention.GetRegisterAt(0), Immediate(type_index.index_)); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 271 | x86_codegen->InvokeRuntime(do_clinit_ ? kQuickInitializeStaticStorage |
| 272 | : kQuickInitializeType, |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 273 | instruction_, |
| 274 | dex_pc_, |
| 275 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 276 | if (do_clinit_) { |
| 277 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 278 | } else { |
| 279 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 280 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 281 | |
| 282 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 283 | Location out = locations->Out(); |
| 284 | if (out.IsValid()) { |
| 285 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 286 | x86_codegen->Move32(out, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 287 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 288 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 289 | __ jmp(GetExitLabel()); |
| 290 | } |
| 291 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 292 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86"; } |
| 293 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 294 | private: |
| 295 | // The class this slow path will load. |
| 296 | HLoadClass* const cls_; |
| 297 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 298 | // The dex PC of `at_`. |
| 299 | const uint32_t dex_pc_; |
| 300 | |
| 301 | // Whether to initialize the class. |
| 302 | const bool do_clinit_; |
| 303 | |
| 304 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86); |
| 305 | }; |
| 306 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 307 | class TypeCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 308 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 309 | TypeCheckSlowPathX86(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 310 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 311 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 312 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 313 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 314 | DCHECK(instruction_->IsCheckCast() |
| 315 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 316 | |
| 317 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 318 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 319 | |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 320 | if (kPoisonHeapReferences && |
| 321 | instruction_->IsCheckCast() && |
| 322 | instruction_->AsCheckCast()->GetTypeCheckKind() == TypeCheckKind::kInterfaceCheck) { |
| 323 | // First, unpoison the `cls` reference that was poisoned for direct memory comparison. |
| 324 | __ UnpoisonHeapReference(locations->InAt(1).AsRegister<Register>()); |
| 325 | } |
| 326 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 327 | if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 328 | SaveLiveRegisters(codegen, locations); |
| 329 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 330 | |
| 331 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 332 | // move resolver. |
| 333 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 334 | x86_codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 335 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 336 | DataType::Type::kReference, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 337 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 338 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 339 | DataType::Type::kReference); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 340 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 341 | x86_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 342 | instruction_, |
| 343 | instruction_->GetDexPc(), |
| 344 | this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 345 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 346 | } else { |
| 347 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 348 | x86_codegen->InvokeRuntime(kQuickCheckInstanceOf, |
| 349 | instruction_, |
| 350 | instruction_->GetDexPc(), |
| 351 | this); |
| 352 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 353 | } |
| 354 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 355 | if (!is_fatal_) { |
| 356 | if (instruction_->IsInstanceOf()) { |
| 357 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 358 | } |
| 359 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 360 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 361 | __ jmp(GetExitLabel()); |
| 362 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 363 | } |
| 364 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 365 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86"; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 366 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 367 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 368 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 369 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 370 | |
| 371 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86); |
| 372 | }; |
| 373 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 374 | class DeoptimizationSlowPathX86 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 375 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 376 | explicit DeoptimizationSlowPathX86(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 377 | : SlowPathCode(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 378 | |
| 379 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 380 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 381 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 382 | LocationSummary* locations = instruction_->GetLocations(); |
| 383 | SaveLiveRegisters(codegen, locations); |
| 384 | InvokeRuntimeCallingConvention calling_convention; |
| 385 | x86_codegen->Load32BitValue( |
| 386 | calling_convention.GetRegisterAt(0), |
| 387 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 388 | x86_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 389 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 390 | } |
| 391 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 392 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86"; } |
| 393 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 394 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 395 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86); |
| 396 | }; |
| 397 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 398 | class ArraySetSlowPathX86 : public SlowPathCode { |
| 399 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 400 | explicit ArraySetSlowPathX86(HInstruction* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 401 | |
| 402 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 403 | LocationSummary* locations = instruction_->GetLocations(); |
| 404 | __ Bind(GetEntryLabel()); |
| 405 | SaveLiveRegisters(codegen, locations); |
| 406 | |
| 407 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 408 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 409 | parallel_move.AddMove( |
| 410 | locations->InAt(0), |
| 411 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 412 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 413 | nullptr); |
| 414 | parallel_move.AddMove( |
| 415 | locations->InAt(1), |
| 416 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 417 | DataType::Type::kInt32, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 418 | nullptr); |
| 419 | parallel_move.AddMove( |
| 420 | locations->InAt(2), |
| 421 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 422 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 423 | nullptr); |
| 424 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 425 | |
| 426 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 427 | x86_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 428 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 429 | RestoreLiveRegisters(codegen, locations); |
| 430 | __ jmp(GetExitLabel()); |
| 431 | } |
| 432 | |
| 433 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86"; } |
| 434 | |
| 435 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 436 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86); |
| 437 | }; |
| 438 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 439 | // Slow path marking an object reference `ref` during a read |
| 440 | // barrier. The field `obj.field` in the object `obj` holding this |
| 441 | // reference does not get updated by this slow path after marking (see |
| 442 | // ReadBarrierMarkAndUpdateFieldSlowPathX86 below for that). |
| 443 | // |
| 444 | // This means that after the execution of this slow path, `ref` will |
| 445 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 446 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 447 | // probably still be a from-space reference (unless it gets updated by |
| 448 | // another thread, or if another thread installed another object |
| 449 | // reference (different from `ref`) in `obj.field`). |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 450 | class ReadBarrierMarkSlowPathX86 : public SlowPathCode { |
| 451 | public: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 452 | ReadBarrierMarkSlowPathX86(HInstruction* instruction, |
| 453 | Location ref, |
| 454 | bool unpoison_ref_before_marking) |
| 455 | : SlowPathCode(instruction), |
| 456 | ref_(ref), |
| 457 | unpoison_ref_before_marking_(unpoison_ref_before_marking) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 458 | DCHECK(kEmitCompilerReadBarrier); |
| 459 | } |
| 460 | |
| 461 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathX86"; } |
| 462 | |
| 463 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 464 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 465 | Register ref_reg = ref_.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 466 | DCHECK(locations->CanCall()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 467 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 468 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 469 | instruction_->IsStaticFieldGet() || |
| 470 | instruction_->IsArrayGet() || |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 471 | instruction_->IsArraySet() || |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 472 | instruction_->IsLoadClass() || |
| 473 | instruction_->IsLoadString() || |
| 474 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 475 | instruction_->IsCheckCast() || |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 476 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 477 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 478 | << "Unexpected instruction in read barrier marking slow path: " |
| 479 | << instruction_->DebugName(); |
| 480 | |
| 481 | __ Bind(GetEntryLabel()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 482 | if (unpoison_ref_before_marking_) { |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 483 | // Object* ref = ref_addr->AsMirrorPtr() |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 484 | __ MaybeUnpoisonHeapReference(ref_reg); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 485 | } |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 486 | // No need to save live registers; it's taken care of by the |
| 487 | // entrypoint. Also, there is no need to update the stack mask, |
| 488 | // as this runtime call will not trigger a garbage collection. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 489 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 490 | DCHECK_NE(ref_reg, ESP); |
| 491 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 492 | // "Compact" slow path, saving two moves. |
| 493 | // |
| 494 | // Instead of using the standard runtime calling convention (input |
| 495 | // and output in EAX): |
| 496 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 497 | // EAX <- ref |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 498 | // EAX <- ReadBarrierMark(EAX) |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 499 | // ref <- EAX |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 500 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 501 | // we just use rX (the register containing `ref`) as input and output |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 502 | // of a dedicated entrypoint: |
| 503 | // |
| 504 | // rX <- ReadBarrierMarkRegX(rX) |
| 505 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 506 | int32_t entry_point_offset = Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(ref_reg); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 507 | // This runtime call does not require a stack map. |
| 508 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 509 | __ jmp(GetExitLabel()); |
| 510 | } |
| 511 | |
| 512 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 513 | // The location (register) of the marked object reference. |
| 514 | const Location ref_; |
| 515 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 516 | const bool unpoison_ref_before_marking_; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 517 | |
| 518 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86); |
| 519 | }; |
| 520 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 521 | // Slow path marking an object reference `ref` during a read barrier, |
| 522 | // and if needed, atomically updating the field `obj.field` in the |
| 523 | // object `obj` holding this reference after marking (contrary to |
| 524 | // ReadBarrierMarkSlowPathX86 above, which never tries to update |
| 525 | // `obj.field`). |
| 526 | // |
| 527 | // This means that after the execution of this slow path, both `ref` |
| 528 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 529 | // hold the same to-space reference (unless another thread installed |
| 530 | // another object reference (different from `ref`) in `obj.field`). |
| 531 | class ReadBarrierMarkAndUpdateFieldSlowPathX86 : public SlowPathCode { |
| 532 | public: |
| 533 | ReadBarrierMarkAndUpdateFieldSlowPathX86(HInstruction* instruction, |
| 534 | Location ref, |
| 535 | Register obj, |
| 536 | const Address& field_addr, |
| 537 | bool unpoison_ref_before_marking, |
| 538 | Register temp) |
| 539 | : SlowPathCode(instruction), |
| 540 | ref_(ref), |
| 541 | obj_(obj), |
| 542 | field_addr_(field_addr), |
| 543 | unpoison_ref_before_marking_(unpoison_ref_before_marking), |
| 544 | temp_(temp) { |
| 545 | DCHECK(kEmitCompilerReadBarrier); |
| 546 | } |
| 547 | |
| 548 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkAndUpdateFieldSlowPathX86"; } |
| 549 | |
| 550 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 551 | LocationSummary* locations = instruction_->GetLocations(); |
| 552 | Register ref_reg = ref_.AsRegister<Register>(); |
| 553 | DCHECK(locations->CanCall()); |
| 554 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 555 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 556 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 557 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 558 | << instruction_->DebugName(); |
| 559 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 560 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 561 | |
| 562 | __ Bind(GetEntryLabel()); |
| 563 | if (unpoison_ref_before_marking_) { |
| 564 | // Object* ref = ref_addr->AsMirrorPtr() |
| 565 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 566 | } |
| 567 | |
| 568 | // Save the old (unpoisoned) reference. |
| 569 | __ movl(temp_, ref_reg); |
| 570 | |
| 571 | // No need to save live registers; it's taken care of by the |
| 572 | // entrypoint. Also, there is no need to update the stack mask, |
| 573 | // as this runtime call will not trigger a garbage collection. |
| 574 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 575 | DCHECK_NE(ref_reg, ESP); |
| 576 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
| 577 | // "Compact" slow path, saving two moves. |
| 578 | // |
| 579 | // Instead of using the standard runtime calling convention (input |
| 580 | // and output in EAX): |
| 581 | // |
| 582 | // EAX <- ref |
| 583 | // EAX <- ReadBarrierMark(EAX) |
| 584 | // ref <- EAX |
| 585 | // |
| 586 | // we just use rX (the register containing `ref`) as input and output |
| 587 | // of a dedicated entrypoint: |
| 588 | // |
| 589 | // rX <- ReadBarrierMarkRegX(rX) |
| 590 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 591 | int32_t entry_point_offset = Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(ref_reg); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 592 | // This runtime call does not require a stack map. |
| 593 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 594 | |
| 595 | // If the new reference is different from the old reference, |
| 596 | // update the field in the holder (`*field_addr`). |
| 597 | // |
| 598 | // Note that this field could also hold a different object, if |
| 599 | // another thread had concurrently changed it. In that case, the |
| 600 | // LOCK CMPXCHGL instruction in the compare-and-set (CAS) |
| 601 | // operation below would abort the CAS, leaving the field as-is. |
| 602 | NearLabel done; |
| 603 | __ cmpl(temp_, ref_reg); |
| 604 | __ j(kEqual, &done); |
| 605 | |
| 606 | // Update the the holder's field atomically. This may fail if |
| 607 | // mutator updates before us, but it's OK. This is achieved |
| 608 | // using a strong compare-and-set (CAS) operation with relaxed |
| 609 | // memory synchronization ordering, where the expected value is |
| 610 | // the old reference and the desired value is the new reference. |
| 611 | // This operation is implemented with a 32-bit LOCK CMPXLCHG |
| 612 | // instruction, which requires the expected value (the old |
| 613 | // reference) to be in EAX. Save EAX beforehand, and move the |
| 614 | // expected value (stored in `temp_`) into EAX. |
| 615 | __ pushl(EAX); |
| 616 | __ movl(EAX, temp_); |
| 617 | |
| 618 | // Convenience aliases. |
| 619 | Register base = obj_; |
| 620 | Register expected = EAX; |
| 621 | Register value = ref_reg; |
| 622 | |
| 623 | bool base_equals_value = (base == value); |
| 624 | if (kPoisonHeapReferences) { |
| 625 | if (base_equals_value) { |
| 626 | // If `base` and `value` are the same register location, move |
| 627 | // `value` to a temporary register. This way, poisoning |
| 628 | // `value` won't invalidate `base`. |
| 629 | value = temp_; |
| 630 | __ movl(value, base); |
| 631 | } |
| 632 | |
| 633 | // Check that the register allocator did not assign the location |
| 634 | // of `expected` (EAX) to `value` nor to `base`, so that heap |
| 635 | // poisoning (when enabled) works as intended below. |
| 636 | // - If `value` were equal to `expected`, both references would |
| 637 | // be poisoned twice, meaning they would not be poisoned at |
| 638 | // all, as heap poisoning uses address negation. |
| 639 | // - If `base` were equal to `expected`, poisoning `expected` |
| 640 | // would invalidate `base`. |
| 641 | DCHECK_NE(value, expected); |
| 642 | DCHECK_NE(base, expected); |
| 643 | |
| 644 | __ PoisonHeapReference(expected); |
| 645 | __ PoisonHeapReference(value); |
| 646 | } |
| 647 | |
| 648 | __ LockCmpxchgl(field_addr_, value); |
| 649 | |
| 650 | // If heap poisoning is enabled, we need to unpoison the values |
| 651 | // that were poisoned earlier. |
| 652 | if (kPoisonHeapReferences) { |
| 653 | if (base_equals_value) { |
| 654 | // `value` has been moved to a temporary register, no need |
| 655 | // to unpoison it. |
| 656 | } else { |
| 657 | __ UnpoisonHeapReference(value); |
| 658 | } |
| 659 | // No need to unpoison `expected` (EAX), as it is be overwritten below. |
| 660 | } |
| 661 | |
| 662 | // Restore EAX. |
| 663 | __ popl(EAX); |
| 664 | |
| 665 | __ Bind(&done); |
| 666 | __ jmp(GetExitLabel()); |
| 667 | } |
| 668 | |
| 669 | private: |
| 670 | // The location (register) of the marked object reference. |
| 671 | const Location ref_; |
| 672 | // The register containing the object holding the marked object reference field. |
| 673 | const Register obj_; |
| 674 | // The address of the marked reference field. The base of this address must be `obj_`. |
| 675 | const Address field_addr_; |
| 676 | |
| 677 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 678 | const bool unpoison_ref_before_marking_; |
| 679 | |
| 680 | const Register temp_; |
| 681 | |
| 682 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathX86); |
| 683 | }; |
| 684 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 685 | // Slow path generating a read barrier for a heap reference. |
| 686 | class ReadBarrierForHeapReferenceSlowPathX86 : public SlowPathCode { |
| 687 | public: |
| 688 | ReadBarrierForHeapReferenceSlowPathX86(HInstruction* instruction, |
| 689 | Location out, |
| 690 | Location ref, |
| 691 | Location obj, |
| 692 | uint32_t offset, |
| 693 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 694 | : SlowPathCode(instruction), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 695 | out_(out), |
| 696 | ref_(ref), |
| 697 | obj_(obj), |
| 698 | offset_(offset), |
| 699 | index_(index) { |
| 700 | DCHECK(kEmitCompilerReadBarrier); |
| 701 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 702 | // has been overwritten by (or after) the heap object reference load |
| 703 | // to be instrumented, e.g.: |
| 704 | // |
| 705 | // __ movl(out, Address(out, offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 706 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 707 | // |
| 708 | // In that case, we have lost the information about the original |
| 709 | // object, and the emitted read barrier cannot work properly. |
| 710 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 711 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 712 | } |
| 713 | |
| 714 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 715 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 716 | LocationSummary* locations = instruction_->GetLocations(); |
| 717 | Register reg_out = out_.AsRegister<Register>(); |
| 718 | DCHECK(locations->CanCall()); |
| 719 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 720 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 721 | instruction_->IsStaticFieldGet() || |
| 722 | instruction_->IsArrayGet() || |
| 723 | instruction_->IsInstanceOf() || |
| 724 | instruction_->IsCheckCast() || |
Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 725 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 726 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 727 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 728 | |
| 729 | __ Bind(GetEntryLabel()); |
| 730 | SaveLiveRegisters(codegen, locations); |
| 731 | |
| 732 | // We may have to change the index's value, but as `index_` is a |
| 733 | // constant member (like other "inputs" of this slow path), |
| 734 | // introduce a copy of it, `index`. |
| 735 | Location index = index_; |
| 736 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 737 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 738 | if (instruction_->IsArrayGet()) { |
| 739 | // Compute the actual memory offset and store it in `index`. |
| 740 | Register index_reg = index_.AsRegister<Register>(); |
| 741 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 742 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 743 | // We are about to change the value of `index_reg` (see the |
| 744 | // calls to art::x86::X86Assembler::shll and |
| 745 | // art::x86::X86Assembler::AddImmediate below), but it has |
| 746 | // not been saved by the previous call to |
| 747 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 748 | // callee-save register -- |
| 749 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 750 | // callee-save registers, as it has been designed with the |
| 751 | // assumption that callee-save registers are supposed to be |
| 752 | // handled by the called function. So, as a callee-save |
| 753 | // register, `index_reg` _would_ eventually be saved onto |
| 754 | // the stack, but it would be too late: we would have |
| 755 | // changed its value earlier. Therefore, we manually save |
| 756 | // it here into another freely available register, |
| 757 | // `free_reg`, chosen of course among the caller-save |
| 758 | // registers (as a callee-save `free_reg` register would |
| 759 | // exhibit the same problem). |
| 760 | // |
| 761 | // Note we could have requested a temporary register from |
| 762 | // the register allocator instead; but we prefer not to, as |
| 763 | // this is a slow path, and we know we can find a |
| 764 | // caller-save register that is available. |
| 765 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 766 | __ movl(free_reg, index_reg); |
| 767 | index_reg = free_reg; |
| 768 | index = Location::RegisterLocation(index_reg); |
| 769 | } else { |
| 770 | // The initial register stored in `index_` has already been |
| 771 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 772 | // (as it is not a callee-save register), so we can freely |
| 773 | // use it. |
| 774 | } |
| 775 | // Shifting the index value contained in `index_reg` by the scale |
| 776 | // factor (2) cannot overflow in practice, as the runtime is |
| 777 | // unable to allocate object arrays with a size larger than |
| 778 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 779 | __ shll(index_reg, Immediate(TIMES_4)); |
| 780 | static_assert( |
| 781 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 782 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 783 | __ AddImmediate(index_reg, Immediate(offset_)); |
| 784 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 785 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 786 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 787 | // (as in the case of ArrayGet), as it is actually an offset |
| 788 | // to an object field within an object. |
| 789 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 790 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 791 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 792 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 793 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 794 | DCHECK_EQ(offset_, 0U); |
| 795 | DCHECK(index_.IsRegisterPair()); |
| 796 | // UnsafeGet's offset location is a register pair, the low |
| 797 | // part contains the correct offset. |
| 798 | index = index_.ToLow(); |
| 799 | } |
| 800 | } |
| 801 | |
| 802 | // We're moving two or three locations to locations that could |
| 803 | // overlap, so we need a parallel move resolver. |
| 804 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 805 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 806 | parallel_move.AddMove(ref_, |
| 807 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 808 | DataType::Type::kReference, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 809 | nullptr); |
| 810 | parallel_move.AddMove(obj_, |
| 811 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 812 | DataType::Type::kReference, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 813 | nullptr); |
| 814 | if (index.IsValid()) { |
| 815 | parallel_move.AddMove(index, |
| 816 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 817 | DataType::Type::kInt32, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 818 | nullptr); |
| 819 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 820 | } else { |
| 821 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 822 | __ movl(calling_convention.GetRegisterAt(2), Immediate(offset_)); |
| 823 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 824 | x86_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 825 | CheckEntrypointTypes< |
| 826 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 827 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 828 | |
| 829 | RestoreLiveRegisters(codegen, locations); |
| 830 | __ jmp(GetExitLabel()); |
| 831 | } |
| 832 | |
| 833 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathX86"; } |
| 834 | |
| 835 | private: |
| 836 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 837 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 838 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 839 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 840 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 841 | return static_cast<Register>(i); |
| 842 | } |
| 843 | } |
| 844 | // We shall never fail to find a free caller-save register, as |
| 845 | // there are more than two core caller-save registers on x86 |
| 846 | // (meaning it is possible to find one which is different from |
| 847 | // `ref` and `obj`). |
| 848 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 849 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 850 | UNREACHABLE(); |
| 851 | } |
| 852 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 853 | const Location out_; |
| 854 | const Location ref_; |
| 855 | const Location obj_; |
| 856 | const uint32_t offset_; |
| 857 | // An additional location containing an index to an array. |
| 858 | // Only used for HArrayGet and the UnsafeGetObject & |
| 859 | // UnsafeGetObjectVolatile intrinsics. |
| 860 | const Location index_; |
| 861 | |
| 862 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86); |
| 863 | }; |
| 864 | |
| 865 | // Slow path generating a read barrier for a GC root. |
| 866 | class ReadBarrierForRootSlowPathX86 : public SlowPathCode { |
| 867 | public: |
| 868 | ReadBarrierForRootSlowPathX86(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 869 | : SlowPathCode(instruction), out_(out), root_(root) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 870 | DCHECK(kEmitCompilerReadBarrier); |
| 871 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 872 | |
| 873 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 874 | LocationSummary* locations = instruction_->GetLocations(); |
| 875 | Register reg_out = out_.AsRegister<Register>(); |
| 876 | DCHECK(locations->CanCall()); |
| 877 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 878 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 879 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 880 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 881 | |
| 882 | __ Bind(GetEntryLabel()); |
| 883 | SaveLiveRegisters(codegen, locations); |
| 884 | |
| 885 | InvokeRuntimeCallingConvention calling_convention; |
| 886 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 887 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 888 | x86_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 889 | instruction_, |
| 890 | instruction_->GetDexPc(), |
| 891 | this); |
| 892 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 893 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 894 | |
| 895 | RestoreLiveRegisters(codegen, locations); |
| 896 | __ jmp(GetExitLabel()); |
| 897 | } |
| 898 | |
| 899 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathX86"; } |
| 900 | |
| 901 | private: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 902 | const Location out_; |
| 903 | const Location root_; |
| 904 | |
| 905 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86); |
| 906 | }; |
| 907 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 908 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 909 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 910 | #define __ down_cast<X86Assembler*>(GetAssembler())-> // NOLINT |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 911 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 912 | inline Condition X86Condition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 913 | switch (cond) { |
| 914 | case kCondEQ: return kEqual; |
| 915 | case kCondNE: return kNotEqual; |
| 916 | case kCondLT: return kLess; |
| 917 | case kCondLE: return kLessEqual; |
| 918 | case kCondGT: return kGreater; |
| 919 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 920 | case kCondB: return kBelow; |
| 921 | case kCondBE: return kBelowEqual; |
| 922 | case kCondA: return kAbove; |
| 923 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 924 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 925 | LOG(FATAL) << "Unreachable"; |
| 926 | UNREACHABLE(); |
| 927 | } |
| 928 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 929 | // Maps signed condition to unsigned condition and FP condition to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 930 | inline Condition X86UnsignedOrFPCondition(IfCondition cond) { |
| 931 | switch (cond) { |
| 932 | case kCondEQ: return kEqual; |
| 933 | case kCondNE: return kNotEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 934 | // Signed to unsigned, and FP to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 935 | case kCondLT: return kBelow; |
| 936 | case kCondLE: return kBelowEqual; |
| 937 | case kCondGT: return kAbove; |
| 938 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 939 | // Unsigned remain unchanged. |
| 940 | case kCondB: return kBelow; |
| 941 | case kCondBE: return kBelowEqual; |
| 942 | case kCondA: return kAbove; |
| 943 | case kCondAE: return kAboveEqual; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 944 | } |
| 945 | LOG(FATAL) << "Unreachable"; |
| 946 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 947 | } |
| 948 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 949 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 950 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 951 | } |
| 952 | |
| 953 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 954 | stream << XmmRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 955 | } |
| 956 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 957 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 958 | __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); |
| 959 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 960 | } |
| 961 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 962 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 963 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); |
| 964 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 965 | } |
| 966 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 967 | size_t CodeGeneratorX86::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 968 | if (GetGraph()->HasSIMD()) { |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 969 | __ movups(Address(ESP, stack_index), XmmRegister(reg_id)); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 970 | } else { |
| 971 | __ movsd(Address(ESP, stack_index), XmmRegister(reg_id)); |
| 972 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 973 | return GetFloatingPointSpillSlotSize(); |
| 974 | } |
| 975 | |
| 976 | size_t CodeGeneratorX86::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 977 | if (GetGraph()->HasSIMD()) { |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 978 | __ movups(XmmRegister(reg_id), Address(ESP, stack_index)); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 979 | } else { |
| 980 | __ movsd(XmmRegister(reg_id), Address(ESP, stack_index)); |
| 981 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 982 | return GetFloatingPointSpillSlotSize(); |
| 983 | } |
| 984 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 985 | void CodeGeneratorX86::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 986 | HInstruction* instruction, |
| 987 | uint32_t dex_pc, |
| 988 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 989 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 990 | GenerateInvokeRuntime(GetThreadOffset<kX86PointerSize>(entrypoint).Int32Value()); |
| 991 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 992 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 993 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 994 | } |
| 995 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 996 | void CodeGeneratorX86::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 997 | HInstruction* instruction, |
| 998 | SlowPathCode* slow_path) { |
| 999 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1000 | GenerateInvokeRuntime(entry_point_offset); |
| 1001 | } |
| 1002 | |
| 1003 | void CodeGeneratorX86::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1004 | __ fs()->call(Address::Absolute(entry_point_offset)); |
| 1005 | } |
| 1006 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1007 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1008 | const X86InstructionSetFeatures& isa_features, |
| 1009 | const CompilerOptions& compiler_options, |
| 1010 | OptimizingCompilerStats* stats) |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1011 | : CodeGenerator(graph, |
| 1012 | kNumberOfCpuRegisters, |
| 1013 | kNumberOfXmmRegisters, |
| 1014 | kNumberOfRegisterPairs, |
| 1015 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1016 | arraysize(kCoreCalleeSaves)) |
| 1017 | | (1 << kFakeReturnRegister), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1018 | 0, |
| 1019 | compiler_options, |
| 1020 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1021 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1022 | location_builder_(graph, this), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1023 | instruction_visitor_(graph, this), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1024 | move_resolver_(graph->GetAllocator(), this), |
| 1025 | assembler_(graph->GetAllocator()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1026 | isa_features_(isa_features), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1027 | boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1028 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1029 | boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1030 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1031 | boot_image_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1032 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1033 | jit_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1034 | jit_class_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1035 | constant_area_start_(-1), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1036 | fixups_to_jump_tables_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1037 | method_address_offset_(std::less<uint32_t>(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1038 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1039 | // Use a fake return address register to mimic Quick. |
| 1040 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1041 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1042 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1043 | void CodeGeneratorX86::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1044 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1045 | blocked_core_registers_[ESP] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1046 | } |
| 1047 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1048 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1049 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1050 | assembler_(codegen->GetAssembler()), |
| 1051 | codegen_(codegen) {} |
| 1052 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1053 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1054 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1055 | } |
| 1056 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1057 | void CodeGeneratorX86::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1058 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1059 | __ Bind(&frame_entry_label_); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1060 | bool skip_overflow_check = |
| 1061 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1062 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 1063 | |
Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 1064 | if (GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 1065 | __ addw(Address(kMethodRegisterArgument, ArtMethod::HotnessCountOffset().Int32Value()), |
| 1066 | Immediate(1)); |
| 1067 | } |
| 1068 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1069 | if (!skip_overflow_check) { |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1070 | size_t reserved_bytes = GetStackOverflowReservedBytes(InstructionSet::kX86); |
| 1071 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(reserved_bytes))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1072 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 1073 | } |
| 1074 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1075 | if (HasEmptyFrame()) { |
| 1076 | return; |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1077 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1078 | |
| 1079 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 1080 | Register reg = kCoreCalleeSaves[i]; |
| 1081 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1082 | __ pushl(reg); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1083 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 1084 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1085 | } |
| 1086 | } |
| 1087 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1088 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1089 | __ subl(ESP, Immediate(adjust)); |
| 1090 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1091 | // Save the current method if we need it. Note that we do not |
| 1092 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1093 | // in the SSA graph. |
| 1094 | if (RequiresCurrentMethod()) { |
| 1095 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
| 1096 | } |
Nicolas Geoffray | f789353 | 2017-06-15 12:34:36 +0100 | [diff] [blame] | 1097 | |
| 1098 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1099 | // Initialize should_deoptimize flag to 0. |
| 1100 | __ movl(Address(ESP, GetStackOffsetOfShouldDeoptimizeFlag()), Immediate(0)); |
| 1101 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1102 | } |
| 1103 | |
| 1104 | void CodeGeneratorX86::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1105 | __ cfi().RememberState(); |
| 1106 | if (!HasEmptyFrame()) { |
| 1107 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1108 | __ addl(ESP, Immediate(adjust)); |
| 1109 | __ cfi().AdjustCFAOffset(-adjust); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1110 | |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1111 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1112 | Register reg = kCoreCalleeSaves[i]; |
| 1113 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1114 | __ popl(reg); |
| 1115 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 1116 | __ cfi().Restore(DWARFReg(reg)); |
| 1117 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1118 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1119 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1120 | __ ret(); |
| 1121 | __ cfi().RestoreState(); |
| 1122 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1123 | } |
| 1124 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1125 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 1126 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1127 | } |
| 1128 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1129 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(DataType::Type type) const { |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1130 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1131 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1132 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1133 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1134 | case DataType::Type::kInt8: |
| 1135 | case DataType::Type::kUint16: |
| 1136 | case DataType::Type::kInt16: |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1137 | case DataType::Type::kUint32: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1138 | case DataType::Type::kInt32: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1139 | return Location::RegisterLocation(EAX); |
| 1140 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1141 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1142 | case DataType::Type::kInt64: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1143 | return Location::RegisterPairLocation(EAX, EDX); |
| 1144 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1145 | case DataType::Type::kVoid: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1146 | return Location::NoLocation(); |
| 1147 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1148 | case DataType::Type::kFloat64: |
| 1149 | case DataType::Type::kFloat32: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1150 | return Location::FpuRegisterLocation(XMM0); |
| 1151 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1152 | |
| 1153 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1154 | } |
| 1155 | |
| 1156 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 1157 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1158 | } |
| 1159 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1160 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(DataType::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1161 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1162 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1163 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1164 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1165 | case DataType::Type::kInt8: |
| 1166 | case DataType::Type::kUint16: |
| 1167 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1168 | case DataType::Type::kInt32: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1169 | uint32_t index = gp_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1170 | stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1171 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1172 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1173 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1174 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1175 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1176 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1177 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1178 | case DataType::Type::kInt64: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1179 | uint32_t index = gp_index_; |
| 1180 | gp_index_ += 2; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1181 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1182 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1183 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 1184 | calling_convention.GetRegisterPairAt(index)); |
| 1185 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1186 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1187 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1188 | } |
| 1189 | } |
| 1190 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1191 | case DataType::Type::kFloat32: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1192 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1193 | stack_index_++; |
| 1194 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1195 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1196 | } else { |
| 1197 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1198 | } |
| 1199 | } |
| 1200 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1201 | case DataType::Type::kFloat64: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1202 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1203 | stack_index_ += 2; |
| 1204 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1205 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1206 | } else { |
| 1207 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1208 | } |
| 1209 | } |
| 1210 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1211 | case DataType::Type::kUint32: |
| 1212 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1213 | case DataType::Type::kVoid: |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1214 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1215 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1216 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1217 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1218 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1219 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1220 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 1221 | if (source.Equals(destination)) { |
| 1222 | return; |
| 1223 | } |
| 1224 | if (destination.IsRegister()) { |
| 1225 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1226 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1227 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1228 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1229 | } else { |
| 1230 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1231 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1232 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1233 | } else if (destination.IsFpuRegister()) { |
| 1234 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1235 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1236 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1237 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1238 | } else { |
| 1239 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1240 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1241 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1242 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1243 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1244 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1245 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1246 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1247 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1248 | } else if (source.IsConstant()) { |
| 1249 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1250 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1251 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1252 | } else { |
| 1253 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1254 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 1255 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1256 | } |
| 1257 | } |
| 1258 | } |
| 1259 | |
| 1260 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 1261 | if (source.Equals(destination)) { |
| 1262 | return; |
| 1263 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1264 | if (destination.IsRegisterPair()) { |
| 1265 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1266 | EmitParallelMoves( |
| 1267 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1268 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1269 | DataType::Type::kInt32, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1270 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1271 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1272 | DataType::Type::kInt32); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1273 | } else if (source.IsFpuRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1274 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 1275 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 1276 | __ psrlq(src_reg, Immediate(32)); |
| 1277 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1278 | } else { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1279 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1280 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1281 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 1282 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1283 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 1284 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1285 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1286 | if (source.IsFpuRegister()) { |
| 1287 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 1288 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1289 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1290 | } else if (source.IsRegisterPair()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1291 | size_t elem_size = DataType::Size(DataType::Type::kInt32); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1292 | // Create stack space for 2 elements. |
| 1293 | __ subl(ESP, Immediate(2 * elem_size)); |
| 1294 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 1295 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 1296 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 1297 | // And remove the temporary stack space we allocated. |
| 1298 | __ addl(ESP, Immediate(2 * elem_size)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1299 | } else { |
| 1300 | LOG(FATAL) << "Unimplemented"; |
| 1301 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1302 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1303 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1304 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1305 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1306 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1307 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1308 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1309 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1310 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1311 | } else if (source.IsConstant()) { |
| 1312 | HConstant* constant = source.GetConstant(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1313 | DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant()); |
| 1314 | int64_t value = GetInt64ValueOf(constant); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1315 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1316 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
| 1317 | Immediate(High32Bits(value))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1318 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1319 | DCHECK(source.IsDoubleStackSlot()) << source; |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1320 | EmitParallelMoves( |
| 1321 | Location::StackSlot(source.GetStackIndex()), |
| 1322 | Location::StackSlot(destination.GetStackIndex()), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1323 | DataType::Type::kInt32, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1324 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1325 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1326 | DataType::Type::kInt32); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1327 | } |
| 1328 | } |
| 1329 | } |
| 1330 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1331 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { |
| 1332 | DCHECK(location.IsRegister()); |
| 1333 | __ movl(location.AsRegister<Register>(), Immediate(value)); |
| 1334 | } |
| 1335 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1336 | void CodeGeneratorX86::MoveLocation(Location dst, Location src, DataType::Type dst_type) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1337 | HParallelMove move(GetGraph()->GetAllocator()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1338 | if (dst_type == DataType::Type::kInt64 && !src.IsConstant() && !src.IsFpuRegister()) { |
| 1339 | move.AddMove(src.ToLow(), dst.ToLow(), DataType::Type::kInt32, nullptr); |
| 1340 | move.AddMove(src.ToHigh(), dst.ToHigh(), DataType::Type::kInt32, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1341 | } else { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1342 | move.AddMove(src, dst, dst_type, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1343 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1344 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1345 | } |
| 1346 | |
| 1347 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1348 | if (location.IsRegister()) { |
| 1349 | locations->AddTemp(location); |
| 1350 | } else if (location.IsRegisterPair()) { |
| 1351 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1352 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1353 | } else { |
| 1354 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1355 | } |
| 1356 | } |
| 1357 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1358 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 1359 | if (successor->IsExitBlock()) { |
| 1360 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 1361 | return; // no code needed |
| 1362 | } |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1363 | |
| 1364 | HBasicBlock* block = got->GetBlock(); |
| 1365 | HInstruction* previous = got->GetPrevious(); |
| 1366 | |
| 1367 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1368 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 1369 | if (codegen_->GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 1370 | __ pushl(EAX); |
| 1371 | __ movl(EAX, Address(ESP, kX86WordSize)); |
| 1372 | __ addw(Address(EAX, ArtMethod::HotnessCountOffset().Int32Value()), Immediate(1)); |
| 1373 | __ popl(EAX); |
| 1374 | } |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1375 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1376 | return; |
| 1377 | } |
| 1378 | |
| 1379 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1380 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1381 | } |
| 1382 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1383 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1384 | } |
| 1385 | } |
| 1386 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1387 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 1388 | got->SetLocations(nullptr); |
| 1389 | } |
| 1390 | |
| 1391 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 1392 | HandleGoto(got, got->GetSuccessor()); |
| 1393 | } |
| 1394 | |
| 1395 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1396 | try_boundary->SetLocations(nullptr); |
| 1397 | } |
| 1398 | |
| 1399 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1400 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1401 | if (!successor->IsExitBlock()) { |
| 1402 | HandleGoto(try_boundary, successor); |
| 1403 | } |
| 1404 | } |
| 1405 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1406 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1407 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1408 | } |
| 1409 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1410 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1411 | } |
| 1412 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1413 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1414 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1415 | LabelType* true_label, |
| 1416 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1417 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1418 | __ j(kUnordered, true_label); |
| 1419 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1420 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1421 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1422 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1423 | } |
| 1424 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1425 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1426 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1427 | LabelType* true_label, |
| 1428 | LabelType* false_label) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1429 | LocationSummary* locations = cond->GetLocations(); |
| 1430 | Location left = locations->InAt(0); |
| 1431 | Location right = locations->InAt(1); |
| 1432 | IfCondition if_cond = cond->GetCondition(); |
| 1433 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1434 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1435 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1436 | IfCondition true_high_cond = if_cond; |
| 1437 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1438 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); // unsigned on lower part |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1439 | |
| 1440 | // Set the conditions for the test, remembering that == needs to be |
| 1441 | // decided using the low words. |
| 1442 | switch (if_cond) { |
| 1443 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1444 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1445 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1446 | break; |
| 1447 | case kCondLT: |
| 1448 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1449 | break; |
| 1450 | case kCondLE: |
| 1451 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1452 | break; |
| 1453 | case kCondGT: |
| 1454 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1455 | break; |
| 1456 | case kCondGE: |
| 1457 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1458 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1459 | case kCondB: |
| 1460 | false_high_cond = kCondA; |
| 1461 | break; |
| 1462 | case kCondBE: |
| 1463 | true_high_cond = kCondB; |
| 1464 | break; |
| 1465 | case kCondA: |
| 1466 | false_high_cond = kCondB; |
| 1467 | break; |
| 1468 | case kCondAE: |
| 1469 | true_high_cond = kCondA; |
| 1470 | break; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1471 | } |
| 1472 | |
| 1473 | if (right.IsConstant()) { |
| 1474 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1475 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1476 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1477 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1478 | codegen_->Compare32BitValue(left_high, val_high); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1479 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1480 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1481 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1482 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1483 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1484 | __ j(X86Condition(true_high_cond), true_label); |
| 1485 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1486 | } |
| 1487 | // Must be equal high, so compare the lows. |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1488 | codegen_->Compare32BitValue(left_low, val_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1489 | } else if (right.IsRegisterPair()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1490 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1491 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1492 | |
| 1493 | __ cmpl(left_high, right_high); |
| 1494 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1495 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1496 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1497 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1498 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1499 | __ j(X86Condition(true_high_cond), true_label); |
| 1500 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1501 | } |
| 1502 | // Must be equal high, so compare the lows. |
| 1503 | __ cmpl(left_low, right_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1504 | } else { |
| 1505 | DCHECK(right.IsDoubleStackSlot()); |
| 1506 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
| 1507 | if (if_cond == kCondNE) { |
| 1508 | __ j(X86Condition(true_high_cond), true_label); |
| 1509 | } else if (if_cond == kCondEQ) { |
| 1510 | __ j(X86Condition(false_high_cond), false_label); |
| 1511 | } else { |
| 1512 | __ j(X86Condition(true_high_cond), true_label); |
| 1513 | __ j(X86Condition(false_high_cond), false_label); |
| 1514 | } |
| 1515 | // Must be equal high, so compare the lows. |
| 1516 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1517 | } |
| 1518 | // The last comparison might be unsigned. |
| 1519 | __ j(final_condition, true_label); |
| 1520 | } |
| 1521 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1522 | void InstructionCodeGeneratorX86::GenerateFPCompare(Location lhs, |
| 1523 | Location rhs, |
| 1524 | HInstruction* insn, |
| 1525 | bool is_double) { |
| 1526 | HX86LoadFromConstantTable* const_area = insn->InputAt(1)->AsX86LoadFromConstantTable(); |
| 1527 | if (is_double) { |
| 1528 | if (rhs.IsFpuRegister()) { |
| 1529 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1530 | } else if (const_area != nullptr) { |
| 1531 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1532 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), |
| 1533 | codegen_->LiteralDoubleAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1534 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 1535 | const_area->GetBaseMethodAddress(), |
| 1536 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1537 | } else { |
| 1538 | DCHECK(rhs.IsDoubleStackSlot()); |
| 1539 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1540 | } |
| 1541 | } else { |
| 1542 | if (rhs.IsFpuRegister()) { |
| 1543 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1544 | } else if (const_area != nullptr) { |
| 1545 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1546 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), |
| 1547 | codegen_->LiteralFloatAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1548 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 1549 | const_area->GetBaseMethodAddress(), |
| 1550 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1551 | } else { |
| 1552 | DCHECK(rhs.IsStackSlot()); |
| 1553 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1554 | } |
| 1555 | } |
| 1556 | } |
| 1557 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1558 | template<class LabelType> |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1559 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1560 | LabelType* true_target_in, |
| 1561 | LabelType* false_target_in) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1562 | // Generated branching requires both targets to be explicit. If either of the |
| 1563 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1564 | LabelType fallthrough_target; |
| 1565 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1566 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1567 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1568 | LocationSummary* locations = condition->GetLocations(); |
| 1569 | Location left = locations->InAt(0); |
| 1570 | Location right = locations->InAt(1); |
| 1571 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1572 | DataType::Type type = condition->InputAt(0)->GetType(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1573 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1574 | case DataType::Type::kInt64: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1575 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1576 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1577 | case DataType::Type::kFloat32: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1578 | GenerateFPCompare(left, right, condition, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1579 | GenerateFPJumps(condition, true_target, false_target); |
| 1580 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1581 | case DataType::Type::kFloat64: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1582 | GenerateFPCompare(left, right, condition, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1583 | GenerateFPJumps(condition, true_target, false_target); |
| 1584 | break; |
| 1585 | default: |
| 1586 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1587 | } |
| 1588 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1589 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1590 | __ jmp(false_target); |
| 1591 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1592 | |
| 1593 | if (fallthrough_target.IsLinked()) { |
| 1594 | __ Bind(&fallthrough_target); |
| 1595 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1596 | } |
| 1597 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1598 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1599 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1600 | // are set only strictly before `branch`. We can't use the eflags on long/FP |
| 1601 | // conditions if they are materialized due to the complex branching. |
| 1602 | return cond->IsCondition() && |
| 1603 | cond->GetNext() == branch && |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1604 | cond->InputAt(0)->GetType() != DataType::Type::kInt64 && |
| 1605 | !DataType::IsFloatingPointType(cond->InputAt(0)->GetType()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1606 | } |
| 1607 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1608 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1609 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1610 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1611 | LabelType* true_target, |
| 1612 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1613 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1614 | |
| 1615 | if (true_target == nullptr && false_target == nullptr) { |
| 1616 | // Nothing to do. The code always falls through. |
| 1617 | return; |
| 1618 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1619 | // Constant condition, statically compared against "true" (integer value 1). |
| 1620 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1621 | if (true_target != nullptr) { |
| 1622 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1623 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1624 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1625 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1626 | if (false_target != nullptr) { |
| 1627 | __ jmp(false_target); |
| 1628 | } |
| 1629 | } |
| 1630 | return; |
| 1631 | } |
| 1632 | |
| 1633 | // The following code generates these patterns: |
| 1634 | // (1) true_target == nullptr && false_target != nullptr |
| 1635 | // - opposite condition true => branch to false_target |
| 1636 | // (2) true_target != nullptr && false_target == nullptr |
| 1637 | // - condition true => branch to true_target |
| 1638 | // (3) true_target != nullptr && false_target != nullptr |
| 1639 | // - condition true => branch to true_target |
| 1640 | // - branch to false_target |
| 1641 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1642 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1643 | if (true_target == nullptr) { |
| 1644 | __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1645 | } else { |
| 1646 | __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); |
| 1647 | } |
| 1648 | } else { |
| 1649 | // Materialized condition, compare against 0. |
| 1650 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1651 | if (lhs.IsRegister()) { |
| 1652 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1653 | } else { |
| 1654 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1655 | } |
| 1656 | if (true_target == nullptr) { |
| 1657 | __ j(kEqual, false_target); |
| 1658 | } else { |
| 1659 | __ j(kNotEqual, true_target); |
| 1660 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1661 | } |
| 1662 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1663 | // Condition has not been materialized, use its inputs as the comparison and |
| 1664 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1665 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1666 | |
| 1667 | // If this is a long or FP comparison that has been folded into |
| 1668 | // the HCondition, generate the comparison directly. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1669 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 1670 | if (type == DataType::Type::kInt64 || DataType::IsFloatingPointType(type)) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1671 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1672 | return; |
| 1673 | } |
| 1674 | |
| 1675 | Location lhs = condition->GetLocations()->InAt(0); |
| 1676 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1677 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition). |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1678 | codegen_->GenerateIntCompare(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1679 | if (true_target == nullptr) { |
| 1680 | __ j(X86Condition(condition->GetOppositeCondition()), false_target); |
| 1681 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1682 | __ j(X86Condition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1683 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1684 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1685 | |
| 1686 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1687 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1688 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1689 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1690 | } |
| 1691 | } |
| 1692 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1693 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1694 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1695 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1696 | locations->SetInAt(0, Location::Any()); |
| 1697 | } |
| 1698 | } |
| 1699 | |
| 1700 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1701 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1702 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1703 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1704 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1705 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1706 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1707 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1708 | } |
| 1709 | |
| 1710 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1711 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1712 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 1713 | InvokeRuntimeCallingConvention calling_convention; |
| 1714 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 1715 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1716 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1717 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1718 | locations->SetInAt(0, Location::Any()); |
| 1719 | } |
| 1720 | } |
| 1721 | |
| 1722 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1723 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1724 | GenerateTestAndBranch<Label>(deoptimize, |
| 1725 | /* condition_input_index */ 0, |
| 1726 | slow_path->GetEntryLabel(), |
| 1727 | /* false_target */ nullptr); |
| 1728 | } |
| 1729 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1730 | void LocationsBuilderX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1731 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1732 | LocationSummary(flag, LocationSummary::kNoCall); |
| 1733 | locations->SetOut(Location::RequiresRegister()); |
| 1734 | } |
| 1735 | |
| 1736 | void InstructionCodeGeneratorX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1737 | __ movl(flag->GetLocations()->Out().AsRegister<Register>(), |
| 1738 | Address(ESP, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1739 | } |
| 1740 | |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1741 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1742 | // There are no conditional move instructions for XMMs. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1743 | if (DataType::IsFloatingPointType(select->GetType())) { |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1744 | return false; |
| 1745 | } |
| 1746 | |
| 1747 | // A FP condition doesn't generate the single CC that we need. |
| 1748 | // In 32 bit mode, a long condition doesn't generate a single CC either. |
| 1749 | HInstruction* condition = select->GetCondition(); |
| 1750 | if (condition->IsCondition()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1751 | DataType::Type compare_type = condition->InputAt(0)->GetType(); |
| 1752 | if (compare_type == DataType::Type::kInt64 || |
| 1753 | DataType::IsFloatingPointType(compare_type)) { |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1754 | return false; |
| 1755 | } |
| 1756 | } |
| 1757 | |
| 1758 | // We can generate a CMOV for this Select. |
| 1759 | return true; |
| 1760 | } |
| 1761 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1762 | void LocationsBuilderX86::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1763 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1764 | if (DataType::IsFloatingPointType(select->GetType())) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1765 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1766 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1767 | } else { |
| 1768 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1769 | if (SelectCanUseCMOV(select)) { |
| 1770 | if (select->InputAt(1)->IsConstant()) { |
| 1771 | // Cmov can't handle a constant value. |
| 1772 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1773 | } else { |
| 1774 | locations->SetInAt(1, Location::Any()); |
| 1775 | } |
| 1776 | } else { |
| 1777 | locations->SetInAt(1, Location::Any()); |
| 1778 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1779 | } |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1780 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1781 | locations->SetInAt(2, Location::RequiresRegister()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1782 | } |
| 1783 | locations->SetOut(Location::SameAsFirstInput()); |
| 1784 | } |
| 1785 | |
| 1786 | void InstructionCodeGeneratorX86::VisitSelect(HSelect* select) { |
| 1787 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1788 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1789 | if (SelectCanUseCMOV(select)) { |
| 1790 | // If both the condition and the source types are integer, we can generate |
| 1791 | // a CMOV to implement Select. |
| 1792 | |
| 1793 | HInstruction* select_condition = select->GetCondition(); |
| 1794 | Condition cond = kNotEqual; |
| 1795 | |
| 1796 | // Figure out how to test the 'condition'. |
| 1797 | if (select_condition->IsCondition()) { |
| 1798 | HCondition* condition = select_condition->AsCondition(); |
| 1799 | if (!condition->IsEmittedAtUseSite()) { |
| 1800 | // This was a previously materialized condition. |
| 1801 | // Can we use the existing condition code? |
| 1802 | if (AreEflagsSetFrom(condition, select)) { |
| 1803 | // Materialization was the previous instruction. Condition codes are right. |
| 1804 | cond = X86Condition(condition->GetCondition()); |
| 1805 | } else { |
| 1806 | // No, we have to recreate the condition code. |
| 1807 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1808 | __ testl(cond_reg, cond_reg); |
| 1809 | } |
| 1810 | } else { |
| 1811 | // We can't handle FP or long here. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1812 | DCHECK_NE(condition->InputAt(0)->GetType(), DataType::Type::kInt64); |
| 1813 | DCHECK(!DataType::IsFloatingPointType(condition->InputAt(0)->GetType())); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1814 | LocationSummary* cond_locations = condition->GetLocations(); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1815 | codegen_->GenerateIntCompare(cond_locations->InAt(0), cond_locations->InAt(1)); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1816 | cond = X86Condition(condition->GetCondition()); |
| 1817 | } |
| 1818 | } else { |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 1819 | // Must be a Boolean condition, which needs to be compared to 0. |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1820 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1821 | __ testl(cond_reg, cond_reg); |
| 1822 | } |
| 1823 | |
| 1824 | // If the condition is true, overwrite the output, which already contains false. |
| 1825 | Location false_loc = locations->InAt(0); |
| 1826 | Location true_loc = locations->InAt(1); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1827 | if (select->GetType() == DataType::Type::kInt64) { |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1828 | // 64 bit conditional move. |
| 1829 | Register false_high = false_loc.AsRegisterPairHigh<Register>(); |
| 1830 | Register false_low = false_loc.AsRegisterPairLow<Register>(); |
| 1831 | if (true_loc.IsRegisterPair()) { |
| 1832 | __ cmovl(cond, false_high, true_loc.AsRegisterPairHigh<Register>()); |
| 1833 | __ cmovl(cond, false_low, true_loc.AsRegisterPairLow<Register>()); |
| 1834 | } else { |
| 1835 | __ cmovl(cond, false_high, Address(ESP, true_loc.GetHighStackIndex(kX86WordSize))); |
| 1836 | __ cmovl(cond, false_low, Address(ESP, true_loc.GetStackIndex())); |
| 1837 | } |
| 1838 | } else { |
| 1839 | // 32 bit conditional move. |
| 1840 | Register false_reg = false_loc.AsRegister<Register>(); |
| 1841 | if (true_loc.IsRegister()) { |
| 1842 | __ cmovl(cond, false_reg, true_loc.AsRegister<Register>()); |
| 1843 | } else { |
| 1844 | __ cmovl(cond, false_reg, Address(ESP, true_loc.GetStackIndex())); |
| 1845 | } |
| 1846 | } |
| 1847 | } else { |
| 1848 | NearLabel false_target; |
| 1849 | GenerateTestAndBranch<NearLabel>( |
| 1850 | select, /* condition_input_index */ 2, /* true_target */ nullptr, &false_target); |
| 1851 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1852 | __ Bind(&false_target); |
| 1853 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1854 | } |
| 1855 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1856 | void LocationsBuilderX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1857 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1858 | } |
| 1859 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1860 | void InstructionCodeGeneratorX86::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1861 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1862 | } |
| 1863 | |
| 1864 | void CodeGeneratorX86::GenerateNop() { |
| 1865 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1866 | } |
| 1867 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1868 | void LocationsBuilderX86::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1869 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1870 | new (GetGraph()->GetAllocator()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1871 | // Handle the long/FP comparisons made in instruction simplification. |
| 1872 | switch (cond->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1873 | case DataType::Type::kInt64: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1874 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1875 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1876 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1877 | locations->SetOut(Location::RequiresRegister()); |
| 1878 | } |
| 1879 | break; |
| 1880 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1881 | case DataType::Type::kFloat32: |
| 1882 | case DataType::Type::kFloat64: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1883 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1884 | if (cond->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 1885 | DCHECK(cond->InputAt(1)->IsEmittedAtUseSite()); |
| 1886 | } else if (cond->InputAt(1)->IsConstant()) { |
| 1887 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1888 | } else { |
| 1889 | locations->SetInAt(1, Location::Any()); |
| 1890 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1891 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1892 | locations->SetOut(Location::RequiresRegister()); |
| 1893 | } |
| 1894 | break; |
| 1895 | } |
| 1896 | default: |
| 1897 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1898 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1899 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1900 | // We need a byte register. |
| 1901 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1902 | } |
| 1903 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1904 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1905 | } |
| 1906 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1907 | void InstructionCodeGeneratorX86::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1908 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1909 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1910 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1911 | |
| 1912 | LocationSummary* locations = cond->GetLocations(); |
| 1913 | Location lhs = locations->InAt(0); |
| 1914 | Location rhs = locations->InAt(1); |
| 1915 | Register reg = locations->Out().AsRegister<Register>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1916 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1917 | |
| 1918 | switch (cond->InputAt(0)->GetType()) { |
| 1919 | default: { |
| 1920 | // Integer case. |
| 1921 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 1922 | // Clear output register: setb only sets the low byte. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1923 | __ xorl(reg, reg); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1924 | codegen_->GenerateIntCompare(lhs, rhs); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1925 | __ setb(X86Condition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1926 | return; |
| 1927 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1928 | case DataType::Type::kInt64: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1929 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1930 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1931 | case DataType::Type::kFloat32: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1932 | GenerateFPCompare(lhs, rhs, cond, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1933 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1934 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1935 | case DataType::Type::kFloat64: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1936 | GenerateFPCompare(lhs, rhs, cond, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1937 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1938 | break; |
| 1939 | } |
| 1940 | |
| 1941 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1942 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1943 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1944 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1945 | __ Bind(&false_label); |
| 1946 | __ xorl(reg, reg); |
| 1947 | __ jmp(&done_label); |
| 1948 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1949 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1950 | __ Bind(&true_label); |
| 1951 | __ movl(reg, Immediate(1)); |
| 1952 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1953 | } |
| 1954 | |
| 1955 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1956 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1957 | } |
| 1958 | |
| 1959 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1960 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1961 | } |
| 1962 | |
| 1963 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1964 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1965 | } |
| 1966 | |
| 1967 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1968 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1969 | } |
| 1970 | |
| 1971 | void LocationsBuilderX86::VisitLessThan(HLessThan* 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::VisitLessThan(HLessThan* 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::VisitLessThanOrEqual(HLessThanOrEqual* 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::VisitLessThanOrEqual(HLessThanOrEqual* 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::VisitGreaterThan(HGreaterThan* 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::VisitGreaterThan(HGreaterThan* 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::VisitGreaterThanOrEqual(HGreaterThanOrEqual* 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::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2000 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2001 | } |
| 2002 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2003 | void LocationsBuilderX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2004 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2005 | } |
| 2006 | |
| 2007 | void InstructionCodeGeneratorX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2008 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2009 | } |
| 2010 | |
| 2011 | void LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2012 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2013 | } |
| 2014 | |
| 2015 | void InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2016 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2017 | } |
| 2018 | |
| 2019 | void LocationsBuilderX86::VisitAbove(HAbove* 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::VisitAbove(HAbove* 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::VisitAboveOrEqual(HAboveOrEqual* 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::VisitAboveOrEqual(HAboveOrEqual* 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 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2035 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2036 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2037 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2038 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2039 | } |
| 2040 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2041 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2042 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2043 | } |
| 2044 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2045 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 2046 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2047 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2048 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2049 | } |
| 2050 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2051 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2052 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2053 | } |
| 2054 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2055 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2056 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2057 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2058 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2059 | } |
| 2060 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2061 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2062 | // Will be generated at use site. |
| 2063 | } |
| 2064 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2065 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 2066 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2067 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2068 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2069 | } |
| 2070 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2071 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2072 | // Will be generated at use site. |
| 2073 | } |
| 2074 | |
| 2075 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2076 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2077 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2078 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2079 | } |
| 2080 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2081 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2082 | // Will be generated at use site. |
| 2083 | } |
| 2084 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2085 | void LocationsBuilderX86::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 2086 | constructor_fence->SetLocations(nullptr); |
| 2087 | } |
| 2088 | |
| 2089 | void InstructionCodeGeneratorX86::VisitConstructorFence( |
| 2090 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 2091 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 2092 | } |
| 2093 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2094 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2095 | memory_barrier->SetLocations(nullptr); |
| 2096 | } |
| 2097 | |
| 2098 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 2099 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2100 | } |
| 2101 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2102 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2103 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2104 | } |
| 2105 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2106 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2107 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2108 | } |
| 2109 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2110 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2111 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2112 | new (GetGraph()->GetAllocator()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2113 | switch (ret->InputAt(0)->GetType()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2114 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2115 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2116 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2117 | case DataType::Type::kInt8: |
| 2118 | case DataType::Type::kUint16: |
| 2119 | case DataType::Type::kInt16: |
| 2120 | case DataType::Type::kInt32: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2121 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2122 | break; |
| 2123 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2124 | case DataType::Type::kInt64: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2125 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2126 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2127 | break; |
| 2128 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2129 | case DataType::Type::kFloat32: |
| 2130 | case DataType::Type::kFloat64: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2131 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2132 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2133 | break; |
| 2134 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2135 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2136 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2137 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2138 | } |
| 2139 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2140 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2141 | if (kIsDebugBuild) { |
| 2142 | switch (ret->InputAt(0)->GetType()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2143 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2144 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2145 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2146 | case DataType::Type::kInt8: |
| 2147 | case DataType::Type::kUint16: |
| 2148 | case DataType::Type::kInt16: |
| 2149 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2150 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2151 | break; |
| 2152 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2153 | case DataType::Type::kInt64: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2154 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 2155 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2156 | break; |
| 2157 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2158 | case DataType::Type::kFloat32: |
| 2159 | case DataType::Type::kFloat64: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2160 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2161 | break; |
| 2162 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2163 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2164 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2165 | } |
| 2166 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2167 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2168 | } |
| 2169 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2170 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2171 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2172 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2173 | // the method_idx. |
| 2174 | HandleInvoke(invoke); |
| 2175 | } |
| 2176 | |
| 2177 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2178 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2179 | } |
| 2180 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2181 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2182 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2183 | // art::PrepareForRegisterAllocation. |
| 2184 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2185 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2186 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2187 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 2188 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeMethodLoadKind()) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 2189 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2190 | } |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2191 | return; |
| 2192 | } |
| 2193 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2194 | HandleInvoke(invoke); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2195 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2196 | // 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] | 2197 | if (invoke->HasPcRelativeMethodLoadKind()) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2198 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2199 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2200 | } |
| 2201 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2202 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 2203 | if (invoke->GetLocations()->Intrinsified()) { |
| 2204 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 2205 | intrinsic.Dispatch(invoke); |
| 2206 | return true; |
| 2207 | } |
| 2208 | return false; |
| 2209 | } |
| 2210 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2211 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2212 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2213 | // art::PrepareForRegisterAllocation. |
| 2214 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2215 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2216 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2217 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2218 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2219 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2220 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2221 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2222 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2223 | } |
| 2224 | |
| 2225 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 2226 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 2227 | if (intrinsic.TryDispatch(invoke)) { |
| 2228 | return; |
| 2229 | } |
| 2230 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2231 | HandleInvoke(invoke); |
| 2232 | } |
| 2233 | |
| 2234 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2235 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2236 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2237 | } |
| 2238 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2239 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2240 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2241 | return; |
| 2242 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2243 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2244 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2245 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2246 | } |
| 2247 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2248 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2249 | // This call to HandleInvoke allocates a temporary (core) register |
| 2250 | // which is also used to transfer the hidden argument from FP to |
| 2251 | // core register. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2252 | HandleInvoke(invoke); |
| 2253 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2254 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2255 | } |
| 2256 | |
| 2257 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2258 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2259 | LocationSummary* locations = invoke->GetLocations(); |
| 2260 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2261 | XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2262 | Location receiver = locations->InAt(0); |
| 2263 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2264 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2265 | // Set the hidden argument. This is safe to do this here, as XMM7 |
| 2266 | // won't be modified thereafter, before the `call` instruction. |
| 2267 | DCHECK_EQ(XMM7, hidden_reg); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2268 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2269 | __ movd(hidden_reg, temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2270 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2271 | if (receiver.IsStackSlot()) { |
| 2272 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2273 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2274 | __ movl(temp, Address(temp, class_offset)); |
| 2275 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2276 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2277 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2278 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2279 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2280 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2281 | // emit a read barrier for the previous class reference load. |
| 2282 | // However this is not required in practice, as this is an |
| 2283 | // intermediate/temporary reference and because the current |
| 2284 | // concurrent copying collector keeps the from-space memory |
| 2285 | // intact/accessible until the end of the marking phase (the |
| 2286 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2287 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2288 | // temp = temp->GetAddressOfIMT() |
| 2289 | __ movl(temp, |
| 2290 | Address(temp, mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2291 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2292 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2293 | invoke->GetImtIndex(), kX86PointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2294 | __ movl(temp, Address(temp, method_offset)); |
| 2295 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2296 | __ call(Address(temp, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2297 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2298 | |
| 2299 | DCHECK(!codegen_->IsLeafMethod()); |
| 2300 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2301 | } |
| 2302 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2303 | void LocationsBuilderX86::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2304 | HandleInvoke(invoke); |
| 2305 | } |
| 2306 | |
| 2307 | void InstructionCodeGeneratorX86::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2308 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 2309 | } |
| 2310 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2311 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 2312 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2313 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2314 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2315 | case DataType::Type::kInt32: |
| 2316 | case DataType::Type::kInt64: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2317 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2318 | locations->SetOut(Location::SameAsFirstInput()); |
| 2319 | break; |
| 2320 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2321 | case DataType::Type::kFloat32: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2322 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2323 | locations->SetOut(Location::SameAsFirstInput()); |
| 2324 | locations->AddTemp(Location::RequiresRegister()); |
| 2325 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2326 | break; |
| 2327 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2328 | case DataType::Type::kFloat64: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2329 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2330 | locations->SetOut(Location::SameAsFirstInput()); |
| 2331 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2332 | break; |
| 2333 | |
| 2334 | default: |
| 2335 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2336 | } |
| 2337 | } |
| 2338 | |
| 2339 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 2340 | LocationSummary* locations = neg->GetLocations(); |
| 2341 | Location out = locations->Out(); |
| 2342 | Location in = locations->InAt(0); |
| 2343 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2344 | case DataType::Type::kInt32: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2345 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2346 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2347 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2348 | break; |
| 2349 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2350 | case DataType::Type::kInt64: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2351 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2352 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2353 | __ negl(out.AsRegisterPairLow<Register>()); |
| 2354 | // Negation is similar to subtraction from zero. The least |
| 2355 | // significant byte triggers a borrow when it is different from |
| 2356 | // zero; to take it into account, add 1 to the most significant |
| 2357 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 2358 | // operation. |
| 2359 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2360 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 2361 | break; |
| 2362 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2363 | case DataType::Type::kFloat32: { |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2364 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2365 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 2366 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2367 | // Implement float negation with an exclusive or with value |
| 2368 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2369 | // single-precision floating-point number). |
| 2370 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 2371 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2372 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2373 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2374 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2375 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2376 | case DataType::Type::kFloat64: { |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2377 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2378 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2379 | // Implement double negation with an exclusive or with value |
| 2380 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 2381 | // a double-precision floating-point number). |
| 2382 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2383 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2384 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2385 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2386 | |
| 2387 | default: |
| 2388 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2389 | } |
| 2390 | } |
| 2391 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2392 | void LocationsBuilderX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2393 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2394 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2395 | DCHECK(DataType::IsFloatingPointType(neg->GetType())); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2396 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2397 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2398 | locations->SetOut(Location::SameAsFirstInput()); |
| 2399 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2400 | } |
| 2401 | |
| 2402 | void InstructionCodeGeneratorX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2403 | LocationSummary* locations = neg->GetLocations(); |
| 2404 | Location out = locations->Out(); |
| 2405 | DCHECK(locations->InAt(0).Equals(out)); |
| 2406 | |
| 2407 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 2408 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2409 | if (neg->GetType() == DataType::Type::kFloat32) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 2410 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x80000000), |
| 2411 | neg->GetBaseMethodAddress(), |
| 2412 | constant_area)); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2413 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| 2414 | } else { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 2415 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000), |
| 2416 | neg->GetBaseMethodAddress(), |
| 2417 | constant_area)); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2418 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| 2419 | } |
| 2420 | } |
| 2421 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2422 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2423 | DataType::Type result_type = conversion->GetResultType(); |
| 2424 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2425 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 2426 | << input_type << " -> " << result_type; |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2427 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2428 | // The float-to-long and double-to-long type conversions rely on a |
| 2429 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2430 | LocationSummary::CallKind call_kind = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2431 | ((input_type == DataType::Type::kFloat32 || input_type == DataType::Type::kFloat64) |
| 2432 | && result_type == DataType::Type::kInt64) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2433 | ? LocationSummary::kCallOnMainOnly |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2434 | : LocationSummary::kNoCall; |
| 2435 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2436 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, call_kind); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2437 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2438 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2439 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2440 | case DataType::Type::kInt8: |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2441 | switch (input_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2442 | case DataType::Type::kUint8: |
| 2443 | case DataType::Type::kInt8: |
| 2444 | case DataType::Type::kUint16: |
| 2445 | case DataType::Type::kInt16: |
| 2446 | case DataType::Type::kInt32: |
| 2447 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 2448 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2449 | // the validation of the linear scan implementation |
| 2450 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2451 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2452 | case DataType::Type::kInt64: { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2453 | HInstruction* input = conversion->InputAt(0); |
| 2454 | Location input_location = input->IsConstant() |
| 2455 | ? Location::ConstantLocation(input->AsConstant()) |
| 2456 | : Location::RegisterPairLocation(EAX, EDX); |
| 2457 | locations->SetInAt(0, input_location); |
| 2458 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2459 | // the validation of the linear scan implementation |
| 2460 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2461 | break; |
| 2462 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2463 | |
| 2464 | default: |
| 2465 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2466 | << " to " << result_type; |
| 2467 | } |
| 2468 | break; |
| 2469 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2470 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2471 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2472 | DCHECK(DataType::IsIntegralType(input_type)) << input_type; |
| 2473 | locations->SetInAt(0, Location::Any()); |
| 2474 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2475 | break; |
| 2476 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2477 | case DataType::Type::kInt32: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2478 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2479 | case DataType::Type::kInt64: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2480 | locations->SetInAt(0, Location::Any()); |
| 2481 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2482 | break; |
| 2483 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2484 | case DataType::Type::kFloat32: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2485 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2486 | locations->SetOut(Location::RequiresRegister()); |
| 2487 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2488 | break; |
| 2489 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2490 | case DataType::Type::kFloat64: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2491 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2492 | locations->SetOut(Location::RequiresRegister()); |
| 2493 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2494 | break; |
| 2495 | |
| 2496 | default: |
| 2497 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2498 | << " to " << result_type; |
| 2499 | } |
| 2500 | break; |
| 2501 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2502 | case DataType::Type::kInt64: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2503 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2504 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2505 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2506 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2507 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2508 | case DataType::Type::kInt16: |
| 2509 | case DataType::Type::kInt32: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2510 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 2511 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2512 | break; |
| 2513 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2514 | case DataType::Type::kFloat32: |
| 2515 | case DataType::Type::kFloat64: { |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2516 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2517 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 2518 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 2519 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2520 | // The runtime helper puts the result in EAX, EDX. |
| 2521 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2522 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2523 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2524 | |
| 2525 | default: |
| 2526 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2527 | << " to " << result_type; |
| 2528 | } |
| 2529 | break; |
| 2530 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2531 | case DataType::Type::kFloat32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2532 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2533 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2534 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2535 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2536 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2537 | case DataType::Type::kInt16: |
| 2538 | case DataType::Type::kInt32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2539 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2540 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2541 | break; |
| 2542 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2543 | case DataType::Type::kInt64: |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2544 | locations->SetInAt(0, Location::Any()); |
| 2545 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2546 | break; |
| 2547 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2548 | case DataType::Type::kFloat64: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2549 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2550 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2551 | break; |
| 2552 | |
| 2553 | default: |
| 2554 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2555 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 2556 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2557 | break; |
| 2558 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2559 | case DataType::Type::kFloat64: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2560 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2561 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2562 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2563 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2564 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2565 | case DataType::Type::kInt16: |
| 2566 | case DataType::Type::kInt32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2567 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2568 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2569 | break; |
| 2570 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2571 | case DataType::Type::kInt64: |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2572 | locations->SetInAt(0, Location::Any()); |
| 2573 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2574 | break; |
| 2575 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2576 | case DataType::Type::kFloat32: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2577 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2578 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2579 | break; |
| 2580 | |
| 2581 | default: |
| 2582 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2583 | << " to " << result_type; |
| 2584 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2585 | break; |
| 2586 | |
| 2587 | default: |
| 2588 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2589 | << " to " << result_type; |
| 2590 | } |
| 2591 | } |
| 2592 | |
| 2593 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 2594 | LocationSummary* locations = conversion->GetLocations(); |
| 2595 | Location out = locations->Out(); |
| 2596 | Location in = locations->InAt(0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2597 | DataType::Type result_type = conversion->GetResultType(); |
| 2598 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2599 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 2600 | << input_type << " -> " << result_type; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2601 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2602 | case DataType::Type::kUint8: |
| 2603 | switch (input_type) { |
| 2604 | case DataType::Type::kInt8: |
| 2605 | case DataType::Type::kUint16: |
| 2606 | case DataType::Type::kInt16: |
| 2607 | case DataType::Type::kInt32: |
| 2608 | if (in.IsRegister()) { |
| 2609 | __ movzxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
| 2610 | } else { |
| 2611 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2612 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2613 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint8_t>(value))); |
| 2614 | } |
| 2615 | break; |
| 2616 | case DataType::Type::kInt64: |
| 2617 | if (in.IsRegisterPair()) { |
| 2618 | __ movzxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 2619 | } else { |
| 2620 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2621 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2622 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint8_t>(value))); |
| 2623 | } |
| 2624 | break; |
| 2625 | |
| 2626 | default: |
| 2627 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2628 | << " to " << result_type; |
| 2629 | } |
| 2630 | break; |
| 2631 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2632 | case DataType::Type::kInt8: |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2633 | switch (input_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2634 | case DataType::Type::kUint8: |
| 2635 | case DataType::Type::kUint16: |
| 2636 | case DataType::Type::kInt16: |
| 2637 | case DataType::Type::kInt32: |
| 2638 | if (in.IsRegister()) { |
| 2639 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
| 2640 | } else { |
| 2641 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2642 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2643 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2644 | } |
| 2645 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2646 | case DataType::Type::kInt64: |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2647 | if (in.IsRegisterPair()) { |
| 2648 | __ movsxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 2649 | } else { |
| 2650 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2651 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2652 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2653 | } |
| 2654 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2655 | |
| 2656 | default: |
| 2657 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2658 | << " to " << result_type; |
| 2659 | } |
| 2660 | break; |
| 2661 | |
| 2662 | case DataType::Type::kUint16: |
| 2663 | switch (input_type) { |
| 2664 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2665 | case DataType::Type::kInt16: |
| 2666 | case DataType::Type::kInt32: |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2667 | if (in.IsRegister()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2668 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
| 2669 | } else if (in.IsStackSlot()) { |
| 2670 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2671 | } else { |
| 2672 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2673 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2674 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
| 2675 | } |
| 2676 | break; |
| 2677 | case DataType::Type::kInt64: |
| 2678 | if (in.IsRegisterPair()) { |
| 2679 | __ movzxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2680 | } else if (in.IsDoubleStackSlot()) { |
| 2681 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2682 | } else { |
| 2683 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2684 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2685 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2686 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2687 | break; |
| 2688 | |
| 2689 | default: |
| 2690 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2691 | << " to " << result_type; |
| 2692 | } |
| 2693 | break; |
| 2694 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2695 | case DataType::Type::kInt16: |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2696 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2697 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2698 | case DataType::Type::kInt32: |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2699 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2700 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2701 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2702 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2703 | } else { |
| 2704 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2705 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2706 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2707 | } |
| 2708 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2709 | case DataType::Type::kInt64: |
| 2710 | if (in.IsRegisterPair()) { |
| 2711 | __ movsxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2712 | } else if (in.IsDoubleStackSlot()) { |
| 2713 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2714 | } else { |
| 2715 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2716 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2717 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
| 2718 | } |
| 2719 | break; |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2720 | |
| 2721 | default: |
| 2722 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2723 | << " to " << result_type; |
| 2724 | } |
| 2725 | break; |
| 2726 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2727 | case DataType::Type::kInt32: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2728 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2729 | case DataType::Type::kInt64: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2730 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2731 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2732 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2733 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2734 | } else { |
| 2735 | DCHECK(in.IsConstant()); |
| 2736 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2737 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2738 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2739 | } |
| 2740 | break; |
| 2741 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2742 | case DataType::Type::kFloat32: { |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2743 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2744 | Register output = out.AsRegister<Register>(); |
| 2745 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2746 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2747 | |
| 2748 | __ movl(output, Immediate(kPrimIntMax)); |
| 2749 | // temp = int-to-float(output) |
| 2750 | __ cvtsi2ss(temp, output); |
| 2751 | // if input >= temp goto done |
| 2752 | __ comiss(input, temp); |
| 2753 | __ j(kAboveEqual, &done); |
| 2754 | // if input == NaN goto nan |
| 2755 | __ j(kUnordered, &nan); |
| 2756 | // output = float-to-int-truncate(input) |
| 2757 | __ cvttss2si(output, input); |
| 2758 | __ jmp(&done); |
| 2759 | __ Bind(&nan); |
| 2760 | // output = 0 |
| 2761 | __ xorl(output, output); |
| 2762 | __ Bind(&done); |
| 2763 | break; |
| 2764 | } |
| 2765 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2766 | case DataType::Type::kFloat64: { |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2767 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2768 | Register output = out.AsRegister<Register>(); |
| 2769 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2770 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2771 | |
| 2772 | __ movl(output, Immediate(kPrimIntMax)); |
| 2773 | // temp = int-to-double(output) |
| 2774 | __ cvtsi2sd(temp, output); |
| 2775 | // if input >= temp goto done |
| 2776 | __ comisd(input, temp); |
| 2777 | __ j(kAboveEqual, &done); |
| 2778 | // if input == NaN goto nan |
| 2779 | __ j(kUnordered, &nan); |
| 2780 | // output = double-to-int-truncate(input) |
| 2781 | __ cvttsd2si(output, input); |
| 2782 | __ jmp(&done); |
| 2783 | __ Bind(&nan); |
| 2784 | // output = 0 |
| 2785 | __ xorl(output, output); |
| 2786 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2787 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2788 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2789 | |
| 2790 | default: |
| 2791 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2792 | << " to " << result_type; |
| 2793 | } |
| 2794 | break; |
| 2795 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2796 | case DataType::Type::kInt64: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2797 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2798 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2799 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2800 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2801 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2802 | case DataType::Type::kInt16: |
| 2803 | case DataType::Type::kInt32: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2804 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2805 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2806 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2807 | __ cdq(); |
| 2808 | break; |
| 2809 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2810 | case DataType::Type::kFloat32: |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2811 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2812 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2813 | break; |
| 2814 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2815 | case DataType::Type::kFloat64: |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2816 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2817 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2818 | break; |
| 2819 | |
| 2820 | default: |
| 2821 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2822 | << " to " << result_type; |
| 2823 | } |
| 2824 | break; |
| 2825 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2826 | case DataType::Type::kFloat32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2827 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2828 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2829 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2830 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2831 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2832 | case DataType::Type::kInt16: |
| 2833 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2834 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2835 | break; |
| 2836 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2837 | case DataType::Type::kInt64: { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2838 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2839 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2840 | // Create stack space for the call to |
| 2841 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2842 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2843 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2844 | adjustment = DataType::Size(DataType::Type::kInt64); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2845 | __ subl(ESP, Immediate(adjustment)); |
| 2846 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2847 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2848 | // Load the value to the FP stack, using temporaries if needed. |
| 2849 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2850 | |
| 2851 | if (out.IsStackSlot()) { |
| 2852 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2853 | } else { |
| 2854 | __ fstps(Address(ESP, 0)); |
| 2855 | Location stack_temp = Location::StackSlot(0); |
| 2856 | codegen_->Move32(out, stack_temp); |
| 2857 | } |
| 2858 | |
| 2859 | // Remove the temporary stack space we allocated. |
| 2860 | if (adjustment != 0) { |
| 2861 | __ addl(ESP, Immediate(adjustment)); |
| 2862 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2863 | break; |
| 2864 | } |
| 2865 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2866 | case DataType::Type::kFloat64: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2867 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2868 | break; |
| 2869 | |
| 2870 | default: |
| 2871 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2872 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 2873 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2874 | break; |
| 2875 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2876 | case DataType::Type::kFloat64: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2877 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2878 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2879 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2880 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2881 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2882 | case DataType::Type::kInt16: |
| 2883 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2884 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2885 | break; |
| 2886 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2887 | case DataType::Type::kInt64: { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2888 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2889 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2890 | // Create stack space for the call to |
| 2891 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2892 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2893 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2894 | adjustment = DataType::Size(DataType::Type::kInt64); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2895 | __ subl(ESP, Immediate(adjustment)); |
| 2896 | } |
| 2897 | |
| 2898 | // Load the value to the FP stack, using temporaries if needed. |
| 2899 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2900 | |
| 2901 | if (out.IsDoubleStackSlot()) { |
| 2902 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2903 | } else { |
| 2904 | __ fstpl(Address(ESP, 0)); |
| 2905 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2906 | codegen_->Move64(out, stack_temp); |
| 2907 | } |
| 2908 | |
| 2909 | // Remove the temporary stack space we allocated. |
| 2910 | if (adjustment != 0) { |
| 2911 | __ addl(ESP, Immediate(adjustment)); |
| 2912 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2913 | break; |
| 2914 | } |
| 2915 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2916 | case DataType::Type::kFloat32: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2917 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2918 | break; |
| 2919 | |
| 2920 | default: |
| 2921 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2922 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 2923 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2924 | break; |
| 2925 | |
| 2926 | default: |
| 2927 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2928 | << " to " << result_type; |
| 2929 | } |
| 2930 | } |
| 2931 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2932 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2933 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2934 | new (GetGraph()->GetAllocator()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2935 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2936 | case DataType::Type::kInt32: { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2937 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2938 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2939 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2940 | break; |
| 2941 | } |
| 2942 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2943 | case DataType::Type::kInt64: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2944 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2945 | locations->SetInAt(1, Location::Any()); |
| 2946 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2947 | break; |
| 2948 | } |
| 2949 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2950 | case DataType::Type::kFloat32: |
| 2951 | case DataType::Type::kFloat64: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2952 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2953 | if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2954 | DCHECK(add->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2955 | } else if (add->InputAt(1)->IsConstant()) { |
| 2956 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2957 | } else { |
| 2958 | locations->SetInAt(1, Location::Any()); |
| 2959 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2960 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2961 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2962 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2963 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2964 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2965 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2966 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2967 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2968 | } |
| 2969 | |
| 2970 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 2971 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2972 | Location first = locations->InAt(0); |
| 2973 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2974 | Location out = locations->Out(); |
| 2975 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2976 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2977 | case DataType::Type::kInt32: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2978 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2979 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2980 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2981 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2982 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2983 | } else { |
| 2984 | __ leal(out.AsRegister<Register>(), Address( |
| 2985 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 2986 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2987 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2988 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2989 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2990 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 2991 | } else { |
| 2992 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 2993 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2994 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2995 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2996 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2997 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2998 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2999 | } |
| 3000 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3001 | case DataType::Type::kInt64: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3002 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3003 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3004 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3005 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3006 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 3007 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3008 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3009 | } else { |
| 3010 | DCHECK(second.IsConstant()) << second; |
| 3011 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3012 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 3013 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3014 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3015 | break; |
| 3016 | } |
| 3017 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3018 | case DataType::Type::kFloat32: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3019 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3020 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3021 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3022 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3023 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3024 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 3025 | codegen_->LiteralFloatAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3026 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3027 | const_area->GetBaseMethodAddress(), |
| 3028 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3029 | } else { |
| 3030 | DCHECK(second.IsStackSlot()); |
| 3031 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3032 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3033 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3034 | } |
| 3035 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3036 | case DataType::Type::kFloat64: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3037 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3038 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3039 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3040 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3041 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3042 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 3043 | codegen_->LiteralDoubleAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3044 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3045 | const_area->GetBaseMethodAddress(), |
| 3046 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3047 | } else { |
| 3048 | DCHECK(second.IsDoubleStackSlot()); |
| 3049 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3050 | } |
| 3051 | break; |
| 3052 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3053 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3054 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3055 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3056 | } |
| 3057 | } |
| 3058 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3059 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3060 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3061 | new (GetGraph()->GetAllocator()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3062 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3063 | case DataType::Type::kInt32: |
| 3064 | case DataType::Type::kInt64: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3065 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3066 | locations->SetInAt(1, Location::Any()); |
| 3067 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3068 | break; |
| 3069 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3070 | case DataType::Type::kFloat32: |
| 3071 | case DataType::Type::kFloat64: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3072 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3073 | if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3074 | DCHECK(sub->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3075 | } else if (sub->InputAt(1)->IsConstant()) { |
| 3076 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3077 | } else { |
| 3078 | locations->SetInAt(1, Location::Any()); |
| 3079 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3080 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3081 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3082 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3083 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3084 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3085 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3086 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3087 | } |
| 3088 | |
| 3089 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 3090 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3091 | Location first = locations->InAt(0); |
| 3092 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3093 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3094 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3095 | case DataType::Type::kInt32: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3096 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3097 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3098 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3099 | __ subl(first.AsRegister<Register>(), |
| 3100 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3101 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3102 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3103 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3104 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3105 | } |
| 3106 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3107 | case DataType::Type::kInt64: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3108 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3109 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3110 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3111 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3112 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3113 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 3114 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3115 | } else { |
| 3116 | DCHECK(second.IsConstant()) << second; |
| 3117 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3118 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 3119 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3120 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3121 | break; |
| 3122 | } |
| 3123 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3124 | case DataType::Type::kFloat32: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3125 | if (second.IsFpuRegister()) { |
| 3126 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3127 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3128 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3129 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3130 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3131 | codegen_->LiteralFloatAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3132 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3133 | const_area->GetBaseMethodAddress(), |
| 3134 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3135 | } else { |
| 3136 | DCHECK(second.IsStackSlot()); |
| 3137 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3138 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3139 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3140 | } |
| 3141 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3142 | case DataType::Type::kFloat64: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3143 | if (second.IsFpuRegister()) { |
| 3144 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3145 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3146 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3147 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3148 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3149 | codegen_->LiteralDoubleAddress( |
| 3150 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3151 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3152 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3153 | } else { |
| 3154 | DCHECK(second.IsDoubleStackSlot()); |
| 3155 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3156 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3157 | break; |
| 3158 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3159 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3160 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3161 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3162 | } |
| 3163 | } |
| 3164 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3165 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 3166 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3167 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3168 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3169 | case DataType::Type::kInt32: |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3170 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3171 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3172 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3173 | // Can use 3 operand multiply. |
| 3174 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3175 | } else { |
| 3176 | locations->SetOut(Location::SameAsFirstInput()); |
| 3177 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3178 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3179 | case DataType::Type::kInt64: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3180 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3181 | locations->SetInAt(1, Location::Any()); |
| 3182 | locations->SetOut(Location::SameAsFirstInput()); |
| 3183 | // Needed for imul on 32bits with 64bits output. |
| 3184 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 3185 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 3186 | break; |
| 3187 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3188 | case DataType::Type::kFloat32: |
| 3189 | case DataType::Type::kFloat64: { |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3190 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3191 | if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3192 | DCHECK(mul->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3193 | } else if (mul->InputAt(1)->IsConstant()) { |
| 3194 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3195 | } else { |
| 3196 | locations->SetInAt(1, Location::Any()); |
| 3197 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3198 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3199 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3200 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3201 | |
| 3202 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3203 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3204 | } |
| 3205 | } |
| 3206 | |
| 3207 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 3208 | LocationSummary* locations = mul->GetLocations(); |
| 3209 | Location first = locations->InAt(0); |
| 3210 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3211 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3212 | |
| 3213 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3214 | case DataType::Type::kInt32: |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3215 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3216 | // problems where the output may not be the same as the first operand. |
| 3217 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3218 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3219 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 3220 | } else if (second.IsRegister()) { |
| 3221 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3222 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3223 | } else { |
| 3224 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3225 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3226 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3227 | } |
| 3228 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3229 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3230 | case DataType::Type::kInt64: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3231 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 3232 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3233 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 3234 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3235 | |
| 3236 | DCHECK_EQ(EAX, eax); |
| 3237 | DCHECK_EQ(EDX, edx); |
| 3238 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3239 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3240 | // output: in1 |
| 3241 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3242 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3243 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3244 | if (second.IsConstant()) { |
| 3245 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3246 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3247 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3248 | int32_t low_value = Low32Bits(value); |
| 3249 | int32_t high_value = High32Bits(value); |
| 3250 | Immediate low(low_value); |
| 3251 | Immediate high(high_value); |
| 3252 | |
| 3253 | __ movl(eax, high); |
| 3254 | // eax <- in1.lo * in2.hi |
| 3255 | __ imull(eax, in1_lo); |
| 3256 | // in1.hi <- in1.hi * in2.lo |
| 3257 | __ imull(in1_hi, low); |
| 3258 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3259 | __ addl(in1_hi, eax); |
| 3260 | // move in2_lo to eax to prepare for double precision |
| 3261 | __ movl(eax, low); |
| 3262 | // edx:eax <- in1.lo * in2.lo |
| 3263 | __ mull(in1_lo); |
| 3264 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3265 | __ addl(in1_hi, edx); |
| 3266 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3267 | __ movl(in1_lo, eax); |
| 3268 | } else if (second.IsRegisterPair()) { |
| 3269 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3270 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3271 | |
| 3272 | __ movl(eax, in2_hi); |
| 3273 | // eax <- in1.lo * in2.hi |
| 3274 | __ imull(eax, in1_lo); |
| 3275 | // in1.hi <- in1.hi * in2.lo |
| 3276 | __ imull(in1_hi, in2_lo); |
| 3277 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3278 | __ addl(in1_hi, eax); |
| 3279 | // move in1_lo to eax to prepare for double precision |
| 3280 | __ movl(eax, in1_lo); |
| 3281 | // edx:eax <- in1.lo * in2.lo |
| 3282 | __ mull(in2_lo); |
| 3283 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3284 | __ addl(in1_hi, edx); |
| 3285 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3286 | __ movl(in1_lo, eax); |
| 3287 | } else { |
| 3288 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 3289 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 3290 | Address in2_lo(ESP, second.GetStackIndex()); |
| 3291 | |
| 3292 | __ movl(eax, in2_hi); |
| 3293 | // eax <- in1.lo * in2.hi |
| 3294 | __ imull(eax, in1_lo); |
| 3295 | // in1.hi <- in1.hi * in2.lo |
| 3296 | __ imull(in1_hi, in2_lo); |
| 3297 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3298 | __ addl(in1_hi, eax); |
| 3299 | // move in1_lo to eax to prepare for double precision |
| 3300 | __ movl(eax, in1_lo); |
| 3301 | // edx:eax <- in1.lo * in2.lo |
| 3302 | __ mull(in2_lo); |
| 3303 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3304 | __ addl(in1_hi, edx); |
| 3305 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3306 | __ movl(in1_lo, eax); |
| 3307 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3308 | |
| 3309 | break; |
| 3310 | } |
| 3311 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3312 | case DataType::Type::kFloat32: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3313 | DCHECK(first.Equals(locations->Out())); |
| 3314 | if (second.IsFpuRegister()) { |
| 3315 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3316 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3317 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3318 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3319 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3320 | codegen_->LiteralFloatAddress( |
| 3321 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3322 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3323 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3324 | } else { |
| 3325 | DCHECK(second.IsStackSlot()); |
| 3326 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3327 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3328 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3329 | } |
| 3330 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3331 | case DataType::Type::kFloat64: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3332 | DCHECK(first.Equals(locations->Out())); |
| 3333 | if (second.IsFpuRegister()) { |
| 3334 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3335 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3336 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3337 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3338 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3339 | codegen_->LiteralDoubleAddress( |
| 3340 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3341 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3342 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3343 | } else { |
| 3344 | DCHECK(second.IsDoubleStackSlot()); |
| 3345 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3346 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3347 | break; |
| 3348 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3349 | |
| 3350 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3351 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3352 | } |
| 3353 | } |
| 3354 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3355 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 3356 | uint32_t temp_offset, |
| 3357 | uint32_t stack_adjustment, |
| 3358 | bool is_fp, |
| 3359 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3360 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3361 | DCHECK(!is_wide); |
| 3362 | if (is_fp) { |
| 3363 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3364 | } else { |
| 3365 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3366 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3367 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3368 | DCHECK(is_wide); |
| 3369 | if (is_fp) { |
| 3370 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3371 | } else { |
| 3372 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3373 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3374 | } else { |
| 3375 | // 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] | 3376 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3377 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3378 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3379 | if (is_fp) { |
| 3380 | __ flds(Address(ESP, temp_offset)); |
| 3381 | } else { |
| 3382 | __ filds(Address(ESP, temp_offset)); |
| 3383 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3384 | } else { |
| 3385 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3386 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3387 | if (is_fp) { |
| 3388 | __ fldl(Address(ESP, temp_offset)); |
| 3389 | } else { |
| 3390 | __ fildl(Address(ESP, temp_offset)); |
| 3391 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3392 | } |
| 3393 | } |
| 3394 | } |
| 3395 | |
| 3396 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3397 | DataType::Type type = rem->GetResultType(); |
| 3398 | bool is_float = type == DataType::Type::kFloat32; |
| 3399 | size_t elem_size = DataType::Size(type); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3400 | LocationSummary* locations = rem->GetLocations(); |
| 3401 | Location first = locations->InAt(0); |
| 3402 | Location second = locations->InAt(1); |
| 3403 | Location out = locations->Out(); |
| 3404 | |
| 3405 | // Create stack space for 2 elements. |
| 3406 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3407 | __ subl(ESP, Immediate(2 * elem_size)); |
| 3408 | |
| 3409 | // 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] | 3410 | const bool is_wide = !is_float; |
| 3411 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); |
| 3412 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3413 | |
| 3414 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3415 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3416 | __ Bind(&retry); |
| 3417 | __ fprem(); |
| 3418 | |
| 3419 | // Move FP status to AX. |
| 3420 | __ fstsw(); |
| 3421 | |
| 3422 | // And see if the argument reduction is complete. This is signaled by the |
| 3423 | // C2 FPU flag bit set to 0. |
| 3424 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 3425 | __ j(kNotEqual, &retry); |
| 3426 | |
| 3427 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3428 | // Store FP top of stack to real stack. |
| 3429 | if (is_float) { |
| 3430 | __ fsts(Address(ESP, 0)); |
| 3431 | } else { |
| 3432 | __ fstl(Address(ESP, 0)); |
| 3433 | } |
| 3434 | |
| 3435 | // Pop the 2 items from the FP stack. |
| 3436 | __ fucompp(); |
| 3437 | |
| 3438 | // Load the value from the stack into an XMM register. |
| 3439 | DCHECK(out.IsFpuRegister()) << out; |
| 3440 | if (is_float) { |
| 3441 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3442 | } else { |
| 3443 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3444 | } |
| 3445 | |
| 3446 | // And remove the temporary stack space we allocated. |
| 3447 | __ addl(ESP, Immediate(2 * elem_size)); |
| 3448 | } |
| 3449 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3450 | |
| 3451 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3452 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3453 | |
| 3454 | LocationSummary* locations = instruction->GetLocations(); |
| 3455 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3456 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3457 | |
| 3458 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3459 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3460 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3461 | |
| 3462 | DCHECK(imm == 1 || imm == -1); |
| 3463 | |
| 3464 | if (instruction->IsRem()) { |
| 3465 | __ xorl(out_register, out_register); |
| 3466 | } else { |
| 3467 | __ movl(out_register, input_register); |
| 3468 | if (imm == -1) { |
| 3469 | __ negl(out_register); |
| 3470 | } |
| 3471 | } |
| 3472 | } |
| 3473 | |
| 3474 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3475 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3476 | LocationSummary* locations = instruction->GetLocations(); |
| 3477 | |
| 3478 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3479 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3480 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3481 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3482 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3483 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3484 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 3485 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3486 | __ leal(num, Address(input_register, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3487 | __ testl(input_register, input_register); |
| 3488 | __ cmovl(kGreaterEqual, num, input_register); |
| 3489 | int shift = CTZ(imm); |
| 3490 | __ sarl(num, Immediate(shift)); |
| 3491 | |
| 3492 | if (imm < 0) { |
| 3493 | __ negl(num); |
| 3494 | } |
| 3495 | |
| 3496 | __ movl(out_register, num); |
| 3497 | } |
| 3498 | |
| 3499 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3500 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3501 | |
| 3502 | LocationSummary* locations = instruction->GetLocations(); |
| 3503 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 3504 | |
| 3505 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 3506 | Register out = locations->Out().AsRegister<Register>(); |
| 3507 | Register num; |
| 3508 | Register edx; |
| 3509 | |
| 3510 | if (instruction->IsDiv()) { |
| 3511 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 3512 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 3513 | } else { |
| 3514 | edx = locations->Out().AsRegister<Register>(); |
| 3515 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 3516 | } |
| 3517 | |
| 3518 | DCHECK_EQ(EAX, eax); |
| 3519 | DCHECK_EQ(EDX, edx); |
| 3520 | if (instruction->IsDiv()) { |
| 3521 | DCHECK_EQ(EAX, out); |
| 3522 | } else { |
| 3523 | DCHECK_EQ(EDX, out); |
| 3524 | } |
| 3525 | |
| 3526 | int64_t magic; |
| 3527 | int shift; |
| 3528 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3529 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3530 | // Save the numerator. |
| 3531 | __ movl(num, eax); |
| 3532 | |
| 3533 | // EAX = magic |
| 3534 | __ movl(eax, Immediate(magic)); |
| 3535 | |
| 3536 | // EDX:EAX = magic * numerator |
| 3537 | __ imull(num); |
| 3538 | |
| 3539 | if (imm > 0 && magic < 0) { |
| 3540 | // EDX += num |
| 3541 | __ addl(edx, num); |
| 3542 | } else if (imm < 0 && magic > 0) { |
| 3543 | __ subl(edx, num); |
| 3544 | } |
| 3545 | |
| 3546 | // Shift if needed. |
| 3547 | if (shift != 0) { |
| 3548 | __ sarl(edx, Immediate(shift)); |
| 3549 | } |
| 3550 | |
| 3551 | // EDX += 1 if EDX < 0 |
| 3552 | __ movl(eax, edx); |
| 3553 | __ shrl(edx, Immediate(31)); |
| 3554 | __ addl(edx, eax); |
| 3555 | |
| 3556 | if (instruction->IsRem()) { |
| 3557 | __ movl(eax, num); |
| 3558 | __ imull(edx, Immediate(imm)); |
| 3559 | __ subl(eax, edx); |
| 3560 | __ movl(edx, eax); |
| 3561 | } else { |
| 3562 | __ movl(eax, edx); |
| 3563 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3564 | } |
| 3565 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3566 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3567 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3568 | |
| 3569 | LocationSummary* locations = instruction->GetLocations(); |
| 3570 | Location out = locations->Out(); |
| 3571 | Location first = locations->InAt(0); |
| 3572 | Location second = locations->InAt(1); |
| 3573 | bool is_div = instruction->IsDiv(); |
| 3574 | |
| 3575 | switch (instruction->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3576 | case DataType::Type::kInt32: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3577 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 3578 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3579 | |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3580 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3581 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3582 | |
| 3583 | if (imm == 0) { |
| 3584 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 3585 | } else if (imm == 1 || imm == -1) { |
| 3586 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3587 | } else if (is_div && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3588 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3589 | } else { |
| 3590 | DCHECK(imm <= -2 || imm >= 2); |
| 3591 | GenerateDivRemWithAnyConstant(instruction); |
| 3592 | } |
| 3593 | } else { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3594 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) DivRemMinusOneSlowPathX86( |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3595 | instruction, out.AsRegister<Register>(), is_div); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3596 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3597 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3598 | Register second_reg = second.AsRegister<Register>(); |
| 3599 | // 0x80000000/-1 triggers an arithmetic exception! |
| 3600 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 3601 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3602 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3603 | __ cmpl(second_reg, Immediate(-1)); |
| 3604 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3605 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3606 | // edx:eax <- sign-extended of eax |
| 3607 | __ cdq(); |
| 3608 | // eax = quotient, edx = remainder |
| 3609 | __ idivl(second_reg); |
| 3610 | __ Bind(slow_path->GetExitLabel()); |
| 3611 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3612 | break; |
| 3613 | } |
| 3614 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3615 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3616 | InvokeRuntimeCallingConvention calling_convention; |
| 3617 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3618 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3619 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3620 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3621 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 3622 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 3623 | |
| 3624 | if (is_div) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3625 | codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3626 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3627 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3628 | codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3629 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3630 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3631 | break; |
| 3632 | } |
| 3633 | |
| 3634 | default: |
| 3635 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 3636 | } |
| 3637 | } |
| 3638 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3639 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3640 | LocationSummary::CallKind call_kind = (div->GetResultType() == DataType::Type::kInt64) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3641 | ? LocationSummary::kCallOnMainOnly |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3642 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3643 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(div, call_kind); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3644 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3645 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3646 | case DataType::Type::kInt32: { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3647 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3648 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3649 | locations->SetOut(Location::SameAsFirstInput()); |
| 3650 | // Intel uses edx:eax as the dividend. |
| 3651 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3652 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3653 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 3654 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3655 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3656 | locations->AddTemp(Location::RequiresRegister()); |
| 3657 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3658 | break; |
| 3659 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3660 | case DataType::Type::kInt64: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3661 | InvokeRuntimeCallingConvention calling_convention; |
| 3662 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3663 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3664 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3665 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3666 | // Runtime helper puts the result in EAX, EDX. |
| 3667 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3668 | break; |
| 3669 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3670 | case DataType::Type::kFloat32: |
| 3671 | case DataType::Type::kFloat64: { |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3672 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3673 | if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3674 | DCHECK(div->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3675 | } else if (div->InputAt(1)->IsConstant()) { |
| 3676 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3677 | } else { |
| 3678 | locations->SetInAt(1, Location::Any()); |
| 3679 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3680 | locations->SetOut(Location::SameAsFirstInput()); |
| 3681 | break; |
| 3682 | } |
| 3683 | |
| 3684 | default: |
| 3685 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3686 | } |
| 3687 | } |
| 3688 | |
| 3689 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 3690 | LocationSummary* locations = div->GetLocations(); |
| 3691 | Location first = locations->InAt(0); |
| 3692 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3693 | |
| 3694 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3695 | case DataType::Type::kInt32: |
| 3696 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3697 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3698 | break; |
| 3699 | } |
| 3700 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3701 | case DataType::Type::kFloat32: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3702 | if (second.IsFpuRegister()) { |
| 3703 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3704 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3705 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3706 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3707 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3708 | codegen_->LiteralFloatAddress( |
| 3709 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3710 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3711 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3712 | } else { |
| 3713 | DCHECK(second.IsStackSlot()); |
| 3714 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3715 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3716 | break; |
| 3717 | } |
| 3718 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3719 | case DataType::Type::kFloat64: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3720 | if (second.IsFpuRegister()) { |
| 3721 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3722 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3723 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3724 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3725 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3726 | codegen_->LiteralDoubleAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3727 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3728 | const_area->GetBaseMethodAddress(), |
| 3729 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3730 | } else { |
| 3731 | DCHECK(second.IsDoubleStackSlot()); |
| 3732 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3733 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3734 | break; |
| 3735 | } |
| 3736 | |
| 3737 | default: |
| 3738 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3739 | } |
| 3740 | } |
| 3741 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3742 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3743 | DataType::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3744 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3745 | LocationSummary::CallKind call_kind = (rem->GetResultType() == DataType::Type::kInt64) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3746 | ? LocationSummary::kCallOnMainOnly |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3747 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3748 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3749 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3750 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3751 | case DataType::Type::kInt32: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3752 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3753 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3754 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3755 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3756 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 3757 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3758 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3759 | locations->AddTemp(Location::RequiresRegister()); |
| 3760 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3761 | break; |
| 3762 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3763 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3764 | InvokeRuntimeCallingConvention calling_convention; |
| 3765 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3766 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3767 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3768 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3769 | // Runtime helper puts the result in EAX, EDX. |
| 3770 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3771 | break; |
| 3772 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3773 | case DataType::Type::kFloat64: |
| 3774 | case DataType::Type::kFloat32: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3775 | locations->SetInAt(0, Location::Any()); |
| 3776 | locations->SetInAt(1, Location::Any()); |
| 3777 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3778 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3779 | break; |
| 3780 | } |
| 3781 | |
| 3782 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3783 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3784 | } |
| 3785 | } |
| 3786 | |
| 3787 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3788 | DataType::Type type = rem->GetResultType(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3789 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3790 | case DataType::Type::kInt32: |
| 3791 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3792 | GenerateDivRemIntegral(rem); |
| 3793 | break; |
| 3794 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3795 | case DataType::Type::kFloat32: |
| 3796 | case DataType::Type::kFloat64: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3797 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3798 | break; |
| 3799 | } |
| 3800 | default: |
| 3801 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3802 | } |
| 3803 | } |
| 3804 | |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 3805 | void LocationsBuilderX86::VisitAbs(HAbs* abs) { |
| 3806 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 3807 | switch (abs->GetResultType()) { |
| 3808 | case DataType::Type::kInt32: |
| 3809 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 3810 | locations->SetOut(Location::SameAsFirstInput()); |
| 3811 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 3812 | break; |
| 3813 | case DataType::Type::kInt64: |
| 3814 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3815 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3816 | locations->AddTemp(Location::RequiresRegister()); |
| 3817 | break; |
| 3818 | case DataType::Type::kFloat32: |
| 3819 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3820 | locations->SetOut(Location::SameAsFirstInput()); |
| 3821 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3822 | locations->AddTemp(Location::RequiresRegister()); |
| 3823 | break; |
| 3824 | case DataType::Type::kFloat64: |
| 3825 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3826 | locations->SetOut(Location::SameAsFirstInput()); |
| 3827 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3828 | break; |
| 3829 | default: |
| 3830 | LOG(FATAL) << "Unexpected type for HAbs " << abs->GetResultType(); |
| 3831 | } |
| 3832 | } |
| 3833 | |
| 3834 | void InstructionCodeGeneratorX86::VisitAbs(HAbs* abs) { |
| 3835 | LocationSummary* locations = abs->GetLocations(); |
| 3836 | switch (abs->GetResultType()) { |
| 3837 | case DataType::Type::kInt32: { |
| 3838 | Register out = locations->Out().AsRegister<Register>(); |
| 3839 | DCHECK_EQ(out, EAX); |
| 3840 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3841 | DCHECK_EQ(temp, EDX); |
| 3842 | // Sign extend EAX into EDX. |
| 3843 | __ cdq(); |
| 3844 | // XOR EAX with sign. |
| 3845 | __ xorl(EAX, EDX); |
| 3846 | // Subtract out sign to correct. |
| 3847 | __ subl(EAX, EDX); |
| 3848 | // The result is in EAX. |
| 3849 | break; |
| 3850 | } |
| 3851 | case DataType::Type::kInt64: { |
| 3852 | Location input = locations->InAt(0); |
| 3853 | Register input_lo = input.AsRegisterPairLow<Register>(); |
| 3854 | Register input_hi = input.AsRegisterPairHigh<Register>(); |
| 3855 | Location output = locations->Out(); |
| 3856 | Register output_lo = output.AsRegisterPairLow<Register>(); |
| 3857 | Register output_hi = output.AsRegisterPairHigh<Register>(); |
| 3858 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3859 | // Compute the sign into the temporary. |
| 3860 | __ movl(temp, input_hi); |
| 3861 | __ sarl(temp, Immediate(31)); |
| 3862 | // Store the sign into the output. |
| 3863 | __ movl(output_lo, temp); |
| 3864 | __ movl(output_hi, temp); |
| 3865 | // XOR the input to the output. |
| 3866 | __ xorl(output_lo, input_lo); |
| 3867 | __ xorl(output_hi, input_hi); |
| 3868 | // Subtract the sign. |
| 3869 | __ subl(output_lo, temp); |
| 3870 | __ sbbl(output_hi, temp); |
| 3871 | break; |
| 3872 | } |
| 3873 | case DataType::Type::kFloat32: { |
| 3874 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 3875 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 3876 | Register constant = locations->GetTemp(1).AsRegister<Register>(); |
| 3877 | __ movl(constant, Immediate(INT32_C(0x7FFFFFFF))); |
| 3878 | __ movd(temp, constant); |
| 3879 | __ andps(out, temp); |
| 3880 | break; |
| 3881 | } |
| 3882 | case DataType::Type::kFloat64: { |
| 3883 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 3884 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 3885 | // TODO: Use a constant from the constant table (requires extra input). |
| 3886 | __ LoadLongConstant(temp, INT64_C(0x7FFFFFFFFFFFFFFF)); |
| 3887 | __ andpd(out, temp); |
| 3888 | break; |
| 3889 | } |
| 3890 | default: |
| 3891 | LOG(FATAL) << "Unexpected type for HAbs " << abs->GetResultType(); |
| 3892 | } |
| 3893 | } |
| 3894 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3895 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3896 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3897 | switch (instruction->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3898 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3899 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3900 | case DataType::Type::kInt8: |
| 3901 | case DataType::Type::kUint16: |
| 3902 | case DataType::Type::kInt16: |
| 3903 | case DataType::Type::kInt32: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3904 | locations->SetInAt(0, Location::Any()); |
| 3905 | break; |
| 3906 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3907 | case DataType::Type::kInt64: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3908 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 3909 | if (!instruction->IsConstant()) { |
| 3910 | locations->AddTemp(Location::RequiresRegister()); |
| 3911 | } |
| 3912 | break; |
| 3913 | } |
| 3914 | default: |
| 3915 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3916 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3917 | } |
| 3918 | |
| 3919 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3920 | SlowPathCode* slow_path = |
| 3921 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathX86(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3922 | codegen_->AddSlowPath(slow_path); |
| 3923 | |
| 3924 | LocationSummary* locations = instruction->GetLocations(); |
| 3925 | Location value = locations->InAt(0); |
| 3926 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3927 | switch (instruction->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3928 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3929 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3930 | case DataType::Type::kInt8: |
| 3931 | case DataType::Type::kUint16: |
| 3932 | case DataType::Type::kInt16: |
| 3933 | case DataType::Type::kInt32: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3934 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3935 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3936 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3937 | } else if (value.IsStackSlot()) { |
| 3938 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 3939 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3940 | } else { |
| 3941 | DCHECK(value.IsConstant()) << value; |
| 3942 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 3943 | __ jmp(slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3944 | } |
| 3945 | } |
| 3946 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3947 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3948 | case DataType::Type::kInt64: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3949 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3950 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3951 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 3952 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 3953 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3954 | } else { |
| 3955 | DCHECK(value.IsConstant()) << value; |
| 3956 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3957 | __ jmp(slow_path->GetEntryLabel()); |
| 3958 | } |
| 3959 | } |
| 3960 | break; |
| 3961 | } |
| 3962 | default: |
| 3963 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3964 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3965 | } |
| 3966 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3967 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 3968 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3969 | |
| 3970 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3971 | new (GetGraph()->GetAllocator()) LocationSummary(op, LocationSummary::kNoCall); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3972 | |
| 3973 | switch (op->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3974 | case DataType::Type::kInt32: |
| 3975 | case DataType::Type::kInt64: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3976 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3977 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3978 | // The shift count needs to be in CL or a constant. |
| 3979 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3980 | locations->SetOut(Location::SameAsFirstInput()); |
| 3981 | break; |
| 3982 | } |
| 3983 | default: |
| 3984 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3985 | } |
| 3986 | } |
| 3987 | |
| 3988 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 3989 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3990 | |
| 3991 | LocationSummary* locations = op->GetLocations(); |
| 3992 | Location first = locations->InAt(0); |
| 3993 | Location second = locations->InAt(1); |
| 3994 | DCHECK(first.Equals(locations->Out())); |
| 3995 | |
| 3996 | switch (op->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3997 | case DataType::Type::kInt32: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3998 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3999 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4000 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4001 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4002 | DCHECK_EQ(ECX, second_reg); |
| 4003 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4004 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4005 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4006 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4007 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4008 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4009 | } |
| 4010 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4011 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4012 | if (shift == 0) { |
| 4013 | return; |
| 4014 | } |
| 4015 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4016 | if (op->IsShl()) { |
| 4017 | __ shll(first_reg, imm); |
| 4018 | } else if (op->IsShr()) { |
| 4019 | __ sarl(first_reg, imm); |
| 4020 | } else { |
| 4021 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4022 | } |
| 4023 | } |
| 4024 | break; |
| 4025 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4026 | case DataType::Type::kInt64: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4027 | if (second.IsRegister()) { |
| 4028 | Register second_reg = second.AsRegister<Register>(); |
| 4029 | DCHECK_EQ(ECX, second_reg); |
| 4030 | if (op->IsShl()) { |
| 4031 | GenerateShlLong(first, second_reg); |
| 4032 | } else if (op->IsShr()) { |
| 4033 | GenerateShrLong(first, second_reg); |
| 4034 | } else { |
| 4035 | GenerateUShrLong(first, second_reg); |
| 4036 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4037 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4038 | // Shift by a constant. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4039 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4040 | // Nothing to do if the shift is 0, as the input is already the output. |
| 4041 | if (shift != 0) { |
| 4042 | if (op->IsShl()) { |
| 4043 | GenerateShlLong(first, shift); |
| 4044 | } else if (op->IsShr()) { |
| 4045 | GenerateShrLong(first, shift); |
| 4046 | } else { |
| 4047 | GenerateUShrLong(first, shift); |
| 4048 | } |
| 4049 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4050 | } |
| 4051 | break; |
| 4052 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4053 | default: |
| 4054 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 4055 | } |
| 4056 | } |
| 4057 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4058 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 4059 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4060 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 4061 | if (shift == 1) { |
| 4062 | // This is just an addition. |
| 4063 | __ addl(low, low); |
| 4064 | __ adcl(high, high); |
| 4065 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4066 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 4067 | codegen_->EmitParallelMoves( |
| 4068 | loc.ToLow(), |
| 4069 | loc.ToHigh(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4070 | DataType::Type::kInt32, |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4071 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 4072 | loc.ToLow(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4073 | DataType::Type::kInt32); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4074 | } else if (shift > 32) { |
| 4075 | // Low part becomes 0. High part is low part << (shift-32). |
| 4076 | __ movl(high, low); |
| 4077 | __ shll(high, Immediate(shift - 32)); |
| 4078 | __ xorl(low, low); |
| 4079 | } else { |
| 4080 | // Between 1 and 31. |
| 4081 | __ shld(high, low, Immediate(shift)); |
| 4082 | __ shll(low, Immediate(shift)); |
| 4083 | } |
| 4084 | } |
| 4085 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4086 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4087 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4088 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 4089 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 4090 | __ testl(shifter, Immediate(32)); |
| 4091 | __ j(kEqual, &done); |
| 4092 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 4093 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 4094 | __ Bind(&done); |
| 4095 | } |
| 4096 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4097 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 4098 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4099 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 4100 | if (shift == 32) { |
| 4101 | // Need to copy the sign. |
| 4102 | DCHECK_NE(low, high); |
| 4103 | __ movl(low, high); |
| 4104 | __ sarl(high, Immediate(31)); |
| 4105 | } else if (shift > 32) { |
| 4106 | DCHECK_NE(low, high); |
| 4107 | // High part becomes sign. Low part is shifted by shift - 32. |
| 4108 | __ movl(low, high); |
| 4109 | __ sarl(high, Immediate(31)); |
| 4110 | __ sarl(low, Immediate(shift - 32)); |
| 4111 | } else { |
| 4112 | // Between 1 and 31. |
| 4113 | __ shrd(low, high, Immediate(shift)); |
| 4114 | __ sarl(high, Immediate(shift)); |
| 4115 | } |
| 4116 | } |
| 4117 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4118 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4119 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4120 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4121 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4122 | __ testl(shifter, Immediate(32)); |
| 4123 | __ j(kEqual, &done); |
| 4124 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4125 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 4126 | __ Bind(&done); |
| 4127 | } |
| 4128 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4129 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 4130 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4131 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 4132 | if (shift == 32) { |
| 4133 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 4134 | codegen_->EmitParallelMoves( |
| 4135 | loc.ToHigh(), |
| 4136 | loc.ToLow(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4137 | DataType::Type::kInt32, |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4138 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 4139 | loc.ToHigh(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4140 | DataType::Type::kInt32); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4141 | } else if (shift > 32) { |
| 4142 | // Low part is high >> (shift - 32). High part becomes 0. |
| 4143 | __ movl(low, high); |
| 4144 | __ shrl(low, Immediate(shift - 32)); |
| 4145 | __ xorl(high, high); |
| 4146 | } else { |
| 4147 | // Between 1 and 31. |
| 4148 | __ shrd(low, high, Immediate(shift)); |
| 4149 | __ shrl(high, Immediate(shift)); |
| 4150 | } |
| 4151 | } |
| 4152 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4153 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4154 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4155 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4156 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4157 | __ testl(shifter, Immediate(32)); |
| 4158 | __ j(kEqual, &done); |
| 4159 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4160 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 4161 | __ Bind(&done); |
| 4162 | } |
| 4163 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4164 | void LocationsBuilderX86::VisitRor(HRor* ror) { |
| 4165 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4166 | new (GetGraph()->GetAllocator()) LocationSummary(ror, LocationSummary::kNoCall); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4167 | |
| 4168 | switch (ror->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4169 | case DataType::Type::kInt64: |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4170 | // Add the temporary needed. |
| 4171 | locations->AddTemp(Location::RequiresRegister()); |
| 4172 | FALLTHROUGH_INTENDED; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4173 | case DataType::Type::kInt32: |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4174 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4175 | // The shift count needs to be in CL (unless it is a constant). |
| 4176 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); |
| 4177 | locations->SetOut(Location::SameAsFirstInput()); |
| 4178 | break; |
| 4179 | default: |
| 4180 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4181 | UNREACHABLE(); |
| 4182 | } |
| 4183 | } |
| 4184 | |
| 4185 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { |
| 4186 | LocationSummary* locations = ror->GetLocations(); |
| 4187 | Location first = locations->InAt(0); |
| 4188 | Location second = locations->InAt(1); |
| 4189 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4190 | if (ror->GetResultType() == DataType::Type::kInt32) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4191 | Register first_reg = first.AsRegister<Register>(); |
| 4192 | if (second.IsRegister()) { |
| 4193 | Register second_reg = second.AsRegister<Register>(); |
| 4194 | __ rorl(first_reg, second_reg); |
| 4195 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4196 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4197 | __ rorl(first_reg, imm); |
| 4198 | } |
| 4199 | return; |
| 4200 | } |
| 4201 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4202 | DCHECK_EQ(ror->GetResultType(), DataType::Type::kInt64); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4203 | Register first_reg_lo = first.AsRegisterPairLow<Register>(); |
| 4204 | Register first_reg_hi = first.AsRegisterPairHigh<Register>(); |
| 4205 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 4206 | if (second.IsRegister()) { |
| 4207 | Register second_reg = second.AsRegister<Register>(); |
| 4208 | DCHECK_EQ(second_reg, ECX); |
| 4209 | __ movl(temp_reg, first_reg_hi); |
| 4210 | __ shrd(first_reg_hi, first_reg_lo, second_reg); |
| 4211 | __ shrd(first_reg_lo, temp_reg, second_reg); |
| 4212 | __ movl(temp_reg, first_reg_hi); |
| 4213 | __ testl(second_reg, Immediate(32)); |
| 4214 | __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); |
| 4215 | __ cmovl(kNotEqual, first_reg_lo, temp_reg); |
| 4216 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4217 | int32_t shift_amt = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4218 | if (shift_amt == 0) { |
| 4219 | // Already fine. |
| 4220 | return; |
| 4221 | } |
| 4222 | if (shift_amt == 32) { |
| 4223 | // Just swap. |
| 4224 | __ movl(temp_reg, first_reg_lo); |
| 4225 | __ movl(first_reg_lo, first_reg_hi); |
| 4226 | __ movl(first_reg_hi, temp_reg); |
| 4227 | return; |
| 4228 | } |
| 4229 | |
| 4230 | Immediate imm(shift_amt); |
| 4231 | // Save the constents of the low value. |
| 4232 | __ movl(temp_reg, first_reg_lo); |
| 4233 | |
| 4234 | // Shift right into low, feeding bits from high. |
| 4235 | __ shrd(first_reg_lo, first_reg_hi, imm); |
| 4236 | |
| 4237 | // Shift right into high, feeding bits from the original low. |
| 4238 | __ shrd(first_reg_hi, temp_reg, imm); |
| 4239 | |
| 4240 | // Swap if needed. |
| 4241 | if (shift_amt > 32) { |
| 4242 | __ movl(temp_reg, first_reg_lo); |
| 4243 | __ movl(first_reg_lo, first_reg_hi); |
| 4244 | __ movl(first_reg_hi, temp_reg); |
| 4245 | } |
| 4246 | } |
| 4247 | } |
| 4248 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4249 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 4250 | HandleShift(shl); |
| 4251 | } |
| 4252 | |
| 4253 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 4254 | HandleShift(shl); |
| 4255 | } |
| 4256 | |
| 4257 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 4258 | HandleShift(shr); |
| 4259 | } |
| 4260 | |
| 4261 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 4262 | HandleShift(shr); |
| 4263 | } |
| 4264 | |
| 4265 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 4266 | HandleShift(ushr); |
| 4267 | } |
| 4268 | |
| 4269 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 4270 | HandleShift(ushr); |
| 4271 | } |
| 4272 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4273 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4274 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4275 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4276 | locations->SetOut(Location::RegisterLocation(EAX)); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4277 | if (instruction->IsStringAlloc()) { |
| 4278 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4279 | } else { |
| 4280 | InvokeRuntimeCallingConvention calling_convention; |
| 4281 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4282 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4283 | } |
| 4284 | |
| 4285 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4286 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4287 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4288 | if (instruction->IsStringAlloc()) { |
| 4289 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4290 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4291 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4292 | __ fs()->movl(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString))); |
| 4293 | __ call(Address(temp, code_offset.Int32Value())); |
| 4294 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4295 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 4296 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 4297 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4298 | DCHECK(!codegen_->IsLeafMethod()); |
| 4299 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4300 | } |
| 4301 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4302 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4303 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4304 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4305 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 4306 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4307 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4308 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4309 | } |
| 4310 | |
| 4311 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4312 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4313 | // of poisoning the reference. |
Nicolas Geoffray | d095844 | 2017-01-30 14:57:16 +0000 | [diff] [blame] | 4314 | QuickEntrypointEnum entrypoint = |
| 4315 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 4316 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4317 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4318 | DCHECK(!codegen_->IsLeafMethod()); |
| 4319 | } |
| 4320 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4321 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4322 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4323 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4324 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4325 | if (location.IsStackSlot()) { |
| 4326 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4327 | } else if (location.IsDoubleStackSlot()) { |
| 4328 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4329 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4330 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4331 | } |
| 4332 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4333 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 4334 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 4335 | } |
| 4336 | |
| 4337 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4338 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4339 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4340 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4341 | } |
| 4342 | |
| 4343 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4344 | } |
| 4345 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4346 | void LocationsBuilderX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4347 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4348 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4349 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4350 | locations->SetOut(Location::RequiresRegister()); |
| 4351 | } |
| 4352 | |
| 4353 | void InstructionCodeGeneratorX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4354 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4355 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4356 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4357 | instruction->GetIndex(), kX86PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4358 | __ movl(locations->Out().AsRegister<Register>(), |
| 4359 | Address(locations->InAt(0).AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4360 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4361 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4362 | instruction->GetIndex(), kX86PointerSize)); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4363 | __ movl(locations->Out().AsRegister<Register>(), |
| 4364 | Address(locations->InAt(0).AsRegister<Register>(), |
| 4365 | mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
| 4366 | // temp = temp->GetImtEntryAt(method_offset); |
| 4367 | __ movl(locations->Out().AsRegister<Register>(), |
| 4368 | Address(locations->Out().AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4369 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4370 | } |
| 4371 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4372 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4373 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4374 | new (GetGraph()->GetAllocator()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4375 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4376 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4377 | } |
| 4378 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4379 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 4380 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4381 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4382 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4383 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4384 | switch (not_->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4385 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4386 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4387 | break; |
| 4388 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4389 | case DataType::Type::kInt64: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4390 | __ notl(out.AsRegisterPairLow<Register>()); |
| 4391 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4392 | break; |
| 4393 | |
| 4394 | default: |
| 4395 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4396 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4397 | } |
| 4398 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4399 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4400 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4401 | new (GetGraph()->GetAllocator()) LocationSummary(bool_not, LocationSummary::kNoCall); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4402 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4403 | locations->SetOut(Location::SameAsFirstInput()); |
| 4404 | } |
| 4405 | |
| 4406 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4407 | LocationSummary* locations = bool_not->GetLocations(); |
| 4408 | Location in = locations->InAt(0); |
| 4409 | Location out = locations->Out(); |
| 4410 | DCHECK(in.Equals(out)); |
| 4411 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 4412 | } |
| 4413 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4414 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4415 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4416 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4417 | switch (compare->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4418 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4419 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4420 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4421 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4422 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4423 | case DataType::Type::kInt32: |
| 4424 | case DataType::Type::kInt64: { |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4425 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4426 | locations->SetInAt(1, Location::Any()); |
| 4427 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4428 | break; |
| 4429 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4430 | case DataType::Type::kFloat32: |
| 4431 | case DataType::Type::kFloat64: { |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4432 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4433 | if (compare->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4434 | DCHECK(compare->InputAt(1)->IsEmittedAtUseSite()); |
| 4435 | } else if (compare->InputAt(1)->IsConstant()) { |
| 4436 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4437 | } else { |
| 4438 | locations->SetInAt(1, Location::Any()); |
| 4439 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4440 | locations->SetOut(Location::RequiresRegister()); |
| 4441 | break; |
| 4442 | } |
| 4443 | default: |
| 4444 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4445 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4446 | } |
| 4447 | |
| 4448 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4449 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4450 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4451 | Location left = locations->InAt(0); |
| 4452 | Location right = locations->InAt(1); |
| 4453 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4454 | NearLabel less, greater, done; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4455 | Condition less_cond = kLess; |
| 4456 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4457 | switch (compare->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4458 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4459 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4460 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4461 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4462 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4463 | case DataType::Type::kInt32: { |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 4464 | codegen_->GenerateIntCompare(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4465 | break; |
| 4466 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4467 | case DataType::Type::kInt64: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4468 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 4469 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 4470 | int32_t val_low = 0; |
| 4471 | int32_t val_high = 0; |
| 4472 | bool right_is_const = false; |
| 4473 | |
| 4474 | if (right.IsConstant()) { |
| 4475 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 4476 | right_is_const = true; |
| 4477 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 4478 | val_low = Low32Bits(val); |
| 4479 | val_high = High32Bits(val); |
| 4480 | } |
| 4481 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4482 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4483 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4484 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4485 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4486 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4487 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4488 | codegen_->Compare32BitValue(left_high, val_high); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4489 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4490 | __ j(kLess, &less); // Signed compare. |
| 4491 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4492 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4493 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4494 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4495 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4496 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4497 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4498 | codegen_->Compare32BitValue(left_low, val_low); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4499 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4500 | less_cond = kBelow; // for CF (unsigned). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4501 | break; |
| 4502 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4503 | case DataType::Type::kFloat32: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4504 | GenerateFPCompare(left, right, compare, false); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4505 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4506 | less_cond = kBelow; // for CF (floats). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4507 | break; |
| 4508 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4509 | case DataType::Type::kFloat64: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4510 | GenerateFPCompare(left, right, compare, true); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4511 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4512 | less_cond = kBelow; // for CF (floats). |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4513 | break; |
| 4514 | } |
| 4515 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4516 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4517 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4518 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4519 | __ movl(out, Immediate(0)); |
| 4520 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4521 | __ j(less_cond, &less); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4522 | |
| 4523 | __ Bind(&greater); |
| 4524 | __ movl(out, Immediate(1)); |
| 4525 | __ jmp(&done); |
| 4526 | |
| 4527 | __ Bind(&less); |
| 4528 | __ movl(out, Immediate(-1)); |
| 4529 | |
| 4530 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4531 | } |
| 4532 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4533 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4534 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4535 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4536 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4537 | locations->SetInAt(i, Location::Any()); |
| 4538 | } |
| 4539 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4540 | } |
| 4541 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4542 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4543 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4544 | } |
| 4545 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4546 | void CodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4547 | /* |
| 4548 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 4549 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 4550 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4551 | */ |
| 4552 | switch (kind) { |
| 4553 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4554 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4555 | break; |
| 4556 | } |
| 4557 | case MemBarrierKind::kAnyStore: |
| 4558 | case MemBarrierKind::kLoadAny: |
| 4559 | case MemBarrierKind::kStoreStore: { |
| 4560 | // nop |
| 4561 | break; |
| 4562 | } |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4563 | case MemBarrierKind::kNTStoreStore: |
| 4564 | // Non-Temporal Store/Store needs an explicit fence. |
| 4565 | MemoryFence(/* non-temporal */ true); |
| 4566 | break; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4567 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4568 | } |
| 4569 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4570 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( |
| 4571 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4572 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4573 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4574 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4575 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4576 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 4577 | Register temp) { |
| 4578 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4579 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4580 | if (!invoke->GetLocations()->Intrinsified()) { |
| 4581 | return location.AsRegister<Register>(); |
| 4582 | } |
| 4583 | // For intrinsics we allow any location, so it may be on the stack. |
| 4584 | if (!location.IsRegister()) { |
| 4585 | __ movl(temp, Address(ESP, location.GetStackIndex())); |
| 4586 | return temp; |
| 4587 | } |
| 4588 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 4589 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 4590 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 4591 | // simple and more robust approach rather that trying to determine if that's the case. |
| 4592 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
Vladimir Marko | 4ee8e29 | 2017-06-02 15:39:30 +0000 | [diff] [blame] | 4593 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 4594 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 4595 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 4596 | __ movl(temp, Address(ESP, stack_offset)); |
| 4597 | return temp; |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4598 | } |
| 4599 | return location.AsRegister<Register>(); |
| 4600 | } |
| 4601 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4602 | void CodeGeneratorX86::GenerateStaticOrDirectCall( |
| 4603 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4604 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4605 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4606 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4607 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4608 | uint32_t offset = |
| 4609 | GetThreadOffset<kX86PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 4610 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4611 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4612 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4613 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4614 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4615 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4616 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 4617 | DCHECK(GetCompilerOptions().IsBootImage()); |
| 4618 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4619 | temp.AsRegister<Register>()); |
| 4620 | __ leal(temp.AsRegister<Register>(), Address(base_reg, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4621 | RecordBootImageMethodPatch(invoke); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4622 | break; |
| 4623 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4624 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4625 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 4626 | break; |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4627 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4628 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4629 | temp.AsRegister<Register>()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4630 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4631 | RecordMethodBssEntryPatch(invoke); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4632 | break; |
| 4633 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4634 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 4635 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 4636 | return; // No code pointer retrieval; the runtime performs the call directly. |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4637 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4638 | } |
| 4639 | |
| 4640 | switch (invoke->GetCodePtrLocation()) { |
| 4641 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 4642 | __ call(GetFrameEntryLabel()); |
| 4643 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4644 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4645 | // (callee_method + offset_of_quick_compiled_code)() |
| 4646 | __ call(Address(callee_method.AsRegister<Register>(), |
| 4647 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4648 | kX86PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4649 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4650 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4651 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4652 | |
| 4653 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4654 | } |
| 4655 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4656 | void CodeGeneratorX86::GenerateVirtualCall( |
| 4657 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4658 | Register temp = temp_in.AsRegister<Register>(); |
| 4659 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4660 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4661 | |
| 4662 | // Use the calling convention instead of the location of the receiver, as |
| 4663 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4664 | // slow path, the arguments have been moved to the right place, so here we are |
| 4665 | // guaranteed that the receiver is the first register of the calling convention. |
| 4666 | InvokeDexCallingConvention calling_convention; |
| 4667 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4668 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4669 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4670 | __ movl(temp, Address(receiver, class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4671 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4672 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4673 | // emit a read barrier for the previous class reference load. |
| 4674 | // However this is not required in practice, as this is an |
| 4675 | // intermediate/temporary reference and because the current |
| 4676 | // concurrent copying collector keeps the from-space memory |
| 4677 | // intact/accessible until the end of the marking phase (the |
| 4678 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4679 | __ MaybeUnpoisonHeapReference(temp); |
| 4680 | // temp = temp->GetMethodAt(method_offset); |
| 4681 | __ movl(temp, Address(temp, method_offset)); |
| 4682 | // call temp->GetEntryPoint(); |
| 4683 | __ call(Address( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4684 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4685 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4686 | } |
| 4687 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4688 | void CodeGeneratorX86::RecordBootImageMethodPatch(HInvokeStaticOrDirect* invoke) { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4689 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4690 | HX86ComputeBaseMethodAddress* method_address = |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4691 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4692 | boot_image_method_patches_.emplace_back( |
| 4693 | method_address, invoke->GetTargetMethod().dex_file, invoke->GetTargetMethod().index); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4694 | __ Bind(&boot_image_method_patches_.back().label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4695 | } |
| 4696 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4697 | void CodeGeneratorX86::RecordMethodBssEntryPatch(HInvokeStaticOrDirect* invoke) { |
| 4698 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 4699 | HX86ComputeBaseMethodAddress* method_address = |
| 4700 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4701 | // 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] | 4702 | method_bss_entry_patches_.emplace_back( |
| 4703 | method_address, &GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()); |
| 4704 | __ Bind(&method_bss_entry_patches_.back().label); |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4705 | } |
| 4706 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4707 | void CodeGeneratorX86::RecordBootImageTypePatch(HLoadClass* load_class) { |
| 4708 | HX86ComputeBaseMethodAddress* method_address = |
| 4709 | load_class->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 4710 | boot_image_type_patches_.emplace_back( |
| 4711 | method_address, &load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4712 | __ Bind(&boot_image_type_patches_.back().label); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4713 | } |
| 4714 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4715 | Label* CodeGeneratorX86::NewTypeBssEntryPatch(HLoadClass* load_class) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4716 | HX86ComputeBaseMethodAddress* method_address = |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4717 | load_class->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 4718 | type_bss_entry_patches_.emplace_back( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4719 | method_address, &load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4720 | return &type_bss_entry_patches_.back().label; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4721 | } |
| 4722 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4723 | void CodeGeneratorX86::RecordBootImageStringPatch(HLoadString* load_string) { |
| 4724 | HX86ComputeBaseMethodAddress* method_address = |
| 4725 | load_string->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 4726 | boot_image_string_patches_.emplace_back( |
| 4727 | method_address, &load_string->GetDexFile(), load_string->GetStringIndex().index_); |
| 4728 | __ Bind(&boot_image_string_patches_.back().label); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4729 | } |
| 4730 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4731 | Label* CodeGeneratorX86::NewStringBssEntryPatch(HLoadString* load_string) { |
| 4732 | DCHECK(!GetCompilerOptions().IsBootImage()); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4733 | HX86ComputeBaseMethodAddress* method_address = |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4734 | load_string->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4735 | string_bss_entry_patches_.emplace_back( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4736 | method_address, &load_string->GetDexFile(), load_string->GetStringIndex().index_); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4737 | return &string_bss_entry_patches_.back().label; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4738 | } |
| 4739 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4740 | // The label points to the end of the "movl" or another instruction but the literal offset |
| 4741 | // for method patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 4742 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
| 4743 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4744 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4745 | inline void CodeGeneratorX86::EmitPcRelativeLinkerPatches( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4746 | const ArenaDeque<X86PcRelativePatchInfo>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4747 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4748 | for (const X86PcRelativePatchInfo& info : infos) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4749 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4750 | linker_patches->push_back(Factory(literal_offset, |
| 4751 | info.target_dex_file, |
| 4752 | GetMethodAddressOffset(info.method_address), |
| 4753 | info.offset_or_index)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4754 | } |
| 4755 | } |
| 4756 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4757 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4758 | DCHECK(linker_patches->empty()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4759 | size_t size = |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4760 | boot_image_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4761 | method_bss_entry_patches_.size() + |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4762 | boot_image_type_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4763 | type_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4764 | boot_image_string_patches_.size() + |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4765 | string_bss_entry_patches_.size(); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4766 | linker_patches->reserve(size); |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 4767 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4768 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
| 4769 | boot_image_method_patches_, linker_patches); |
| 4770 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
| 4771 | boot_image_type_patches_, linker_patches); |
| 4772 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4773 | boot_image_string_patches_, linker_patches); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4774 | } else { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4775 | DCHECK(boot_image_method_patches_.empty()); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4776 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeClassTablePatch>( |
| 4777 | boot_image_type_patches_, linker_patches); |
| 4778 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringInternTablePatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4779 | boot_image_string_patches_, linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4780 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4781 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 4782 | method_bss_entry_patches_, linker_patches); |
| 4783 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 4784 | type_bss_entry_patches_, linker_patches); |
| 4785 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 4786 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4787 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4788 | } |
| 4789 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4790 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 4791 | Register card, |
| 4792 | Register object, |
| 4793 | Register value, |
| 4794 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4795 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4796 | if (value_can_be_null) { |
| 4797 | __ testl(value, value); |
| 4798 | __ j(kEqual, &is_null); |
| 4799 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4800 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86PointerSize>().Int32Value())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4801 | __ movl(temp, object); |
| 4802 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4803 | __ movb(Address(temp, card, TIMES_1, 0), |
| 4804 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4805 | if (value_can_be_null) { |
| 4806 | __ Bind(&is_null); |
| 4807 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4808 | } |
| 4809 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4810 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4811 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4812 | |
| 4813 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4814 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4815 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4816 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 4817 | kEmitCompilerReadBarrier |
| 4818 | ? LocationSummary::kCallOnSlowPath |
| 4819 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4820 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4821 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4822 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4823 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4824 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4825 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4826 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4827 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4828 | // The output overlaps in case of long: we don't want the low move |
| 4829 | // to overwrite the object's location. Likewise, in the case of |
| 4830 | // an object field get with read barriers enabled, we do not want |
| 4831 | // the move to overwrite the object's location, as we need it to emit |
| 4832 | // the read barrier. |
| 4833 | locations->SetOut( |
| 4834 | Location::RequiresRegister(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4835 | (object_field_get_with_read_barrier || instruction->GetType() == DataType::Type::kInt64) ? |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4836 | Location::kOutputOverlap : |
| 4837 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4838 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4839 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4840 | if (field_info.IsVolatile() && (field_info.GetFieldType() == DataType::Type::kInt64)) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4841 | // Long values can be loaded atomically into an XMM using movsd. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4842 | // So we use an XMM register as a temp to achieve atomicity (first |
| 4843 | // load the temp into the XMM and then copy the XMM into the |
| 4844 | // output, 32 bits at a time). |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4845 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4846 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4847 | } |
| 4848 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4849 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 4850 | const FieldInfo& field_info) { |
| 4851 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4852 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4853 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4854 | Location base_loc = locations->InAt(0); |
| 4855 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4856 | Location out = locations->Out(); |
| 4857 | bool is_volatile = field_info.IsVolatile(); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4858 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 4859 | DataType::Type load_type = instruction->GetType(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4860 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4861 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4862 | switch (load_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4863 | case DataType::Type::kBool: |
| 4864 | case DataType::Type::kUint8: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4865 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4866 | break; |
| 4867 | } |
| 4868 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4869 | case DataType::Type::kInt8: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4870 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4871 | break; |
| 4872 | } |
| 4873 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4874 | case DataType::Type::kUint16: { |
| 4875 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4876 | break; |
| 4877 | } |
| 4878 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4879 | case DataType::Type::kInt16: { |
| 4880 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4881 | break; |
| 4882 | } |
| 4883 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4884 | case DataType::Type::kInt32: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4885 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4886 | break; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4887 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4888 | case DataType::Type::kReference: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4889 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4890 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4891 | // Note that a potential implicit null check is handled in this |
| 4892 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 4893 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 4894 | instruction, out, base, offset, /* needs_null_check */ true); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4895 | if (is_volatile) { |
| 4896 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4897 | } |
| 4898 | } else { |
| 4899 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| 4900 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4901 | if (is_volatile) { |
| 4902 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4903 | } |
| 4904 | // If read barriers are enabled, emit read barriers other than |
| 4905 | // Baker's using a slow path (and also unpoison the loaded |
| 4906 | // reference, if heap poisoning is enabled). |
| 4907 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4908 | } |
| 4909 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4910 | } |
| 4911 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4912 | case DataType::Type::kInt64: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4913 | if (is_volatile) { |
| 4914 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4915 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4916 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4917 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 4918 | __ psrlq(temp, Immediate(32)); |
| 4919 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 4920 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4921 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4922 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4923 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4924 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 4925 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4926 | break; |
| 4927 | } |
| 4928 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4929 | case DataType::Type::kFloat32: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4930 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4931 | break; |
| 4932 | } |
| 4933 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4934 | case DataType::Type::kFloat64: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4935 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4936 | break; |
| 4937 | } |
| 4938 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 4939 | case DataType::Type::kUint32: |
| 4940 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4941 | case DataType::Type::kVoid: |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4942 | LOG(FATAL) << "Unreachable type " << load_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4943 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4944 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4945 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4946 | if (load_type == DataType::Type::kReference || load_type == DataType::Type::kInt64) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4947 | // Potential implicit null checks, in the case of reference or |
| 4948 | // long fields, are handled in the previous switch statement. |
| 4949 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4950 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4951 | } |
| 4952 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4953 | if (is_volatile) { |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4954 | if (load_type == DataType::Type::kReference) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4955 | // Memory barriers, in the case of references, are also handled |
| 4956 | // in the previous switch statement. |
| 4957 | } else { |
| 4958 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4959 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4960 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4961 | } |
| 4962 | |
| 4963 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4964 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4965 | |
| 4966 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4967 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4968 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4969 | bool is_volatile = field_info.IsVolatile(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4970 | DataType::Type field_type = field_info.GetFieldType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4971 | bool is_byte_type = DataType::Size(field_type) == 1u; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4972 | |
| 4973 | // The register allocator does not support multiple |
| 4974 | // inputs that die at entry with one in a specific register. |
| 4975 | if (is_byte_type) { |
| 4976 | // Ensure the value is in a byte register. |
| 4977 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4978 | } else if (DataType::IsFloatingPointType(field_type)) { |
| 4979 | if (is_volatile && field_type == DataType::Type::kFloat64) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4980 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4981 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4982 | } else { |
| 4983 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4984 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4985 | } else if (is_volatile && field_type == DataType::Type::kInt64) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4986 | // 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] | 4987 | locations->SetInAt(1, Location::RequiresRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4988 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4989 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 4990 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 4991 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 4992 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 4993 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 4994 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4995 | locations->AddTemp(Location::RequiresFpuRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4996 | } else { |
| 4997 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4998 | |
| 4999 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 5000 | // Temporary registers for the write barrier. |
| 5001 | locations->AddTemp(Location::RequiresRegister()); // May be used for reference poisoning too. |
| 5002 | // Ensure the card is in a byte register. |
| 5003 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 5004 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5005 | } |
| 5006 | } |
| 5007 | |
| 5008 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5009 | const FieldInfo& field_info, |
| 5010 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5011 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5012 | |
| 5013 | LocationSummary* locations = instruction->GetLocations(); |
| 5014 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 5015 | Location value = locations->InAt(1); |
| 5016 | bool is_volatile = field_info.IsVolatile(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5017 | DataType::Type field_type = field_info.GetFieldType(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5018 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5019 | bool needs_write_barrier = |
| 5020 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5021 | |
| 5022 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5023 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5024 | } |
| 5025 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5026 | bool maybe_record_implicit_null_check_done = false; |
| 5027 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5028 | switch (field_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5029 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5030 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5031 | case DataType::Type::kInt8: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5032 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 5033 | break; |
| 5034 | } |
| 5035 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5036 | case DataType::Type::kUint16: |
| 5037 | case DataType::Type::kInt16: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5038 | if (value.IsConstant()) { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5039 | __ movw(Address(base, offset), |
| 5040 | Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5041 | } else { |
| 5042 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 5043 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5044 | break; |
| 5045 | } |
| 5046 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5047 | case DataType::Type::kInt32: |
| 5048 | case DataType::Type::kReference: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5049 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 5050 | // Note that in the case where `value` is a null reference, |
| 5051 | // we do not enter this block, as the reference does not |
| 5052 | // need poisoning. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5053 | DCHECK_EQ(field_type, DataType::Type::kReference); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5054 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5055 | __ movl(temp, value.AsRegister<Register>()); |
| 5056 | __ PoisonHeapReference(temp); |
| 5057 | __ movl(Address(base, offset), temp); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5058 | } else if (value.IsConstant()) { |
| 5059 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5060 | __ movl(Address(base, offset), Immediate(v)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5061 | } else { |
Nicolas Geoffray | 0397163 | 2016-03-17 10:44:24 +0000 | [diff] [blame] | 5062 | DCHECK(value.IsRegister()) << value; |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5063 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 5064 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5065 | break; |
| 5066 | } |
| 5067 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5068 | case DataType::Type::kInt64: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5069 | if (is_volatile) { |
| 5070 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 5071 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 5072 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 5073 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 5074 | __ punpckldq(temp1, temp2); |
| 5075 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5076 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5077 | } else if (value.IsConstant()) { |
| 5078 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 5079 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 5080 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5081 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5082 | } else { |
| 5083 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5084 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5085 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 5086 | } |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5087 | maybe_record_implicit_null_check_done = true; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5088 | break; |
| 5089 | } |
| 5090 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5091 | case DataType::Type::kFloat32: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5092 | if (value.IsConstant()) { |
| 5093 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5094 | __ movl(Address(base, offset), Immediate(v)); |
| 5095 | } else { |
| 5096 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 5097 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5098 | break; |
| 5099 | } |
| 5100 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5101 | case DataType::Type::kFloat64: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5102 | if (value.IsConstant()) { |
| 5103 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 5104 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 5105 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5106 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
| 5107 | maybe_record_implicit_null_check_done = true; |
| 5108 | } else { |
| 5109 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 5110 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5111 | break; |
| 5112 | } |
| 5113 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5114 | case DataType::Type::kUint32: |
| 5115 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5116 | case DataType::Type::kVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5117 | LOG(FATAL) << "Unreachable type " << field_type; |
| 5118 | UNREACHABLE(); |
| 5119 | } |
| 5120 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5121 | if (!maybe_record_implicit_null_check_done) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5122 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5123 | } |
| 5124 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5125 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5126 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5127 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5128 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5129 | } |
| 5130 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5131 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5132 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5133 | } |
| 5134 | } |
| 5135 | |
| 5136 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5137 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5138 | } |
| 5139 | |
| 5140 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5141 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5142 | } |
| 5143 | |
| 5144 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 5145 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5146 | } |
| 5147 | |
| 5148 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5149 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5150 | } |
| 5151 | |
| 5152 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5153 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5154 | } |
| 5155 | |
| 5156 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5157 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5158 | } |
| 5159 | |
| 5160 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5161 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5162 | } |
| 5163 | |
| 5164 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5165 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5166 | } |
| 5167 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5168 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 5169 | HUnresolvedInstanceFieldGet* instruction) { |
| 5170 | FieldAccessCallingConventionX86 calling_convention; |
| 5171 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5172 | instruction, instruction->GetFieldType(), calling_convention); |
| 5173 | } |
| 5174 | |
| 5175 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 5176 | HUnresolvedInstanceFieldGet* instruction) { |
| 5177 | FieldAccessCallingConventionX86 calling_convention; |
| 5178 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5179 | instruction->GetFieldType(), |
| 5180 | instruction->GetFieldIndex(), |
| 5181 | instruction->GetDexPc(), |
| 5182 | calling_convention); |
| 5183 | } |
| 5184 | |
| 5185 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 5186 | HUnresolvedInstanceFieldSet* instruction) { |
| 5187 | FieldAccessCallingConventionX86 calling_convention; |
| 5188 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5189 | instruction, instruction->GetFieldType(), calling_convention); |
| 5190 | } |
| 5191 | |
| 5192 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 5193 | HUnresolvedInstanceFieldSet* instruction) { |
| 5194 | FieldAccessCallingConventionX86 calling_convention; |
| 5195 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5196 | instruction->GetFieldType(), |
| 5197 | instruction->GetFieldIndex(), |
| 5198 | instruction->GetDexPc(), |
| 5199 | calling_convention); |
| 5200 | } |
| 5201 | |
| 5202 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 5203 | HUnresolvedStaticFieldGet* instruction) { |
| 5204 | FieldAccessCallingConventionX86 calling_convention; |
| 5205 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5206 | instruction, instruction->GetFieldType(), calling_convention); |
| 5207 | } |
| 5208 | |
| 5209 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 5210 | HUnresolvedStaticFieldGet* instruction) { |
| 5211 | FieldAccessCallingConventionX86 calling_convention; |
| 5212 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5213 | instruction->GetFieldType(), |
| 5214 | instruction->GetFieldIndex(), |
| 5215 | instruction->GetDexPc(), |
| 5216 | calling_convention); |
| 5217 | } |
| 5218 | |
| 5219 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 5220 | HUnresolvedStaticFieldSet* instruction) { |
| 5221 | FieldAccessCallingConventionX86 calling_convention; |
| 5222 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5223 | instruction, instruction->GetFieldType(), calling_convention); |
| 5224 | } |
| 5225 | |
| 5226 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 5227 | HUnresolvedStaticFieldSet* instruction) { |
| 5228 | FieldAccessCallingConventionX86 calling_convention; |
| 5229 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5230 | instruction->GetFieldType(), |
| 5231 | instruction->GetFieldIndex(), |
| 5232 | instruction->GetDexPc(), |
| 5233 | calling_convention); |
| 5234 | } |
| 5235 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5236 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5237 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5238 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 5239 | ? Location::RequiresRegister() |
| 5240 | : Location::Any(); |
| 5241 | locations->SetInAt(0, loc); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5242 | } |
| 5243 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5244 | void CodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5245 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5246 | return; |
| 5247 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5248 | LocationSummary* locations = instruction->GetLocations(); |
| 5249 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5250 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5251 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5252 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5253 | } |
| 5254 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5255 | void CodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5256 | SlowPathCode* slow_path = new (GetScopedAllocator()) NullCheckSlowPathX86(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5257 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5258 | |
| 5259 | LocationSummary* locations = instruction->GetLocations(); |
| 5260 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5261 | |
| 5262 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 5263 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5264 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5265 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5266 | } else { |
| 5267 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5268 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5269 | __ jmp(slow_path->GetEntryLabel()); |
| 5270 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5271 | } |
| 5272 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5273 | } |
| 5274 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5275 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5276 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5277 | } |
| 5278 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5279 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5280 | bool object_array_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5281 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5282 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5283 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 5284 | object_array_get_with_read_barrier |
| 5285 | ? LocationSummary::kCallOnSlowPath |
| 5286 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5287 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5288 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5289 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5290 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5291 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5292 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5293 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5294 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5295 | // The output overlaps in case of long: we don't want the low move |
| 5296 | // to overwrite the array's location. Likewise, in the case of an |
| 5297 | // object array get with read barriers enabled, we do not want the |
| 5298 | // move to overwrite the array's location, as we need it to emit |
| 5299 | // the read barrier. |
| 5300 | locations->SetOut( |
| 5301 | Location::RequiresRegister(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5302 | (instruction->GetType() == DataType::Type::kInt64 || object_array_get_with_read_barrier) |
| 5303 | ? Location::kOutputOverlap |
| 5304 | : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5305 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5306 | } |
| 5307 | |
| 5308 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 5309 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5310 | Location obj_loc = locations->InAt(0); |
| 5311 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5312 | Location index = locations->InAt(1); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5313 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5314 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5315 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5316 | DataType::Type type = instruction->GetType(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5317 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5318 | case DataType::Type::kBool: |
| 5319 | case DataType::Type::kUint8: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5320 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5321 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5322 | break; |
| 5323 | } |
| 5324 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5325 | case DataType::Type::kInt8: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5326 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5327 | __ movsxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5328 | break; |
| 5329 | } |
| 5330 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5331 | case DataType::Type::kUint16: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5332 | Register out = out_loc.AsRegister<Register>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5333 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5334 | // Branch cases into compressed and uncompressed for each index's type. |
| 5335 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 5336 | NearLabel done, not_compressed; |
Vladimir Marko | 3c89d42 | 2017-02-17 11:30:23 +0000 | [diff] [blame] | 5337 | __ testb(Address(obj, count_offset), Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5338 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5339 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 5340 | "Expecting 0=compressed, 1=uncompressed"); |
| 5341 | __ j(kNotZero, ¬_compressed); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5342 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| 5343 | __ jmp(&done); |
| 5344 | __ Bind(¬_compressed); |
| 5345 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5346 | __ Bind(&done); |
| 5347 | } else { |
| 5348 | // Common case for charAt of array of char or when string compression's |
| 5349 | // feature is turned off. |
| 5350 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5351 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5352 | break; |
| 5353 | } |
| 5354 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5355 | case DataType::Type::kInt16: { |
| 5356 | Register out = out_loc.AsRegister<Register>(); |
| 5357 | __ movsxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5358 | break; |
| 5359 | } |
| 5360 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5361 | case DataType::Type::kInt32: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5362 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5363 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5364 | break; |
| 5365 | } |
| 5366 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5367 | case DataType::Type::kReference: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5368 | static_assert( |
| 5369 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5370 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5371 | // /* HeapReference<Object> */ out = |
| 5372 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5373 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5374 | // Note that a potential implicit null check is handled in this |
| 5375 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 5376 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5377 | instruction, out_loc, obj, data_offset, index, /* needs_null_check */ true); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5378 | } else { |
| 5379 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5380 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| 5381 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5382 | // If read barriers are enabled, emit read barriers other than |
| 5383 | // Baker's using a slow path (and also unpoison the loaded |
| 5384 | // reference, if heap poisoning is enabled). |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5385 | if (index.IsConstant()) { |
| 5386 | uint32_t offset = |
| 5387 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5388 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5389 | } else { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5390 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5391 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5392 | } |
| 5393 | } |
| 5394 | break; |
| 5395 | } |
| 5396 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5397 | case DataType::Type::kInt64: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5398 | DCHECK_NE(obj, out_loc.AsRegisterPairLow<Register>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5399 | __ movl(out_loc.AsRegisterPairLow<Register>(), |
| 5400 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
| 5401 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5402 | __ movl(out_loc.AsRegisterPairHigh<Register>(), |
| 5403 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5404 | break; |
| 5405 | } |
| 5406 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5407 | case DataType::Type::kFloat32: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5408 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5409 | __ movss(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5410 | break; |
| 5411 | } |
| 5412 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5413 | case DataType::Type::kFloat64: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5414 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5415 | __ movsd(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5416 | break; |
| 5417 | } |
| 5418 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5419 | case DataType::Type::kUint32: |
| 5420 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5421 | case DataType::Type::kVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5422 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5423 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5424 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5425 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5426 | if (type == DataType::Type::kReference || type == DataType::Type::kInt64) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5427 | // Potential implicit null checks, in the case of reference or |
| 5428 | // long arrays, are handled in the previous switch statement. |
| 5429 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5430 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5431 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5432 | } |
| 5433 | |
| 5434 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5435 | DataType::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5436 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5437 | bool needs_write_barrier = |
| 5438 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5439 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5440 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5441 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5442 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 5443 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5444 | LocationSummary::kCallOnSlowPath : |
| 5445 | LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5446 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5447 | bool is_byte_type = DataType::Size(value_type) == 1u; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5448 | // We need the inputs to be different than the output in case of long operation. |
| 5449 | // In case of a byte operation, the register allocator does not support multiple |
| 5450 | // inputs that die at entry with one in a specific register. |
| 5451 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5452 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5453 | if (is_byte_type) { |
| 5454 | // Ensure the value is in a byte register. |
| 5455 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5456 | } else if (DataType::IsFloatingPointType(value_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5457 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5458 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5459 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 5460 | } |
| 5461 | if (needs_write_barrier) { |
| 5462 | // Temporary registers for the write barrier. |
| 5463 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 5464 | // Ensure the card is in a byte register. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5465 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5466 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5467 | } |
| 5468 | |
| 5469 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 5470 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5471 | Location array_loc = locations->InAt(0); |
| 5472 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5473 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5474 | Location value = locations->InAt(2); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5475 | DataType::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5476 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5477 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5478 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5479 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5480 | bool needs_write_barrier = |
| 5481 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5482 | |
| 5483 | switch (value_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5484 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5485 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5486 | case DataType::Type::kInt8: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5487 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5488 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_1, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5489 | if (value.IsRegister()) { |
| 5490 | __ movb(address, value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5491 | } else { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5492 | __ movb(address, Immediate(CodeGenerator::GetInt8ValueOf(value.GetConstant()))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5493 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5494 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5495 | break; |
| 5496 | } |
| 5497 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5498 | case DataType::Type::kUint16: |
| 5499 | case DataType::Type::kInt16: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5500 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5501 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_2, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5502 | if (value.IsRegister()) { |
| 5503 | __ movw(address, value.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5504 | } else { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5505 | __ movw(address, Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5506 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5507 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5508 | break; |
| 5509 | } |
| 5510 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5511 | case DataType::Type::kReference: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5512 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5513 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5514 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5515 | if (!value.IsRegister()) { |
| 5516 | // Just setting null. |
| 5517 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5518 | DCHECK(value.IsConstant()) << value; |
| 5519 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5520 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5521 | DCHECK(!needs_write_barrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5522 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5523 | break; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5524 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5525 | |
| 5526 | DCHECK(needs_write_barrier); |
| 5527 | Register register_value = value.AsRegister<Register>(); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5528 | // We cannot use a NearLabel for `done`, as its range may be too |
| 5529 | // short when Baker read barriers are enabled. |
| 5530 | Label done; |
| 5531 | NearLabel not_null, do_put; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5532 | SlowPathCode* slow_path = nullptr; |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5533 | Location temp_loc = locations->GetTemp(0); |
| 5534 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5535 | if (may_need_runtime_call_for_type_check) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5536 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathX86(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5537 | codegen_->AddSlowPath(slow_path); |
| 5538 | if (instruction->GetValueCanBeNull()) { |
| 5539 | __ testl(register_value, register_value); |
| 5540 | __ j(kNotEqual, ¬_null); |
| 5541 | __ movl(address, Immediate(0)); |
| 5542 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5543 | __ jmp(&done); |
| 5544 | __ Bind(¬_null); |
| 5545 | } |
| 5546 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5547 | // Note that when Baker read barriers are enabled, the type |
| 5548 | // checks are performed without read barriers. This is fine, |
| 5549 | // even in the case where a class object is in the from-space |
| 5550 | // after the flip, as a comparison involving such a type would |
| 5551 | // not produce a false positive; it may of course produce a |
| 5552 | // false negative, in which case we would take the ArraySet |
| 5553 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5554 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5555 | // /* HeapReference<Class> */ temp = array->klass_ |
| 5556 | __ movl(temp, Address(array, class_offset)); |
| 5557 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5558 | __ MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5559 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5560 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5561 | __ movl(temp, Address(temp, component_offset)); |
| 5562 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 5563 | // nor the object reference in `register_value->klass`, as |
| 5564 | // we are comparing two poisoned references. |
| 5565 | __ cmpl(temp, Address(register_value, class_offset)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5566 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5567 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5568 | __ j(kEqual, &do_put); |
| 5569 | // If heap poisoning is enabled, the `temp` reference has |
| 5570 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5571 | __ MaybeUnpoisonHeapReference(temp); |
| 5572 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5573 | // If heap poisoning is enabled, no need to unpoison the |
| 5574 | // heap reference loaded below, as it is only used for a |
| 5575 | // comparison with null. |
| 5576 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 5577 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5578 | __ Bind(&do_put); |
| 5579 | } else { |
| 5580 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5581 | } |
| 5582 | } |
| 5583 | |
| 5584 | if (kPoisonHeapReferences) { |
| 5585 | __ movl(temp, register_value); |
| 5586 | __ PoisonHeapReference(temp); |
| 5587 | __ movl(address, temp); |
| 5588 | } else { |
| 5589 | __ movl(address, register_value); |
| 5590 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5591 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5592 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5593 | } |
| 5594 | |
| 5595 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 5596 | codegen_->MarkGCCard( |
| 5597 | temp, card, array, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); |
| 5598 | __ Bind(&done); |
| 5599 | |
| 5600 | if (slow_path != nullptr) { |
| 5601 | __ Bind(slow_path->GetExitLabel()); |
| 5602 | } |
| 5603 | |
| 5604 | break; |
| 5605 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5606 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5607 | case DataType::Type::kInt32: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5608 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5609 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5610 | if (value.IsRegister()) { |
| 5611 | __ movl(address, value.AsRegister<Register>()); |
| 5612 | } else { |
| 5613 | DCHECK(value.IsConstant()) << value; |
| 5614 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5615 | __ movl(address, Immediate(v)); |
| 5616 | } |
| 5617 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5618 | break; |
| 5619 | } |
| 5620 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5621 | case DataType::Type::kInt64: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5622 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5623 | if (value.IsRegisterPair()) { |
| 5624 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 5625 | value.AsRegisterPairLow<Register>()); |
| 5626 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5627 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 5628 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5629 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5630 | DCHECK(value.IsConstant()); |
| 5631 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
| 5632 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 5633 | Immediate(Low32Bits(val))); |
| 5634 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5635 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 5636 | Immediate(High32Bits(val))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5637 | } |
| 5638 | break; |
| 5639 | } |
| 5640 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5641 | case DataType::Type::kFloat32: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5642 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5643 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5644 | if (value.IsFpuRegister()) { |
| 5645 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5646 | } else { |
| 5647 | DCHECK(value.IsConstant()); |
| 5648 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 5649 | __ movl(address, Immediate(v)); |
| 5650 | } |
| 5651 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5652 | break; |
| 5653 | } |
| 5654 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5655 | case DataType::Type::kFloat64: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5656 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5657 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5658 | if (value.IsFpuRegister()) { |
| 5659 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5660 | } else { |
| 5661 | DCHECK(value.IsConstant()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5662 | Address address_hi = |
| 5663 | CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset + kX86WordSize); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5664 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 5665 | __ movl(address, Immediate(Low32Bits(v))); |
| 5666 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5667 | __ movl(address_hi, Immediate(High32Bits(v))); |
| 5668 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5669 | break; |
| 5670 | } |
| 5671 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5672 | case DataType::Type::kUint32: |
| 5673 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5674 | case DataType::Type::kVoid: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5675 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5676 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5677 | } |
| 5678 | } |
| 5679 | |
| 5680 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5681 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5682 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5683 | if (!instruction->IsEmittedAtUseSite()) { |
| 5684 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5685 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5686 | } |
| 5687 | |
| 5688 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5689 | if (instruction->IsEmittedAtUseSite()) { |
| 5690 | return; |
| 5691 | } |
| 5692 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5693 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5694 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5695 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5696 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5697 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5698 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5699 | // Mask out most significant bit in case the array is String's array of char. |
| 5700 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5701 | __ shrl(out, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5702 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5703 | } |
| 5704 | |
| 5705 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5706 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5707 | InvokeRuntimeCallingConvention calling_convention; |
| 5708 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5709 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5710 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5711 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5712 | HInstruction* length = instruction->InputAt(1); |
| 5713 | if (!length->IsEmittedAtUseSite()) { |
| 5714 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5715 | } |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5716 | // Need register to see array's length. |
| 5717 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5718 | locations->AddTemp(Location::RequiresRegister()); |
| 5719 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5720 | } |
| 5721 | |
| 5722 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5723 | const bool is_string_compressed_char_at = |
| 5724 | mirror::kUseStringCompression && instruction->IsStringCharAt(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5725 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5726 | Location index_loc = locations->InAt(0); |
| 5727 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5728 | SlowPathCode* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5729 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathX86(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5730 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5731 | if (length_loc.IsConstant()) { |
| 5732 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5733 | if (index_loc.IsConstant()) { |
| 5734 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5735 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5736 | if (index < 0 || index >= length) { |
| 5737 | codegen_->AddSlowPath(slow_path); |
| 5738 | __ jmp(slow_path->GetEntryLabel()); |
| 5739 | } else { |
| 5740 | // Some optimization after BCE may have generated this, and we should not |
| 5741 | // generate a bounds check if it is a valid range. |
| 5742 | } |
| 5743 | return; |
| 5744 | } |
| 5745 | |
| 5746 | // We have to reverse the jump condition because the length is the constant. |
| 5747 | Register index_reg = index_loc.AsRegister<Register>(); |
| 5748 | __ cmpl(index_reg, Immediate(length)); |
| 5749 | codegen_->AddSlowPath(slow_path); |
| 5750 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5751 | } else { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5752 | HInstruction* array_length = instruction->InputAt(1); |
| 5753 | if (array_length->IsEmittedAtUseSite()) { |
| 5754 | // Address the length field in the array. |
| 5755 | DCHECK(array_length->IsArrayLength()); |
| 5756 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 5757 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 5758 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5759 | if (is_string_compressed_char_at) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5760 | // TODO: if index_loc.IsConstant(), compare twice the index (to compensate for |
| 5761 | // the string compression flag) with the in-memory length and avoid the temporary. |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5762 | Register length_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 5763 | __ movl(length_reg, array_len); |
| 5764 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5765 | __ shrl(length_reg, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5766 | codegen_->GenerateIntCompare(length_reg, index_loc); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5767 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5768 | // Checking bounds for general case: |
| 5769 | // Array of char or string's array with feature compression off. |
| 5770 | if (index_loc.IsConstant()) { |
| 5771 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5772 | __ cmpl(array_len, Immediate(value)); |
| 5773 | } else { |
| 5774 | __ cmpl(array_len, index_loc.AsRegister<Register>()); |
| 5775 | } |
| 5776 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5777 | } |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5778 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5779 | codegen_->GenerateIntCompare(length_loc, index_loc); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5780 | } |
| 5781 | codegen_->AddSlowPath(slow_path); |
| 5782 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5783 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5784 | } |
| 5785 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5786 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5787 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5788 | } |
| 5789 | |
| 5790 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 5791 | if (instruction->GetNext()->IsSuspendCheck() && |
| 5792 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 5793 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 5794 | // The back edge will generate the suspend check. |
| 5795 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 5796 | } |
| 5797 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5798 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5799 | } |
| 5800 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5801 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5802 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5803 | instruction, LocationSummary::kCallOnSlowPath); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 5804 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 5805 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 5806 | // registers in full width (since the runtime only saves/restores lower part). |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5807 | locations->SetCustomSlowPathCallerSaves( |
| 5808 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5809 | } |
| 5810 | |
| 5811 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5812 | HBasicBlock* block = instruction->GetBlock(); |
| 5813 | if (block->GetLoopInformation() != nullptr) { |
| 5814 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5815 | // The back edge will generate the suspend check. |
| 5816 | return; |
| 5817 | } |
| 5818 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5819 | // The goto will generate the suspend check. |
| 5820 | return; |
| 5821 | } |
| 5822 | GenerateSuspendCheck(instruction, nullptr); |
| 5823 | } |
| 5824 | |
| 5825 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5826 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5827 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5828 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 5829 | if (slow_path == nullptr) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5830 | slow_path = |
| 5831 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathX86(instruction, successor); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5832 | instruction->SetSlowPath(slow_path); |
| 5833 | codegen_->AddSlowPath(slow_path); |
| 5834 | if (successor != nullptr) { |
| 5835 | DCHECK(successor->IsLoopHeader()); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5836 | } |
| 5837 | } else { |
| 5838 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5839 | } |
| 5840 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5841 | __ fs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86PointerSize>().Int32Value()), |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5842 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5843 | if (successor == nullptr) { |
| 5844 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5845 | __ Bind(slow_path->GetReturnLabel()); |
| 5846 | } else { |
| 5847 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5848 | __ jmp(slow_path->GetEntryLabel()); |
| 5849 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5850 | } |
| 5851 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5852 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 5853 | return codegen_->GetAssembler(); |
| 5854 | } |
| 5855 | |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5856 | void ParallelMoveResolverX86::MoveMemoryToMemory(int dst, int src, int number_of_words) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5857 | ScratchRegisterScope ensure_scratch( |
| 5858 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5859 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5860 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5861 | |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5862 | // Now that temp register is available (possibly spilled), move blocks of memory. |
| 5863 | for (int i = 0; i < number_of_words; i++) { |
| 5864 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5865 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 5866 | stack_offset += kX86WordSize; |
| 5867 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5868 | } |
| 5869 | |
| 5870 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5871 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5872 | Location source = move->GetSource(); |
| 5873 | Location destination = move->GetDestination(); |
| 5874 | |
| 5875 | if (source.IsRegister()) { |
| 5876 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5877 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5878 | } else if (destination.IsFpuRegister()) { |
| 5879 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5880 | } else { |
| 5881 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5882 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5883 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5884 | } else if (source.IsRegisterPair()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5885 | size_t elem_size = DataType::Size(DataType::Type::kInt32); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5886 | // Create stack space for 2 elements. |
| 5887 | __ subl(ESP, Immediate(2 * elem_size)); |
| 5888 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 5889 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 5890 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 5891 | // And remove the temporary stack space we allocated. |
| 5892 | __ addl(ESP, Immediate(2 * elem_size)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5893 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5894 | if (destination.IsRegister()) { |
| 5895 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
| 5896 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5897 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5898 | } else if (destination.IsRegisterPair()) { |
| 5899 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 5900 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 5901 | __ psrlq(src_reg, Immediate(32)); |
| 5902 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5903 | } else if (destination.IsStackSlot()) { |
| 5904 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5905 | } else if (destination.IsDoubleStackSlot()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5906 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5907 | } else { |
| 5908 | DCHECK(destination.IsSIMDStackSlot()); |
| 5909 | __ movups(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5910 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5911 | } else if (source.IsStackSlot()) { |
| 5912 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5913 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5914 | } else if (destination.IsFpuRegister()) { |
| 5915 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5916 | } else { |
| 5917 | DCHECK(destination.IsStackSlot()); |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5918 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 1); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5919 | } |
| 5920 | } else if (source.IsDoubleStackSlot()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5921 | if (destination.IsRegisterPair()) { |
| 5922 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 5923 | __ movl(destination.AsRegisterPairHigh<Register>(), |
| 5924 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 5925 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5926 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 5927 | } else { |
| 5928 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5929 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 2); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5930 | } |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5931 | } else if (source.IsSIMDStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5932 | if (destination.IsFpuRegister()) { |
| 5933 | __ movups(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 5934 | } else { |
| 5935 | DCHECK(destination.IsSIMDStackSlot()); |
| 5936 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 4); |
| 5937 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5938 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5939 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5940 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5941 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5942 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5943 | if (value == 0) { |
| 5944 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5945 | } else { |
| 5946 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 5947 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5948 | } else { |
| 5949 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5950 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5951 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5952 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5953 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5954 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5955 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5956 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5957 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5958 | if (value == 0) { |
| 5959 | // Easy handling of 0.0. |
| 5960 | __ xorps(dest, dest); |
| 5961 | } else { |
| 5962 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5963 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5964 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5965 | __ movl(temp, Immediate(value)); |
| 5966 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5967 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5968 | } else { |
| 5969 | DCHECK(destination.IsStackSlot()) << destination; |
| 5970 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 5971 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5972 | } else if (constant->IsLongConstant()) { |
| 5973 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5974 | int32_t low_value = Low32Bits(value); |
| 5975 | int32_t high_value = High32Bits(value); |
| 5976 | Immediate low(low_value); |
| 5977 | Immediate high(high_value); |
| 5978 | if (destination.IsDoubleStackSlot()) { |
| 5979 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5980 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5981 | } else { |
| 5982 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 5983 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 5984 | } |
| 5985 | } else { |
| 5986 | DCHECK(constant->IsDoubleConstant()); |
| 5987 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5988 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5989 | int32_t low_value = Low32Bits(value); |
| 5990 | int32_t high_value = High32Bits(value); |
| 5991 | Immediate low(low_value); |
| 5992 | Immediate high(high_value); |
| 5993 | if (destination.IsFpuRegister()) { |
| 5994 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5995 | if (value == 0) { |
| 5996 | // Easy handling of 0.0. |
| 5997 | __ xorpd(dest, dest); |
| 5998 | } else { |
| 5999 | __ pushl(high); |
| 6000 | __ pushl(low); |
| 6001 | __ movsd(dest, Address(ESP, 0)); |
| 6002 | __ addl(ESP, Immediate(8)); |
| 6003 | } |
| 6004 | } else { |
| 6005 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6006 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 6007 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 6008 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 6009 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6010 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 6011 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6012 | } |
| 6013 | } |
| 6014 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 6015 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6016 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 6017 | ScratchRegisterScope ensure_scratch( |
| 6018 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 6019 | |
| 6020 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 6021 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 6022 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 6023 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6024 | } |
| 6025 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6026 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6027 | ScratchRegisterScope ensure_scratch( |
| 6028 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 6029 | |
| 6030 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 6031 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 6032 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 6033 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 6034 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6035 | } |
| 6036 | |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6037 | void ParallelMoveResolverX86::Exchange128(XmmRegister reg, int mem) { |
| 6038 | size_t extra_slot = 4 * kX86WordSize; |
| 6039 | __ subl(ESP, Immediate(extra_slot)); |
| 6040 | __ movups(Address(ESP, 0), XmmRegister(reg)); |
| 6041 | ExchangeMemory(0, mem + extra_slot, 4); |
| 6042 | __ movups(XmmRegister(reg), Address(ESP, 0)); |
| 6043 | __ addl(ESP, Immediate(extra_slot)); |
| 6044 | } |
| 6045 | |
| 6046 | void ParallelMoveResolverX86::ExchangeMemory(int mem1, int mem2, int number_of_words) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6047 | ScratchRegisterScope ensure_scratch1( |
| 6048 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6049 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6050 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 6051 | ScratchRegisterScope ensure_scratch2( |
| 6052 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6053 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6054 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 6055 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6056 | |
| 6057 | // Now that temp registers are available (possibly spilled), exchange blocks of memory. |
| 6058 | for (int i = 0; i < number_of_words; i++) { |
| 6059 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 6060 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 6061 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 6062 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
| 6063 | stack_offset += kX86WordSize; |
| 6064 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6065 | } |
| 6066 | |
| 6067 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6068 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6069 | Location source = move->GetSource(); |
| 6070 | Location destination = move->GetDestination(); |
| 6071 | |
| 6072 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 6073 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 6074 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 6075 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 6076 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 6077 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6078 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6079 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6080 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6081 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6082 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6083 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 1); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6084 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 6085 | // Use XOR Swap algorithm to avoid a temporary. |
| 6086 | DCHECK_NE(source.reg(), destination.reg()); |
| 6087 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 6088 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 6089 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 6090 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 6091 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 6092 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 6093 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6094 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 6095 | // Take advantage of the 16 bytes in the XMM register. |
| 6096 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 6097 | Address stack(ESP, destination.GetStackIndex()); |
| 6098 | // Load the double into the high doubleword. |
| 6099 | __ movhpd(reg, stack); |
| 6100 | |
| 6101 | // Store the low double into the destination. |
| 6102 | __ movsd(stack, reg); |
| 6103 | |
| 6104 | // Move the high double to the low double. |
| 6105 | __ psrldq(reg, Immediate(8)); |
| 6106 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 6107 | // Take advantage of the 16 bytes in the XMM register. |
| 6108 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 6109 | Address stack(ESP, source.GetStackIndex()); |
| 6110 | // Load the double into the high doubleword. |
| 6111 | __ movhpd(reg, stack); |
| 6112 | |
| 6113 | // Store the low double into the destination. |
| 6114 | __ movsd(stack, reg); |
| 6115 | |
| 6116 | // Move the high double to the low double. |
| 6117 | __ psrldq(reg, Immediate(8)); |
| 6118 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6119 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 2); |
| 6120 | } else if (source.IsSIMDStackSlot() && destination.IsSIMDStackSlot()) { |
| 6121 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 4); |
| 6122 | } else if (source.IsFpuRegister() && destination.IsSIMDStackSlot()) { |
| 6123 | Exchange128(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 6124 | } else if (destination.IsFpuRegister() && source.IsSIMDStackSlot()) { |
| 6125 | Exchange128(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6126 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6127 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6128 | } |
| 6129 | } |
| 6130 | |
| 6131 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 6132 | __ pushl(static_cast<Register>(reg)); |
| 6133 | } |
| 6134 | |
| 6135 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 6136 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6137 | } |
| 6138 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6139 | HLoadClass::LoadKind CodeGeneratorX86::GetSupportedLoadClassKind( |
| 6140 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6141 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6142 | case HLoadClass::LoadKind::kInvalid: |
| 6143 | LOG(FATAL) << "UNREACHABLE"; |
| 6144 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6145 | case HLoadClass::LoadKind::kReferrersClass: |
| 6146 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6147 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6148 | case HLoadClass::LoadKind::kBootImageClassTable: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6149 | case HLoadClass::LoadKind::kBssEntry: |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6150 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6151 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6152 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6153 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6154 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6155 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6156 | case HLoadClass::LoadKind::kRuntimeCall: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6157 | break; |
| 6158 | } |
| 6159 | return desired_class_load_kind; |
| 6160 | } |
| 6161 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6162 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6163 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6164 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6165 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6166 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6167 | cls, |
| 6168 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6169 | Location::RegisterLocation(EAX)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6170 | DCHECK_EQ(calling_convention.GetRegisterAt(0), EAX); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6171 | return; |
| 6172 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6173 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6174 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6175 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 6176 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6177 | ? LocationSummary::kCallOnSlowPath |
| 6178 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6179 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6180 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6181 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6182 | } |
| 6183 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6184 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6185 | load_kind == HLoadClass::LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6186 | load_kind == HLoadClass::LoadKind::kBootImageClassTable || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6187 | load_kind == HLoadClass::LoadKind::kBssEntry) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6188 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6189 | } |
| 6190 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6191 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 6192 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 6193 | // Rely on the type resolution and/or initialization to save everything. |
| 6194 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6195 | InvokeRuntimeCallingConvention calling_convention; |
| 6196 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6197 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6198 | } else { |
| 6199 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6200 | } |
| 6201 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6202 | } |
| 6203 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6204 | Label* CodeGeneratorX86::NewJitRootClassPatch(const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6205 | dex::TypeIndex type_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6206 | Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6207 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6208 | // Add a patch entry and return the label. |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6209 | jit_class_patches_.emplace_back(&dex_file, type_index.index_); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6210 | PatchInfo<Label>* info = &jit_class_patches_.back(); |
| 6211 | return &info->label; |
| 6212 | } |
| 6213 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6214 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6215 | // move. |
| 6216 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6217 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6218 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6219 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6220 | return; |
| 6221 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6222 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6223 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6224 | LocationSummary* locations = cls->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6225 | Location out_loc = locations->Out(); |
| 6226 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6227 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6228 | bool generate_null_check = false; |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6229 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 6230 | ? kWithoutReadBarrier |
| 6231 | : kCompilerReadBarrierOption; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6232 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6233 | case HLoadClass::LoadKind::kReferrersClass: { |
| 6234 | DCHECK(!cls->CanCallRuntime()); |
| 6235 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 6236 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6237 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 6238 | GenerateGcRootFieldLoad( |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6239 | cls, |
| 6240 | out_loc, |
| 6241 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 6242 | /* fixup_label */ nullptr, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6243 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6244 | break; |
| 6245 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6246 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6247 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6248 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6249 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6250 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6251 | codegen_->RecordBootImageTypePatch(cls); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6252 | break; |
| 6253 | } |
| 6254 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6255 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6256 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6257 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 6258 | DCHECK_NE(address, 0u); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6259 | __ movl(out, Immediate(address)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6260 | break; |
| 6261 | } |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6262 | case HLoadClass::LoadKind::kBootImageClassTable: { |
| 6263 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 6264 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6265 | __ movl(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6266 | codegen_->RecordBootImageTypePatch(cls); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6267 | // Extract the reference from the slot data, i.e. clear the hash bits. |
| 6268 | int32_t masked_hash = ClassTable::TableSlot::MaskHash( |
| 6269 | ComputeModifiedUtf8Hash(cls->GetDexFile().StringByTypeIdx(cls->GetTypeIndex()))); |
| 6270 | if (masked_hash != 0) { |
| 6271 | __ subl(out, Immediate(masked_hash)); |
| 6272 | } |
| 6273 | break; |
| 6274 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6275 | case HLoadClass::LoadKind::kBssEntry: { |
| 6276 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6277 | Address address(method_address, CodeGeneratorX86::kDummy32BitOffset); |
| 6278 | Label* fixup_label = codegen_->NewTypeBssEntryPatch(cls); |
| 6279 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
| 6280 | generate_null_check = true; |
| 6281 | break; |
| 6282 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6283 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 6284 | Address address = Address::Absolute(CodeGeneratorX86::kDummy32BitOffset); |
| 6285 | Label* fixup_label = codegen_->NewJitRootClassPatch( |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6286 | cls->GetDexFile(), cls->GetTypeIndex(), cls->GetClass()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6287 | // /* GcRoot<mirror::Class> */ out = *address |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6288 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6289 | break; |
| 6290 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6291 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6292 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6293 | LOG(FATAL) << "UNREACHABLE"; |
| 6294 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6295 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6296 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6297 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6298 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6299 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6300 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 6301 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6302 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6303 | if (generate_null_check) { |
| 6304 | __ testl(out, out); |
| 6305 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6306 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6307 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6308 | if (cls->MustGenerateClinitCheck()) { |
| 6309 | GenerateClassInitializationCheck(slow_path, out); |
| 6310 | } else { |
| 6311 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6312 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6313 | } |
| 6314 | } |
| 6315 | |
| 6316 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 6317 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6318 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6319 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6320 | if (check->HasUses()) { |
| 6321 | locations->SetOut(Location::SameAsFirstInput()); |
| 6322 | } |
| 6323 | } |
| 6324 | |
| 6325 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6326 | // We assume the class to not be null. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6327 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6328 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6329 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6330 | GenerateClassInitializationCheck(slow_path, |
| 6331 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6332 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6333 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6334 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6335 | SlowPathCode* slow_path, Register class_reg) { |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 6336 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
| 6337 | const size_t status_byte_offset = |
| 6338 | mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte); |
| 6339 | constexpr uint32_t shifted_initialized_value = |
| 6340 | enum_cast<uint32_t>(ClassStatus::kInitialized) << (status_lsb_position % kBitsPerByte); |
| 6341 | |
| 6342 | __ cmpb(Address(class_reg, status_byte_offset), Immediate(shifted_initialized_value)); |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 6343 | __ j(kBelow, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6344 | __ Bind(slow_path->GetExitLabel()); |
| 6345 | // No need for memory fence, thanks to the X86 memory model. |
| 6346 | } |
| 6347 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6348 | HLoadString::LoadKind CodeGeneratorX86::GetSupportedLoadStringKind( |
| 6349 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6350 | switch (desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6351 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6352 | case HLoadString::LoadKind::kBootImageInternTable: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6353 | case HLoadString::LoadKind::kBssEntry: |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6354 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6355 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6356 | case HLoadString::LoadKind::kJitTableAddress: |
| 6357 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6358 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6359 | case HLoadString::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6360 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6361 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6362 | } |
| 6363 | return desired_string_load_kind; |
| 6364 | } |
| 6365 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6366 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6367 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6368 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6369 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6370 | if (load_kind == HLoadString::LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6371 | load_kind == HLoadString::LoadKind::kBootImageInternTable || |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6372 | load_kind == HLoadString::LoadKind::kBssEntry) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6373 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6374 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6375 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6376 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 6377 | } else { |
| 6378 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6379 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 6380 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6381 | // Rely on the pResolveString to save everything. |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6382 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6383 | InvokeRuntimeCallingConvention calling_convention; |
| 6384 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6385 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6386 | } else { |
| 6387 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6388 | } |
| 6389 | } |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6390 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6391 | } |
| 6392 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6393 | Label* CodeGeneratorX86::NewJitRootStringPatch(const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6394 | dex::StringIndex string_index, |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6395 | Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6396 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6397 | // Add a patch entry and return the label. |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6398 | jit_string_patches_.emplace_back(&dex_file, string_index.index_); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6399 | PatchInfo<Label>* info = &jit_string_patches_.back(); |
| 6400 | return &info->label; |
| 6401 | } |
| 6402 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6403 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6404 | // move. |
| 6405 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6406 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6407 | Location out_loc = locations->Out(); |
| 6408 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6409 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6410 | switch (load->GetLoadKind()) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6411 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6412 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6413 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6414 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6415 | codegen_->RecordBootImageStringPatch(load); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6416 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6417 | } |
| 6418 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6419 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6420 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 6421 | DCHECK_NE(address, 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6422 | __ movl(out, Immediate(address)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6423 | return; |
| 6424 | } |
| 6425 | case HLoadString::LoadKind::kBootImageInternTable: { |
| 6426 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 6427 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6428 | __ movl(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6429 | codegen_->RecordBootImageStringPatch(load); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6430 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6431 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6432 | case HLoadString::LoadKind::kBssEntry: { |
| 6433 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6434 | Address address = Address(method_address, CodeGeneratorX86::kDummy32BitOffset); |
| 6435 | Label* fixup_label = codegen_->NewStringBssEntryPatch(load); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6436 | // /* GcRoot<mirror::String> */ out = *address /* PC-relative */ |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6437 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6438 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadStringSlowPathX86(load); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6439 | codegen_->AddSlowPath(slow_path); |
| 6440 | __ testl(out, out); |
| 6441 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6442 | __ Bind(slow_path->GetExitLabel()); |
| 6443 | return; |
| 6444 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6445 | case HLoadString::LoadKind::kJitTableAddress: { |
| 6446 | Address address = Address::Absolute(CodeGeneratorX86::kDummy32BitOffset); |
| 6447 | Label* fixup_label = codegen_->NewJitRootStringPatch( |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6448 | load->GetDexFile(), load->GetStringIndex(), load->GetString()); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6449 | // /* GcRoot<mirror::String> */ out = *address |
| 6450 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
| 6451 | return; |
| 6452 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6453 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6454 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6455 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6456 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6457 | // 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] | 6458 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6459 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6460 | __ movl(calling_convention.GetRegisterAt(0), Immediate(load->GetStringIndex().index_)); |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6461 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 6462 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6463 | } |
| 6464 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6465 | static Address GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6466 | return Address::Absolute(Thread::ExceptionOffset<kX86PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6467 | } |
| 6468 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6469 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 6470 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6471 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6472 | locations->SetOut(Location::RequiresRegister()); |
| 6473 | } |
| 6474 | |
| 6475 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6476 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 6477 | } |
| 6478 | |
| 6479 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6480 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6481 | } |
| 6482 | |
| 6483 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6484 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6485 | } |
| 6486 | |
| 6487 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6488 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6489 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6490 | InvokeRuntimeCallingConvention calling_convention; |
| 6491 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6492 | } |
| 6493 | |
| 6494 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6495 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6496 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6497 | } |
| 6498 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6499 | // Temp is used for read barrier. |
| 6500 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 6501 | if (kEmitCompilerReadBarrier && |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6502 | !kUseBakerReadBarrier && |
| 6503 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6504 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6505 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 6506 | return 1; |
| 6507 | } |
| 6508 | return 0; |
| 6509 | } |
| 6510 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6511 | // Interface case has 3 temps, one for holding the number of interfaces, one for the current |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6512 | // interface pointer, one for loading the current interface. |
| 6513 | // The other checks have one temp for loading the object's class. |
| 6514 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 6515 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6516 | return 2; |
| 6517 | } |
| 6518 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6519 | } |
| 6520 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6521 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6522 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6523 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6524 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6525 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6526 | case TypeCheckKind::kExactCheck: |
| 6527 | case TypeCheckKind::kAbstractClassCheck: |
| 6528 | case TypeCheckKind::kClassHierarchyCheck: |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6529 | case TypeCheckKind::kArrayObjectCheck: { |
| 6530 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 6531 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 6532 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6533 | break; |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6534 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6535 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6536 | case TypeCheckKind::kUnresolvedCheck: |
| 6537 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6538 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6539 | break; |
| 6540 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6541 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6542 | LocationSummary* locations = |
| 6543 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6544 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6545 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6546 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6547 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 6548 | locations->SetInAt(1, Location::Any()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6549 | // Note that TypeCheckSlowPathX86 uses this "out" register too. |
| 6550 | locations->SetOut(Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6551 | // When read barriers are enabled, we need a temporary register for some cases. |
| 6552 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6553 | } |
| 6554 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6555 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6556 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6557 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6558 | Location obj_loc = locations->InAt(0); |
| 6559 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6560 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6561 | Location out_loc = locations->Out(); |
| 6562 | Register out = out_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6563 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 6564 | DCHECK_LE(num_temps, 1u); |
| 6565 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6566 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6567 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6568 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6569 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6570 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6571 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6572 | |
| 6573 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6574 | // Avoid null check if we know obj is not null. |
| 6575 | if (instruction->MustDoNullCheck()) { |
| 6576 | __ testl(obj, obj); |
| 6577 | __ j(kEqual, &zero); |
| 6578 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6579 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6580 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6581 | case TypeCheckKind::kExactCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6582 | ReadBarrierOption read_barrier_option = |
| 6583 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6584 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6585 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6586 | out_loc, |
| 6587 | obj_loc, |
| 6588 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6589 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6590 | if (cls.IsRegister()) { |
| 6591 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6592 | } else { |
| 6593 | DCHECK(cls.IsStackSlot()) << cls; |
| 6594 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6595 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6596 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6597 | // Classes must be equal for the instanceof to succeed. |
| 6598 | __ j(kNotEqual, &zero); |
| 6599 | __ movl(out, Immediate(1)); |
| 6600 | __ jmp(&done); |
| 6601 | break; |
| 6602 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6603 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6604 | case TypeCheckKind::kAbstractClassCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6605 | ReadBarrierOption read_barrier_option = |
| 6606 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6607 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6608 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6609 | out_loc, |
| 6610 | obj_loc, |
| 6611 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6612 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6613 | // If the class is abstract, we eagerly fetch the super class of the |
| 6614 | // object to avoid doing a comparison we know will fail. |
| 6615 | NearLabel loop; |
| 6616 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6617 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6618 | GenerateReferenceLoadOneRegister(instruction, |
| 6619 | out_loc, |
| 6620 | super_offset, |
| 6621 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6622 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6623 | __ testl(out, out); |
| 6624 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6625 | __ j(kEqual, &done); |
| 6626 | if (cls.IsRegister()) { |
| 6627 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6628 | } else { |
| 6629 | DCHECK(cls.IsStackSlot()) << cls; |
| 6630 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6631 | } |
| 6632 | __ j(kNotEqual, &loop); |
| 6633 | __ movl(out, Immediate(1)); |
| 6634 | if (zero.IsLinked()) { |
| 6635 | __ jmp(&done); |
| 6636 | } |
| 6637 | break; |
| 6638 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6639 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6640 | case TypeCheckKind::kClassHierarchyCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6641 | ReadBarrierOption read_barrier_option = |
| 6642 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6643 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6644 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6645 | out_loc, |
| 6646 | obj_loc, |
| 6647 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6648 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6649 | // Walk over the class hierarchy to find a match. |
| 6650 | NearLabel loop, success; |
| 6651 | __ Bind(&loop); |
| 6652 | if (cls.IsRegister()) { |
| 6653 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6654 | } else { |
| 6655 | DCHECK(cls.IsStackSlot()) << cls; |
| 6656 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6657 | } |
| 6658 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6659 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6660 | GenerateReferenceLoadOneRegister(instruction, |
| 6661 | out_loc, |
| 6662 | super_offset, |
| 6663 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6664 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6665 | __ testl(out, out); |
| 6666 | __ j(kNotEqual, &loop); |
| 6667 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6668 | __ jmp(&done); |
| 6669 | __ Bind(&success); |
| 6670 | __ movl(out, Immediate(1)); |
| 6671 | if (zero.IsLinked()) { |
| 6672 | __ jmp(&done); |
| 6673 | } |
| 6674 | break; |
| 6675 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6676 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6677 | case TypeCheckKind::kArrayObjectCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6678 | ReadBarrierOption read_barrier_option = |
| 6679 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6680 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6681 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6682 | out_loc, |
| 6683 | obj_loc, |
| 6684 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6685 | read_barrier_option); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6686 | // Do an exact check. |
| 6687 | NearLabel exact_check; |
| 6688 | if (cls.IsRegister()) { |
| 6689 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6690 | } else { |
| 6691 | DCHECK(cls.IsStackSlot()) << cls; |
| 6692 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6693 | } |
| 6694 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6695 | // 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] | 6696 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6697 | GenerateReferenceLoadOneRegister(instruction, |
| 6698 | out_loc, |
| 6699 | component_offset, |
| 6700 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6701 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6702 | __ testl(out, out); |
| 6703 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6704 | __ j(kEqual, &done); |
| 6705 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 6706 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6707 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6708 | __ movl(out, Immediate(1)); |
| 6709 | __ jmp(&done); |
| 6710 | break; |
| 6711 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6712 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6713 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6714 | // No read barrier since the slow path will retry upon failure. |
| 6715 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6716 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6717 | out_loc, |
| 6718 | obj_loc, |
| 6719 | class_offset, |
| 6720 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6721 | if (cls.IsRegister()) { |
| 6722 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6723 | } else { |
| 6724 | DCHECK(cls.IsStackSlot()) << cls; |
| 6725 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6726 | } |
| 6727 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6728 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
| 6729 | instruction, /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6730 | codegen_->AddSlowPath(slow_path); |
| 6731 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6732 | __ movl(out, Immediate(1)); |
| 6733 | if (zero.IsLinked()) { |
| 6734 | __ jmp(&done); |
| 6735 | } |
| 6736 | break; |
| 6737 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6738 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6739 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6740 | case TypeCheckKind::kInterfaceCheck: { |
| 6741 | // 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] | 6742 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6743 | // cases. |
| 6744 | // |
| 6745 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6746 | // entry point without resorting to a type checking slow path |
| 6747 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6748 | // require to assign fixed registers for the inputs of this |
| 6749 | // HInstanceOf instruction (following the runtime calling |
| 6750 | // convention), which might be cluttered by the potential first |
| 6751 | // read barrier emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6752 | // |
| 6753 | // TODO: Introduce a new runtime entry point taking the object |
| 6754 | // to test (instead of its class) as argument, and let it deal |
| 6755 | // with the read barrier issues. This will let us refactor this |
| 6756 | // case of the `switch` code as it was previously (with a direct |
| 6757 | // call to the runtime not using a type checking slow path). |
| 6758 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6759 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6760 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
| 6761 | instruction, /* is_fatal */ false); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6762 | codegen_->AddSlowPath(slow_path); |
| 6763 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6764 | if (zero.IsLinked()) { |
| 6765 | __ jmp(&done); |
| 6766 | } |
| 6767 | break; |
| 6768 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6769 | } |
| 6770 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6771 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6772 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6773 | __ xorl(out, out); |
| 6774 | } |
| 6775 | |
| 6776 | if (done.IsLinked()) { |
| 6777 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6778 | } |
| 6779 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6780 | if (slow_path != nullptr) { |
| 6781 | __ Bind(slow_path->GetExitLabel()); |
| 6782 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6783 | } |
| 6784 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6785 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6786 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6787 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6788 | LocationSummary* locations = |
| 6789 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6790 | locations->SetInAt(0, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6791 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6792 | // Require a register for the interface check since there is a loop that compares the class to |
| 6793 | // a memory address. |
| 6794 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6795 | } else { |
| 6796 | locations->SetInAt(1, Location::Any()); |
| 6797 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6798 | // Note that TypeCheckSlowPathX86 uses this "temp" register too. |
| 6799 | locations->AddTemp(Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6800 | // When read barriers are enabled, we need an additional temporary register for some cases. |
| 6801 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
| 6802 | } |
| 6803 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6804 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6805 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6806 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6807 | Location obj_loc = locations->InAt(0); |
| 6808 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6809 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6810 | Location temp_loc = locations->GetTemp(0); |
| 6811 | Register temp = temp_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6812 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 6813 | DCHECK_GE(num_temps, 1u); |
| 6814 | DCHECK_LE(num_temps, 2u); |
| 6815 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 6816 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6817 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6818 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6819 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 6820 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 6821 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 6822 | const uint32_t object_array_data_offset = |
| 6823 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6824 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6825 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6826 | SlowPathCode* type_check_slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6827 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
| 6828 | instruction, is_type_check_slow_path_fatal); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6829 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6830 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6831 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6832 | // Avoid null check if we know obj is not null. |
| 6833 | if (instruction->MustDoNullCheck()) { |
| 6834 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6835 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6836 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6837 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6838 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6839 | case TypeCheckKind::kExactCheck: |
| 6840 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6841 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6842 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6843 | temp_loc, |
| 6844 | obj_loc, |
| 6845 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6846 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6847 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6848 | if (cls.IsRegister()) { |
| 6849 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6850 | } else { |
| 6851 | DCHECK(cls.IsStackSlot()) << cls; |
| 6852 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6853 | } |
| 6854 | // Jump to slow path for throwing the exception or doing a |
| 6855 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6856 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6857 | break; |
| 6858 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6859 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6860 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6861 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6862 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6863 | temp_loc, |
| 6864 | obj_loc, |
| 6865 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6866 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6867 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6868 | // If the class is abstract, we eagerly fetch the super class of the |
| 6869 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6870 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6871 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6872 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6873 | GenerateReferenceLoadOneRegister(instruction, |
| 6874 | temp_loc, |
| 6875 | super_offset, |
| 6876 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6877 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6878 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6879 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 6880 | // exception. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6881 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6882 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6883 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6884 | // Otherwise, compare the classes |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6885 | if (cls.IsRegister()) { |
| 6886 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6887 | } else { |
| 6888 | DCHECK(cls.IsStackSlot()) << cls; |
| 6889 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6890 | } |
| 6891 | __ j(kNotEqual, &loop); |
| 6892 | break; |
| 6893 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6894 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6895 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6896 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6897 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6898 | temp_loc, |
| 6899 | obj_loc, |
| 6900 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6901 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6902 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6903 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6904 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6905 | __ Bind(&loop); |
| 6906 | if (cls.IsRegister()) { |
| 6907 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6908 | } else { |
| 6909 | DCHECK(cls.IsStackSlot()) << cls; |
| 6910 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6911 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6912 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6913 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6914 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6915 | GenerateReferenceLoadOneRegister(instruction, |
| 6916 | temp_loc, |
| 6917 | super_offset, |
| 6918 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6919 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6920 | |
| 6921 | // If the class reference currently in `temp` is not null, jump |
| 6922 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6923 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6924 | __ j(kNotZero, &loop); |
| 6925 | // Otherwise, jump to the slow path to throw the exception.; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6926 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6927 | break; |
| 6928 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6929 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6930 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6931 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6932 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6933 | temp_loc, |
| 6934 | obj_loc, |
| 6935 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6936 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6937 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6938 | // Do an exact check. |
| 6939 | if (cls.IsRegister()) { |
| 6940 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6941 | } else { |
| 6942 | DCHECK(cls.IsStackSlot()) << cls; |
| 6943 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6944 | } |
| 6945 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6946 | |
| 6947 | // 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] | 6948 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6949 | GenerateReferenceLoadOneRegister(instruction, |
| 6950 | temp_loc, |
| 6951 | component_offset, |
| 6952 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6953 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6954 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6955 | // If the component type is null (i.e. the object not an array), jump to the slow path to |
| 6956 | // throw the exception. Otherwise proceed with the check. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6957 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6958 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6959 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6960 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6961 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6962 | break; |
| 6963 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6964 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6965 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6966 | // 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] | 6967 | // We cannot directly call the CheckCast runtime entry point |
| 6968 | // without resorting to a type checking slow path here (i.e. by |
| 6969 | // calling InvokeRuntime directly), as it would require to |
| 6970 | // assign fixed registers for the inputs of this HInstanceOf |
| 6971 | // instruction (following the runtime calling convention), which |
| 6972 | // might be cluttered by the potential first read barrier |
| 6973 | // emission at the beginning of this method. |
| 6974 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6975 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6976 | |
| 6977 | case TypeCheckKind::kInterfaceCheck: { |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 6978 | // Fast path for the interface check. Try to avoid read barriers to improve the fast path. |
| 6979 | // We can not get false positives by doing this. |
| 6980 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6981 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6982 | temp_loc, |
| 6983 | obj_loc, |
| 6984 | class_offset, |
| 6985 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6986 | |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 6987 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 6988 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6989 | temp_loc, |
| 6990 | temp_loc, |
| 6991 | iftable_offset, |
| 6992 | kWithoutReadBarrier); |
| 6993 | // Iftable is never null. |
| 6994 | __ movl(maybe_temp2_loc.AsRegister<Register>(), Address(temp, array_length_offset)); |
| 6995 | // Maybe poison the `cls` for direct comparison with memory. |
| 6996 | __ MaybePoisonHeapReference(cls.AsRegister<Register>()); |
| 6997 | // Loop through the iftable and check if any class matches. |
| 6998 | NearLabel start_loop; |
| 6999 | __ Bind(&start_loop); |
| 7000 | // Need to subtract first to handle the empty array case. |
| 7001 | __ subl(maybe_temp2_loc.AsRegister<Register>(), Immediate(2)); |
| 7002 | __ j(kNegative, type_check_slow_path->GetEntryLabel()); |
| 7003 | // Go to next interface if the classes do not match. |
| 7004 | __ cmpl(cls.AsRegister<Register>(), |
| 7005 | CodeGeneratorX86::ArrayAddress(temp, |
| 7006 | maybe_temp2_loc, |
| 7007 | TIMES_4, |
| 7008 | object_array_data_offset)); |
| 7009 | __ j(kNotEqual, &start_loop); |
| 7010 | // If `cls` was poisoned above, unpoison it. |
| 7011 | __ MaybeUnpoisonHeapReference(cls.AsRegister<Register>()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7012 | break; |
| 7013 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7014 | } |
| 7015 | __ Bind(&done); |
| 7016 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7017 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7018 | } |
| 7019 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7020 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7021 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 7022 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7023 | InvokeRuntimeCallingConvention calling_convention; |
| 7024 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 7025 | } |
| 7026 | |
| 7027 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 7028 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject |
| 7029 | : kQuickUnlockObject, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 7030 | instruction, |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 7031 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7032 | if (instruction->IsEnter()) { |
| 7033 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 7034 | } else { |
| 7035 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 7036 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7037 | } |
| 7038 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7039 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 7040 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 7041 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 7042 | |
| 7043 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 7044 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7045 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7046 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 |
| 7047 | || instruction->GetResultType() == DataType::Type::kInt64); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7048 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7049 | locations->SetInAt(1, Location::Any()); |
| 7050 | locations->SetOut(Location::SameAsFirstInput()); |
| 7051 | } |
| 7052 | |
| 7053 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 7054 | HandleBitwiseOperation(instruction); |
| 7055 | } |
| 7056 | |
| 7057 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 7058 | HandleBitwiseOperation(instruction); |
| 7059 | } |
| 7060 | |
| 7061 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 7062 | HandleBitwiseOperation(instruction); |
| 7063 | } |
| 7064 | |
| 7065 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 7066 | LocationSummary* locations = instruction->GetLocations(); |
| 7067 | Location first = locations->InAt(0); |
| 7068 | Location second = locations->InAt(1); |
| 7069 | DCHECK(first.Equals(locations->Out())); |
| 7070 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7071 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7072 | if (second.IsRegister()) { |
| 7073 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7074 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7075 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7076 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7077 | } else { |
| 7078 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7079 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7080 | } |
| 7081 | } else if (second.IsConstant()) { |
| 7082 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 7083 | __ andl(first.AsRegister<Register>(), |
| 7084 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7085 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 7086 | __ orl(first.AsRegister<Register>(), |
| 7087 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7088 | } else { |
| 7089 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 7090 | __ xorl(first.AsRegister<Register>(), |
| 7091 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7092 | } |
| 7093 | } else { |
| 7094 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7095 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7096 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7097 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7098 | } else { |
| 7099 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7100 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7101 | } |
| 7102 | } |
| 7103 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7104 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7105 | if (second.IsRegisterPair()) { |
| 7106 | if (instruction->IsAnd()) { |
| 7107 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 7108 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 7109 | } else if (instruction->IsOr()) { |
| 7110 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 7111 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 7112 | } else { |
| 7113 | DCHECK(instruction->IsXor()); |
| 7114 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 7115 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 7116 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7117 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7118 | if (instruction->IsAnd()) { |
| 7119 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7120 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 7121 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7122 | } else if (instruction->IsOr()) { |
| 7123 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7124 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 7125 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7126 | } else { |
| 7127 | DCHECK(instruction->IsXor()); |
| 7128 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7129 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 7130 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7131 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7132 | } else { |
| 7133 | DCHECK(second.IsConstant()) << second; |
| 7134 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7135 | int32_t low_value = Low32Bits(value); |
| 7136 | int32_t high_value = High32Bits(value); |
| 7137 | Immediate low(low_value); |
| 7138 | Immediate high(high_value); |
| 7139 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 7140 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7141 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7142 | if (low_value == 0) { |
| 7143 | __ xorl(first_low, first_low); |
| 7144 | } else if (low_value != -1) { |
| 7145 | __ andl(first_low, low); |
| 7146 | } |
| 7147 | if (high_value == 0) { |
| 7148 | __ xorl(first_high, first_high); |
| 7149 | } else if (high_value != -1) { |
| 7150 | __ andl(first_high, high); |
| 7151 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7152 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7153 | if (low_value != 0) { |
| 7154 | __ orl(first_low, low); |
| 7155 | } |
| 7156 | if (high_value != 0) { |
| 7157 | __ orl(first_high, high); |
| 7158 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7159 | } else { |
| 7160 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7161 | if (low_value != 0) { |
| 7162 | __ xorl(first_low, low); |
| 7163 | } |
| 7164 | if (high_value != 0) { |
| 7165 | __ xorl(first_high, high); |
| 7166 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7167 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7168 | } |
| 7169 | } |
| 7170 | } |
| 7171 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7172 | void InstructionCodeGeneratorX86::GenerateReferenceLoadOneRegister( |
| 7173 | HInstruction* instruction, |
| 7174 | Location out, |
| 7175 | uint32_t offset, |
| 7176 | Location maybe_temp, |
| 7177 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7178 | Register out_reg = out.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7179 | if (read_barrier_option == kWithReadBarrier) { |
| 7180 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7181 | if (kUseBakerReadBarrier) { |
| 7182 | // Load with fast path based Baker's read barrier. |
| 7183 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7184 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7185 | instruction, out, out_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7186 | } else { |
| 7187 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7188 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7189 | // in the following move operation, as we will need it for the |
| 7190 | // read barrier below. |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7191 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7192 | __ movl(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7193 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7194 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7195 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7196 | } |
| 7197 | } else { |
| 7198 | // Plain load with no read barrier. |
| 7199 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7200 | __ movl(out_reg, Address(out_reg, offset)); |
| 7201 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7202 | } |
| 7203 | } |
| 7204 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7205 | void InstructionCodeGeneratorX86::GenerateReferenceLoadTwoRegisters( |
| 7206 | HInstruction* instruction, |
| 7207 | Location out, |
| 7208 | Location obj, |
| 7209 | uint32_t offset, |
| 7210 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7211 | Register out_reg = out.AsRegister<Register>(); |
| 7212 | Register obj_reg = obj.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7213 | if (read_barrier_option == kWithReadBarrier) { |
| 7214 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7215 | if (kUseBakerReadBarrier) { |
| 7216 | // Load with fast path based Baker's read barrier. |
| 7217 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7218 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7219 | instruction, out, obj_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7220 | } else { |
| 7221 | // Load with slow path based read barrier. |
| 7222 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7223 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7224 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 7225 | } |
| 7226 | } else { |
| 7227 | // Plain load with no read barrier. |
| 7228 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7229 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7230 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7231 | } |
| 7232 | } |
| 7233 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7234 | void InstructionCodeGeneratorX86::GenerateGcRootFieldLoad( |
| 7235 | HInstruction* instruction, |
| 7236 | Location root, |
| 7237 | const Address& address, |
| 7238 | Label* fixup_label, |
| 7239 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7240 | Register root_reg = root.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7241 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7242 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7243 | if (kUseBakerReadBarrier) { |
| 7244 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 7245 | // Baker's read barrier are used: |
| 7246 | // |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7247 | // root = obj.field; |
| 7248 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 7249 | // if (temp != null) { |
| 7250 | // root = temp(root) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7251 | // } |
| 7252 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7253 | // /* GcRoot<mirror::Object> */ root = *address |
| 7254 | __ movl(root_reg, address); |
| 7255 | if (fixup_label != nullptr) { |
| 7256 | __ Bind(fixup_label); |
| 7257 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7258 | static_assert( |
| 7259 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 7260 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 7261 | "have different sizes."); |
| 7262 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 7263 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 7264 | "have different sizes."); |
| 7265 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7266 | // Slow path marking the GC root `root`. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7267 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathX86( |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7268 | instruction, root, /* unpoison_ref_before_marking */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7269 | codegen_->AddSlowPath(slow_path); |
| 7270 | |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7271 | // Test the entrypoint (`Thread::Current()->pReadBarrierMarkReg ## root.reg()`). |
| 7272 | const int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 7273 | Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(root.reg()); |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7274 | __ fs()->cmpl(Address::Absolute(entry_point_offset), Immediate(0)); |
| 7275 | // The entrypoint is null when the GC is not marking. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7276 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 7277 | __ Bind(slow_path->GetExitLabel()); |
| 7278 | } else { |
| 7279 | // GC root loaded through a slow path for read barriers other |
| 7280 | // than Baker's. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7281 | // /* GcRoot<mirror::Object>* */ root = address |
| 7282 | __ leal(root_reg, address); |
| 7283 | if (fixup_label != nullptr) { |
| 7284 | __ Bind(fixup_label); |
| 7285 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7286 | // /* mirror::Object* */ root = root->Read() |
| 7287 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 7288 | } |
| 7289 | } else { |
| 7290 | // Plain GC root load with no read barrier. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7291 | // /* GcRoot<mirror::Object> */ root = *address |
| 7292 | __ movl(root_reg, address); |
| 7293 | if (fixup_label != nullptr) { |
| 7294 | __ Bind(fixup_label); |
| 7295 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7296 | // Note that GC roots are not affected by heap poisoning, thus we |
| 7297 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7298 | } |
| 7299 | } |
| 7300 | |
| 7301 | void CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7302 | Location ref, |
| 7303 | Register obj, |
| 7304 | uint32_t offset, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7305 | bool needs_null_check) { |
| 7306 | DCHECK(kEmitCompilerReadBarrier); |
| 7307 | DCHECK(kUseBakerReadBarrier); |
| 7308 | |
| 7309 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7310 | Address src(obj, offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7311 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7312 | } |
| 7313 | |
| 7314 | void CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7315 | Location ref, |
| 7316 | Register obj, |
| 7317 | uint32_t data_offset, |
| 7318 | Location index, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7319 | bool needs_null_check) { |
| 7320 | DCHECK(kEmitCompilerReadBarrier); |
| 7321 | DCHECK(kUseBakerReadBarrier); |
| 7322 | |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 7323 | static_assert( |
| 7324 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 7325 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7326 | // /* HeapReference<Object> */ ref = |
| 7327 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7328 | Address src = CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7329 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7330 | } |
| 7331 | |
| 7332 | void CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7333 | Location ref, |
| 7334 | Register obj, |
| 7335 | const Address& src, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7336 | bool needs_null_check, |
| 7337 | bool always_update_field, |
| 7338 | Register* temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7339 | DCHECK(kEmitCompilerReadBarrier); |
| 7340 | DCHECK(kUseBakerReadBarrier); |
| 7341 | |
| 7342 | // In slow path based read barriers, the read barrier call is |
| 7343 | // inserted after the original load. However, in fast path based |
| 7344 | // Baker's read barriers, we need to perform the load of |
| 7345 | // mirror::Object::monitor_ *before* the original reference load. |
| 7346 | // This load-load ordering is required by the read barrier. |
| 7347 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 7348 | // |
| 7349 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7350 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7351 | // HeapReference<Object> ref = *src; // Original reference load. |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7352 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7353 | // if (is_gray) { |
| 7354 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 7355 | // } |
| 7356 | // |
| 7357 | // Note: the original implementation in ReadBarrier::Barrier is |
| 7358 | // slightly more complex as: |
| 7359 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7360 | // the high-bits of rb_state, which are expected to be all zeroes |
| 7361 | // (we use CodeGeneratorX86::GenerateMemoryBarrier instead here, |
| 7362 | // which is a no-op thanks to the x86 memory model); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7363 | // - it performs additional checks that we do not do here for |
| 7364 | // performance reasons. |
| 7365 | |
| 7366 | Register ref_reg = ref.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7367 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 7368 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7369 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7370 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 7371 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7372 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 7373 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 7374 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 7375 | |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7376 | // if (rb_state == ReadBarrier::GrayState()) |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7377 | // ref = ReadBarrier::Mark(ref); |
| 7378 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 7379 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7380 | if (needs_null_check) { |
| 7381 | MaybeRecordImplicitNullCheck(instruction); |
| 7382 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7383 | |
| 7384 | // Load fence to prevent load-load reordering. |
| 7385 | // Note that this is a no-op, thanks to the x86 memory model. |
| 7386 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 7387 | |
| 7388 | // The actual reference load. |
| 7389 | // /* HeapReference<Object> */ ref = *src |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7390 | __ movl(ref_reg, src); // Flags are unaffected. |
| 7391 | |
| 7392 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 7393 | // Slow path marking the object `ref` when it is gray. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7394 | SlowPathCode* slow_path; |
| 7395 | if (always_update_field) { |
| 7396 | DCHECK(temp != nullptr); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7397 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkAndUpdateFieldSlowPathX86( |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7398 | instruction, ref, obj, src, /* unpoison_ref_before_marking */ true, *temp); |
| 7399 | } else { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7400 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkSlowPathX86( |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7401 | instruction, ref, /* unpoison_ref_before_marking */ true); |
| 7402 | } |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7403 | AddSlowPath(slow_path); |
| 7404 | |
| 7405 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 7406 | __ j(kNotZero, slow_path->GetEntryLabel()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7407 | |
| 7408 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7409 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7410 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7411 | __ Bind(slow_path->GetExitLabel()); |
| 7412 | } |
| 7413 | |
| 7414 | void CodeGeneratorX86::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7415 | Location out, |
| 7416 | Location ref, |
| 7417 | Location obj, |
| 7418 | uint32_t offset, |
| 7419 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7420 | DCHECK(kEmitCompilerReadBarrier); |
| 7421 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7422 | // Insert a slow path based read barrier *after* the reference load. |
| 7423 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7424 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7425 | // reference will be carried out by the runtime within the slow |
| 7426 | // path. |
| 7427 | // |
| 7428 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7429 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7430 | // not used by the artReadBarrierSlow entry point. |
| 7431 | // |
| 7432 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7433 | SlowPathCode* slow_path = new (GetScopedAllocator()) |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7434 | ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); |
| 7435 | AddSlowPath(slow_path); |
| 7436 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7437 | __ jmp(slow_path->GetEntryLabel()); |
| 7438 | __ Bind(slow_path->GetExitLabel()); |
| 7439 | } |
| 7440 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7441 | void CodeGeneratorX86::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 7442 | Location out, |
| 7443 | Location ref, |
| 7444 | Location obj, |
| 7445 | uint32_t offset, |
| 7446 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7447 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7448 | // Baker's read barriers shall be handled by the fast path |
| 7449 | // (CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier). |
| 7450 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7451 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7452 | // by the runtime within the slow path. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7453 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7454 | } else if (kPoisonHeapReferences) { |
| 7455 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 7456 | } |
| 7457 | } |
| 7458 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7459 | void CodeGeneratorX86::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7460 | Location out, |
| 7461 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7462 | DCHECK(kEmitCompilerReadBarrier); |
| 7463 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7464 | // Insert a slow path based read barrier *after* the GC root load. |
| 7465 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7466 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7467 | // not need to do anything special for this here. |
| 7468 | SlowPathCode* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7469 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathX86(instruction, out, root); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7470 | AddSlowPath(slow_path); |
| 7471 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7472 | __ jmp(slow_path->GetEntryLabel()); |
| 7473 | __ Bind(slow_path->GetExitLabel()); |
| 7474 | } |
| 7475 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7476 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7477 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7478 | LOG(FATAL) << "Unreachable"; |
| 7479 | } |
| 7480 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7481 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7482 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7483 | LOG(FATAL) << "Unreachable"; |
| 7484 | } |
| 7485 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7486 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7487 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7488 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7489 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7490 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7491 | } |
| 7492 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7493 | void InstructionCodeGeneratorX86::GenPackedSwitchWithCompares(Register value_reg, |
| 7494 | int32_t lower_bound, |
| 7495 | uint32_t num_entries, |
| 7496 | HBasicBlock* switch_block, |
| 7497 | HBasicBlock* default_block) { |
| 7498 | // Figure out the correct compare values and jump conditions. |
| 7499 | // Handle the first compare/branch as a special case because it might |
| 7500 | // jump to the default case. |
| 7501 | DCHECK_GT(num_entries, 2u); |
| 7502 | Condition first_condition; |
| 7503 | uint32_t index; |
| 7504 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 7505 | if (lower_bound != 0) { |
| 7506 | first_condition = kLess; |
| 7507 | __ cmpl(value_reg, Immediate(lower_bound)); |
| 7508 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 7509 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7510 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7511 | index = 1; |
| 7512 | } else { |
| 7513 | // Handle all the compare/jumps below. |
| 7514 | first_condition = kBelow; |
| 7515 | index = 0; |
| 7516 | } |
| 7517 | |
| 7518 | // Handle the rest of the compare/jumps. |
| 7519 | for (; index + 1 < num_entries; index += 2) { |
| 7520 | int32_t compare_to_value = lower_bound + index + 1; |
| 7521 | __ cmpl(value_reg, Immediate(compare_to_value)); |
| 7522 | // Jump to successors[index] if value < case_value[index]. |
| 7523 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 7524 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 7525 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 7526 | } |
| 7527 | |
| 7528 | if (index != num_entries) { |
| 7529 | // There are an odd number of entries. Handle the last one. |
| 7530 | DCHECK_EQ(index + 1, num_entries); |
| 7531 | __ cmpl(value_reg, Immediate(lower_bound + index)); |
| 7532 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7533 | } |
| 7534 | |
| 7535 | // And the default for any other value. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7536 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
| 7537 | __ jmp(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7538 | } |
| 7539 | } |
| 7540 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7541 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7542 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 7543 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 7544 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7545 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7546 | |
| 7547 | GenPackedSwitchWithCompares(value_reg, |
| 7548 | lower_bound, |
| 7549 | num_entries, |
| 7550 | switch_instr->GetBlock(), |
| 7551 | switch_instr->GetDefaultBlock()); |
| 7552 | } |
| 7553 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7554 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7555 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7556 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7557 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7558 | |
| 7559 | // Constant area pointer. |
| 7560 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7561 | |
| 7562 | // And the temporary we need. |
| 7563 | locations->AddTemp(Location::RequiresRegister()); |
| 7564 | } |
| 7565 | |
| 7566 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7567 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7568 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7569 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7570 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7571 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7572 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7573 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 7574 | GenPackedSwitchWithCompares(value_reg, |
| 7575 | lower_bound, |
| 7576 | num_entries, |
| 7577 | switch_instr->GetBlock(), |
| 7578 | default_block); |
| 7579 | return; |
| 7580 | } |
| 7581 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7582 | // Optimizing has a jump area. |
| 7583 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 7584 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 7585 | |
| 7586 | // Remove the bias, if needed. |
| 7587 | if (lower_bound != 0) { |
| 7588 | __ leal(temp_reg, Address(value_reg, -lower_bound)); |
| 7589 | value_reg = temp_reg; |
| 7590 | } |
| 7591 | |
| 7592 | // Is the value in range? |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7593 | DCHECK_GE(num_entries, 1u); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7594 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 7595 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| 7596 | |
| 7597 | // We are in the range of the table. |
| 7598 | // Load (target-constant_area) from the jump table, indexing by the value. |
| 7599 | __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); |
| 7600 | |
| 7601 | // Compute the actual target address by adding in constant_area. |
| 7602 | __ addl(temp_reg, constant_area); |
| 7603 | |
| 7604 | // And jump. |
| 7605 | __ jmp(temp_reg); |
| 7606 | } |
| 7607 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7608 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 7609 | HX86ComputeBaseMethodAddress* insn) { |
| 7610 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7611 | new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7612 | locations->SetOut(Location::RequiresRegister()); |
| 7613 | } |
| 7614 | |
| 7615 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 7616 | HX86ComputeBaseMethodAddress* insn) { |
| 7617 | LocationSummary* locations = insn->GetLocations(); |
| 7618 | Register reg = locations->Out().AsRegister<Register>(); |
| 7619 | |
| 7620 | // Generate call to next instruction. |
| 7621 | Label next_instruction; |
| 7622 | __ call(&next_instruction); |
| 7623 | __ Bind(&next_instruction); |
| 7624 | |
| 7625 | // Remember this offset for later use with constant area. |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7626 | codegen_->AddMethodAddressOffset(insn, GetAssembler()->CodeSize()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7627 | |
| 7628 | // Grab the return address off the stack. |
| 7629 | __ popl(reg); |
| 7630 | } |
| 7631 | |
| 7632 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 7633 | HX86LoadFromConstantTable* insn) { |
| 7634 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7635 | new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7636 | |
| 7637 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7638 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 7639 | |
| 7640 | // 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] | 7641 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7642 | return; |
| 7643 | } |
| 7644 | |
| 7645 | switch (insn->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7646 | case DataType::Type::kFloat32: |
| 7647 | case DataType::Type::kFloat64: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7648 | locations->SetOut(Location::RequiresFpuRegister()); |
| 7649 | break; |
| 7650 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7651 | case DataType::Type::kInt32: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7652 | locations->SetOut(Location::RequiresRegister()); |
| 7653 | break; |
| 7654 | |
| 7655 | default: |
| 7656 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7657 | } |
| 7658 | } |
| 7659 | |
| 7660 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 7661 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7662 | return; |
| 7663 | } |
| 7664 | |
| 7665 | LocationSummary* locations = insn->GetLocations(); |
| 7666 | Location out = locations->Out(); |
| 7667 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 7668 | HConstant *value = insn->GetConstant(); |
| 7669 | |
| 7670 | switch (insn->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7671 | case DataType::Type::kFloat32: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7672 | __ movss(out.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7673 | codegen_->LiteralFloatAddress( |
| 7674 | value->AsFloatConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7675 | break; |
| 7676 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7677 | case DataType::Type::kFloat64: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7678 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7679 | codegen_->LiteralDoubleAddress( |
| 7680 | value->AsDoubleConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7681 | break; |
| 7682 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7683 | case DataType::Type::kInt32: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7684 | __ movl(out.AsRegister<Register>(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7685 | codegen_->LiteralInt32Address( |
| 7686 | value->AsIntConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7687 | break; |
| 7688 | |
| 7689 | default: |
| 7690 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7691 | } |
| 7692 | } |
| 7693 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7694 | /** |
| 7695 | * Class to handle late fixup of offsets into constant area. |
| 7696 | */ |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 7697 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7698 | public: |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7699 | RIPFixup(CodeGeneratorX86& codegen, |
| 7700 | HX86ComputeBaseMethodAddress* base_method_address, |
| 7701 | size_t offset) |
| 7702 | : codegen_(&codegen), |
| 7703 | base_method_address_(base_method_address), |
| 7704 | offset_into_constant_area_(offset) {} |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7705 | |
| 7706 | protected: |
| 7707 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 7708 | |
| 7709 | CodeGeneratorX86* codegen_; |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7710 | HX86ComputeBaseMethodAddress* base_method_address_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7711 | |
| 7712 | private: |
| 7713 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 7714 | // Patch the correct offset for the instruction. The place to patch is the |
| 7715 | // last 4 bytes of the instruction. |
| 7716 | // The value to patch is the distance from the offset in the constant area |
| 7717 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7718 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7719 | int32_t relative_position = |
| 7720 | constant_offset - codegen_->GetMethodAddressOffset(base_method_address_); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7721 | |
| 7722 | // Patch in the right value. |
| 7723 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 7724 | } |
| 7725 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7726 | // Location in constant area that the fixup refers to. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7727 | int32_t offset_into_constant_area_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7728 | }; |
| 7729 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7730 | /** |
| 7731 | * Class to handle late fixup of offsets to a jump table that will be created in the |
| 7732 | * constant area. |
| 7733 | */ |
| 7734 | class JumpTableRIPFixup : public RIPFixup { |
| 7735 | public: |
| 7736 | JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7737 | : RIPFixup(codegen, switch_instr->GetBaseMethodAddress(), static_cast<size_t>(-1)), |
| 7738 | switch_instr_(switch_instr) {} |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7739 | |
| 7740 | void CreateJumpTable() { |
| 7741 | X86Assembler* assembler = codegen_->GetAssembler(); |
| 7742 | |
| 7743 | // Ensure that the reference to the jump table has the correct offset. |
| 7744 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 7745 | SetOffset(offset_in_constant_table); |
| 7746 | |
| 7747 | // The label values in the jump table are computed relative to the |
| 7748 | // instruction addressing the constant area. |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7749 | const int32_t relative_offset = codegen_->GetMethodAddressOffset(base_method_address_); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7750 | |
| 7751 | // Populate the jump table with the correct values for the jump table. |
| 7752 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 7753 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 7754 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 7755 | // The value that we want is the target offset - the position of the table. |
| 7756 | for (int32_t i = 0; i < num_entries; i++) { |
| 7757 | HBasicBlock* b = successors[i]; |
| 7758 | Label* l = codegen_->GetLabelOf(b); |
| 7759 | DCHECK(l->IsBound()); |
| 7760 | int32_t offset_to_block = l->Position() - relative_offset; |
| 7761 | assembler->AppendInt32(offset_to_block); |
| 7762 | } |
| 7763 | } |
| 7764 | |
| 7765 | private: |
| 7766 | const HX86PackedSwitch* switch_instr_; |
| 7767 | }; |
| 7768 | |
| 7769 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 7770 | // Generate the constant area if needed. |
| 7771 | X86Assembler* assembler = GetAssembler(); |
| 7772 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7773 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 7774 | // byte values. |
| 7775 | assembler->Align(4, 0); |
| 7776 | constant_area_start_ = assembler->CodeSize(); |
| 7777 | |
| 7778 | // Populate any jump tables. |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7779 | for (JumpTableRIPFixup* jump_table : fixups_to_jump_tables_) { |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7780 | jump_table->CreateJumpTable(); |
| 7781 | } |
| 7782 | |
| 7783 | // And now add the constant area to the generated code. |
| 7784 | assembler->AddConstantArea(); |
| 7785 | } |
| 7786 | |
| 7787 | // And finish up. |
| 7788 | CodeGenerator::Finalize(allocator); |
| 7789 | } |
| 7790 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7791 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, |
| 7792 | HX86ComputeBaseMethodAddress* method_base, |
| 7793 | Register reg) { |
| 7794 | AssemblerFixup* fixup = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7795 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddDouble(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7796 | return Address(reg, kDummy32BitOffset, fixup); |
| 7797 | } |
| 7798 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7799 | Address CodeGeneratorX86::LiteralFloatAddress(float v, |
| 7800 | HX86ComputeBaseMethodAddress* method_base, |
| 7801 | Register reg) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7802 | AssemblerFixup* fixup = |
| 7803 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddFloat(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7804 | return Address(reg, kDummy32BitOffset, fixup); |
| 7805 | } |
| 7806 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7807 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, |
| 7808 | HX86ComputeBaseMethodAddress* method_base, |
| 7809 | Register reg) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7810 | AssemblerFixup* fixup = |
| 7811 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddInt32(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7812 | return Address(reg, kDummy32BitOffset, fixup); |
| 7813 | } |
| 7814 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7815 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, |
| 7816 | HX86ComputeBaseMethodAddress* method_base, |
| 7817 | Register reg) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7818 | AssemblerFixup* fixup = |
| 7819 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddInt64(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7820 | return Address(reg, kDummy32BitOffset, fixup); |
| 7821 | } |
| 7822 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 7823 | void CodeGeneratorX86::Load32BitValue(Register dest, int32_t value) { |
| 7824 | if (value == 0) { |
| 7825 | __ xorl(dest, dest); |
| 7826 | } else { |
| 7827 | __ movl(dest, Immediate(value)); |
| 7828 | } |
| 7829 | } |
| 7830 | |
| 7831 | void CodeGeneratorX86::Compare32BitValue(Register dest, int32_t value) { |
| 7832 | if (value == 0) { |
| 7833 | __ testl(dest, dest); |
| 7834 | } else { |
| 7835 | __ cmpl(dest, Immediate(value)); |
| 7836 | } |
| 7837 | } |
| 7838 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7839 | void CodeGeneratorX86::GenerateIntCompare(Location lhs, Location rhs) { |
| 7840 | Register lhs_reg = lhs.AsRegister<Register>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7841 | GenerateIntCompare(lhs_reg, rhs); |
| 7842 | } |
| 7843 | |
| 7844 | void CodeGeneratorX86::GenerateIntCompare(Register lhs, Location rhs) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7845 | if (rhs.IsConstant()) { |
| 7846 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7847 | Compare32BitValue(lhs, value); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7848 | } else if (rhs.IsStackSlot()) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7849 | __ cmpl(lhs, Address(ESP, rhs.GetStackIndex())); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7850 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7851 | __ cmpl(lhs, rhs.AsRegister<Register>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7852 | } |
| 7853 | } |
| 7854 | |
| 7855 | Address CodeGeneratorX86::ArrayAddress(Register obj, |
| 7856 | Location index, |
| 7857 | ScaleFactor scale, |
| 7858 | uint32_t data_offset) { |
| 7859 | return index.IsConstant() ? |
| 7860 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) : |
| 7861 | Address(obj, index.AsRegister<Register>(), scale, data_offset); |
| 7862 | } |
| 7863 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7864 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, |
| 7865 | Register reg, |
| 7866 | Register value) { |
| 7867 | // Create a fixup to be used to create and address the jump table. |
| 7868 | JumpTableRIPFixup* table_fixup = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7869 | new (GetGraph()->GetAllocator()) JumpTableRIPFixup(*this, switch_instr); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7870 | |
| 7871 | // We have to populate the jump tables. |
| 7872 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7873 | |
| 7874 | // We want a scaled address, as we are extracting the correct offset from the table. |
| 7875 | return Address(reg, value, TIMES_4, kDummy32BitOffset, table_fixup); |
| 7876 | } |
| 7877 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7878 | // TODO: target as memory. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7879 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, DataType::Type type) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7880 | if (!target.IsValid()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7881 | DCHECK_EQ(type, DataType::Type::kVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7882 | return; |
| 7883 | } |
| 7884 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7885 | DCHECK_NE(type, DataType::Type::kVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7886 | |
| 7887 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 7888 | if (target.Equals(return_loc)) { |
| 7889 | return; |
| 7890 | } |
| 7891 | |
| 7892 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 7893 | // with the else branch. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7894 | if (type == DataType::Type::kInt64) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7895 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7896 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), DataType::Type::kInt32, nullptr); |
| 7897 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), DataType::Type::kInt32, nullptr); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7898 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7899 | } else { |
| 7900 | // Let the parallel move resolver take care of all of this. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7901 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7902 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 7903 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7904 | } |
| 7905 | } |
| 7906 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7907 | void CodeGeneratorX86::PatchJitRootUse(uint8_t* code, |
| 7908 | const uint8_t* roots_data, |
| 7909 | const PatchInfo<Label>& info, |
| 7910 | uint64_t index_in_table) const { |
| 7911 | uint32_t code_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 7912 | uintptr_t address = |
| 7913 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 7914 | typedef __attribute__((__aligned__(1))) uint32_t unaligned_uint32_t; |
| 7915 | reinterpret_cast<unaligned_uint32_t*>(code + code_offset)[0] = |
| 7916 | dchecked_integral_cast<uint32_t>(address); |
| 7917 | } |
| 7918 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7919 | void CodeGeneratorX86::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 7920 | for (const PatchInfo<Label>& info : jit_string_patches_) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7921 | 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] | 7922 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7923 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7924 | } |
| 7925 | |
| 7926 | for (const PatchInfo<Label>& info : jit_class_patches_) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7927 | 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] | 7928 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7929 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7930 | } |
| 7931 | } |
| 7932 | |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7933 | void LocationsBuilderX86::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 7934 | ATTRIBUTE_UNUSED) { |
| 7935 | LOG(FATAL) << "Unreachable"; |
| 7936 | } |
| 7937 | |
| 7938 | void InstructionCodeGeneratorX86::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 7939 | ATTRIBUTE_UNUSED) { |
| 7940 | LOG(FATAL) << "Unreachable"; |
| 7941 | } |
| 7942 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7943 | #undef __ |
| 7944 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7945 | } // namespace x86 |
| 7946 | } // namespace art |