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 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 320 | if (!is_fatal_) { |
| 321 | SaveLiveRegisters(codegen, locations); |
| 322 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 323 | |
| 324 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 325 | // move resolver. |
| 326 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 327 | x86_codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 328 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 329 | DataType::Type::kReference, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 330 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 331 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 332 | DataType::Type::kReference); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 333 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 334 | x86_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 335 | instruction_, |
| 336 | instruction_->GetDexPc(), |
| 337 | this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 338 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 339 | } else { |
| 340 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 341 | x86_codegen->InvokeRuntime(kQuickCheckInstanceOf, |
| 342 | instruction_, |
| 343 | instruction_->GetDexPc(), |
| 344 | this); |
| 345 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 346 | } |
| 347 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 348 | if (!is_fatal_) { |
| 349 | if (instruction_->IsInstanceOf()) { |
| 350 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 351 | } |
| 352 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 353 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 354 | __ jmp(GetExitLabel()); |
| 355 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 356 | } |
| 357 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 358 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86"; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 359 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 360 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 361 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 362 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 363 | |
| 364 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86); |
| 365 | }; |
| 366 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 367 | class DeoptimizationSlowPathX86 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 368 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 369 | explicit DeoptimizationSlowPathX86(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 370 | : SlowPathCode(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 371 | |
| 372 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 373 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 374 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 375 | LocationSummary* locations = instruction_->GetLocations(); |
| 376 | SaveLiveRegisters(codegen, locations); |
| 377 | InvokeRuntimeCallingConvention calling_convention; |
| 378 | x86_codegen->Load32BitValue( |
| 379 | calling_convention.GetRegisterAt(0), |
| 380 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 381 | x86_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 382 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 383 | } |
| 384 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 385 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86"; } |
| 386 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 387 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 388 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86); |
| 389 | }; |
| 390 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 391 | class ArraySetSlowPathX86 : public SlowPathCode { |
| 392 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 393 | explicit ArraySetSlowPathX86(HInstruction* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 394 | |
| 395 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 396 | LocationSummary* locations = instruction_->GetLocations(); |
| 397 | __ Bind(GetEntryLabel()); |
| 398 | SaveLiveRegisters(codegen, locations); |
| 399 | |
| 400 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 401 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 402 | parallel_move.AddMove( |
| 403 | locations->InAt(0), |
| 404 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 405 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 406 | nullptr); |
| 407 | parallel_move.AddMove( |
| 408 | locations->InAt(1), |
| 409 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 410 | DataType::Type::kInt32, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 411 | nullptr); |
| 412 | parallel_move.AddMove( |
| 413 | locations->InAt(2), |
| 414 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 415 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 416 | nullptr); |
| 417 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 418 | |
| 419 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 420 | x86_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 421 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 422 | RestoreLiveRegisters(codegen, locations); |
| 423 | __ jmp(GetExitLabel()); |
| 424 | } |
| 425 | |
| 426 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86"; } |
| 427 | |
| 428 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 429 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86); |
| 430 | }; |
| 431 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 432 | // Slow path marking an object reference `ref` during a read |
| 433 | // barrier. The field `obj.field` in the object `obj` holding this |
| 434 | // reference does not get updated by this slow path after marking (see |
| 435 | // ReadBarrierMarkAndUpdateFieldSlowPathX86 below for that). |
| 436 | // |
| 437 | // This means that after the execution of this slow path, `ref` will |
| 438 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 439 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 440 | // probably still be a from-space reference (unless it gets updated by |
| 441 | // another thread, or if another thread installed another object |
| 442 | // reference (different from `ref`) in `obj.field`). |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 443 | class ReadBarrierMarkSlowPathX86 : public SlowPathCode { |
| 444 | public: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 445 | ReadBarrierMarkSlowPathX86(HInstruction* instruction, |
| 446 | Location ref, |
| 447 | bool unpoison_ref_before_marking) |
| 448 | : SlowPathCode(instruction), |
| 449 | ref_(ref), |
| 450 | unpoison_ref_before_marking_(unpoison_ref_before_marking) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 451 | DCHECK(kEmitCompilerReadBarrier); |
| 452 | } |
| 453 | |
| 454 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathX86"; } |
| 455 | |
| 456 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 457 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 458 | Register ref_reg = ref_.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 459 | DCHECK(locations->CanCall()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 460 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 461 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 462 | instruction_->IsStaticFieldGet() || |
| 463 | instruction_->IsArrayGet() || |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 464 | instruction_->IsArraySet() || |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 465 | instruction_->IsLoadClass() || |
| 466 | instruction_->IsLoadString() || |
| 467 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 468 | instruction_->IsCheckCast() || |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 469 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 470 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 471 | << "Unexpected instruction in read barrier marking slow path: " |
| 472 | << instruction_->DebugName(); |
| 473 | |
| 474 | __ Bind(GetEntryLabel()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 475 | if (unpoison_ref_before_marking_) { |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 476 | // Object* ref = ref_addr->AsMirrorPtr() |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 477 | __ MaybeUnpoisonHeapReference(ref_reg); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 478 | } |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 479 | // No need to save live registers; it's taken care of by the |
| 480 | // entrypoint. Also, there is no need to update the stack mask, |
| 481 | // as this runtime call will not trigger a garbage collection. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 482 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 483 | DCHECK_NE(ref_reg, ESP); |
| 484 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 485 | // "Compact" slow path, saving two moves. |
| 486 | // |
| 487 | // Instead of using the standard runtime calling convention (input |
| 488 | // and output in EAX): |
| 489 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 490 | // EAX <- ref |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 491 | // EAX <- ReadBarrierMark(EAX) |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 492 | // ref <- EAX |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 493 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 494 | // we just use rX (the register containing `ref`) as input and output |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 495 | // of a dedicated entrypoint: |
| 496 | // |
| 497 | // rX <- ReadBarrierMarkRegX(rX) |
| 498 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 499 | int32_t entry_point_offset = Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(ref_reg); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 500 | // This runtime call does not require a stack map. |
| 501 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 502 | __ jmp(GetExitLabel()); |
| 503 | } |
| 504 | |
| 505 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 506 | // The location (register) of the marked object reference. |
| 507 | const Location ref_; |
| 508 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 509 | const bool unpoison_ref_before_marking_; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 510 | |
| 511 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86); |
| 512 | }; |
| 513 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 514 | // Slow path marking an object reference `ref` during a read barrier, |
| 515 | // and if needed, atomically updating the field `obj.field` in the |
| 516 | // object `obj` holding this reference after marking (contrary to |
| 517 | // ReadBarrierMarkSlowPathX86 above, which never tries to update |
| 518 | // `obj.field`). |
| 519 | // |
| 520 | // This means that after the execution of this slow path, both `ref` |
| 521 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 522 | // hold the same to-space reference (unless another thread installed |
| 523 | // another object reference (different from `ref`) in `obj.field`). |
| 524 | class ReadBarrierMarkAndUpdateFieldSlowPathX86 : public SlowPathCode { |
| 525 | public: |
| 526 | ReadBarrierMarkAndUpdateFieldSlowPathX86(HInstruction* instruction, |
| 527 | Location ref, |
| 528 | Register obj, |
| 529 | const Address& field_addr, |
| 530 | bool unpoison_ref_before_marking, |
| 531 | Register temp) |
| 532 | : SlowPathCode(instruction), |
| 533 | ref_(ref), |
| 534 | obj_(obj), |
| 535 | field_addr_(field_addr), |
| 536 | unpoison_ref_before_marking_(unpoison_ref_before_marking), |
| 537 | temp_(temp) { |
| 538 | DCHECK(kEmitCompilerReadBarrier); |
| 539 | } |
| 540 | |
| 541 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkAndUpdateFieldSlowPathX86"; } |
| 542 | |
| 543 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 544 | LocationSummary* locations = instruction_->GetLocations(); |
| 545 | Register ref_reg = ref_.AsRegister<Register>(); |
| 546 | DCHECK(locations->CanCall()); |
| 547 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 548 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 549 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 550 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 551 | << instruction_->DebugName(); |
| 552 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 553 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 554 | |
| 555 | __ Bind(GetEntryLabel()); |
| 556 | if (unpoison_ref_before_marking_) { |
| 557 | // Object* ref = ref_addr->AsMirrorPtr() |
| 558 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 559 | } |
| 560 | |
| 561 | // Save the old (unpoisoned) reference. |
| 562 | __ movl(temp_, ref_reg); |
| 563 | |
| 564 | // No need to save live registers; it's taken care of by the |
| 565 | // entrypoint. Also, there is no need to update the stack mask, |
| 566 | // as this runtime call will not trigger a garbage collection. |
| 567 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 568 | DCHECK_NE(ref_reg, ESP); |
| 569 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
| 570 | // "Compact" slow path, saving two moves. |
| 571 | // |
| 572 | // Instead of using the standard runtime calling convention (input |
| 573 | // and output in EAX): |
| 574 | // |
| 575 | // EAX <- ref |
| 576 | // EAX <- ReadBarrierMark(EAX) |
| 577 | // ref <- EAX |
| 578 | // |
| 579 | // we just use rX (the register containing `ref`) as input and output |
| 580 | // of a dedicated entrypoint: |
| 581 | // |
| 582 | // rX <- ReadBarrierMarkRegX(rX) |
| 583 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 584 | int32_t entry_point_offset = Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(ref_reg); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 585 | // This runtime call does not require a stack map. |
| 586 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 587 | |
| 588 | // If the new reference is different from the old reference, |
| 589 | // update the field in the holder (`*field_addr`). |
| 590 | // |
| 591 | // Note that this field could also hold a different object, if |
| 592 | // another thread had concurrently changed it. In that case, the |
| 593 | // LOCK CMPXCHGL instruction in the compare-and-set (CAS) |
| 594 | // operation below would abort the CAS, leaving the field as-is. |
| 595 | NearLabel done; |
| 596 | __ cmpl(temp_, ref_reg); |
| 597 | __ j(kEqual, &done); |
| 598 | |
| 599 | // Update the the holder's field atomically. This may fail if |
| 600 | // mutator updates before us, but it's OK. This is achieved |
| 601 | // using a strong compare-and-set (CAS) operation with relaxed |
| 602 | // memory synchronization ordering, where the expected value is |
| 603 | // the old reference and the desired value is the new reference. |
| 604 | // This operation is implemented with a 32-bit LOCK CMPXLCHG |
| 605 | // instruction, which requires the expected value (the old |
| 606 | // reference) to be in EAX. Save EAX beforehand, and move the |
| 607 | // expected value (stored in `temp_`) into EAX. |
| 608 | __ pushl(EAX); |
| 609 | __ movl(EAX, temp_); |
| 610 | |
| 611 | // Convenience aliases. |
| 612 | Register base = obj_; |
| 613 | Register expected = EAX; |
| 614 | Register value = ref_reg; |
| 615 | |
| 616 | bool base_equals_value = (base == value); |
| 617 | if (kPoisonHeapReferences) { |
| 618 | if (base_equals_value) { |
| 619 | // If `base` and `value` are the same register location, move |
| 620 | // `value` to a temporary register. This way, poisoning |
| 621 | // `value` won't invalidate `base`. |
| 622 | value = temp_; |
| 623 | __ movl(value, base); |
| 624 | } |
| 625 | |
| 626 | // Check that the register allocator did not assign the location |
| 627 | // of `expected` (EAX) to `value` nor to `base`, so that heap |
| 628 | // poisoning (when enabled) works as intended below. |
| 629 | // - If `value` were equal to `expected`, both references would |
| 630 | // be poisoned twice, meaning they would not be poisoned at |
| 631 | // all, as heap poisoning uses address negation. |
| 632 | // - If `base` were equal to `expected`, poisoning `expected` |
| 633 | // would invalidate `base`. |
| 634 | DCHECK_NE(value, expected); |
| 635 | DCHECK_NE(base, expected); |
| 636 | |
| 637 | __ PoisonHeapReference(expected); |
| 638 | __ PoisonHeapReference(value); |
| 639 | } |
| 640 | |
| 641 | __ LockCmpxchgl(field_addr_, value); |
| 642 | |
| 643 | // If heap poisoning is enabled, we need to unpoison the values |
| 644 | // that were poisoned earlier. |
| 645 | if (kPoisonHeapReferences) { |
| 646 | if (base_equals_value) { |
| 647 | // `value` has been moved to a temporary register, no need |
| 648 | // to unpoison it. |
| 649 | } else { |
| 650 | __ UnpoisonHeapReference(value); |
| 651 | } |
| 652 | // No need to unpoison `expected` (EAX), as it is be overwritten below. |
| 653 | } |
| 654 | |
| 655 | // Restore EAX. |
| 656 | __ popl(EAX); |
| 657 | |
| 658 | __ Bind(&done); |
| 659 | __ jmp(GetExitLabel()); |
| 660 | } |
| 661 | |
| 662 | private: |
| 663 | // The location (register) of the marked object reference. |
| 664 | const Location ref_; |
| 665 | // The register containing the object holding the marked object reference field. |
| 666 | const Register obj_; |
| 667 | // The address of the marked reference field. The base of this address must be `obj_`. |
| 668 | const Address field_addr_; |
| 669 | |
| 670 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 671 | const bool unpoison_ref_before_marking_; |
| 672 | |
| 673 | const Register temp_; |
| 674 | |
| 675 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathX86); |
| 676 | }; |
| 677 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 678 | // Slow path generating a read barrier for a heap reference. |
| 679 | class ReadBarrierForHeapReferenceSlowPathX86 : public SlowPathCode { |
| 680 | public: |
| 681 | ReadBarrierForHeapReferenceSlowPathX86(HInstruction* instruction, |
| 682 | Location out, |
| 683 | Location ref, |
| 684 | Location obj, |
| 685 | uint32_t offset, |
| 686 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 687 | : SlowPathCode(instruction), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 688 | out_(out), |
| 689 | ref_(ref), |
| 690 | obj_(obj), |
| 691 | offset_(offset), |
| 692 | index_(index) { |
| 693 | DCHECK(kEmitCompilerReadBarrier); |
| 694 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 695 | // has been overwritten by (or after) the heap object reference load |
| 696 | // to be instrumented, e.g.: |
| 697 | // |
| 698 | // __ movl(out, Address(out, offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 699 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 700 | // |
| 701 | // In that case, we have lost the information about the original |
| 702 | // object, and the emitted read barrier cannot work properly. |
| 703 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 704 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 705 | } |
| 706 | |
| 707 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 708 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 709 | LocationSummary* locations = instruction_->GetLocations(); |
| 710 | Register reg_out = out_.AsRegister<Register>(); |
| 711 | DCHECK(locations->CanCall()); |
| 712 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 713 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 714 | instruction_->IsStaticFieldGet() || |
| 715 | instruction_->IsArrayGet() || |
| 716 | instruction_->IsInstanceOf() || |
| 717 | instruction_->IsCheckCast() || |
Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 718 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 719 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 720 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 721 | |
| 722 | __ Bind(GetEntryLabel()); |
| 723 | SaveLiveRegisters(codegen, locations); |
| 724 | |
| 725 | // We may have to change the index's value, but as `index_` is a |
| 726 | // constant member (like other "inputs" of this slow path), |
| 727 | // introduce a copy of it, `index`. |
| 728 | Location index = index_; |
| 729 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 730 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 731 | if (instruction_->IsArrayGet()) { |
| 732 | // Compute the actual memory offset and store it in `index`. |
| 733 | Register index_reg = index_.AsRegister<Register>(); |
| 734 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 735 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 736 | // We are about to change the value of `index_reg` (see the |
| 737 | // calls to art::x86::X86Assembler::shll and |
| 738 | // art::x86::X86Assembler::AddImmediate below), but it has |
| 739 | // not been saved by the previous call to |
| 740 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 741 | // callee-save register -- |
| 742 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 743 | // callee-save registers, as it has been designed with the |
| 744 | // assumption that callee-save registers are supposed to be |
| 745 | // handled by the called function. So, as a callee-save |
| 746 | // register, `index_reg` _would_ eventually be saved onto |
| 747 | // the stack, but it would be too late: we would have |
| 748 | // changed its value earlier. Therefore, we manually save |
| 749 | // it here into another freely available register, |
| 750 | // `free_reg`, chosen of course among the caller-save |
| 751 | // registers (as a callee-save `free_reg` register would |
| 752 | // exhibit the same problem). |
| 753 | // |
| 754 | // Note we could have requested a temporary register from |
| 755 | // the register allocator instead; but we prefer not to, as |
| 756 | // this is a slow path, and we know we can find a |
| 757 | // caller-save register that is available. |
| 758 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 759 | __ movl(free_reg, index_reg); |
| 760 | index_reg = free_reg; |
| 761 | index = Location::RegisterLocation(index_reg); |
| 762 | } else { |
| 763 | // The initial register stored in `index_` has already been |
| 764 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 765 | // (as it is not a callee-save register), so we can freely |
| 766 | // use it. |
| 767 | } |
| 768 | // Shifting the index value contained in `index_reg` by the scale |
| 769 | // factor (2) cannot overflow in practice, as the runtime is |
| 770 | // unable to allocate object arrays with a size larger than |
| 771 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 772 | __ shll(index_reg, Immediate(TIMES_4)); |
| 773 | static_assert( |
| 774 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 775 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 776 | __ AddImmediate(index_reg, Immediate(offset_)); |
| 777 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 778 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 779 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 780 | // (as in the case of ArrayGet), as it is actually an offset |
| 781 | // to an object field within an object. |
| 782 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 783 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 784 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 785 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 786 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 787 | DCHECK_EQ(offset_, 0U); |
| 788 | DCHECK(index_.IsRegisterPair()); |
| 789 | // UnsafeGet's offset location is a register pair, the low |
| 790 | // part contains the correct offset. |
| 791 | index = index_.ToLow(); |
| 792 | } |
| 793 | } |
| 794 | |
| 795 | // We're moving two or three locations to locations that could |
| 796 | // overlap, so we need a parallel move resolver. |
| 797 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 798 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 799 | parallel_move.AddMove(ref_, |
| 800 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 801 | DataType::Type::kReference, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 802 | nullptr); |
| 803 | parallel_move.AddMove(obj_, |
| 804 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 805 | DataType::Type::kReference, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 806 | nullptr); |
| 807 | if (index.IsValid()) { |
| 808 | parallel_move.AddMove(index, |
| 809 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 810 | DataType::Type::kInt32, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 811 | nullptr); |
| 812 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 813 | } else { |
| 814 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 815 | __ movl(calling_convention.GetRegisterAt(2), Immediate(offset_)); |
| 816 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 817 | x86_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 818 | CheckEntrypointTypes< |
| 819 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 820 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 821 | |
| 822 | RestoreLiveRegisters(codegen, locations); |
| 823 | __ jmp(GetExitLabel()); |
| 824 | } |
| 825 | |
| 826 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathX86"; } |
| 827 | |
| 828 | private: |
| 829 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 830 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 831 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 832 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 833 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 834 | return static_cast<Register>(i); |
| 835 | } |
| 836 | } |
| 837 | // We shall never fail to find a free caller-save register, as |
| 838 | // there are more than two core caller-save registers on x86 |
| 839 | // (meaning it is possible to find one which is different from |
| 840 | // `ref` and `obj`). |
| 841 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 842 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 843 | UNREACHABLE(); |
| 844 | } |
| 845 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 846 | const Location out_; |
| 847 | const Location ref_; |
| 848 | const Location obj_; |
| 849 | const uint32_t offset_; |
| 850 | // An additional location containing an index to an array. |
| 851 | // Only used for HArrayGet and the UnsafeGetObject & |
| 852 | // UnsafeGetObjectVolatile intrinsics. |
| 853 | const Location index_; |
| 854 | |
| 855 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86); |
| 856 | }; |
| 857 | |
| 858 | // Slow path generating a read barrier for a GC root. |
| 859 | class ReadBarrierForRootSlowPathX86 : public SlowPathCode { |
| 860 | public: |
| 861 | ReadBarrierForRootSlowPathX86(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 862 | : SlowPathCode(instruction), out_(out), root_(root) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 863 | DCHECK(kEmitCompilerReadBarrier); |
| 864 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 865 | |
| 866 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 867 | LocationSummary* locations = instruction_->GetLocations(); |
| 868 | Register reg_out = out_.AsRegister<Register>(); |
| 869 | DCHECK(locations->CanCall()); |
| 870 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 871 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 872 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 873 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 874 | |
| 875 | __ Bind(GetEntryLabel()); |
| 876 | SaveLiveRegisters(codegen, locations); |
| 877 | |
| 878 | InvokeRuntimeCallingConvention calling_convention; |
| 879 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 880 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 881 | x86_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 882 | instruction_, |
| 883 | instruction_->GetDexPc(), |
| 884 | this); |
| 885 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 886 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 887 | |
| 888 | RestoreLiveRegisters(codegen, locations); |
| 889 | __ jmp(GetExitLabel()); |
| 890 | } |
| 891 | |
| 892 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathX86"; } |
| 893 | |
| 894 | private: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 895 | const Location out_; |
| 896 | const Location root_; |
| 897 | |
| 898 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86); |
| 899 | }; |
| 900 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 901 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 902 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 903 | #define __ down_cast<X86Assembler*>(GetAssembler())-> // NOLINT |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 904 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 905 | inline Condition X86Condition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 906 | switch (cond) { |
| 907 | case kCondEQ: return kEqual; |
| 908 | case kCondNE: return kNotEqual; |
| 909 | case kCondLT: return kLess; |
| 910 | case kCondLE: return kLessEqual; |
| 911 | case kCondGT: return kGreater; |
| 912 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 913 | case kCondB: return kBelow; |
| 914 | case kCondBE: return kBelowEqual; |
| 915 | case kCondA: return kAbove; |
| 916 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 917 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 918 | LOG(FATAL) << "Unreachable"; |
| 919 | UNREACHABLE(); |
| 920 | } |
| 921 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 922 | // Maps signed condition to unsigned condition and FP condition to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 923 | inline Condition X86UnsignedOrFPCondition(IfCondition cond) { |
| 924 | switch (cond) { |
| 925 | case kCondEQ: return kEqual; |
| 926 | case kCondNE: return kNotEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 927 | // Signed to unsigned, and FP to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 928 | case kCondLT: return kBelow; |
| 929 | case kCondLE: return kBelowEqual; |
| 930 | case kCondGT: return kAbove; |
| 931 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 932 | // Unsigned remain unchanged. |
| 933 | case kCondB: return kBelow; |
| 934 | case kCondBE: return kBelowEqual; |
| 935 | case kCondA: return kAbove; |
| 936 | case kCondAE: return kAboveEqual; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 937 | } |
| 938 | LOG(FATAL) << "Unreachable"; |
| 939 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 940 | } |
| 941 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 942 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 943 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 947 | stream << XmmRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 948 | } |
| 949 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 950 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 951 | __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); |
| 952 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 953 | } |
| 954 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 955 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 956 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); |
| 957 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 958 | } |
| 959 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 960 | size_t CodeGeneratorX86::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 961 | if (GetGraph()->HasSIMD()) { |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 962 | __ movups(Address(ESP, stack_index), XmmRegister(reg_id)); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 963 | } else { |
| 964 | __ movsd(Address(ESP, stack_index), XmmRegister(reg_id)); |
| 965 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 966 | return GetFloatingPointSpillSlotSize(); |
| 967 | } |
| 968 | |
| 969 | size_t CodeGeneratorX86::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 970 | if (GetGraph()->HasSIMD()) { |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 971 | __ movups(XmmRegister(reg_id), Address(ESP, stack_index)); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 972 | } else { |
| 973 | __ movsd(XmmRegister(reg_id), Address(ESP, stack_index)); |
| 974 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 975 | return GetFloatingPointSpillSlotSize(); |
| 976 | } |
| 977 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 978 | void CodeGeneratorX86::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 979 | HInstruction* instruction, |
| 980 | uint32_t dex_pc, |
| 981 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 982 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 983 | GenerateInvokeRuntime(GetThreadOffset<kX86PointerSize>(entrypoint).Int32Value()); |
| 984 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 985 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 986 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 987 | } |
| 988 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 989 | void CodeGeneratorX86::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 990 | HInstruction* instruction, |
| 991 | SlowPathCode* slow_path) { |
| 992 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 993 | GenerateInvokeRuntime(entry_point_offset); |
| 994 | } |
| 995 | |
| 996 | void CodeGeneratorX86::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 997 | __ fs()->call(Address::Absolute(entry_point_offset)); |
| 998 | } |
| 999 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1000 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1001 | const X86InstructionSetFeatures& isa_features, |
| 1002 | const CompilerOptions& compiler_options, |
| 1003 | OptimizingCompilerStats* stats) |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1004 | : CodeGenerator(graph, |
| 1005 | kNumberOfCpuRegisters, |
| 1006 | kNumberOfXmmRegisters, |
| 1007 | kNumberOfRegisterPairs, |
| 1008 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1009 | arraysize(kCoreCalleeSaves)) |
| 1010 | | (1 << kFakeReturnRegister), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1011 | 0, |
| 1012 | compiler_options, |
| 1013 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1014 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1015 | location_builder_(graph, this), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1016 | instruction_visitor_(graph, this), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1017 | move_resolver_(graph->GetAllocator(), this), |
| 1018 | assembler_(graph->GetAllocator()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1019 | isa_features_(isa_features), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1020 | boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1021 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1022 | boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1023 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1024 | string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1025 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1026 | jit_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1027 | jit_class_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1028 | constant_area_start_(-1), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1029 | fixups_to_jump_tables_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1030 | method_address_offset_(std::less<uint32_t>(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1031 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1032 | // Use a fake return address register to mimic Quick. |
| 1033 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1034 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1035 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1036 | void CodeGeneratorX86::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1037 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1038 | blocked_core_registers_[ESP] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1039 | } |
| 1040 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1041 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1042 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1043 | assembler_(codegen->GetAssembler()), |
| 1044 | codegen_(codegen) {} |
| 1045 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1046 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1047 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1048 | } |
| 1049 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1050 | void CodeGeneratorX86::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1051 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1052 | __ Bind(&frame_entry_label_); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1053 | bool skip_overflow_check = |
| 1054 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1055 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 1056 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1057 | if (!skip_overflow_check) { |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1058 | size_t reserved_bytes = GetStackOverflowReservedBytes(InstructionSet::kX86); |
| 1059 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(reserved_bytes))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1060 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 1061 | } |
| 1062 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1063 | if (HasEmptyFrame()) { |
| 1064 | return; |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1065 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1066 | |
| 1067 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 1068 | Register reg = kCoreCalleeSaves[i]; |
| 1069 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1070 | __ pushl(reg); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1071 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 1072 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1073 | } |
| 1074 | } |
| 1075 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1076 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1077 | __ subl(ESP, Immediate(adjust)); |
| 1078 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1079 | // Save the current method if we need it. Note that we do not |
| 1080 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1081 | // in the SSA graph. |
| 1082 | if (RequiresCurrentMethod()) { |
| 1083 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
| 1084 | } |
Nicolas Geoffray | f789353 | 2017-06-15 12:34:36 +0100 | [diff] [blame] | 1085 | |
| 1086 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1087 | // Initialize should_deoptimize flag to 0. |
| 1088 | __ movl(Address(ESP, GetStackOffsetOfShouldDeoptimizeFlag()), Immediate(0)); |
| 1089 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1090 | } |
| 1091 | |
| 1092 | void CodeGeneratorX86::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1093 | __ cfi().RememberState(); |
| 1094 | if (!HasEmptyFrame()) { |
| 1095 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1096 | __ addl(ESP, Immediate(adjust)); |
| 1097 | __ cfi().AdjustCFAOffset(-adjust); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1098 | |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1099 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1100 | Register reg = kCoreCalleeSaves[i]; |
| 1101 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1102 | __ popl(reg); |
| 1103 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 1104 | __ cfi().Restore(DWARFReg(reg)); |
| 1105 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1106 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1107 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1108 | __ ret(); |
| 1109 | __ cfi().RestoreState(); |
| 1110 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1111 | } |
| 1112 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1113 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 1114 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1115 | } |
| 1116 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1117 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(DataType::Type type) const { |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1118 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1119 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1120 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1121 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1122 | case DataType::Type::kInt8: |
| 1123 | case DataType::Type::kUint16: |
| 1124 | case DataType::Type::kInt16: |
| 1125 | case DataType::Type::kInt32: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1126 | return Location::RegisterLocation(EAX); |
| 1127 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1128 | case DataType::Type::kInt64: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1129 | return Location::RegisterPairLocation(EAX, EDX); |
| 1130 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1131 | case DataType::Type::kVoid: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1132 | return Location::NoLocation(); |
| 1133 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1134 | case DataType::Type::kFloat64: |
| 1135 | case DataType::Type::kFloat32: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1136 | return Location::FpuRegisterLocation(XMM0); |
| 1137 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1138 | |
| 1139 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1140 | } |
| 1141 | |
| 1142 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 1143 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1144 | } |
| 1145 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1146 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(DataType::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1147 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1148 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1149 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1150 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1151 | case DataType::Type::kInt8: |
| 1152 | case DataType::Type::kUint16: |
| 1153 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1154 | case DataType::Type::kInt32: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1155 | uint32_t index = gp_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1156 | stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1157 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1158 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1159 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1160 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1161 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1162 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1163 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1164 | case DataType::Type::kInt64: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1165 | uint32_t index = gp_index_; |
| 1166 | gp_index_ += 2; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1167 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1168 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1169 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 1170 | calling_convention.GetRegisterPairAt(index)); |
| 1171 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1172 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1173 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1174 | } |
| 1175 | } |
| 1176 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1177 | case DataType::Type::kFloat32: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1178 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1179 | stack_index_++; |
| 1180 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1181 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1182 | } else { |
| 1183 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1184 | } |
| 1185 | } |
| 1186 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1187 | case DataType::Type::kFloat64: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1188 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1189 | stack_index_ += 2; |
| 1190 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1191 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1192 | } else { |
| 1193 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1194 | } |
| 1195 | } |
| 1196 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1197 | case DataType::Type::kVoid: |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1198 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1199 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1200 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1201 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1202 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1203 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1204 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 1205 | if (source.Equals(destination)) { |
| 1206 | return; |
| 1207 | } |
| 1208 | if (destination.IsRegister()) { |
| 1209 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1210 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1211 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1212 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1213 | } else { |
| 1214 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1215 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1216 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1217 | } else if (destination.IsFpuRegister()) { |
| 1218 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1219 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1220 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1221 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1222 | } else { |
| 1223 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1224 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1225 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1226 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1227 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1228 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1229 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1230 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1231 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1232 | } else if (source.IsConstant()) { |
| 1233 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1234 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1235 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1236 | } else { |
| 1237 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1238 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 1239 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1240 | } |
| 1241 | } |
| 1242 | } |
| 1243 | |
| 1244 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 1245 | if (source.Equals(destination)) { |
| 1246 | return; |
| 1247 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1248 | if (destination.IsRegisterPair()) { |
| 1249 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1250 | EmitParallelMoves( |
| 1251 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1252 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1253 | DataType::Type::kInt32, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1254 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1255 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1256 | DataType::Type::kInt32); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1257 | } else if (source.IsFpuRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1258 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 1259 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 1260 | __ psrlq(src_reg, Immediate(32)); |
| 1261 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1262 | } else { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1263 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1264 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1265 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 1266 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1267 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 1268 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1269 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1270 | if (source.IsFpuRegister()) { |
| 1271 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 1272 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1273 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1274 | } else if (source.IsRegisterPair()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1275 | size_t elem_size = DataType::Size(DataType::Type::kInt32); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1276 | // Create stack space for 2 elements. |
| 1277 | __ subl(ESP, Immediate(2 * elem_size)); |
| 1278 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 1279 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 1280 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 1281 | // And remove the temporary stack space we allocated. |
| 1282 | __ addl(ESP, Immediate(2 * elem_size)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1283 | } else { |
| 1284 | LOG(FATAL) << "Unimplemented"; |
| 1285 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1286 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1287 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1288 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1289 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1290 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1291 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1292 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1293 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1294 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1295 | } else if (source.IsConstant()) { |
| 1296 | HConstant* constant = source.GetConstant(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1297 | DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant()); |
| 1298 | int64_t value = GetInt64ValueOf(constant); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1299 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1300 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
| 1301 | Immediate(High32Bits(value))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1302 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1303 | DCHECK(source.IsDoubleStackSlot()) << source; |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1304 | EmitParallelMoves( |
| 1305 | Location::StackSlot(source.GetStackIndex()), |
| 1306 | Location::StackSlot(destination.GetStackIndex()), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1307 | DataType::Type::kInt32, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1308 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1309 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1310 | DataType::Type::kInt32); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1311 | } |
| 1312 | } |
| 1313 | } |
| 1314 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1315 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { |
| 1316 | DCHECK(location.IsRegister()); |
| 1317 | __ movl(location.AsRegister<Register>(), Immediate(value)); |
| 1318 | } |
| 1319 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1320 | void CodeGeneratorX86::MoveLocation(Location dst, Location src, DataType::Type dst_type) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1321 | HParallelMove move(GetGraph()->GetAllocator()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1322 | if (dst_type == DataType::Type::kInt64 && !src.IsConstant() && !src.IsFpuRegister()) { |
| 1323 | move.AddMove(src.ToLow(), dst.ToLow(), DataType::Type::kInt32, nullptr); |
| 1324 | move.AddMove(src.ToHigh(), dst.ToHigh(), DataType::Type::kInt32, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1325 | } else { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1326 | move.AddMove(src, dst, dst_type, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1327 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1328 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1329 | } |
| 1330 | |
| 1331 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1332 | if (location.IsRegister()) { |
| 1333 | locations->AddTemp(location); |
| 1334 | } else if (location.IsRegisterPair()) { |
| 1335 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1336 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1337 | } else { |
| 1338 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1339 | } |
| 1340 | } |
| 1341 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1342 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1343 | DCHECK(!successor->IsExitBlock()); |
| 1344 | |
| 1345 | HBasicBlock* block = got->GetBlock(); |
| 1346 | HInstruction* previous = got->GetPrevious(); |
| 1347 | |
| 1348 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1349 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1350 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1351 | return; |
| 1352 | } |
| 1353 | |
| 1354 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1355 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1356 | } |
| 1357 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1358 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1359 | } |
| 1360 | } |
| 1361 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1362 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 1363 | got->SetLocations(nullptr); |
| 1364 | } |
| 1365 | |
| 1366 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 1367 | HandleGoto(got, got->GetSuccessor()); |
| 1368 | } |
| 1369 | |
| 1370 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1371 | try_boundary->SetLocations(nullptr); |
| 1372 | } |
| 1373 | |
| 1374 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1375 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1376 | if (!successor->IsExitBlock()) { |
| 1377 | HandleGoto(try_boundary, successor); |
| 1378 | } |
| 1379 | } |
| 1380 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1381 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1382 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1383 | } |
| 1384 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1385 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1386 | } |
| 1387 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1388 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1389 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1390 | LabelType* true_label, |
| 1391 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1392 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1393 | __ j(kUnordered, true_label); |
| 1394 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1395 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1396 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1397 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1398 | } |
| 1399 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1400 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1401 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1402 | LabelType* true_label, |
| 1403 | LabelType* false_label) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1404 | LocationSummary* locations = cond->GetLocations(); |
| 1405 | Location left = locations->InAt(0); |
| 1406 | Location right = locations->InAt(1); |
| 1407 | IfCondition if_cond = cond->GetCondition(); |
| 1408 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1409 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1410 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1411 | IfCondition true_high_cond = if_cond; |
| 1412 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1413 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); // unsigned on lower part |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1414 | |
| 1415 | // Set the conditions for the test, remembering that == needs to be |
| 1416 | // decided using the low words. |
| 1417 | switch (if_cond) { |
| 1418 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1419 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1420 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1421 | break; |
| 1422 | case kCondLT: |
| 1423 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1424 | break; |
| 1425 | case kCondLE: |
| 1426 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1427 | break; |
| 1428 | case kCondGT: |
| 1429 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1430 | break; |
| 1431 | case kCondGE: |
| 1432 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1433 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1434 | case kCondB: |
| 1435 | false_high_cond = kCondA; |
| 1436 | break; |
| 1437 | case kCondBE: |
| 1438 | true_high_cond = kCondB; |
| 1439 | break; |
| 1440 | case kCondA: |
| 1441 | false_high_cond = kCondB; |
| 1442 | break; |
| 1443 | case kCondAE: |
| 1444 | true_high_cond = kCondA; |
| 1445 | break; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1446 | } |
| 1447 | |
| 1448 | if (right.IsConstant()) { |
| 1449 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1450 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1451 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1452 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1453 | codegen_->Compare32BitValue(left_high, val_high); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1454 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1455 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1456 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1457 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1458 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1459 | __ j(X86Condition(true_high_cond), true_label); |
| 1460 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1461 | } |
| 1462 | // Must be equal high, so compare the lows. |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1463 | codegen_->Compare32BitValue(left_low, val_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1464 | } else if (right.IsRegisterPair()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1465 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1466 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1467 | |
| 1468 | __ cmpl(left_high, right_high); |
| 1469 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1470 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1471 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1472 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1473 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1474 | __ j(X86Condition(true_high_cond), true_label); |
| 1475 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1476 | } |
| 1477 | // Must be equal high, so compare the lows. |
| 1478 | __ cmpl(left_low, right_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1479 | } else { |
| 1480 | DCHECK(right.IsDoubleStackSlot()); |
| 1481 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
| 1482 | if (if_cond == kCondNE) { |
| 1483 | __ j(X86Condition(true_high_cond), true_label); |
| 1484 | } else if (if_cond == kCondEQ) { |
| 1485 | __ j(X86Condition(false_high_cond), false_label); |
| 1486 | } else { |
| 1487 | __ j(X86Condition(true_high_cond), true_label); |
| 1488 | __ j(X86Condition(false_high_cond), false_label); |
| 1489 | } |
| 1490 | // Must be equal high, so compare the lows. |
| 1491 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1492 | } |
| 1493 | // The last comparison might be unsigned. |
| 1494 | __ j(final_condition, true_label); |
| 1495 | } |
| 1496 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1497 | void InstructionCodeGeneratorX86::GenerateFPCompare(Location lhs, |
| 1498 | Location rhs, |
| 1499 | HInstruction* insn, |
| 1500 | bool is_double) { |
| 1501 | HX86LoadFromConstantTable* const_area = insn->InputAt(1)->AsX86LoadFromConstantTable(); |
| 1502 | if (is_double) { |
| 1503 | if (rhs.IsFpuRegister()) { |
| 1504 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1505 | } else if (const_area != nullptr) { |
| 1506 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1507 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), |
| 1508 | codegen_->LiteralDoubleAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1509 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 1510 | const_area->GetBaseMethodAddress(), |
| 1511 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1512 | } else { |
| 1513 | DCHECK(rhs.IsDoubleStackSlot()); |
| 1514 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1515 | } |
| 1516 | } else { |
| 1517 | if (rhs.IsFpuRegister()) { |
| 1518 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1519 | } else if (const_area != nullptr) { |
| 1520 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1521 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), |
| 1522 | codegen_->LiteralFloatAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1523 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 1524 | const_area->GetBaseMethodAddress(), |
| 1525 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1526 | } else { |
| 1527 | DCHECK(rhs.IsStackSlot()); |
| 1528 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1529 | } |
| 1530 | } |
| 1531 | } |
| 1532 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1533 | template<class LabelType> |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1534 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1535 | LabelType* true_target_in, |
| 1536 | LabelType* false_target_in) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1537 | // Generated branching requires both targets to be explicit. If either of the |
| 1538 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1539 | LabelType fallthrough_target; |
| 1540 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1541 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1542 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1543 | LocationSummary* locations = condition->GetLocations(); |
| 1544 | Location left = locations->InAt(0); |
| 1545 | Location right = locations->InAt(1); |
| 1546 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1547 | DataType::Type type = condition->InputAt(0)->GetType(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1548 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1549 | case DataType::Type::kInt64: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1550 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1551 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1552 | case DataType::Type::kFloat32: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1553 | GenerateFPCompare(left, right, condition, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1554 | GenerateFPJumps(condition, true_target, false_target); |
| 1555 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1556 | case DataType::Type::kFloat64: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1557 | GenerateFPCompare(left, right, condition, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1558 | GenerateFPJumps(condition, true_target, false_target); |
| 1559 | break; |
| 1560 | default: |
| 1561 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1562 | } |
| 1563 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1564 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1565 | __ jmp(false_target); |
| 1566 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1567 | |
| 1568 | if (fallthrough_target.IsLinked()) { |
| 1569 | __ Bind(&fallthrough_target); |
| 1570 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1571 | } |
| 1572 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1573 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1574 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1575 | // are set only strictly before `branch`. We can't use the eflags on long/FP |
| 1576 | // conditions if they are materialized due to the complex branching. |
| 1577 | return cond->IsCondition() && |
| 1578 | cond->GetNext() == branch && |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1579 | cond->InputAt(0)->GetType() != DataType::Type::kInt64 && |
| 1580 | !DataType::IsFloatingPointType(cond->InputAt(0)->GetType()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1581 | } |
| 1582 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1583 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1584 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1585 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1586 | LabelType* true_target, |
| 1587 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1588 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1589 | |
| 1590 | if (true_target == nullptr && false_target == nullptr) { |
| 1591 | // Nothing to do. The code always falls through. |
| 1592 | return; |
| 1593 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1594 | // Constant condition, statically compared against "true" (integer value 1). |
| 1595 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1596 | if (true_target != nullptr) { |
| 1597 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1598 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1599 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1600 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1601 | if (false_target != nullptr) { |
| 1602 | __ jmp(false_target); |
| 1603 | } |
| 1604 | } |
| 1605 | return; |
| 1606 | } |
| 1607 | |
| 1608 | // The following code generates these patterns: |
| 1609 | // (1) true_target == nullptr && false_target != nullptr |
| 1610 | // - opposite condition true => branch to false_target |
| 1611 | // (2) true_target != nullptr && false_target == nullptr |
| 1612 | // - condition true => branch to true_target |
| 1613 | // (3) true_target != nullptr && false_target != nullptr |
| 1614 | // - condition true => branch to true_target |
| 1615 | // - branch to false_target |
| 1616 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1617 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1618 | if (true_target == nullptr) { |
| 1619 | __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1620 | } else { |
| 1621 | __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); |
| 1622 | } |
| 1623 | } else { |
| 1624 | // Materialized condition, compare against 0. |
| 1625 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1626 | if (lhs.IsRegister()) { |
| 1627 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1628 | } else { |
| 1629 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1630 | } |
| 1631 | if (true_target == nullptr) { |
| 1632 | __ j(kEqual, false_target); |
| 1633 | } else { |
| 1634 | __ j(kNotEqual, true_target); |
| 1635 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1636 | } |
| 1637 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1638 | // Condition has not been materialized, use its inputs as the comparison and |
| 1639 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1640 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1641 | |
| 1642 | // If this is a long or FP comparison that has been folded into |
| 1643 | // the HCondition, generate the comparison directly. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1644 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 1645 | if (type == DataType::Type::kInt64 || DataType::IsFloatingPointType(type)) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1646 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1647 | return; |
| 1648 | } |
| 1649 | |
| 1650 | Location lhs = condition->GetLocations()->InAt(0); |
| 1651 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1652 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition). |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1653 | codegen_->GenerateIntCompare(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1654 | if (true_target == nullptr) { |
| 1655 | __ j(X86Condition(condition->GetOppositeCondition()), false_target); |
| 1656 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1657 | __ j(X86Condition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1658 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1659 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1660 | |
| 1661 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1662 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1663 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1664 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1665 | } |
| 1666 | } |
| 1667 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1668 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1669 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1670 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1671 | locations->SetInAt(0, Location::Any()); |
| 1672 | } |
| 1673 | } |
| 1674 | |
| 1675 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1676 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1677 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1678 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1679 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1680 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1681 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1682 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1683 | } |
| 1684 | |
| 1685 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1686 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1687 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 1688 | InvokeRuntimeCallingConvention calling_convention; |
| 1689 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 1690 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1691 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1692 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1693 | locations->SetInAt(0, Location::Any()); |
| 1694 | } |
| 1695 | } |
| 1696 | |
| 1697 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1698 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1699 | GenerateTestAndBranch<Label>(deoptimize, |
| 1700 | /* condition_input_index */ 0, |
| 1701 | slow_path->GetEntryLabel(), |
| 1702 | /* false_target */ nullptr); |
| 1703 | } |
| 1704 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1705 | void LocationsBuilderX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1706 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1707 | LocationSummary(flag, LocationSummary::kNoCall); |
| 1708 | locations->SetOut(Location::RequiresRegister()); |
| 1709 | } |
| 1710 | |
| 1711 | void InstructionCodeGeneratorX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1712 | __ movl(flag->GetLocations()->Out().AsRegister<Register>(), |
| 1713 | Address(ESP, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1714 | } |
| 1715 | |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1716 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1717 | // There are no conditional move instructions for XMMs. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1718 | if (DataType::IsFloatingPointType(select->GetType())) { |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1719 | return false; |
| 1720 | } |
| 1721 | |
| 1722 | // A FP condition doesn't generate the single CC that we need. |
| 1723 | // In 32 bit mode, a long condition doesn't generate a single CC either. |
| 1724 | HInstruction* condition = select->GetCondition(); |
| 1725 | if (condition->IsCondition()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1726 | DataType::Type compare_type = condition->InputAt(0)->GetType(); |
| 1727 | if (compare_type == DataType::Type::kInt64 || |
| 1728 | DataType::IsFloatingPointType(compare_type)) { |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1729 | return false; |
| 1730 | } |
| 1731 | } |
| 1732 | |
| 1733 | // We can generate a CMOV for this Select. |
| 1734 | return true; |
| 1735 | } |
| 1736 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1737 | void LocationsBuilderX86::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1738 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1739 | if (DataType::IsFloatingPointType(select->GetType())) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1740 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1741 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1742 | } else { |
| 1743 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1744 | if (SelectCanUseCMOV(select)) { |
| 1745 | if (select->InputAt(1)->IsConstant()) { |
| 1746 | // Cmov can't handle a constant value. |
| 1747 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1748 | } else { |
| 1749 | locations->SetInAt(1, Location::Any()); |
| 1750 | } |
| 1751 | } else { |
| 1752 | locations->SetInAt(1, Location::Any()); |
| 1753 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1754 | } |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1755 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1756 | locations->SetInAt(2, Location::RequiresRegister()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1757 | } |
| 1758 | locations->SetOut(Location::SameAsFirstInput()); |
| 1759 | } |
| 1760 | |
| 1761 | void InstructionCodeGeneratorX86::VisitSelect(HSelect* select) { |
| 1762 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1763 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1764 | if (SelectCanUseCMOV(select)) { |
| 1765 | // If both the condition and the source types are integer, we can generate |
| 1766 | // a CMOV to implement Select. |
| 1767 | |
| 1768 | HInstruction* select_condition = select->GetCondition(); |
| 1769 | Condition cond = kNotEqual; |
| 1770 | |
| 1771 | // Figure out how to test the 'condition'. |
| 1772 | if (select_condition->IsCondition()) { |
| 1773 | HCondition* condition = select_condition->AsCondition(); |
| 1774 | if (!condition->IsEmittedAtUseSite()) { |
| 1775 | // This was a previously materialized condition. |
| 1776 | // Can we use the existing condition code? |
| 1777 | if (AreEflagsSetFrom(condition, select)) { |
| 1778 | // Materialization was the previous instruction. Condition codes are right. |
| 1779 | cond = X86Condition(condition->GetCondition()); |
| 1780 | } else { |
| 1781 | // No, we have to recreate the condition code. |
| 1782 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1783 | __ testl(cond_reg, cond_reg); |
| 1784 | } |
| 1785 | } else { |
| 1786 | // We can't handle FP or long here. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1787 | DCHECK_NE(condition->InputAt(0)->GetType(), DataType::Type::kInt64); |
| 1788 | DCHECK(!DataType::IsFloatingPointType(condition->InputAt(0)->GetType())); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1789 | LocationSummary* cond_locations = condition->GetLocations(); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1790 | codegen_->GenerateIntCompare(cond_locations->InAt(0), cond_locations->InAt(1)); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1791 | cond = X86Condition(condition->GetCondition()); |
| 1792 | } |
| 1793 | } else { |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 1794 | // Must be a Boolean condition, which needs to be compared to 0. |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1795 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1796 | __ testl(cond_reg, cond_reg); |
| 1797 | } |
| 1798 | |
| 1799 | // If the condition is true, overwrite the output, which already contains false. |
| 1800 | Location false_loc = locations->InAt(0); |
| 1801 | Location true_loc = locations->InAt(1); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1802 | if (select->GetType() == DataType::Type::kInt64) { |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1803 | // 64 bit conditional move. |
| 1804 | Register false_high = false_loc.AsRegisterPairHigh<Register>(); |
| 1805 | Register false_low = false_loc.AsRegisterPairLow<Register>(); |
| 1806 | if (true_loc.IsRegisterPair()) { |
| 1807 | __ cmovl(cond, false_high, true_loc.AsRegisterPairHigh<Register>()); |
| 1808 | __ cmovl(cond, false_low, true_loc.AsRegisterPairLow<Register>()); |
| 1809 | } else { |
| 1810 | __ cmovl(cond, false_high, Address(ESP, true_loc.GetHighStackIndex(kX86WordSize))); |
| 1811 | __ cmovl(cond, false_low, Address(ESP, true_loc.GetStackIndex())); |
| 1812 | } |
| 1813 | } else { |
| 1814 | // 32 bit conditional move. |
| 1815 | Register false_reg = false_loc.AsRegister<Register>(); |
| 1816 | if (true_loc.IsRegister()) { |
| 1817 | __ cmovl(cond, false_reg, true_loc.AsRegister<Register>()); |
| 1818 | } else { |
| 1819 | __ cmovl(cond, false_reg, Address(ESP, true_loc.GetStackIndex())); |
| 1820 | } |
| 1821 | } |
| 1822 | } else { |
| 1823 | NearLabel false_target; |
| 1824 | GenerateTestAndBranch<NearLabel>( |
| 1825 | select, /* condition_input_index */ 2, /* true_target */ nullptr, &false_target); |
| 1826 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1827 | __ Bind(&false_target); |
| 1828 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1829 | } |
| 1830 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1831 | void LocationsBuilderX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1832 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1833 | } |
| 1834 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1835 | void InstructionCodeGeneratorX86::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1836 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1837 | } |
| 1838 | |
| 1839 | void CodeGeneratorX86::GenerateNop() { |
| 1840 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1841 | } |
| 1842 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1843 | void LocationsBuilderX86::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1844 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1845 | new (GetGraph()->GetAllocator()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1846 | // Handle the long/FP comparisons made in instruction simplification. |
| 1847 | switch (cond->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1848 | case DataType::Type::kInt64: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1849 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1850 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1851 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1852 | locations->SetOut(Location::RequiresRegister()); |
| 1853 | } |
| 1854 | break; |
| 1855 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1856 | case DataType::Type::kFloat32: |
| 1857 | case DataType::Type::kFloat64: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1858 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1859 | if (cond->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 1860 | DCHECK(cond->InputAt(1)->IsEmittedAtUseSite()); |
| 1861 | } else if (cond->InputAt(1)->IsConstant()) { |
| 1862 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1863 | } else { |
| 1864 | locations->SetInAt(1, Location::Any()); |
| 1865 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1866 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1867 | locations->SetOut(Location::RequiresRegister()); |
| 1868 | } |
| 1869 | break; |
| 1870 | } |
| 1871 | default: |
| 1872 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1873 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1874 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1875 | // We need a byte register. |
| 1876 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1877 | } |
| 1878 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1879 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1880 | } |
| 1881 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1882 | void InstructionCodeGeneratorX86::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1883 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1884 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1885 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1886 | |
| 1887 | LocationSummary* locations = cond->GetLocations(); |
| 1888 | Location lhs = locations->InAt(0); |
| 1889 | Location rhs = locations->InAt(1); |
| 1890 | Register reg = locations->Out().AsRegister<Register>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1891 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1892 | |
| 1893 | switch (cond->InputAt(0)->GetType()) { |
| 1894 | default: { |
| 1895 | // Integer case. |
| 1896 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 1897 | // Clear output register: setb only sets the low byte. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1898 | __ xorl(reg, reg); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1899 | codegen_->GenerateIntCompare(lhs, rhs); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1900 | __ setb(X86Condition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1901 | return; |
| 1902 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1903 | case DataType::Type::kInt64: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1904 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1905 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1906 | case DataType::Type::kFloat32: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1907 | GenerateFPCompare(lhs, rhs, cond, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1908 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1909 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1910 | case DataType::Type::kFloat64: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1911 | GenerateFPCompare(lhs, rhs, cond, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1912 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1913 | break; |
| 1914 | } |
| 1915 | |
| 1916 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1917 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1918 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1919 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1920 | __ Bind(&false_label); |
| 1921 | __ xorl(reg, reg); |
| 1922 | __ jmp(&done_label); |
| 1923 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1924 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1925 | __ Bind(&true_label); |
| 1926 | __ movl(reg, Immediate(1)); |
| 1927 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1928 | } |
| 1929 | |
| 1930 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1931 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1932 | } |
| 1933 | |
| 1934 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1935 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1936 | } |
| 1937 | |
| 1938 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1939 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1940 | } |
| 1941 | |
| 1942 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1943 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1944 | } |
| 1945 | |
| 1946 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1947 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1948 | } |
| 1949 | |
| 1950 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1951 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1952 | } |
| 1953 | |
| 1954 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1955 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1956 | } |
| 1957 | |
| 1958 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1959 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1960 | } |
| 1961 | |
| 1962 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1963 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1964 | } |
| 1965 | |
| 1966 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1967 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1968 | } |
| 1969 | |
| 1970 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1971 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1972 | } |
| 1973 | |
| 1974 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1975 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1976 | } |
| 1977 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1978 | void LocationsBuilderX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1979 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1980 | } |
| 1981 | |
| 1982 | void InstructionCodeGeneratorX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1983 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1984 | } |
| 1985 | |
| 1986 | void LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1987 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1988 | } |
| 1989 | |
| 1990 | void InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1991 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1992 | } |
| 1993 | |
| 1994 | void LocationsBuilderX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1995 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1996 | } |
| 1997 | |
| 1998 | void InstructionCodeGeneratorX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1999 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2000 | } |
| 2001 | |
| 2002 | void LocationsBuilderX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2003 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2004 | } |
| 2005 | |
| 2006 | void InstructionCodeGeneratorX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2007 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2008 | } |
| 2009 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2010 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2011 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2012 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2013 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2014 | } |
| 2015 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2016 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2017 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2018 | } |
| 2019 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2020 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 2021 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2022 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2023 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2024 | } |
| 2025 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2026 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2027 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2028 | } |
| 2029 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2030 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2031 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2032 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2033 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2034 | } |
| 2035 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2036 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2037 | // Will be generated at use site. |
| 2038 | } |
| 2039 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2040 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 2041 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2042 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2043 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2044 | } |
| 2045 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2046 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2047 | // Will be generated at use site. |
| 2048 | } |
| 2049 | |
| 2050 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2051 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2052 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2053 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2054 | } |
| 2055 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2056 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2057 | // Will be generated at use site. |
| 2058 | } |
| 2059 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2060 | void LocationsBuilderX86::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 2061 | constructor_fence->SetLocations(nullptr); |
| 2062 | } |
| 2063 | |
| 2064 | void InstructionCodeGeneratorX86::VisitConstructorFence( |
| 2065 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 2066 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 2067 | } |
| 2068 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2069 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2070 | memory_barrier->SetLocations(nullptr); |
| 2071 | } |
| 2072 | |
| 2073 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 2074 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2075 | } |
| 2076 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2077 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2078 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2079 | } |
| 2080 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2081 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2082 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2083 | } |
| 2084 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2085 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2086 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2087 | new (GetGraph()->GetAllocator()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2088 | switch (ret->InputAt(0)->GetType()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2089 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2090 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2091 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2092 | case DataType::Type::kInt8: |
| 2093 | case DataType::Type::kUint16: |
| 2094 | case DataType::Type::kInt16: |
| 2095 | case DataType::Type::kInt32: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2096 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2097 | break; |
| 2098 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2099 | case DataType::Type::kInt64: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2100 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2101 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2102 | break; |
| 2103 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2104 | case DataType::Type::kFloat32: |
| 2105 | case DataType::Type::kFloat64: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2106 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2107 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2108 | break; |
| 2109 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2110 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2111 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2112 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2113 | } |
| 2114 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2115 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2116 | if (kIsDebugBuild) { |
| 2117 | switch (ret->InputAt(0)->GetType()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2118 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2119 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2120 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2121 | case DataType::Type::kInt8: |
| 2122 | case DataType::Type::kUint16: |
| 2123 | case DataType::Type::kInt16: |
| 2124 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2125 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2126 | break; |
| 2127 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2128 | case DataType::Type::kInt64: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2129 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 2130 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2131 | break; |
| 2132 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2133 | case DataType::Type::kFloat32: |
| 2134 | case DataType::Type::kFloat64: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2135 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2136 | break; |
| 2137 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2138 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2139 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2140 | } |
| 2141 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2142 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2143 | } |
| 2144 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2145 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2146 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2147 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2148 | // the method_idx. |
| 2149 | HandleInvoke(invoke); |
| 2150 | } |
| 2151 | |
| 2152 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2153 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2154 | } |
| 2155 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2156 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2157 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2158 | // art::PrepareForRegisterAllocation. |
| 2159 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2160 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2161 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2162 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 2163 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeMethodLoadKind()) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 2164 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2165 | } |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2166 | return; |
| 2167 | } |
| 2168 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2169 | HandleInvoke(invoke); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2170 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2171 | // 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] | 2172 | if (invoke->HasPcRelativeMethodLoadKind()) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2173 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2174 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2175 | } |
| 2176 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2177 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 2178 | if (invoke->GetLocations()->Intrinsified()) { |
| 2179 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 2180 | intrinsic.Dispatch(invoke); |
| 2181 | return true; |
| 2182 | } |
| 2183 | return false; |
| 2184 | } |
| 2185 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2186 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2187 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2188 | // art::PrepareForRegisterAllocation. |
| 2189 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2190 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2191 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2192 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2193 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2194 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2195 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2196 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2197 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2198 | } |
| 2199 | |
| 2200 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 2201 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 2202 | if (intrinsic.TryDispatch(invoke)) { |
| 2203 | return; |
| 2204 | } |
| 2205 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2206 | HandleInvoke(invoke); |
| 2207 | } |
| 2208 | |
| 2209 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2210 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2211 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2212 | } |
| 2213 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2214 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2215 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2216 | return; |
| 2217 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2218 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2219 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2220 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2221 | } |
| 2222 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2223 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2224 | // This call to HandleInvoke allocates a temporary (core) register |
| 2225 | // which is also used to transfer the hidden argument from FP to |
| 2226 | // core register. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2227 | HandleInvoke(invoke); |
| 2228 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2229 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2230 | } |
| 2231 | |
| 2232 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2233 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2234 | LocationSummary* locations = invoke->GetLocations(); |
| 2235 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2236 | XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2237 | Location receiver = locations->InAt(0); |
| 2238 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2239 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2240 | // Set the hidden argument. This is safe to do this here, as XMM7 |
| 2241 | // won't be modified thereafter, before the `call` instruction. |
| 2242 | DCHECK_EQ(XMM7, hidden_reg); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2243 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2244 | __ movd(hidden_reg, temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2245 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2246 | if (receiver.IsStackSlot()) { |
| 2247 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2248 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2249 | __ movl(temp, Address(temp, class_offset)); |
| 2250 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2251 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2252 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2253 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2254 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2255 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2256 | // emit a read barrier for the previous class reference load. |
| 2257 | // However this is not required in practice, as this is an |
| 2258 | // intermediate/temporary reference and because the current |
| 2259 | // concurrent copying collector keeps the from-space memory |
| 2260 | // intact/accessible until the end of the marking phase (the |
| 2261 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2262 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2263 | // temp = temp->GetAddressOfIMT() |
| 2264 | __ movl(temp, |
| 2265 | Address(temp, mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2266 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2267 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2268 | invoke->GetImtIndex(), kX86PointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2269 | __ movl(temp, Address(temp, method_offset)); |
| 2270 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2271 | __ call(Address(temp, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2272 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2273 | |
| 2274 | DCHECK(!codegen_->IsLeafMethod()); |
| 2275 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2276 | } |
| 2277 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2278 | void LocationsBuilderX86::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2279 | HandleInvoke(invoke); |
| 2280 | } |
| 2281 | |
| 2282 | void InstructionCodeGeneratorX86::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2283 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 2284 | } |
| 2285 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2286 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 2287 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2288 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2289 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2290 | case DataType::Type::kInt32: |
| 2291 | case DataType::Type::kInt64: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2292 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2293 | locations->SetOut(Location::SameAsFirstInput()); |
| 2294 | break; |
| 2295 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2296 | case DataType::Type::kFloat32: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2297 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2298 | locations->SetOut(Location::SameAsFirstInput()); |
| 2299 | locations->AddTemp(Location::RequiresRegister()); |
| 2300 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2301 | break; |
| 2302 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2303 | case DataType::Type::kFloat64: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2304 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2305 | locations->SetOut(Location::SameAsFirstInput()); |
| 2306 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2307 | break; |
| 2308 | |
| 2309 | default: |
| 2310 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2311 | } |
| 2312 | } |
| 2313 | |
| 2314 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 2315 | LocationSummary* locations = neg->GetLocations(); |
| 2316 | Location out = locations->Out(); |
| 2317 | Location in = locations->InAt(0); |
| 2318 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2319 | case DataType::Type::kInt32: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2320 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2321 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2322 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2323 | break; |
| 2324 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2325 | case DataType::Type::kInt64: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2326 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2327 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2328 | __ negl(out.AsRegisterPairLow<Register>()); |
| 2329 | // Negation is similar to subtraction from zero. The least |
| 2330 | // significant byte triggers a borrow when it is different from |
| 2331 | // zero; to take it into account, add 1 to the most significant |
| 2332 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 2333 | // operation. |
| 2334 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2335 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 2336 | break; |
| 2337 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2338 | case DataType::Type::kFloat32: { |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2339 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2340 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 2341 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2342 | // Implement float negation with an exclusive or with value |
| 2343 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2344 | // single-precision floating-point number). |
| 2345 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 2346 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2347 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2348 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2349 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2350 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2351 | case DataType::Type::kFloat64: { |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2352 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2353 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2354 | // Implement double negation with an exclusive or with value |
| 2355 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 2356 | // a double-precision floating-point number). |
| 2357 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2358 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2359 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2360 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2361 | |
| 2362 | default: |
| 2363 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2364 | } |
| 2365 | } |
| 2366 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2367 | void LocationsBuilderX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2368 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2369 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2370 | DCHECK(DataType::IsFloatingPointType(neg->GetType())); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2371 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2372 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2373 | locations->SetOut(Location::SameAsFirstInput()); |
| 2374 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2375 | } |
| 2376 | |
| 2377 | void InstructionCodeGeneratorX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2378 | LocationSummary* locations = neg->GetLocations(); |
| 2379 | Location out = locations->Out(); |
| 2380 | DCHECK(locations->InAt(0).Equals(out)); |
| 2381 | |
| 2382 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 2383 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2384 | if (neg->GetType() == DataType::Type::kFloat32) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 2385 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x80000000), |
| 2386 | neg->GetBaseMethodAddress(), |
| 2387 | constant_area)); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2388 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| 2389 | } else { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 2390 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000), |
| 2391 | neg->GetBaseMethodAddress(), |
| 2392 | constant_area)); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2393 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| 2394 | } |
| 2395 | } |
| 2396 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2397 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2398 | DataType::Type result_type = conversion->GetResultType(); |
| 2399 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2400 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 2401 | << input_type << " -> " << result_type; |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2402 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2403 | // The float-to-long and double-to-long type conversions rely on a |
| 2404 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2405 | LocationSummary::CallKind call_kind = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2406 | ((input_type == DataType::Type::kFloat32 || input_type == DataType::Type::kFloat64) |
| 2407 | && result_type == DataType::Type::kInt64) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2408 | ? LocationSummary::kCallOnMainOnly |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2409 | : LocationSummary::kNoCall; |
| 2410 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2411 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, call_kind); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2412 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2413 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2414 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2415 | case DataType::Type::kInt8: |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2416 | switch (input_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2417 | case DataType::Type::kUint8: |
| 2418 | case DataType::Type::kInt8: |
| 2419 | case DataType::Type::kUint16: |
| 2420 | case DataType::Type::kInt16: |
| 2421 | case DataType::Type::kInt32: |
| 2422 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 2423 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2424 | // the validation of the linear scan implementation |
| 2425 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2426 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2427 | case DataType::Type::kInt64: { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2428 | HInstruction* input = conversion->InputAt(0); |
| 2429 | Location input_location = input->IsConstant() |
| 2430 | ? Location::ConstantLocation(input->AsConstant()) |
| 2431 | : Location::RegisterPairLocation(EAX, EDX); |
| 2432 | locations->SetInAt(0, input_location); |
| 2433 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2434 | // the validation of the linear scan implementation |
| 2435 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2436 | break; |
| 2437 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2438 | |
| 2439 | default: |
| 2440 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2441 | << " to " << result_type; |
| 2442 | } |
| 2443 | break; |
| 2444 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2445 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2446 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2447 | DCHECK(DataType::IsIntegralType(input_type)) << input_type; |
| 2448 | locations->SetInAt(0, Location::Any()); |
| 2449 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2450 | break; |
| 2451 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2452 | case DataType::Type::kInt32: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2453 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2454 | case DataType::Type::kInt64: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2455 | locations->SetInAt(0, Location::Any()); |
| 2456 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2457 | break; |
| 2458 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2459 | case DataType::Type::kFloat32: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2460 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2461 | locations->SetOut(Location::RequiresRegister()); |
| 2462 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2463 | break; |
| 2464 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2465 | case DataType::Type::kFloat64: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2466 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2467 | locations->SetOut(Location::RequiresRegister()); |
| 2468 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2469 | break; |
| 2470 | |
| 2471 | default: |
| 2472 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2473 | << " to " << result_type; |
| 2474 | } |
| 2475 | break; |
| 2476 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2477 | case DataType::Type::kInt64: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2478 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2479 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2480 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2481 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2482 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2483 | case DataType::Type::kInt16: |
| 2484 | case DataType::Type::kInt32: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2485 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 2486 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2487 | break; |
| 2488 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2489 | case DataType::Type::kFloat32: |
| 2490 | case DataType::Type::kFloat64: { |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2491 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2492 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 2493 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 2494 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2495 | // The runtime helper puts the result in EAX, EDX. |
| 2496 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2497 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2498 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2499 | |
| 2500 | default: |
| 2501 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2502 | << " to " << result_type; |
| 2503 | } |
| 2504 | break; |
| 2505 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2506 | case DataType::Type::kFloat32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2507 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2508 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2509 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2510 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2511 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2512 | case DataType::Type::kInt16: |
| 2513 | case DataType::Type::kInt32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2514 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2515 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2516 | break; |
| 2517 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2518 | case DataType::Type::kInt64: |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2519 | locations->SetInAt(0, Location::Any()); |
| 2520 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2521 | break; |
| 2522 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2523 | case DataType::Type::kFloat64: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2524 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2525 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2526 | break; |
| 2527 | |
| 2528 | default: |
| 2529 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2530 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 2531 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2532 | break; |
| 2533 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2534 | case DataType::Type::kFloat64: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2535 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2536 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2537 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2538 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2539 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2540 | case DataType::Type::kInt16: |
| 2541 | case DataType::Type::kInt32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2542 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2543 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2544 | break; |
| 2545 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2546 | case DataType::Type::kInt64: |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2547 | locations->SetInAt(0, Location::Any()); |
| 2548 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2549 | break; |
| 2550 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2551 | case DataType::Type::kFloat32: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2552 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2553 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2554 | break; |
| 2555 | |
| 2556 | default: |
| 2557 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2558 | << " to " << result_type; |
| 2559 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2560 | break; |
| 2561 | |
| 2562 | default: |
| 2563 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2564 | << " to " << result_type; |
| 2565 | } |
| 2566 | } |
| 2567 | |
| 2568 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 2569 | LocationSummary* locations = conversion->GetLocations(); |
| 2570 | Location out = locations->Out(); |
| 2571 | Location in = locations->InAt(0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2572 | DataType::Type result_type = conversion->GetResultType(); |
| 2573 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2574 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 2575 | << input_type << " -> " << result_type; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2576 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2577 | case DataType::Type::kUint8: |
| 2578 | switch (input_type) { |
| 2579 | case DataType::Type::kInt8: |
| 2580 | case DataType::Type::kUint16: |
| 2581 | case DataType::Type::kInt16: |
| 2582 | case DataType::Type::kInt32: |
| 2583 | if (in.IsRegister()) { |
| 2584 | __ movzxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
| 2585 | } else { |
| 2586 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2587 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2588 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint8_t>(value))); |
| 2589 | } |
| 2590 | break; |
| 2591 | case DataType::Type::kInt64: |
| 2592 | if (in.IsRegisterPair()) { |
| 2593 | __ movzxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 2594 | } else { |
| 2595 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2596 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2597 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint8_t>(value))); |
| 2598 | } |
| 2599 | break; |
| 2600 | |
| 2601 | default: |
| 2602 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2603 | << " to " << result_type; |
| 2604 | } |
| 2605 | break; |
| 2606 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2607 | case DataType::Type::kInt8: |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2608 | switch (input_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2609 | case DataType::Type::kUint8: |
| 2610 | case DataType::Type::kUint16: |
| 2611 | case DataType::Type::kInt16: |
| 2612 | case DataType::Type::kInt32: |
| 2613 | if (in.IsRegister()) { |
| 2614 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
| 2615 | } else { |
| 2616 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2617 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2618 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2619 | } |
| 2620 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2621 | case DataType::Type::kInt64: |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2622 | if (in.IsRegisterPair()) { |
| 2623 | __ movsxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 2624 | } else { |
| 2625 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2626 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2627 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2628 | } |
| 2629 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2630 | |
| 2631 | default: |
| 2632 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2633 | << " to " << result_type; |
| 2634 | } |
| 2635 | break; |
| 2636 | |
| 2637 | case DataType::Type::kUint16: |
| 2638 | switch (input_type) { |
| 2639 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2640 | case DataType::Type::kInt16: |
| 2641 | case DataType::Type::kInt32: |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2642 | if (in.IsRegister()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2643 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
| 2644 | } else if (in.IsStackSlot()) { |
| 2645 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2646 | } else { |
| 2647 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2648 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2649 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
| 2650 | } |
| 2651 | break; |
| 2652 | case DataType::Type::kInt64: |
| 2653 | if (in.IsRegisterPair()) { |
| 2654 | __ movzxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2655 | } else if (in.IsDoubleStackSlot()) { |
| 2656 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2657 | } else { |
| 2658 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2659 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2660 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2661 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2662 | break; |
| 2663 | |
| 2664 | default: |
| 2665 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2666 | << " to " << result_type; |
| 2667 | } |
| 2668 | break; |
| 2669 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2670 | case DataType::Type::kInt16: |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2671 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2672 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2673 | case DataType::Type::kInt32: |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2674 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2675 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2676 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2677 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2678 | } else { |
| 2679 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2680 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2681 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2682 | } |
| 2683 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2684 | case DataType::Type::kInt64: |
| 2685 | if (in.IsRegisterPair()) { |
| 2686 | __ movsxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2687 | } else if (in.IsDoubleStackSlot()) { |
| 2688 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2689 | } else { |
| 2690 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2691 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2692 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
| 2693 | } |
| 2694 | break; |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2695 | |
| 2696 | default: |
| 2697 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2698 | << " to " << result_type; |
| 2699 | } |
| 2700 | break; |
| 2701 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2702 | case DataType::Type::kInt32: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2703 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2704 | case DataType::Type::kInt64: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2705 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2706 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2707 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2708 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2709 | } else { |
| 2710 | DCHECK(in.IsConstant()); |
| 2711 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2712 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2713 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2714 | } |
| 2715 | break; |
| 2716 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2717 | case DataType::Type::kFloat32: { |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2718 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2719 | Register output = out.AsRegister<Register>(); |
| 2720 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2721 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2722 | |
| 2723 | __ movl(output, Immediate(kPrimIntMax)); |
| 2724 | // temp = int-to-float(output) |
| 2725 | __ cvtsi2ss(temp, output); |
| 2726 | // if input >= temp goto done |
| 2727 | __ comiss(input, temp); |
| 2728 | __ j(kAboveEqual, &done); |
| 2729 | // if input == NaN goto nan |
| 2730 | __ j(kUnordered, &nan); |
| 2731 | // output = float-to-int-truncate(input) |
| 2732 | __ cvttss2si(output, input); |
| 2733 | __ jmp(&done); |
| 2734 | __ Bind(&nan); |
| 2735 | // output = 0 |
| 2736 | __ xorl(output, output); |
| 2737 | __ Bind(&done); |
| 2738 | break; |
| 2739 | } |
| 2740 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2741 | case DataType::Type::kFloat64: { |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2742 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2743 | Register output = out.AsRegister<Register>(); |
| 2744 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2745 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2746 | |
| 2747 | __ movl(output, Immediate(kPrimIntMax)); |
| 2748 | // temp = int-to-double(output) |
| 2749 | __ cvtsi2sd(temp, output); |
| 2750 | // if input >= temp goto done |
| 2751 | __ comisd(input, temp); |
| 2752 | __ j(kAboveEqual, &done); |
| 2753 | // if input == NaN goto nan |
| 2754 | __ j(kUnordered, &nan); |
| 2755 | // output = double-to-int-truncate(input) |
| 2756 | __ cvttsd2si(output, input); |
| 2757 | __ jmp(&done); |
| 2758 | __ Bind(&nan); |
| 2759 | // output = 0 |
| 2760 | __ xorl(output, output); |
| 2761 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2762 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2763 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2764 | |
| 2765 | default: |
| 2766 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2767 | << " to " << result_type; |
| 2768 | } |
| 2769 | break; |
| 2770 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2771 | case DataType::Type::kInt64: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2772 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2773 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2774 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2775 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2776 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2777 | case DataType::Type::kInt16: |
| 2778 | case DataType::Type::kInt32: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2779 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2780 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2781 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2782 | __ cdq(); |
| 2783 | break; |
| 2784 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2785 | case DataType::Type::kFloat32: |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2786 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2787 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2788 | break; |
| 2789 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2790 | case DataType::Type::kFloat64: |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2791 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2792 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2793 | break; |
| 2794 | |
| 2795 | default: |
| 2796 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2797 | << " to " << result_type; |
| 2798 | } |
| 2799 | break; |
| 2800 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2801 | case DataType::Type::kFloat32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2802 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2803 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2804 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2805 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2806 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2807 | case DataType::Type::kInt16: |
| 2808 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2809 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2810 | break; |
| 2811 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2812 | case DataType::Type::kInt64: { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2813 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2814 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2815 | // Create stack space for the call to |
| 2816 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2817 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2818 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2819 | adjustment = DataType::Size(DataType::Type::kInt64); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2820 | __ subl(ESP, Immediate(adjustment)); |
| 2821 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2822 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2823 | // Load the value to the FP stack, using temporaries if needed. |
| 2824 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2825 | |
| 2826 | if (out.IsStackSlot()) { |
| 2827 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2828 | } else { |
| 2829 | __ fstps(Address(ESP, 0)); |
| 2830 | Location stack_temp = Location::StackSlot(0); |
| 2831 | codegen_->Move32(out, stack_temp); |
| 2832 | } |
| 2833 | |
| 2834 | // Remove the temporary stack space we allocated. |
| 2835 | if (adjustment != 0) { |
| 2836 | __ addl(ESP, Immediate(adjustment)); |
| 2837 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2838 | break; |
| 2839 | } |
| 2840 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2841 | case DataType::Type::kFloat64: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2842 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2843 | break; |
| 2844 | |
| 2845 | default: |
| 2846 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2847 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 2848 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2849 | break; |
| 2850 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2851 | case DataType::Type::kFloat64: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2852 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2853 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2854 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2855 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2856 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2857 | case DataType::Type::kInt16: |
| 2858 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2859 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2860 | break; |
| 2861 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2862 | case DataType::Type::kInt64: { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2863 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2864 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2865 | // Create stack space for the call to |
| 2866 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2867 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2868 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2869 | adjustment = DataType::Size(DataType::Type::kInt64); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2870 | __ subl(ESP, Immediate(adjustment)); |
| 2871 | } |
| 2872 | |
| 2873 | // Load the value to the FP stack, using temporaries if needed. |
| 2874 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2875 | |
| 2876 | if (out.IsDoubleStackSlot()) { |
| 2877 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2878 | } else { |
| 2879 | __ fstpl(Address(ESP, 0)); |
| 2880 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2881 | codegen_->Move64(out, stack_temp); |
| 2882 | } |
| 2883 | |
| 2884 | // Remove the temporary stack space we allocated. |
| 2885 | if (adjustment != 0) { |
| 2886 | __ addl(ESP, Immediate(adjustment)); |
| 2887 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2888 | break; |
| 2889 | } |
| 2890 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2891 | case DataType::Type::kFloat32: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2892 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2893 | break; |
| 2894 | |
| 2895 | default: |
| 2896 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2897 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 2898 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2899 | break; |
| 2900 | |
| 2901 | default: |
| 2902 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2903 | << " to " << result_type; |
| 2904 | } |
| 2905 | } |
| 2906 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2907 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2908 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2909 | new (GetGraph()->GetAllocator()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2910 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2911 | case DataType::Type::kInt32: { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2912 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2913 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2914 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2915 | break; |
| 2916 | } |
| 2917 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2918 | case DataType::Type::kInt64: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2919 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2920 | locations->SetInAt(1, Location::Any()); |
| 2921 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2922 | break; |
| 2923 | } |
| 2924 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2925 | case DataType::Type::kFloat32: |
| 2926 | case DataType::Type::kFloat64: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2927 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2928 | if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2929 | DCHECK(add->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2930 | } else if (add->InputAt(1)->IsConstant()) { |
| 2931 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2932 | } else { |
| 2933 | locations->SetInAt(1, Location::Any()); |
| 2934 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2935 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2936 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2937 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2938 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2939 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2940 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2941 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2942 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2943 | } |
| 2944 | |
| 2945 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 2946 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2947 | Location first = locations->InAt(0); |
| 2948 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2949 | Location out = locations->Out(); |
| 2950 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2951 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2952 | case DataType::Type::kInt32: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2953 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2954 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2955 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2956 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2957 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2958 | } else { |
| 2959 | __ leal(out.AsRegister<Register>(), Address( |
| 2960 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 2961 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2962 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2963 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2964 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2965 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 2966 | } else { |
| 2967 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 2968 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2969 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2970 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2971 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2972 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2973 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2974 | } |
| 2975 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2976 | case DataType::Type::kInt64: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2977 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2978 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2979 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2980 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2981 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 2982 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2983 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2984 | } else { |
| 2985 | DCHECK(second.IsConstant()) << second; |
| 2986 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2987 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2988 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2989 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2990 | break; |
| 2991 | } |
| 2992 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2993 | case DataType::Type::kFloat32: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2994 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2995 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2996 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2997 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2998 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2999 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 3000 | codegen_->LiteralFloatAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3001 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3002 | const_area->GetBaseMethodAddress(), |
| 3003 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3004 | } else { |
| 3005 | DCHECK(second.IsStackSlot()); |
| 3006 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3007 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3008 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3009 | } |
| 3010 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3011 | case DataType::Type::kFloat64: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3012 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3013 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3014 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3015 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3016 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3017 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 3018 | codegen_->LiteralDoubleAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3019 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3020 | const_area->GetBaseMethodAddress(), |
| 3021 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3022 | } else { |
| 3023 | DCHECK(second.IsDoubleStackSlot()); |
| 3024 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3025 | } |
| 3026 | break; |
| 3027 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3028 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3029 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3030 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3031 | } |
| 3032 | } |
| 3033 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3034 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3035 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3036 | new (GetGraph()->GetAllocator()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3037 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3038 | case DataType::Type::kInt32: |
| 3039 | case DataType::Type::kInt64: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3040 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3041 | locations->SetInAt(1, Location::Any()); |
| 3042 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3043 | break; |
| 3044 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3045 | case DataType::Type::kFloat32: |
| 3046 | case DataType::Type::kFloat64: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3047 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3048 | if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3049 | DCHECK(sub->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3050 | } else if (sub->InputAt(1)->IsConstant()) { |
| 3051 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3052 | } else { |
| 3053 | locations->SetInAt(1, Location::Any()); |
| 3054 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3055 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3056 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3057 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3058 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3059 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3060 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3061 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3062 | } |
| 3063 | |
| 3064 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 3065 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3066 | Location first = locations->InAt(0); |
| 3067 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3068 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3069 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3070 | case DataType::Type::kInt32: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3071 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3072 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3073 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3074 | __ subl(first.AsRegister<Register>(), |
| 3075 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3076 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3077 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3078 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3079 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3080 | } |
| 3081 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3082 | case DataType::Type::kInt64: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3083 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3084 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3085 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3086 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3087 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3088 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 3089 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3090 | } else { |
| 3091 | DCHECK(second.IsConstant()) << second; |
| 3092 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3093 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 3094 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3095 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3096 | break; |
| 3097 | } |
| 3098 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3099 | case DataType::Type::kFloat32: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3100 | if (second.IsFpuRegister()) { |
| 3101 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3102 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3103 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3104 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3105 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3106 | codegen_->LiteralFloatAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3107 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3108 | const_area->GetBaseMethodAddress(), |
| 3109 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3110 | } else { |
| 3111 | DCHECK(second.IsStackSlot()); |
| 3112 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3113 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3114 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3115 | } |
| 3116 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3117 | case DataType::Type::kFloat64: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3118 | if (second.IsFpuRegister()) { |
| 3119 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3120 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3121 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3122 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3123 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3124 | codegen_->LiteralDoubleAddress( |
| 3125 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3126 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3127 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3128 | } else { |
| 3129 | DCHECK(second.IsDoubleStackSlot()); |
| 3130 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3131 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3132 | break; |
| 3133 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3134 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3135 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3136 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3137 | } |
| 3138 | } |
| 3139 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3140 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 3141 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3142 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3143 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3144 | case DataType::Type::kInt32: |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3145 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3146 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3147 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3148 | // Can use 3 operand multiply. |
| 3149 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3150 | } else { |
| 3151 | locations->SetOut(Location::SameAsFirstInput()); |
| 3152 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3153 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3154 | case DataType::Type::kInt64: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3155 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3156 | locations->SetInAt(1, Location::Any()); |
| 3157 | locations->SetOut(Location::SameAsFirstInput()); |
| 3158 | // Needed for imul on 32bits with 64bits output. |
| 3159 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 3160 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 3161 | break; |
| 3162 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3163 | case DataType::Type::kFloat32: |
| 3164 | case DataType::Type::kFloat64: { |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3165 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3166 | if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3167 | DCHECK(mul->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3168 | } else if (mul->InputAt(1)->IsConstant()) { |
| 3169 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3170 | } else { |
| 3171 | locations->SetInAt(1, Location::Any()); |
| 3172 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3173 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3174 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3175 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3176 | |
| 3177 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3178 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3179 | } |
| 3180 | } |
| 3181 | |
| 3182 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 3183 | LocationSummary* locations = mul->GetLocations(); |
| 3184 | Location first = locations->InAt(0); |
| 3185 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3186 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3187 | |
| 3188 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3189 | case DataType::Type::kInt32: |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3190 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3191 | // problems where the output may not be the same as the first operand. |
| 3192 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3193 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3194 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 3195 | } else if (second.IsRegister()) { |
| 3196 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3197 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3198 | } else { |
| 3199 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3200 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3201 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3202 | } |
| 3203 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3204 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3205 | case DataType::Type::kInt64: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3206 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 3207 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3208 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 3209 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3210 | |
| 3211 | DCHECK_EQ(EAX, eax); |
| 3212 | DCHECK_EQ(EDX, edx); |
| 3213 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3214 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3215 | // output: in1 |
| 3216 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3217 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3218 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3219 | if (second.IsConstant()) { |
| 3220 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3221 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3222 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3223 | int32_t low_value = Low32Bits(value); |
| 3224 | int32_t high_value = High32Bits(value); |
| 3225 | Immediate low(low_value); |
| 3226 | Immediate high(high_value); |
| 3227 | |
| 3228 | __ movl(eax, high); |
| 3229 | // eax <- in1.lo * in2.hi |
| 3230 | __ imull(eax, in1_lo); |
| 3231 | // in1.hi <- in1.hi * in2.lo |
| 3232 | __ imull(in1_hi, low); |
| 3233 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3234 | __ addl(in1_hi, eax); |
| 3235 | // move in2_lo to eax to prepare for double precision |
| 3236 | __ movl(eax, low); |
| 3237 | // edx:eax <- in1.lo * in2.lo |
| 3238 | __ mull(in1_lo); |
| 3239 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3240 | __ addl(in1_hi, edx); |
| 3241 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3242 | __ movl(in1_lo, eax); |
| 3243 | } else if (second.IsRegisterPair()) { |
| 3244 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3245 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3246 | |
| 3247 | __ movl(eax, in2_hi); |
| 3248 | // eax <- in1.lo * in2.hi |
| 3249 | __ imull(eax, in1_lo); |
| 3250 | // in1.hi <- in1.hi * in2.lo |
| 3251 | __ imull(in1_hi, in2_lo); |
| 3252 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3253 | __ addl(in1_hi, eax); |
| 3254 | // move in1_lo to eax to prepare for double precision |
| 3255 | __ movl(eax, in1_lo); |
| 3256 | // edx:eax <- in1.lo * in2.lo |
| 3257 | __ mull(in2_lo); |
| 3258 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3259 | __ addl(in1_hi, edx); |
| 3260 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3261 | __ movl(in1_lo, eax); |
| 3262 | } else { |
| 3263 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 3264 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 3265 | Address in2_lo(ESP, second.GetStackIndex()); |
| 3266 | |
| 3267 | __ movl(eax, in2_hi); |
| 3268 | // eax <- in1.lo * in2.hi |
| 3269 | __ imull(eax, in1_lo); |
| 3270 | // in1.hi <- in1.hi * in2.lo |
| 3271 | __ imull(in1_hi, in2_lo); |
| 3272 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3273 | __ addl(in1_hi, eax); |
| 3274 | // move in1_lo to eax to prepare for double precision |
| 3275 | __ movl(eax, in1_lo); |
| 3276 | // edx:eax <- in1.lo * in2.lo |
| 3277 | __ mull(in2_lo); |
| 3278 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3279 | __ addl(in1_hi, edx); |
| 3280 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3281 | __ movl(in1_lo, eax); |
| 3282 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3283 | |
| 3284 | break; |
| 3285 | } |
| 3286 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3287 | case DataType::Type::kFloat32: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3288 | DCHECK(first.Equals(locations->Out())); |
| 3289 | if (second.IsFpuRegister()) { |
| 3290 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3291 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3292 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3293 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3294 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3295 | codegen_->LiteralFloatAddress( |
| 3296 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3297 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3298 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3299 | } else { |
| 3300 | DCHECK(second.IsStackSlot()); |
| 3301 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3302 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3303 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3304 | } |
| 3305 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3306 | case DataType::Type::kFloat64: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3307 | DCHECK(first.Equals(locations->Out())); |
| 3308 | if (second.IsFpuRegister()) { |
| 3309 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3310 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3311 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3312 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3313 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3314 | codegen_->LiteralDoubleAddress( |
| 3315 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3316 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3317 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3318 | } else { |
| 3319 | DCHECK(second.IsDoubleStackSlot()); |
| 3320 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3321 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3322 | break; |
| 3323 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3324 | |
| 3325 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3326 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3327 | } |
| 3328 | } |
| 3329 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3330 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 3331 | uint32_t temp_offset, |
| 3332 | uint32_t stack_adjustment, |
| 3333 | bool is_fp, |
| 3334 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3335 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3336 | DCHECK(!is_wide); |
| 3337 | if (is_fp) { |
| 3338 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3339 | } else { |
| 3340 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3341 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3342 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3343 | DCHECK(is_wide); |
| 3344 | if (is_fp) { |
| 3345 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3346 | } else { |
| 3347 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3348 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3349 | } else { |
| 3350 | // 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] | 3351 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3352 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3353 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3354 | if (is_fp) { |
| 3355 | __ flds(Address(ESP, temp_offset)); |
| 3356 | } else { |
| 3357 | __ filds(Address(ESP, temp_offset)); |
| 3358 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3359 | } else { |
| 3360 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3361 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3362 | if (is_fp) { |
| 3363 | __ fldl(Address(ESP, temp_offset)); |
| 3364 | } else { |
| 3365 | __ fildl(Address(ESP, temp_offset)); |
| 3366 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3367 | } |
| 3368 | } |
| 3369 | } |
| 3370 | |
| 3371 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3372 | DataType::Type type = rem->GetResultType(); |
| 3373 | bool is_float = type == DataType::Type::kFloat32; |
| 3374 | size_t elem_size = DataType::Size(type); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3375 | LocationSummary* locations = rem->GetLocations(); |
| 3376 | Location first = locations->InAt(0); |
| 3377 | Location second = locations->InAt(1); |
| 3378 | Location out = locations->Out(); |
| 3379 | |
| 3380 | // Create stack space for 2 elements. |
| 3381 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3382 | __ subl(ESP, Immediate(2 * elem_size)); |
| 3383 | |
| 3384 | // 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] | 3385 | const bool is_wide = !is_float; |
| 3386 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); |
| 3387 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3388 | |
| 3389 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3390 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3391 | __ Bind(&retry); |
| 3392 | __ fprem(); |
| 3393 | |
| 3394 | // Move FP status to AX. |
| 3395 | __ fstsw(); |
| 3396 | |
| 3397 | // And see if the argument reduction is complete. This is signaled by the |
| 3398 | // C2 FPU flag bit set to 0. |
| 3399 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 3400 | __ j(kNotEqual, &retry); |
| 3401 | |
| 3402 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3403 | // Store FP top of stack to real stack. |
| 3404 | if (is_float) { |
| 3405 | __ fsts(Address(ESP, 0)); |
| 3406 | } else { |
| 3407 | __ fstl(Address(ESP, 0)); |
| 3408 | } |
| 3409 | |
| 3410 | // Pop the 2 items from the FP stack. |
| 3411 | __ fucompp(); |
| 3412 | |
| 3413 | // Load the value from the stack into an XMM register. |
| 3414 | DCHECK(out.IsFpuRegister()) << out; |
| 3415 | if (is_float) { |
| 3416 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3417 | } else { |
| 3418 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3419 | } |
| 3420 | |
| 3421 | // And remove the temporary stack space we allocated. |
| 3422 | __ addl(ESP, Immediate(2 * elem_size)); |
| 3423 | } |
| 3424 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3425 | |
| 3426 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3427 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3428 | |
| 3429 | LocationSummary* locations = instruction->GetLocations(); |
| 3430 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3431 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3432 | |
| 3433 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3434 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3435 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3436 | |
| 3437 | DCHECK(imm == 1 || imm == -1); |
| 3438 | |
| 3439 | if (instruction->IsRem()) { |
| 3440 | __ xorl(out_register, out_register); |
| 3441 | } else { |
| 3442 | __ movl(out_register, input_register); |
| 3443 | if (imm == -1) { |
| 3444 | __ negl(out_register); |
| 3445 | } |
| 3446 | } |
| 3447 | } |
| 3448 | |
| 3449 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3450 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3451 | LocationSummary* locations = instruction->GetLocations(); |
| 3452 | |
| 3453 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3454 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3455 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3456 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3457 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3458 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3459 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 3460 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3461 | __ leal(num, Address(input_register, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3462 | __ testl(input_register, input_register); |
| 3463 | __ cmovl(kGreaterEqual, num, input_register); |
| 3464 | int shift = CTZ(imm); |
| 3465 | __ sarl(num, Immediate(shift)); |
| 3466 | |
| 3467 | if (imm < 0) { |
| 3468 | __ negl(num); |
| 3469 | } |
| 3470 | |
| 3471 | __ movl(out_register, num); |
| 3472 | } |
| 3473 | |
| 3474 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3475 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3476 | |
| 3477 | LocationSummary* locations = instruction->GetLocations(); |
| 3478 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 3479 | |
| 3480 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 3481 | Register out = locations->Out().AsRegister<Register>(); |
| 3482 | Register num; |
| 3483 | Register edx; |
| 3484 | |
| 3485 | if (instruction->IsDiv()) { |
| 3486 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 3487 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 3488 | } else { |
| 3489 | edx = locations->Out().AsRegister<Register>(); |
| 3490 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 3491 | } |
| 3492 | |
| 3493 | DCHECK_EQ(EAX, eax); |
| 3494 | DCHECK_EQ(EDX, edx); |
| 3495 | if (instruction->IsDiv()) { |
| 3496 | DCHECK_EQ(EAX, out); |
| 3497 | } else { |
| 3498 | DCHECK_EQ(EDX, out); |
| 3499 | } |
| 3500 | |
| 3501 | int64_t magic; |
| 3502 | int shift; |
| 3503 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3504 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3505 | // Save the numerator. |
| 3506 | __ movl(num, eax); |
| 3507 | |
| 3508 | // EAX = magic |
| 3509 | __ movl(eax, Immediate(magic)); |
| 3510 | |
| 3511 | // EDX:EAX = magic * numerator |
| 3512 | __ imull(num); |
| 3513 | |
| 3514 | if (imm > 0 && magic < 0) { |
| 3515 | // EDX += num |
| 3516 | __ addl(edx, num); |
| 3517 | } else if (imm < 0 && magic > 0) { |
| 3518 | __ subl(edx, num); |
| 3519 | } |
| 3520 | |
| 3521 | // Shift if needed. |
| 3522 | if (shift != 0) { |
| 3523 | __ sarl(edx, Immediate(shift)); |
| 3524 | } |
| 3525 | |
| 3526 | // EDX += 1 if EDX < 0 |
| 3527 | __ movl(eax, edx); |
| 3528 | __ shrl(edx, Immediate(31)); |
| 3529 | __ addl(edx, eax); |
| 3530 | |
| 3531 | if (instruction->IsRem()) { |
| 3532 | __ movl(eax, num); |
| 3533 | __ imull(edx, Immediate(imm)); |
| 3534 | __ subl(eax, edx); |
| 3535 | __ movl(edx, eax); |
| 3536 | } else { |
| 3537 | __ movl(eax, edx); |
| 3538 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3539 | } |
| 3540 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3541 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3542 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3543 | |
| 3544 | LocationSummary* locations = instruction->GetLocations(); |
| 3545 | Location out = locations->Out(); |
| 3546 | Location first = locations->InAt(0); |
| 3547 | Location second = locations->InAt(1); |
| 3548 | bool is_div = instruction->IsDiv(); |
| 3549 | |
| 3550 | switch (instruction->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3551 | case DataType::Type::kInt32: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3552 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 3553 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3554 | |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3555 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3556 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3557 | |
| 3558 | if (imm == 0) { |
| 3559 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 3560 | } else if (imm == 1 || imm == -1) { |
| 3561 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3562 | } else if (is_div && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3563 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3564 | } else { |
| 3565 | DCHECK(imm <= -2 || imm >= 2); |
| 3566 | GenerateDivRemWithAnyConstant(instruction); |
| 3567 | } |
| 3568 | } else { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3569 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) DivRemMinusOneSlowPathX86( |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3570 | instruction, out.AsRegister<Register>(), is_div); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3571 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3572 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3573 | Register second_reg = second.AsRegister<Register>(); |
| 3574 | // 0x80000000/-1 triggers an arithmetic exception! |
| 3575 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 3576 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3577 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3578 | __ cmpl(second_reg, Immediate(-1)); |
| 3579 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3580 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3581 | // edx:eax <- sign-extended of eax |
| 3582 | __ cdq(); |
| 3583 | // eax = quotient, edx = remainder |
| 3584 | __ idivl(second_reg); |
| 3585 | __ Bind(slow_path->GetExitLabel()); |
| 3586 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3587 | break; |
| 3588 | } |
| 3589 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3590 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3591 | InvokeRuntimeCallingConvention calling_convention; |
| 3592 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3593 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3594 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3595 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3596 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 3597 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 3598 | |
| 3599 | if (is_div) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3600 | codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3601 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3602 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3603 | codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3604 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3605 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3606 | break; |
| 3607 | } |
| 3608 | |
| 3609 | default: |
| 3610 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 3611 | } |
| 3612 | } |
| 3613 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3614 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3615 | LocationSummary::CallKind call_kind = (div->GetResultType() == DataType::Type::kInt64) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3616 | ? LocationSummary::kCallOnMainOnly |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3617 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3618 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(div, call_kind); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3619 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3620 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3621 | case DataType::Type::kInt32: { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3622 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3623 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3624 | locations->SetOut(Location::SameAsFirstInput()); |
| 3625 | // Intel uses edx:eax as the dividend. |
| 3626 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3627 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3628 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 3629 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3630 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3631 | locations->AddTemp(Location::RequiresRegister()); |
| 3632 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3633 | break; |
| 3634 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3635 | case DataType::Type::kInt64: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3636 | InvokeRuntimeCallingConvention calling_convention; |
| 3637 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3638 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3639 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3640 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3641 | // Runtime helper puts the result in EAX, EDX. |
| 3642 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3643 | break; |
| 3644 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3645 | case DataType::Type::kFloat32: |
| 3646 | case DataType::Type::kFloat64: { |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3647 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3648 | if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3649 | DCHECK(div->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3650 | } else if (div->InputAt(1)->IsConstant()) { |
| 3651 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3652 | } else { |
| 3653 | locations->SetInAt(1, Location::Any()); |
| 3654 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3655 | locations->SetOut(Location::SameAsFirstInput()); |
| 3656 | break; |
| 3657 | } |
| 3658 | |
| 3659 | default: |
| 3660 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3661 | } |
| 3662 | } |
| 3663 | |
| 3664 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 3665 | LocationSummary* locations = div->GetLocations(); |
| 3666 | Location first = locations->InAt(0); |
| 3667 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3668 | |
| 3669 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3670 | case DataType::Type::kInt32: |
| 3671 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3672 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3673 | break; |
| 3674 | } |
| 3675 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3676 | case DataType::Type::kFloat32: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3677 | if (second.IsFpuRegister()) { |
| 3678 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3679 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3680 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3681 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3682 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3683 | codegen_->LiteralFloatAddress( |
| 3684 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3685 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3686 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3687 | } else { |
| 3688 | DCHECK(second.IsStackSlot()); |
| 3689 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3690 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3691 | break; |
| 3692 | } |
| 3693 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3694 | case DataType::Type::kFloat64: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3695 | if (second.IsFpuRegister()) { |
| 3696 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3697 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3698 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3699 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3700 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3701 | codegen_->LiteralDoubleAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3702 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3703 | const_area->GetBaseMethodAddress(), |
| 3704 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3705 | } else { |
| 3706 | DCHECK(second.IsDoubleStackSlot()); |
| 3707 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3708 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3709 | break; |
| 3710 | } |
| 3711 | |
| 3712 | default: |
| 3713 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3714 | } |
| 3715 | } |
| 3716 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3717 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3718 | DataType::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3719 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3720 | LocationSummary::CallKind call_kind = (rem->GetResultType() == DataType::Type::kInt64) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3721 | ? LocationSummary::kCallOnMainOnly |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3722 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3723 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3724 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3725 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3726 | case DataType::Type::kInt32: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3727 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3728 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3729 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3730 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3731 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 3732 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3733 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3734 | locations->AddTemp(Location::RequiresRegister()); |
| 3735 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3736 | break; |
| 3737 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3738 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3739 | InvokeRuntimeCallingConvention calling_convention; |
| 3740 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3741 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3742 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3743 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3744 | // Runtime helper puts the result in EAX, EDX. |
| 3745 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3746 | break; |
| 3747 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3748 | case DataType::Type::kFloat64: |
| 3749 | case DataType::Type::kFloat32: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3750 | locations->SetInAt(0, Location::Any()); |
| 3751 | locations->SetInAt(1, Location::Any()); |
| 3752 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3753 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3754 | break; |
| 3755 | } |
| 3756 | |
| 3757 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3758 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3759 | } |
| 3760 | } |
| 3761 | |
| 3762 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3763 | DataType::Type type = rem->GetResultType(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3764 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3765 | case DataType::Type::kInt32: |
| 3766 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3767 | GenerateDivRemIntegral(rem); |
| 3768 | break; |
| 3769 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3770 | case DataType::Type::kFloat32: |
| 3771 | case DataType::Type::kFloat64: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3772 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3773 | break; |
| 3774 | } |
| 3775 | default: |
| 3776 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3777 | } |
| 3778 | } |
| 3779 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3780 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3781 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3782 | switch (instruction->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3783 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3784 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3785 | case DataType::Type::kInt8: |
| 3786 | case DataType::Type::kUint16: |
| 3787 | case DataType::Type::kInt16: |
| 3788 | case DataType::Type::kInt32: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3789 | locations->SetInAt(0, Location::Any()); |
| 3790 | break; |
| 3791 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3792 | case DataType::Type::kInt64: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3793 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 3794 | if (!instruction->IsConstant()) { |
| 3795 | locations->AddTemp(Location::RequiresRegister()); |
| 3796 | } |
| 3797 | break; |
| 3798 | } |
| 3799 | default: |
| 3800 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3801 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3802 | } |
| 3803 | |
| 3804 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3805 | SlowPathCode* slow_path = |
| 3806 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathX86(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3807 | codegen_->AddSlowPath(slow_path); |
| 3808 | |
| 3809 | LocationSummary* locations = instruction->GetLocations(); |
| 3810 | Location value = locations->InAt(0); |
| 3811 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3812 | switch (instruction->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3813 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3814 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3815 | case DataType::Type::kInt8: |
| 3816 | case DataType::Type::kUint16: |
| 3817 | case DataType::Type::kInt16: |
| 3818 | case DataType::Type::kInt32: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3819 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3820 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3821 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3822 | } else if (value.IsStackSlot()) { |
| 3823 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 3824 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3825 | } else { |
| 3826 | DCHECK(value.IsConstant()) << value; |
| 3827 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 3828 | __ jmp(slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3829 | } |
| 3830 | } |
| 3831 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3832 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3833 | case DataType::Type::kInt64: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3834 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3835 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3836 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 3837 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 3838 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3839 | } else { |
| 3840 | DCHECK(value.IsConstant()) << value; |
| 3841 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3842 | __ jmp(slow_path->GetEntryLabel()); |
| 3843 | } |
| 3844 | } |
| 3845 | break; |
| 3846 | } |
| 3847 | default: |
| 3848 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3849 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3850 | } |
| 3851 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3852 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 3853 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3854 | |
| 3855 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3856 | new (GetGraph()->GetAllocator()) LocationSummary(op, LocationSummary::kNoCall); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3857 | |
| 3858 | switch (op->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3859 | case DataType::Type::kInt32: |
| 3860 | case DataType::Type::kInt64: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3861 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3862 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3863 | // The shift count needs to be in CL or a constant. |
| 3864 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3865 | locations->SetOut(Location::SameAsFirstInput()); |
| 3866 | break; |
| 3867 | } |
| 3868 | default: |
| 3869 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3870 | } |
| 3871 | } |
| 3872 | |
| 3873 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 3874 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3875 | |
| 3876 | LocationSummary* locations = op->GetLocations(); |
| 3877 | Location first = locations->InAt(0); |
| 3878 | Location second = locations->InAt(1); |
| 3879 | DCHECK(first.Equals(locations->Out())); |
| 3880 | |
| 3881 | switch (op->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3882 | case DataType::Type::kInt32: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3883 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3884 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3885 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3886 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3887 | DCHECK_EQ(ECX, second_reg); |
| 3888 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3889 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3890 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3891 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3892 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3893 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3894 | } |
| 3895 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3896 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3897 | if (shift == 0) { |
| 3898 | return; |
| 3899 | } |
| 3900 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3901 | if (op->IsShl()) { |
| 3902 | __ shll(first_reg, imm); |
| 3903 | } else if (op->IsShr()) { |
| 3904 | __ sarl(first_reg, imm); |
| 3905 | } else { |
| 3906 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3907 | } |
| 3908 | } |
| 3909 | break; |
| 3910 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3911 | case DataType::Type::kInt64: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3912 | if (second.IsRegister()) { |
| 3913 | Register second_reg = second.AsRegister<Register>(); |
| 3914 | DCHECK_EQ(ECX, second_reg); |
| 3915 | if (op->IsShl()) { |
| 3916 | GenerateShlLong(first, second_reg); |
| 3917 | } else if (op->IsShr()) { |
| 3918 | GenerateShrLong(first, second_reg); |
| 3919 | } else { |
| 3920 | GenerateUShrLong(first, second_reg); |
| 3921 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3922 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3923 | // Shift by a constant. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3924 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3925 | // Nothing to do if the shift is 0, as the input is already the output. |
| 3926 | if (shift != 0) { |
| 3927 | if (op->IsShl()) { |
| 3928 | GenerateShlLong(first, shift); |
| 3929 | } else if (op->IsShr()) { |
| 3930 | GenerateShrLong(first, shift); |
| 3931 | } else { |
| 3932 | GenerateUShrLong(first, shift); |
| 3933 | } |
| 3934 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3935 | } |
| 3936 | break; |
| 3937 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3938 | default: |
| 3939 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3940 | } |
| 3941 | } |
| 3942 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3943 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 3944 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3945 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 3946 | if (shift == 1) { |
| 3947 | // This is just an addition. |
| 3948 | __ addl(low, low); |
| 3949 | __ adcl(high, high); |
| 3950 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3951 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 3952 | codegen_->EmitParallelMoves( |
| 3953 | loc.ToLow(), |
| 3954 | loc.ToHigh(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3955 | DataType::Type::kInt32, |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3956 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3957 | loc.ToLow(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3958 | DataType::Type::kInt32); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3959 | } else if (shift > 32) { |
| 3960 | // Low part becomes 0. High part is low part << (shift-32). |
| 3961 | __ movl(high, low); |
| 3962 | __ shll(high, Immediate(shift - 32)); |
| 3963 | __ xorl(low, low); |
| 3964 | } else { |
| 3965 | // Between 1 and 31. |
| 3966 | __ shld(high, low, Immediate(shift)); |
| 3967 | __ shll(low, Immediate(shift)); |
| 3968 | } |
| 3969 | } |
| 3970 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3971 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3972 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3973 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 3974 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 3975 | __ testl(shifter, Immediate(32)); |
| 3976 | __ j(kEqual, &done); |
| 3977 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 3978 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 3979 | __ Bind(&done); |
| 3980 | } |
| 3981 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3982 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 3983 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3984 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3985 | if (shift == 32) { |
| 3986 | // Need to copy the sign. |
| 3987 | DCHECK_NE(low, high); |
| 3988 | __ movl(low, high); |
| 3989 | __ sarl(high, Immediate(31)); |
| 3990 | } else if (shift > 32) { |
| 3991 | DCHECK_NE(low, high); |
| 3992 | // High part becomes sign. Low part is shifted by shift - 32. |
| 3993 | __ movl(low, high); |
| 3994 | __ sarl(high, Immediate(31)); |
| 3995 | __ sarl(low, Immediate(shift - 32)); |
| 3996 | } else { |
| 3997 | // Between 1 and 31. |
| 3998 | __ shrd(low, high, Immediate(shift)); |
| 3999 | __ sarl(high, Immediate(shift)); |
| 4000 | } |
| 4001 | } |
| 4002 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4003 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4004 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4005 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4006 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4007 | __ testl(shifter, Immediate(32)); |
| 4008 | __ j(kEqual, &done); |
| 4009 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4010 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 4011 | __ Bind(&done); |
| 4012 | } |
| 4013 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4014 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 4015 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4016 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 4017 | if (shift == 32) { |
| 4018 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 4019 | codegen_->EmitParallelMoves( |
| 4020 | loc.ToHigh(), |
| 4021 | loc.ToLow(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4022 | DataType::Type::kInt32, |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4023 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 4024 | loc.ToHigh(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4025 | DataType::Type::kInt32); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4026 | } else if (shift > 32) { |
| 4027 | // Low part is high >> (shift - 32). High part becomes 0. |
| 4028 | __ movl(low, high); |
| 4029 | __ shrl(low, Immediate(shift - 32)); |
| 4030 | __ xorl(high, high); |
| 4031 | } else { |
| 4032 | // Between 1 and 31. |
| 4033 | __ shrd(low, high, Immediate(shift)); |
| 4034 | __ shrl(high, Immediate(shift)); |
| 4035 | } |
| 4036 | } |
| 4037 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4038 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4039 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4040 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4041 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4042 | __ testl(shifter, Immediate(32)); |
| 4043 | __ j(kEqual, &done); |
| 4044 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4045 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 4046 | __ Bind(&done); |
| 4047 | } |
| 4048 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4049 | void LocationsBuilderX86::VisitRor(HRor* ror) { |
| 4050 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4051 | new (GetGraph()->GetAllocator()) LocationSummary(ror, LocationSummary::kNoCall); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4052 | |
| 4053 | switch (ror->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4054 | case DataType::Type::kInt64: |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4055 | // Add the temporary needed. |
| 4056 | locations->AddTemp(Location::RequiresRegister()); |
| 4057 | FALLTHROUGH_INTENDED; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4058 | case DataType::Type::kInt32: |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4059 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4060 | // The shift count needs to be in CL (unless it is a constant). |
| 4061 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); |
| 4062 | locations->SetOut(Location::SameAsFirstInput()); |
| 4063 | break; |
| 4064 | default: |
| 4065 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4066 | UNREACHABLE(); |
| 4067 | } |
| 4068 | } |
| 4069 | |
| 4070 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { |
| 4071 | LocationSummary* locations = ror->GetLocations(); |
| 4072 | Location first = locations->InAt(0); |
| 4073 | Location second = locations->InAt(1); |
| 4074 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4075 | if (ror->GetResultType() == DataType::Type::kInt32) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4076 | Register first_reg = first.AsRegister<Register>(); |
| 4077 | if (second.IsRegister()) { |
| 4078 | Register second_reg = second.AsRegister<Register>(); |
| 4079 | __ rorl(first_reg, second_reg); |
| 4080 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4081 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4082 | __ rorl(first_reg, imm); |
| 4083 | } |
| 4084 | return; |
| 4085 | } |
| 4086 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4087 | DCHECK_EQ(ror->GetResultType(), DataType::Type::kInt64); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4088 | Register first_reg_lo = first.AsRegisterPairLow<Register>(); |
| 4089 | Register first_reg_hi = first.AsRegisterPairHigh<Register>(); |
| 4090 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 4091 | if (second.IsRegister()) { |
| 4092 | Register second_reg = second.AsRegister<Register>(); |
| 4093 | DCHECK_EQ(second_reg, ECX); |
| 4094 | __ movl(temp_reg, first_reg_hi); |
| 4095 | __ shrd(first_reg_hi, first_reg_lo, second_reg); |
| 4096 | __ shrd(first_reg_lo, temp_reg, second_reg); |
| 4097 | __ movl(temp_reg, first_reg_hi); |
| 4098 | __ testl(second_reg, Immediate(32)); |
| 4099 | __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); |
| 4100 | __ cmovl(kNotEqual, first_reg_lo, temp_reg); |
| 4101 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4102 | int32_t shift_amt = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4103 | if (shift_amt == 0) { |
| 4104 | // Already fine. |
| 4105 | return; |
| 4106 | } |
| 4107 | if (shift_amt == 32) { |
| 4108 | // Just swap. |
| 4109 | __ movl(temp_reg, first_reg_lo); |
| 4110 | __ movl(first_reg_lo, first_reg_hi); |
| 4111 | __ movl(first_reg_hi, temp_reg); |
| 4112 | return; |
| 4113 | } |
| 4114 | |
| 4115 | Immediate imm(shift_amt); |
| 4116 | // Save the constents of the low value. |
| 4117 | __ movl(temp_reg, first_reg_lo); |
| 4118 | |
| 4119 | // Shift right into low, feeding bits from high. |
| 4120 | __ shrd(first_reg_lo, first_reg_hi, imm); |
| 4121 | |
| 4122 | // Shift right into high, feeding bits from the original low. |
| 4123 | __ shrd(first_reg_hi, temp_reg, imm); |
| 4124 | |
| 4125 | // Swap if needed. |
| 4126 | if (shift_amt > 32) { |
| 4127 | __ movl(temp_reg, first_reg_lo); |
| 4128 | __ movl(first_reg_lo, first_reg_hi); |
| 4129 | __ movl(first_reg_hi, temp_reg); |
| 4130 | } |
| 4131 | } |
| 4132 | } |
| 4133 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4134 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 4135 | HandleShift(shl); |
| 4136 | } |
| 4137 | |
| 4138 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 4139 | HandleShift(shl); |
| 4140 | } |
| 4141 | |
| 4142 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 4143 | HandleShift(shr); |
| 4144 | } |
| 4145 | |
| 4146 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 4147 | HandleShift(shr); |
| 4148 | } |
| 4149 | |
| 4150 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 4151 | HandleShift(ushr); |
| 4152 | } |
| 4153 | |
| 4154 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 4155 | HandleShift(ushr); |
| 4156 | } |
| 4157 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4158 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4159 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4160 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4161 | locations->SetOut(Location::RegisterLocation(EAX)); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4162 | if (instruction->IsStringAlloc()) { |
| 4163 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4164 | } else { |
| 4165 | InvokeRuntimeCallingConvention calling_convention; |
| 4166 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4167 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4168 | } |
| 4169 | |
| 4170 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4171 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4172 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4173 | if (instruction->IsStringAlloc()) { |
| 4174 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4175 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4176 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4177 | __ fs()->movl(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString))); |
| 4178 | __ call(Address(temp, code_offset.Int32Value())); |
| 4179 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4180 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 4181 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 4182 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4183 | DCHECK(!codegen_->IsLeafMethod()); |
| 4184 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4185 | } |
| 4186 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4187 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4188 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4189 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4190 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 4191 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4192 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4193 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4194 | } |
| 4195 | |
| 4196 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4197 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4198 | // of poisoning the reference. |
Nicolas Geoffray | d095844 | 2017-01-30 14:57:16 +0000 | [diff] [blame] | 4199 | QuickEntrypointEnum entrypoint = |
| 4200 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 4201 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4202 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4203 | DCHECK(!codegen_->IsLeafMethod()); |
| 4204 | } |
| 4205 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4206 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4207 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4208 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4209 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4210 | if (location.IsStackSlot()) { |
| 4211 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4212 | } else if (location.IsDoubleStackSlot()) { |
| 4213 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4214 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4215 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4216 | } |
| 4217 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4218 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 4219 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 4220 | } |
| 4221 | |
| 4222 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4223 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4224 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4225 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4226 | } |
| 4227 | |
| 4228 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4229 | } |
| 4230 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4231 | void LocationsBuilderX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4232 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4233 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4234 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4235 | locations->SetOut(Location::RequiresRegister()); |
| 4236 | } |
| 4237 | |
| 4238 | void InstructionCodeGeneratorX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4239 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4240 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4241 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4242 | instruction->GetIndex(), kX86PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4243 | __ movl(locations->Out().AsRegister<Register>(), |
| 4244 | Address(locations->InAt(0).AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4245 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4246 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4247 | instruction->GetIndex(), kX86PointerSize)); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4248 | __ movl(locations->Out().AsRegister<Register>(), |
| 4249 | Address(locations->InAt(0).AsRegister<Register>(), |
| 4250 | mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
| 4251 | // temp = temp->GetImtEntryAt(method_offset); |
| 4252 | __ movl(locations->Out().AsRegister<Register>(), |
| 4253 | Address(locations->Out().AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4254 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4255 | } |
| 4256 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4257 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4258 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4259 | new (GetGraph()->GetAllocator()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4260 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4261 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4262 | } |
| 4263 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4264 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 4265 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4266 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4267 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4268 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4269 | switch (not_->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4270 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4271 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4272 | break; |
| 4273 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4274 | case DataType::Type::kInt64: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4275 | __ notl(out.AsRegisterPairLow<Register>()); |
| 4276 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4277 | break; |
| 4278 | |
| 4279 | default: |
| 4280 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4281 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4282 | } |
| 4283 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4284 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4285 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4286 | new (GetGraph()->GetAllocator()) LocationSummary(bool_not, LocationSummary::kNoCall); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4287 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4288 | locations->SetOut(Location::SameAsFirstInput()); |
| 4289 | } |
| 4290 | |
| 4291 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4292 | LocationSummary* locations = bool_not->GetLocations(); |
| 4293 | Location in = locations->InAt(0); |
| 4294 | Location out = locations->Out(); |
| 4295 | DCHECK(in.Equals(out)); |
| 4296 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 4297 | } |
| 4298 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4299 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4300 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4301 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4302 | switch (compare->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4303 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4304 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4305 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4306 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4307 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4308 | case DataType::Type::kInt32: |
| 4309 | case DataType::Type::kInt64: { |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4310 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4311 | locations->SetInAt(1, Location::Any()); |
| 4312 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4313 | break; |
| 4314 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4315 | case DataType::Type::kFloat32: |
| 4316 | case DataType::Type::kFloat64: { |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4317 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4318 | if (compare->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4319 | DCHECK(compare->InputAt(1)->IsEmittedAtUseSite()); |
| 4320 | } else if (compare->InputAt(1)->IsConstant()) { |
| 4321 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4322 | } else { |
| 4323 | locations->SetInAt(1, Location::Any()); |
| 4324 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4325 | locations->SetOut(Location::RequiresRegister()); |
| 4326 | break; |
| 4327 | } |
| 4328 | default: |
| 4329 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4330 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4331 | } |
| 4332 | |
| 4333 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4334 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4335 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4336 | Location left = locations->InAt(0); |
| 4337 | Location right = locations->InAt(1); |
| 4338 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4339 | NearLabel less, greater, done; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4340 | Condition less_cond = kLess; |
| 4341 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4342 | switch (compare->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4343 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4344 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4345 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4346 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4347 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4348 | case DataType::Type::kInt32: { |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 4349 | codegen_->GenerateIntCompare(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4350 | break; |
| 4351 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4352 | case DataType::Type::kInt64: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4353 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 4354 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 4355 | int32_t val_low = 0; |
| 4356 | int32_t val_high = 0; |
| 4357 | bool right_is_const = false; |
| 4358 | |
| 4359 | if (right.IsConstant()) { |
| 4360 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 4361 | right_is_const = true; |
| 4362 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 4363 | val_low = Low32Bits(val); |
| 4364 | val_high = High32Bits(val); |
| 4365 | } |
| 4366 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4367 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4368 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4369 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4370 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4371 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4372 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4373 | codegen_->Compare32BitValue(left_high, val_high); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4374 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4375 | __ j(kLess, &less); // Signed compare. |
| 4376 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4377 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4378 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4379 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4380 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4381 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4382 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4383 | codegen_->Compare32BitValue(left_low, val_low); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4384 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4385 | less_cond = kBelow; // for CF (unsigned). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4386 | break; |
| 4387 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4388 | case DataType::Type::kFloat32: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4389 | GenerateFPCompare(left, right, compare, false); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4390 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4391 | less_cond = kBelow; // for CF (floats). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4392 | break; |
| 4393 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4394 | case DataType::Type::kFloat64: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4395 | GenerateFPCompare(left, right, compare, true); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4396 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4397 | less_cond = kBelow; // for CF (floats). |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4398 | break; |
| 4399 | } |
| 4400 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4401 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4402 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4403 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4404 | __ movl(out, Immediate(0)); |
| 4405 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4406 | __ j(less_cond, &less); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4407 | |
| 4408 | __ Bind(&greater); |
| 4409 | __ movl(out, Immediate(1)); |
| 4410 | __ jmp(&done); |
| 4411 | |
| 4412 | __ Bind(&less); |
| 4413 | __ movl(out, Immediate(-1)); |
| 4414 | |
| 4415 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4416 | } |
| 4417 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4418 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4419 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4420 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4421 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4422 | locations->SetInAt(i, Location::Any()); |
| 4423 | } |
| 4424 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4425 | } |
| 4426 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4427 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4428 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4429 | } |
| 4430 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4431 | void CodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4432 | /* |
| 4433 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 4434 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 4435 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4436 | */ |
| 4437 | switch (kind) { |
| 4438 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4439 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4440 | break; |
| 4441 | } |
| 4442 | case MemBarrierKind::kAnyStore: |
| 4443 | case MemBarrierKind::kLoadAny: |
| 4444 | case MemBarrierKind::kStoreStore: { |
| 4445 | // nop |
| 4446 | break; |
| 4447 | } |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4448 | case MemBarrierKind::kNTStoreStore: |
| 4449 | // Non-Temporal Store/Store needs an explicit fence. |
| 4450 | MemoryFence(/* non-temporal */ true); |
| 4451 | break; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4452 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4453 | } |
| 4454 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4455 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( |
| 4456 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4457 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4458 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4459 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4460 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4461 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 4462 | Register temp) { |
| 4463 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4464 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4465 | if (!invoke->GetLocations()->Intrinsified()) { |
| 4466 | return location.AsRegister<Register>(); |
| 4467 | } |
| 4468 | // For intrinsics we allow any location, so it may be on the stack. |
| 4469 | if (!location.IsRegister()) { |
| 4470 | __ movl(temp, Address(ESP, location.GetStackIndex())); |
| 4471 | return temp; |
| 4472 | } |
| 4473 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 4474 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 4475 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 4476 | // simple and more robust approach rather that trying to determine if that's the case. |
| 4477 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
Vladimir Marko | 4ee8e29 | 2017-06-02 15:39:30 +0000 | [diff] [blame] | 4478 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 4479 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 4480 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 4481 | __ movl(temp, Address(ESP, stack_offset)); |
| 4482 | return temp; |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4483 | } |
| 4484 | return location.AsRegister<Register>(); |
| 4485 | } |
| 4486 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4487 | void CodeGeneratorX86::GenerateStaticOrDirectCall( |
| 4488 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4489 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4490 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4491 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4492 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4493 | uint32_t offset = |
| 4494 | GetThreadOffset<kX86PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 4495 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4496 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4497 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4498 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4499 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4500 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4501 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 4502 | DCHECK(GetCompilerOptions().IsBootImage()); |
| 4503 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4504 | temp.AsRegister<Register>()); |
| 4505 | __ leal(temp.AsRegister<Register>(), Address(base_reg, CodeGeneratorX86::kDummy32BitOffset)); |
| 4506 | RecordBootMethodPatch(invoke); |
| 4507 | break; |
| 4508 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4509 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4510 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 4511 | break; |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4512 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4513 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4514 | temp.AsRegister<Register>()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4515 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4516 | // Bind a new fixup label at the end of the "movl" insn. |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4517 | __ Bind(NewMethodBssEntryPatch( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4518 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(), |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4519 | MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()))); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4520 | break; |
| 4521 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4522 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 4523 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 4524 | return; // No code pointer retrieval; the runtime performs the call directly. |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4525 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4526 | } |
| 4527 | |
| 4528 | switch (invoke->GetCodePtrLocation()) { |
| 4529 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 4530 | __ call(GetFrameEntryLabel()); |
| 4531 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4532 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4533 | // (callee_method + offset_of_quick_compiled_code)() |
| 4534 | __ call(Address(callee_method.AsRegister<Register>(), |
| 4535 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4536 | kX86PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4537 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4538 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4539 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4540 | |
| 4541 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4542 | } |
| 4543 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4544 | void CodeGeneratorX86::GenerateVirtualCall( |
| 4545 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4546 | Register temp = temp_in.AsRegister<Register>(); |
| 4547 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4548 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4549 | |
| 4550 | // Use the calling convention instead of the location of the receiver, as |
| 4551 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4552 | // slow path, the arguments have been moved to the right place, so here we are |
| 4553 | // guaranteed that the receiver is the first register of the calling convention. |
| 4554 | InvokeDexCallingConvention calling_convention; |
| 4555 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4556 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4557 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4558 | __ movl(temp, Address(receiver, class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4559 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4560 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4561 | // emit a read barrier for the previous class reference load. |
| 4562 | // However this is not required in practice, as this is an |
| 4563 | // intermediate/temporary reference and because the current |
| 4564 | // concurrent copying collector keeps the from-space memory |
| 4565 | // intact/accessible until the end of the marking phase (the |
| 4566 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4567 | __ MaybeUnpoisonHeapReference(temp); |
| 4568 | // temp = temp->GetMethodAt(method_offset); |
| 4569 | __ movl(temp, Address(temp, method_offset)); |
| 4570 | // call temp->GetEntryPoint(); |
| 4571 | __ call(Address( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4572 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4573 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4574 | } |
| 4575 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4576 | void CodeGeneratorX86::RecordBootMethodPatch(HInvokeStaticOrDirect* invoke) { |
| 4577 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 4578 | HX86ComputeBaseMethodAddress* address = |
| 4579 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
| 4580 | boot_image_method_patches_.emplace_back(address, |
| 4581 | *invoke->GetTargetMethod().dex_file, |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 4582 | invoke->GetTargetMethod().index); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4583 | __ Bind(&boot_image_method_patches_.back().label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4584 | } |
| 4585 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4586 | Label* CodeGeneratorX86::NewMethodBssEntryPatch( |
| 4587 | HX86ComputeBaseMethodAddress* method_address, |
| 4588 | MethodReference target_method) { |
| 4589 | // Add the patch entry and bind its label at the end of the instruction. |
| 4590 | method_bss_entry_patches_.emplace_back(method_address, |
| 4591 | *target_method.dex_file, |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 4592 | target_method.index); |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4593 | return &method_bss_entry_patches_.back().label; |
| 4594 | } |
| 4595 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4596 | void CodeGeneratorX86::RecordBootTypePatch(HLoadClass* load_class) { |
Vladimir Marko | 00916b9 | 2017-05-17 17:45:45 +0100 | [diff] [blame] | 4597 | HX86ComputeBaseMethodAddress* address = load_class->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4598 | boot_image_type_patches_.emplace_back(address, |
| 4599 | load_class->GetDexFile(), |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4600 | load_class->GetTypeIndex().index_); |
| 4601 | __ Bind(&boot_image_type_patches_.back().label); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4602 | } |
| 4603 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4604 | Label* CodeGeneratorX86::NewTypeBssEntryPatch(HLoadClass* load_class) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4605 | HX86ComputeBaseMethodAddress* address = |
| 4606 | load_class->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 4607 | type_bss_entry_patches_.emplace_back( |
| 4608 | address, load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4609 | return &type_bss_entry_patches_.back().label; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4610 | } |
| 4611 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4612 | void CodeGeneratorX86::RecordBootStringPatch(HLoadString* load_string) { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4613 | HX86ComputeBaseMethodAddress* address = load_string->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 4614 | string_patches_.emplace_back(address, |
| 4615 | load_string->GetDexFile(), |
| 4616 | load_string->GetStringIndex().index_); |
| 4617 | __ Bind(&string_patches_.back().label); |
| 4618 | } |
| 4619 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4620 | Label* CodeGeneratorX86::NewStringBssEntryPatch(HLoadString* load_string) { |
| 4621 | DCHECK(!GetCompilerOptions().IsBootImage()); |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4622 | HX86ComputeBaseMethodAddress* address = |
| 4623 | load_string->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4624 | string_bss_entry_patches_.emplace_back( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4625 | address, load_string->GetDexFile(), load_string->GetStringIndex().index_); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4626 | return &string_bss_entry_patches_.back().label; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4627 | } |
| 4628 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4629 | // The label points to the end of the "movl" or another instruction but the literal offset |
| 4630 | // for method patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 4631 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
| 4632 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4633 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4634 | inline void CodeGeneratorX86::EmitPcRelativeLinkerPatches( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4635 | const ArenaDeque<X86PcRelativePatchInfo>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4636 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4637 | for (const X86PcRelativePatchInfo& info : infos) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4638 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4639 | linker_patches->push_back(Factory( |
| 4640 | literal_offset, &info.dex_file, GetMethodAddressOffset(info.method_address), info.index)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4641 | } |
| 4642 | } |
| 4643 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4644 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4645 | DCHECK(linker_patches->empty()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4646 | size_t size = |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4647 | boot_image_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4648 | method_bss_entry_patches_.size() + |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4649 | boot_image_type_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4650 | type_bss_entry_patches_.size() + |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4651 | string_patches_.size() + |
| 4652 | string_bss_entry_patches_.size(); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4653 | linker_patches->reserve(size); |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 4654 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4655 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
| 4656 | boot_image_method_patches_, linker_patches); |
| 4657 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
| 4658 | boot_image_type_patches_, linker_patches); |
| 4659 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
| 4660 | string_patches_, linker_patches); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4661 | } else { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4662 | DCHECK(boot_image_method_patches_.empty()); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4663 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeClassTablePatch>( |
| 4664 | boot_image_type_patches_, linker_patches); |
| 4665 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringInternTablePatch>( |
| 4666 | string_patches_, linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4667 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4668 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 4669 | method_bss_entry_patches_, linker_patches); |
| 4670 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 4671 | type_bss_entry_patches_, linker_patches); |
| 4672 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 4673 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4674 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4675 | } |
| 4676 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4677 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 4678 | Register card, |
| 4679 | Register object, |
| 4680 | Register value, |
| 4681 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4682 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4683 | if (value_can_be_null) { |
| 4684 | __ testl(value, value); |
| 4685 | __ j(kEqual, &is_null); |
| 4686 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4687 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86PointerSize>().Int32Value())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4688 | __ movl(temp, object); |
| 4689 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4690 | __ movb(Address(temp, card, TIMES_1, 0), |
| 4691 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4692 | if (value_can_be_null) { |
| 4693 | __ Bind(&is_null); |
| 4694 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4695 | } |
| 4696 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4697 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4698 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4699 | |
| 4700 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4701 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4702 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4703 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 4704 | kEmitCompilerReadBarrier |
| 4705 | ? LocationSummary::kCallOnSlowPath |
| 4706 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4707 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4708 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4709 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4710 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4711 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4712 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4713 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4714 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4715 | // The output overlaps in case of long: we don't want the low move |
| 4716 | // to overwrite the object's location. Likewise, in the case of |
| 4717 | // an object field get with read barriers enabled, we do not want |
| 4718 | // the move to overwrite the object's location, as we need it to emit |
| 4719 | // the read barrier. |
| 4720 | locations->SetOut( |
| 4721 | Location::RequiresRegister(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4722 | (object_field_get_with_read_barrier || instruction->GetType() == DataType::Type::kInt64) ? |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4723 | Location::kOutputOverlap : |
| 4724 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4725 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4726 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4727 | if (field_info.IsVolatile() && (field_info.GetFieldType() == DataType::Type::kInt64)) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4728 | // Long values can be loaded atomically into an XMM using movsd. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4729 | // So we use an XMM register as a temp to achieve atomicity (first |
| 4730 | // load the temp into the XMM and then copy the XMM into the |
| 4731 | // output, 32 bits at a time). |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4732 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4733 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4734 | } |
| 4735 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4736 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 4737 | const FieldInfo& field_info) { |
| 4738 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4739 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4740 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4741 | Location base_loc = locations->InAt(0); |
| 4742 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4743 | Location out = locations->Out(); |
| 4744 | bool is_volatile = field_info.IsVolatile(); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4745 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 4746 | DataType::Type load_type = instruction->GetType(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4747 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4748 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4749 | switch (load_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4750 | case DataType::Type::kBool: |
| 4751 | case DataType::Type::kUint8: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4752 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4753 | break; |
| 4754 | } |
| 4755 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4756 | case DataType::Type::kInt8: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4757 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4758 | break; |
| 4759 | } |
| 4760 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4761 | case DataType::Type::kUint16: { |
| 4762 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4763 | break; |
| 4764 | } |
| 4765 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4766 | case DataType::Type::kInt16: { |
| 4767 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4768 | break; |
| 4769 | } |
| 4770 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4771 | case DataType::Type::kInt32: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4772 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4773 | break; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4774 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4775 | case DataType::Type::kReference: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4776 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4777 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4778 | // Note that a potential implicit null check is handled in this |
| 4779 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 4780 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 4781 | instruction, out, base, offset, /* needs_null_check */ true); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4782 | if (is_volatile) { |
| 4783 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4784 | } |
| 4785 | } else { |
| 4786 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| 4787 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4788 | if (is_volatile) { |
| 4789 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4790 | } |
| 4791 | // If read barriers are enabled, emit read barriers other than |
| 4792 | // Baker's using a slow path (and also unpoison the loaded |
| 4793 | // reference, if heap poisoning is enabled). |
| 4794 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4795 | } |
| 4796 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4797 | } |
| 4798 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4799 | case DataType::Type::kInt64: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4800 | if (is_volatile) { |
| 4801 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4802 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4803 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4804 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 4805 | __ psrlq(temp, Immediate(32)); |
| 4806 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 4807 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4808 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4809 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4810 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4811 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 4812 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4813 | break; |
| 4814 | } |
| 4815 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4816 | case DataType::Type::kFloat32: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4817 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4818 | break; |
| 4819 | } |
| 4820 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4821 | case DataType::Type::kFloat64: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4822 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4823 | break; |
| 4824 | } |
| 4825 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4826 | case DataType::Type::kVoid: |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4827 | LOG(FATAL) << "Unreachable type " << load_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4828 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4829 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4830 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4831 | if (load_type == DataType::Type::kReference || load_type == DataType::Type::kInt64) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4832 | // Potential implicit null checks, in the case of reference or |
| 4833 | // long fields, are handled in the previous switch statement. |
| 4834 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4835 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4836 | } |
| 4837 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4838 | if (is_volatile) { |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4839 | if (load_type == DataType::Type::kReference) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4840 | // Memory barriers, in the case of references, are also handled |
| 4841 | // in the previous switch statement. |
| 4842 | } else { |
| 4843 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4844 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4845 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4846 | } |
| 4847 | |
| 4848 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4849 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4850 | |
| 4851 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4852 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4853 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4854 | bool is_volatile = field_info.IsVolatile(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4855 | DataType::Type field_type = field_info.GetFieldType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4856 | bool is_byte_type = DataType::Size(field_type) == 1u; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4857 | |
| 4858 | // The register allocator does not support multiple |
| 4859 | // inputs that die at entry with one in a specific register. |
| 4860 | if (is_byte_type) { |
| 4861 | // Ensure the value is in a byte register. |
| 4862 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4863 | } else if (DataType::IsFloatingPointType(field_type)) { |
| 4864 | if (is_volatile && field_type == DataType::Type::kFloat64) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4865 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4866 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4867 | } else { |
| 4868 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4869 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4870 | } else if (is_volatile && field_type == DataType::Type::kInt64) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4871 | // 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] | 4872 | locations->SetInAt(1, Location::RequiresRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4873 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4874 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 4875 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 4876 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 4877 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 4878 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 4879 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4880 | locations->AddTemp(Location::RequiresFpuRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4881 | } else { |
| 4882 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4883 | |
| 4884 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4885 | // Temporary registers for the write barrier. |
| 4886 | locations->AddTemp(Location::RequiresRegister()); // May be used for reference poisoning too. |
| 4887 | // Ensure the card is in a byte register. |
| 4888 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 4889 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4890 | } |
| 4891 | } |
| 4892 | |
| 4893 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4894 | const FieldInfo& field_info, |
| 4895 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4896 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4897 | |
| 4898 | LocationSummary* locations = instruction->GetLocations(); |
| 4899 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 4900 | Location value = locations->InAt(1); |
| 4901 | bool is_volatile = field_info.IsVolatile(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4902 | DataType::Type field_type = field_info.GetFieldType(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4903 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4904 | bool needs_write_barrier = |
| 4905 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4906 | |
| 4907 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4908 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4909 | } |
| 4910 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4911 | bool maybe_record_implicit_null_check_done = false; |
| 4912 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4913 | switch (field_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4914 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4915 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4916 | case DataType::Type::kInt8: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4917 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 4918 | break; |
| 4919 | } |
| 4920 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4921 | case DataType::Type::kUint16: |
| 4922 | case DataType::Type::kInt16: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4923 | if (value.IsConstant()) { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 4924 | __ movw(Address(base, offset), |
| 4925 | Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4926 | } else { |
| 4927 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 4928 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4929 | break; |
| 4930 | } |
| 4931 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4932 | case DataType::Type::kInt32: |
| 4933 | case DataType::Type::kReference: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4934 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4935 | // Note that in the case where `value` is a null reference, |
| 4936 | // we do not enter this block, as the reference does not |
| 4937 | // need poisoning. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4938 | DCHECK_EQ(field_type, DataType::Type::kReference); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4939 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4940 | __ movl(temp, value.AsRegister<Register>()); |
| 4941 | __ PoisonHeapReference(temp); |
| 4942 | __ movl(Address(base, offset), temp); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4943 | } else if (value.IsConstant()) { |
| 4944 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4945 | __ movl(Address(base, offset), Immediate(v)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4946 | } else { |
Nicolas Geoffray | 0397163 | 2016-03-17 10:44:24 +0000 | [diff] [blame] | 4947 | DCHECK(value.IsRegister()) << value; |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4948 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 4949 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4950 | break; |
| 4951 | } |
| 4952 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4953 | case DataType::Type::kInt64: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4954 | if (is_volatile) { |
| 4955 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4956 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 4957 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 4958 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 4959 | __ punpckldq(temp1, temp2); |
| 4960 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4961 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4962 | } else if (value.IsConstant()) { |
| 4963 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4964 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4965 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4966 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4967 | } else { |
| 4968 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4969 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4970 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 4971 | } |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4972 | maybe_record_implicit_null_check_done = true; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4973 | break; |
| 4974 | } |
| 4975 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4976 | case DataType::Type::kFloat32: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4977 | if (value.IsConstant()) { |
| 4978 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4979 | __ movl(Address(base, offset), Immediate(v)); |
| 4980 | } else { |
| 4981 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4982 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4983 | break; |
| 4984 | } |
| 4985 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4986 | case DataType::Type::kFloat64: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4987 | if (value.IsConstant()) { |
| 4988 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4989 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4990 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4991 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
| 4992 | maybe_record_implicit_null_check_done = true; |
| 4993 | } else { |
| 4994 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4995 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4996 | break; |
| 4997 | } |
| 4998 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4999 | case DataType::Type::kVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5000 | LOG(FATAL) << "Unreachable type " << field_type; |
| 5001 | UNREACHABLE(); |
| 5002 | } |
| 5003 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5004 | if (!maybe_record_implicit_null_check_done) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5005 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5006 | } |
| 5007 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5008 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5009 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5010 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5011 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5012 | } |
| 5013 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5014 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5015 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5016 | } |
| 5017 | } |
| 5018 | |
| 5019 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5020 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5021 | } |
| 5022 | |
| 5023 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5024 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5025 | } |
| 5026 | |
| 5027 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 5028 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5029 | } |
| 5030 | |
| 5031 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5032 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5033 | } |
| 5034 | |
| 5035 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5036 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5037 | } |
| 5038 | |
| 5039 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5040 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5041 | } |
| 5042 | |
| 5043 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5044 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5045 | } |
| 5046 | |
| 5047 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5048 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5049 | } |
| 5050 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5051 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 5052 | HUnresolvedInstanceFieldGet* instruction) { |
| 5053 | FieldAccessCallingConventionX86 calling_convention; |
| 5054 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5055 | instruction, instruction->GetFieldType(), calling_convention); |
| 5056 | } |
| 5057 | |
| 5058 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 5059 | HUnresolvedInstanceFieldGet* instruction) { |
| 5060 | FieldAccessCallingConventionX86 calling_convention; |
| 5061 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5062 | instruction->GetFieldType(), |
| 5063 | instruction->GetFieldIndex(), |
| 5064 | instruction->GetDexPc(), |
| 5065 | calling_convention); |
| 5066 | } |
| 5067 | |
| 5068 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 5069 | HUnresolvedInstanceFieldSet* instruction) { |
| 5070 | FieldAccessCallingConventionX86 calling_convention; |
| 5071 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5072 | instruction, instruction->GetFieldType(), calling_convention); |
| 5073 | } |
| 5074 | |
| 5075 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 5076 | HUnresolvedInstanceFieldSet* instruction) { |
| 5077 | FieldAccessCallingConventionX86 calling_convention; |
| 5078 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5079 | instruction->GetFieldType(), |
| 5080 | instruction->GetFieldIndex(), |
| 5081 | instruction->GetDexPc(), |
| 5082 | calling_convention); |
| 5083 | } |
| 5084 | |
| 5085 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 5086 | HUnresolvedStaticFieldGet* instruction) { |
| 5087 | FieldAccessCallingConventionX86 calling_convention; |
| 5088 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5089 | instruction, instruction->GetFieldType(), calling_convention); |
| 5090 | } |
| 5091 | |
| 5092 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 5093 | HUnresolvedStaticFieldGet* instruction) { |
| 5094 | FieldAccessCallingConventionX86 calling_convention; |
| 5095 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5096 | instruction->GetFieldType(), |
| 5097 | instruction->GetFieldIndex(), |
| 5098 | instruction->GetDexPc(), |
| 5099 | calling_convention); |
| 5100 | } |
| 5101 | |
| 5102 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 5103 | HUnresolvedStaticFieldSet* instruction) { |
| 5104 | FieldAccessCallingConventionX86 calling_convention; |
| 5105 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5106 | instruction, instruction->GetFieldType(), calling_convention); |
| 5107 | } |
| 5108 | |
| 5109 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 5110 | HUnresolvedStaticFieldSet* instruction) { |
| 5111 | FieldAccessCallingConventionX86 calling_convention; |
| 5112 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5113 | instruction->GetFieldType(), |
| 5114 | instruction->GetFieldIndex(), |
| 5115 | instruction->GetDexPc(), |
| 5116 | calling_convention); |
| 5117 | } |
| 5118 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5119 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5120 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5121 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 5122 | ? Location::RequiresRegister() |
| 5123 | : Location::Any(); |
| 5124 | locations->SetInAt(0, loc); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5125 | } |
| 5126 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5127 | void CodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5128 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5129 | return; |
| 5130 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5131 | LocationSummary* locations = instruction->GetLocations(); |
| 5132 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5133 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5134 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5135 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5136 | } |
| 5137 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5138 | void CodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5139 | SlowPathCode* slow_path = new (GetScopedAllocator()) NullCheckSlowPathX86(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5140 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5141 | |
| 5142 | LocationSummary* locations = instruction->GetLocations(); |
| 5143 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5144 | |
| 5145 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 5146 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5147 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5148 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5149 | } else { |
| 5150 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5151 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5152 | __ jmp(slow_path->GetEntryLabel()); |
| 5153 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5154 | } |
| 5155 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5156 | } |
| 5157 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5158 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5159 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5160 | } |
| 5161 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5162 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5163 | bool object_array_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5164 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5165 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5166 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 5167 | object_array_get_with_read_barrier |
| 5168 | ? LocationSummary::kCallOnSlowPath |
| 5169 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5170 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5171 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5172 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5173 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5174 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5175 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5176 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5177 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5178 | // The output overlaps in case of long: we don't want the low move |
| 5179 | // to overwrite the array's location. Likewise, in the case of an |
| 5180 | // object array get with read barriers enabled, we do not want the |
| 5181 | // move to overwrite the array's location, as we need it to emit |
| 5182 | // the read barrier. |
| 5183 | locations->SetOut( |
| 5184 | Location::RequiresRegister(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5185 | (instruction->GetType() == DataType::Type::kInt64 || object_array_get_with_read_barrier) |
| 5186 | ? Location::kOutputOverlap |
| 5187 | : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5188 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5189 | } |
| 5190 | |
| 5191 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 5192 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5193 | Location obj_loc = locations->InAt(0); |
| 5194 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5195 | Location index = locations->InAt(1); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5196 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5197 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5198 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5199 | DataType::Type type = instruction->GetType(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5200 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5201 | case DataType::Type::kBool: |
| 5202 | case DataType::Type::kUint8: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5203 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5204 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5205 | break; |
| 5206 | } |
| 5207 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5208 | case DataType::Type::kInt8: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5209 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5210 | __ movsxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5211 | break; |
| 5212 | } |
| 5213 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5214 | case DataType::Type::kUint16: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5215 | Register out = out_loc.AsRegister<Register>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5216 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5217 | // Branch cases into compressed and uncompressed for each index's type. |
| 5218 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 5219 | NearLabel done, not_compressed; |
Vladimir Marko | 3c89d42 | 2017-02-17 11:30:23 +0000 | [diff] [blame] | 5220 | __ testb(Address(obj, count_offset), Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5221 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5222 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 5223 | "Expecting 0=compressed, 1=uncompressed"); |
| 5224 | __ j(kNotZero, ¬_compressed); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5225 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| 5226 | __ jmp(&done); |
| 5227 | __ Bind(¬_compressed); |
| 5228 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5229 | __ Bind(&done); |
| 5230 | } else { |
| 5231 | // Common case for charAt of array of char or when string compression's |
| 5232 | // feature is turned off. |
| 5233 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5234 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5235 | break; |
| 5236 | } |
| 5237 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5238 | case DataType::Type::kInt16: { |
| 5239 | Register out = out_loc.AsRegister<Register>(); |
| 5240 | __ movsxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5241 | break; |
| 5242 | } |
| 5243 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5244 | case DataType::Type::kInt32: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5245 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5246 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5247 | break; |
| 5248 | } |
| 5249 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5250 | case DataType::Type::kReference: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5251 | static_assert( |
| 5252 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5253 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5254 | // /* HeapReference<Object> */ out = |
| 5255 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5256 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5257 | // Note that a potential implicit null check is handled in this |
| 5258 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 5259 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5260 | instruction, out_loc, obj, data_offset, index, /* needs_null_check */ true); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5261 | } else { |
| 5262 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5263 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| 5264 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5265 | // If read barriers are enabled, emit read barriers other than |
| 5266 | // Baker's using a slow path (and also unpoison the loaded |
| 5267 | // reference, if heap poisoning is enabled). |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5268 | if (index.IsConstant()) { |
| 5269 | uint32_t offset = |
| 5270 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5271 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5272 | } else { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5273 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5274 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5275 | } |
| 5276 | } |
| 5277 | break; |
| 5278 | } |
| 5279 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5280 | case DataType::Type::kInt64: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5281 | DCHECK_NE(obj, out_loc.AsRegisterPairLow<Register>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5282 | __ movl(out_loc.AsRegisterPairLow<Register>(), |
| 5283 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
| 5284 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5285 | __ movl(out_loc.AsRegisterPairHigh<Register>(), |
| 5286 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5287 | break; |
| 5288 | } |
| 5289 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5290 | case DataType::Type::kFloat32: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5291 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5292 | __ movss(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5293 | break; |
| 5294 | } |
| 5295 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5296 | case DataType::Type::kFloat64: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5297 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5298 | __ movsd(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5299 | break; |
| 5300 | } |
| 5301 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5302 | case DataType::Type::kVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5303 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5304 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5305 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5306 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5307 | if (type == DataType::Type::kReference || type == DataType::Type::kInt64) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5308 | // Potential implicit null checks, in the case of reference or |
| 5309 | // long arrays, are handled in the previous switch statement. |
| 5310 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5311 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5312 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5313 | } |
| 5314 | |
| 5315 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5316 | DataType::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5317 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5318 | bool needs_write_barrier = |
| 5319 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5320 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5321 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5322 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5323 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 5324 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5325 | LocationSummary::kCallOnSlowPath : |
| 5326 | LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5327 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5328 | bool is_byte_type = DataType::Size(value_type) == 1u; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5329 | // We need the inputs to be different than the output in case of long operation. |
| 5330 | // In case of a byte operation, the register allocator does not support multiple |
| 5331 | // inputs that die at entry with one in a specific register. |
| 5332 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5333 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5334 | if (is_byte_type) { |
| 5335 | // Ensure the value is in a byte register. |
| 5336 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5337 | } else if (DataType::IsFloatingPointType(value_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5338 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5339 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5340 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 5341 | } |
| 5342 | if (needs_write_barrier) { |
| 5343 | // Temporary registers for the write barrier. |
| 5344 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 5345 | // Ensure the card is in a byte register. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5346 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5347 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5348 | } |
| 5349 | |
| 5350 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 5351 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5352 | Location array_loc = locations->InAt(0); |
| 5353 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5354 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5355 | Location value = locations->InAt(2); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5356 | DataType::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5357 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5358 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5359 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5360 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5361 | bool needs_write_barrier = |
| 5362 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5363 | |
| 5364 | switch (value_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5365 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5366 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5367 | case DataType::Type::kInt8: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5368 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5369 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_1, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5370 | if (value.IsRegister()) { |
| 5371 | __ movb(address, value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5372 | } else { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5373 | __ movb(address, Immediate(CodeGenerator::GetInt8ValueOf(value.GetConstant()))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5374 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5375 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5376 | break; |
| 5377 | } |
| 5378 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5379 | case DataType::Type::kUint16: |
| 5380 | case DataType::Type::kInt16: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5381 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5382 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_2, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5383 | if (value.IsRegister()) { |
| 5384 | __ movw(address, value.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5385 | } else { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5386 | __ movw(address, Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5387 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5388 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5389 | break; |
| 5390 | } |
| 5391 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5392 | case DataType::Type::kReference: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5393 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5394 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5395 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5396 | if (!value.IsRegister()) { |
| 5397 | // Just setting null. |
| 5398 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5399 | DCHECK(value.IsConstant()) << value; |
| 5400 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5401 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5402 | DCHECK(!needs_write_barrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5403 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5404 | break; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5405 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5406 | |
| 5407 | DCHECK(needs_write_barrier); |
| 5408 | Register register_value = value.AsRegister<Register>(); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5409 | // We cannot use a NearLabel for `done`, as its range may be too |
| 5410 | // short when Baker read barriers are enabled. |
| 5411 | Label done; |
| 5412 | NearLabel not_null, do_put; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5413 | SlowPathCode* slow_path = nullptr; |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5414 | Location temp_loc = locations->GetTemp(0); |
| 5415 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5416 | if (may_need_runtime_call_for_type_check) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5417 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathX86(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5418 | codegen_->AddSlowPath(slow_path); |
| 5419 | if (instruction->GetValueCanBeNull()) { |
| 5420 | __ testl(register_value, register_value); |
| 5421 | __ j(kNotEqual, ¬_null); |
| 5422 | __ movl(address, Immediate(0)); |
| 5423 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5424 | __ jmp(&done); |
| 5425 | __ Bind(¬_null); |
| 5426 | } |
| 5427 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5428 | // Note that when Baker read barriers are enabled, the type |
| 5429 | // checks are performed without read barriers. This is fine, |
| 5430 | // even in the case where a class object is in the from-space |
| 5431 | // after the flip, as a comparison involving such a type would |
| 5432 | // not produce a false positive; it may of course produce a |
| 5433 | // false negative, in which case we would take the ArraySet |
| 5434 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5435 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5436 | // /* HeapReference<Class> */ temp = array->klass_ |
| 5437 | __ movl(temp, Address(array, class_offset)); |
| 5438 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5439 | __ MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5440 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5441 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5442 | __ movl(temp, Address(temp, component_offset)); |
| 5443 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 5444 | // nor the object reference in `register_value->klass`, as |
| 5445 | // we are comparing two poisoned references. |
| 5446 | __ cmpl(temp, Address(register_value, class_offset)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5447 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5448 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5449 | __ j(kEqual, &do_put); |
| 5450 | // If heap poisoning is enabled, the `temp` reference has |
| 5451 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5452 | __ MaybeUnpoisonHeapReference(temp); |
| 5453 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5454 | // If heap poisoning is enabled, no need to unpoison the |
| 5455 | // heap reference loaded below, as it is only used for a |
| 5456 | // comparison with null. |
| 5457 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 5458 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5459 | __ Bind(&do_put); |
| 5460 | } else { |
| 5461 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5462 | } |
| 5463 | } |
| 5464 | |
| 5465 | if (kPoisonHeapReferences) { |
| 5466 | __ movl(temp, register_value); |
| 5467 | __ PoisonHeapReference(temp); |
| 5468 | __ movl(address, temp); |
| 5469 | } else { |
| 5470 | __ movl(address, register_value); |
| 5471 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5472 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5473 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5474 | } |
| 5475 | |
| 5476 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 5477 | codegen_->MarkGCCard( |
| 5478 | temp, card, array, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); |
| 5479 | __ Bind(&done); |
| 5480 | |
| 5481 | if (slow_path != nullptr) { |
| 5482 | __ Bind(slow_path->GetExitLabel()); |
| 5483 | } |
| 5484 | |
| 5485 | break; |
| 5486 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5487 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5488 | case DataType::Type::kInt32: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5489 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5490 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5491 | if (value.IsRegister()) { |
| 5492 | __ movl(address, value.AsRegister<Register>()); |
| 5493 | } else { |
| 5494 | DCHECK(value.IsConstant()) << value; |
| 5495 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5496 | __ movl(address, Immediate(v)); |
| 5497 | } |
| 5498 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5499 | break; |
| 5500 | } |
| 5501 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5502 | case DataType::Type::kInt64: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5503 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5504 | if (value.IsRegisterPair()) { |
| 5505 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 5506 | value.AsRegisterPairLow<Register>()); |
| 5507 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5508 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 5509 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5510 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5511 | DCHECK(value.IsConstant()); |
| 5512 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
| 5513 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 5514 | Immediate(Low32Bits(val))); |
| 5515 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5516 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 5517 | Immediate(High32Bits(val))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5518 | } |
| 5519 | break; |
| 5520 | } |
| 5521 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5522 | case DataType::Type::kFloat32: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5523 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5524 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5525 | if (value.IsFpuRegister()) { |
| 5526 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5527 | } else { |
| 5528 | DCHECK(value.IsConstant()); |
| 5529 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 5530 | __ movl(address, Immediate(v)); |
| 5531 | } |
| 5532 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5533 | break; |
| 5534 | } |
| 5535 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5536 | case DataType::Type::kFloat64: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5537 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5538 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5539 | if (value.IsFpuRegister()) { |
| 5540 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5541 | } else { |
| 5542 | DCHECK(value.IsConstant()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5543 | Address address_hi = |
| 5544 | CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset + kX86WordSize); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5545 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 5546 | __ movl(address, Immediate(Low32Bits(v))); |
| 5547 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5548 | __ movl(address_hi, Immediate(High32Bits(v))); |
| 5549 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5550 | break; |
| 5551 | } |
| 5552 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5553 | case DataType::Type::kVoid: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5554 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5555 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5556 | } |
| 5557 | } |
| 5558 | |
| 5559 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5560 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5561 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5562 | if (!instruction->IsEmittedAtUseSite()) { |
| 5563 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5564 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5565 | } |
| 5566 | |
| 5567 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5568 | if (instruction->IsEmittedAtUseSite()) { |
| 5569 | return; |
| 5570 | } |
| 5571 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5572 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5573 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5574 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5575 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5576 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5577 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5578 | // Mask out most significant bit in case the array is String's array of char. |
| 5579 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5580 | __ shrl(out, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5581 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5582 | } |
| 5583 | |
| 5584 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5585 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5586 | InvokeRuntimeCallingConvention calling_convention; |
| 5587 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5588 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5589 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5590 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5591 | HInstruction* length = instruction->InputAt(1); |
| 5592 | if (!length->IsEmittedAtUseSite()) { |
| 5593 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5594 | } |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5595 | // Need register to see array's length. |
| 5596 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5597 | locations->AddTemp(Location::RequiresRegister()); |
| 5598 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5599 | } |
| 5600 | |
| 5601 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5602 | const bool is_string_compressed_char_at = |
| 5603 | mirror::kUseStringCompression && instruction->IsStringCharAt(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5604 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5605 | Location index_loc = locations->InAt(0); |
| 5606 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5607 | SlowPathCode* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5608 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathX86(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5609 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5610 | if (length_loc.IsConstant()) { |
| 5611 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5612 | if (index_loc.IsConstant()) { |
| 5613 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5614 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5615 | if (index < 0 || index >= length) { |
| 5616 | codegen_->AddSlowPath(slow_path); |
| 5617 | __ jmp(slow_path->GetEntryLabel()); |
| 5618 | } else { |
| 5619 | // Some optimization after BCE may have generated this, and we should not |
| 5620 | // generate a bounds check if it is a valid range. |
| 5621 | } |
| 5622 | return; |
| 5623 | } |
| 5624 | |
| 5625 | // We have to reverse the jump condition because the length is the constant. |
| 5626 | Register index_reg = index_loc.AsRegister<Register>(); |
| 5627 | __ cmpl(index_reg, Immediate(length)); |
| 5628 | codegen_->AddSlowPath(slow_path); |
| 5629 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5630 | } else { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5631 | HInstruction* array_length = instruction->InputAt(1); |
| 5632 | if (array_length->IsEmittedAtUseSite()) { |
| 5633 | // Address the length field in the array. |
| 5634 | DCHECK(array_length->IsArrayLength()); |
| 5635 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 5636 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 5637 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5638 | if (is_string_compressed_char_at) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5639 | // TODO: if index_loc.IsConstant(), compare twice the index (to compensate for |
| 5640 | // the string compression flag) with the in-memory length and avoid the temporary. |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5641 | Register length_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 5642 | __ movl(length_reg, array_len); |
| 5643 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5644 | __ shrl(length_reg, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5645 | codegen_->GenerateIntCompare(length_reg, index_loc); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5646 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5647 | // Checking bounds for general case: |
| 5648 | // Array of char or string's array with feature compression off. |
| 5649 | if (index_loc.IsConstant()) { |
| 5650 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5651 | __ cmpl(array_len, Immediate(value)); |
| 5652 | } else { |
| 5653 | __ cmpl(array_len, index_loc.AsRegister<Register>()); |
| 5654 | } |
| 5655 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5656 | } |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5657 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5658 | codegen_->GenerateIntCompare(length_loc, index_loc); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5659 | } |
| 5660 | codegen_->AddSlowPath(slow_path); |
| 5661 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5662 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5663 | } |
| 5664 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5665 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5666 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5667 | } |
| 5668 | |
| 5669 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 5670 | if (instruction->GetNext()->IsSuspendCheck() && |
| 5671 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 5672 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 5673 | // The back edge will generate the suspend check. |
| 5674 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 5675 | } |
| 5676 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5677 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5678 | } |
| 5679 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5680 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5681 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5682 | instruction, LocationSummary::kCallOnSlowPath); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 5683 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 5684 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 5685 | // registers in full width (since the runtime only saves/restores lower part). |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5686 | locations->SetCustomSlowPathCallerSaves( |
| 5687 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5688 | } |
| 5689 | |
| 5690 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5691 | HBasicBlock* block = instruction->GetBlock(); |
| 5692 | if (block->GetLoopInformation() != nullptr) { |
| 5693 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5694 | // The back edge will generate the suspend check. |
| 5695 | return; |
| 5696 | } |
| 5697 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5698 | // The goto will generate the suspend check. |
| 5699 | return; |
| 5700 | } |
| 5701 | GenerateSuspendCheck(instruction, nullptr); |
| 5702 | } |
| 5703 | |
| 5704 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5705 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5706 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5707 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 5708 | if (slow_path == nullptr) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5709 | slow_path = |
| 5710 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathX86(instruction, successor); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5711 | instruction->SetSlowPath(slow_path); |
| 5712 | codegen_->AddSlowPath(slow_path); |
| 5713 | if (successor != nullptr) { |
| 5714 | DCHECK(successor->IsLoopHeader()); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5715 | } |
| 5716 | } else { |
| 5717 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5718 | } |
| 5719 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5720 | __ fs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86PointerSize>().Int32Value()), |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5721 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5722 | if (successor == nullptr) { |
| 5723 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5724 | __ Bind(slow_path->GetReturnLabel()); |
| 5725 | } else { |
| 5726 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5727 | __ jmp(slow_path->GetEntryLabel()); |
| 5728 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5729 | } |
| 5730 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5731 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 5732 | return codegen_->GetAssembler(); |
| 5733 | } |
| 5734 | |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame^] | 5735 | void ParallelMoveResolverX86::MoveMemoryToMemory(int dst, int src, int number_of_words) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5736 | ScratchRegisterScope ensure_scratch( |
| 5737 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5738 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5739 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5740 | |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame^] | 5741 | // Now that temp register is available (possibly spilled), move blocks of memory. |
| 5742 | for (int i = 0; i < number_of_words; i++) { |
| 5743 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5744 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 5745 | stack_offset += kX86WordSize; |
| 5746 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5747 | } |
| 5748 | |
| 5749 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5750 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5751 | Location source = move->GetSource(); |
| 5752 | Location destination = move->GetDestination(); |
| 5753 | |
| 5754 | if (source.IsRegister()) { |
| 5755 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5756 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5757 | } else if (destination.IsFpuRegister()) { |
| 5758 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5759 | } else { |
| 5760 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5761 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5762 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5763 | } else if (source.IsRegisterPair()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5764 | size_t elem_size = DataType::Size(DataType::Type::kInt32); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5765 | // Create stack space for 2 elements. |
| 5766 | __ subl(ESP, Immediate(2 * elem_size)); |
| 5767 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 5768 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 5769 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 5770 | // And remove the temporary stack space we allocated. |
| 5771 | __ addl(ESP, Immediate(2 * elem_size)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5772 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5773 | if (destination.IsRegister()) { |
| 5774 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
| 5775 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5776 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5777 | } else if (destination.IsRegisterPair()) { |
| 5778 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 5779 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 5780 | __ psrlq(src_reg, Immediate(32)); |
| 5781 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5782 | } else if (destination.IsStackSlot()) { |
| 5783 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5784 | } else if (destination.IsDoubleStackSlot()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5785 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5786 | } else { |
| 5787 | DCHECK(destination.IsSIMDStackSlot()); |
| 5788 | __ movups(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5789 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5790 | } else if (source.IsStackSlot()) { |
| 5791 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5792 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5793 | } else if (destination.IsFpuRegister()) { |
| 5794 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5795 | } else { |
| 5796 | DCHECK(destination.IsStackSlot()); |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame^] | 5797 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 1); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5798 | } |
| 5799 | } else if (source.IsDoubleStackSlot()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5800 | if (destination.IsRegisterPair()) { |
| 5801 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 5802 | __ movl(destination.AsRegisterPairHigh<Register>(), |
| 5803 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 5804 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5805 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 5806 | } else { |
| 5807 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame^] | 5808 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 2); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5809 | } |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5810 | } else if (source.IsSIMDStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame^] | 5811 | if (destination.IsFpuRegister()) { |
| 5812 | __ movups(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 5813 | } else { |
| 5814 | DCHECK(destination.IsSIMDStackSlot()); |
| 5815 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 4); |
| 5816 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5817 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5818 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5819 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5820 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5821 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5822 | if (value == 0) { |
| 5823 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5824 | } else { |
| 5825 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 5826 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5827 | } else { |
| 5828 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5829 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5830 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5831 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5832 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5833 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5834 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5835 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5836 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5837 | if (value == 0) { |
| 5838 | // Easy handling of 0.0. |
| 5839 | __ xorps(dest, dest); |
| 5840 | } else { |
| 5841 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5842 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5843 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5844 | __ movl(temp, Immediate(value)); |
| 5845 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5846 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5847 | } else { |
| 5848 | DCHECK(destination.IsStackSlot()) << destination; |
| 5849 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 5850 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5851 | } else if (constant->IsLongConstant()) { |
| 5852 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5853 | int32_t low_value = Low32Bits(value); |
| 5854 | int32_t high_value = High32Bits(value); |
| 5855 | Immediate low(low_value); |
| 5856 | Immediate high(high_value); |
| 5857 | if (destination.IsDoubleStackSlot()) { |
| 5858 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5859 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5860 | } else { |
| 5861 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 5862 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 5863 | } |
| 5864 | } else { |
| 5865 | DCHECK(constant->IsDoubleConstant()); |
| 5866 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5867 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5868 | int32_t low_value = Low32Bits(value); |
| 5869 | int32_t high_value = High32Bits(value); |
| 5870 | Immediate low(low_value); |
| 5871 | Immediate high(high_value); |
| 5872 | if (destination.IsFpuRegister()) { |
| 5873 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5874 | if (value == 0) { |
| 5875 | // Easy handling of 0.0. |
| 5876 | __ xorpd(dest, dest); |
| 5877 | } else { |
| 5878 | __ pushl(high); |
| 5879 | __ pushl(low); |
| 5880 | __ movsd(dest, Address(ESP, 0)); |
| 5881 | __ addl(ESP, Immediate(8)); |
| 5882 | } |
| 5883 | } else { |
| 5884 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5885 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5886 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5887 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5888 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5889 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5890 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5891 | } |
| 5892 | } |
| 5893 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 5894 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5895 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 5896 | ScratchRegisterScope ensure_scratch( |
| 5897 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 5898 | |
| 5899 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5900 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 5901 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 5902 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5903 | } |
| 5904 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5905 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5906 | ScratchRegisterScope ensure_scratch( |
| 5907 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5908 | |
| 5909 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5910 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5911 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 5912 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 5913 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5914 | } |
| 5915 | |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame^] | 5916 | void ParallelMoveResolverX86::Exchange128(XmmRegister reg, int mem) { |
| 5917 | size_t extra_slot = 4 * kX86WordSize; |
| 5918 | __ subl(ESP, Immediate(extra_slot)); |
| 5919 | __ movups(Address(ESP, 0), XmmRegister(reg)); |
| 5920 | ExchangeMemory(0, mem + extra_slot, 4); |
| 5921 | __ movups(XmmRegister(reg), Address(ESP, 0)); |
| 5922 | __ addl(ESP, Immediate(extra_slot)); |
| 5923 | } |
| 5924 | |
| 5925 | void ParallelMoveResolverX86::ExchangeMemory(int mem1, int mem2, int number_of_words) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5926 | ScratchRegisterScope ensure_scratch1( |
| 5927 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5928 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5929 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 5930 | ScratchRegisterScope ensure_scratch2( |
| 5931 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5932 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5933 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 5934 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame^] | 5935 | |
| 5936 | // Now that temp registers are available (possibly spilled), exchange blocks of memory. |
| 5937 | for (int i = 0; i < number_of_words; i++) { |
| 5938 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 5939 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 5940 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 5941 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
| 5942 | stack_offset += kX86WordSize; |
| 5943 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5944 | } |
| 5945 | |
| 5946 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5947 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5948 | Location source = move->GetSource(); |
| 5949 | Location destination = move->GetDestination(); |
| 5950 | |
| 5951 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 5952 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 5953 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5954 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5955 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5956 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5957 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5958 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5959 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5960 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5961 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame^] | 5962 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 1); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5963 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 5964 | // Use XOR Swap algorithm to avoid a temporary. |
| 5965 | DCHECK_NE(source.reg(), destination.reg()); |
| 5966 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5967 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5968 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5969 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 5970 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 5971 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 5972 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5973 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 5974 | // Take advantage of the 16 bytes in the XMM register. |
| 5975 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 5976 | Address stack(ESP, destination.GetStackIndex()); |
| 5977 | // Load the double into the high doubleword. |
| 5978 | __ movhpd(reg, stack); |
| 5979 | |
| 5980 | // Store the low double into the destination. |
| 5981 | __ movsd(stack, reg); |
| 5982 | |
| 5983 | // Move the high double to the low double. |
| 5984 | __ psrldq(reg, Immediate(8)); |
| 5985 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 5986 | // Take advantage of the 16 bytes in the XMM register. |
| 5987 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 5988 | Address stack(ESP, source.GetStackIndex()); |
| 5989 | // Load the double into the high doubleword. |
| 5990 | __ movhpd(reg, stack); |
| 5991 | |
| 5992 | // Store the low double into the destination. |
| 5993 | __ movsd(stack, reg); |
| 5994 | |
| 5995 | // Move the high double to the low double. |
| 5996 | __ psrldq(reg, Immediate(8)); |
| 5997 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame^] | 5998 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 2); |
| 5999 | } else if (source.IsSIMDStackSlot() && destination.IsSIMDStackSlot()) { |
| 6000 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 4); |
| 6001 | } else if (source.IsFpuRegister() && destination.IsSIMDStackSlot()) { |
| 6002 | Exchange128(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 6003 | } else if (destination.IsFpuRegister() && source.IsSIMDStackSlot()) { |
| 6004 | Exchange128(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6005 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6006 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6007 | } |
| 6008 | } |
| 6009 | |
| 6010 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 6011 | __ pushl(static_cast<Register>(reg)); |
| 6012 | } |
| 6013 | |
| 6014 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 6015 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6016 | } |
| 6017 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6018 | HLoadClass::LoadKind CodeGeneratorX86::GetSupportedLoadClassKind( |
| 6019 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6020 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6021 | case HLoadClass::LoadKind::kInvalid: |
| 6022 | LOG(FATAL) << "UNREACHABLE"; |
| 6023 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6024 | case HLoadClass::LoadKind::kReferrersClass: |
| 6025 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6026 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6027 | case HLoadClass::LoadKind::kBootImageClassTable: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6028 | case HLoadClass::LoadKind::kBssEntry: |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6029 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6030 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6031 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6032 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6033 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6034 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6035 | case HLoadClass::LoadKind::kRuntimeCall: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6036 | break; |
| 6037 | } |
| 6038 | return desired_class_load_kind; |
| 6039 | } |
| 6040 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6041 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6042 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6043 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6044 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6045 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6046 | cls, |
| 6047 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6048 | Location::RegisterLocation(EAX)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6049 | DCHECK_EQ(calling_convention.GetRegisterAt(0), EAX); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6050 | return; |
| 6051 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6052 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6053 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6054 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 6055 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6056 | ? LocationSummary::kCallOnSlowPath |
| 6057 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6058 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6059 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6060 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6061 | } |
| 6062 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6063 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6064 | load_kind == HLoadClass::LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6065 | load_kind == HLoadClass::LoadKind::kBootImageClassTable || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6066 | load_kind == HLoadClass::LoadKind::kBssEntry) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6067 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6068 | } |
| 6069 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6070 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 6071 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 6072 | // Rely on the type resolution and/or initialization to save everything. |
| 6073 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6074 | InvokeRuntimeCallingConvention calling_convention; |
| 6075 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6076 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6077 | } else { |
| 6078 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6079 | } |
| 6080 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6081 | } |
| 6082 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6083 | Label* CodeGeneratorX86::NewJitRootClassPatch(const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6084 | dex::TypeIndex type_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6085 | Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6086 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6087 | // Add a patch entry and return the label. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6088 | jit_class_patches_.emplace_back(dex_file, type_index.index_); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6089 | PatchInfo<Label>* info = &jit_class_patches_.back(); |
| 6090 | return &info->label; |
| 6091 | } |
| 6092 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6093 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6094 | // move. |
| 6095 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6096 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6097 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6098 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6099 | return; |
| 6100 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6101 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6102 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6103 | LocationSummary* locations = cls->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6104 | Location out_loc = locations->Out(); |
| 6105 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6106 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6107 | bool generate_null_check = false; |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6108 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 6109 | ? kWithoutReadBarrier |
| 6110 | : kCompilerReadBarrierOption; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6111 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6112 | case HLoadClass::LoadKind::kReferrersClass: { |
| 6113 | DCHECK(!cls->CanCallRuntime()); |
| 6114 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 6115 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6116 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 6117 | GenerateGcRootFieldLoad( |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6118 | cls, |
| 6119 | out_loc, |
| 6120 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 6121 | /* fixup_label */ nullptr, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6122 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6123 | break; |
| 6124 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6125 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6126 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6127 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6128 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6129 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 6130 | codegen_->RecordBootTypePatch(cls); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6131 | break; |
| 6132 | } |
| 6133 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6134 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6135 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6136 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 6137 | DCHECK_NE(address, 0u); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6138 | __ movl(out, Immediate(address)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6139 | break; |
| 6140 | } |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6141 | case HLoadClass::LoadKind::kBootImageClassTable: { |
| 6142 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 6143 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6144 | __ movl(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
| 6145 | codegen_->RecordBootTypePatch(cls); |
| 6146 | // Extract the reference from the slot data, i.e. clear the hash bits. |
| 6147 | int32_t masked_hash = ClassTable::TableSlot::MaskHash( |
| 6148 | ComputeModifiedUtf8Hash(cls->GetDexFile().StringByTypeIdx(cls->GetTypeIndex()))); |
| 6149 | if (masked_hash != 0) { |
| 6150 | __ subl(out, Immediate(masked_hash)); |
| 6151 | } |
| 6152 | break; |
| 6153 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6154 | case HLoadClass::LoadKind::kBssEntry: { |
| 6155 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6156 | Address address(method_address, CodeGeneratorX86::kDummy32BitOffset); |
| 6157 | Label* fixup_label = codegen_->NewTypeBssEntryPatch(cls); |
| 6158 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
| 6159 | generate_null_check = true; |
| 6160 | break; |
| 6161 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6162 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 6163 | Address address = Address::Absolute(CodeGeneratorX86::kDummy32BitOffset); |
| 6164 | Label* fixup_label = codegen_->NewJitRootClassPatch( |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6165 | cls->GetDexFile(), cls->GetTypeIndex(), cls->GetClass()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6166 | // /* GcRoot<mirror::Class> */ out = *address |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6167 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6168 | break; |
| 6169 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6170 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6171 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6172 | LOG(FATAL) << "UNREACHABLE"; |
| 6173 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6174 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6175 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6176 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6177 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6178 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6179 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 6180 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6181 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6182 | if (generate_null_check) { |
| 6183 | __ testl(out, out); |
| 6184 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6185 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6186 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6187 | if (cls->MustGenerateClinitCheck()) { |
| 6188 | GenerateClassInitializationCheck(slow_path, out); |
| 6189 | } else { |
| 6190 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6191 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6192 | } |
| 6193 | } |
| 6194 | |
| 6195 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 6196 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6197 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6198 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6199 | if (check->HasUses()) { |
| 6200 | locations->SetOut(Location::SameAsFirstInput()); |
| 6201 | } |
| 6202 | } |
| 6203 | |
| 6204 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6205 | // We assume the class to not be null. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6206 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6207 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6208 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6209 | GenerateClassInitializationCheck(slow_path, |
| 6210 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6211 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6212 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6213 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6214 | SlowPathCode* slow_path, Register class_reg) { |
Igor Murashkin | 86083f7 | 2017-10-27 10:59:04 -0700 | [diff] [blame] | 6215 | __ cmpb(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6216 | Immediate(mirror::Class::kStatusInitialized)); |
| 6217 | __ j(kLess, slow_path->GetEntryLabel()); |
| 6218 | __ Bind(slow_path->GetExitLabel()); |
| 6219 | // No need for memory fence, thanks to the X86 memory model. |
| 6220 | } |
| 6221 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6222 | HLoadString::LoadKind CodeGeneratorX86::GetSupportedLoadStringKind( |
| 6223 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6224 | switch (desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6225 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6226 | case HLoadString::LoadKind::kBootImageInternTable: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6227 | case HLoadString::LoadKind::kBssEntry: |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6228 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6229 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6230 | case HLoadString::LoadKind::kJitTableAddress: |
| 6231 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6232 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6233 | case HLoadString::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6234 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6235 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6236 | } |
| 6237 | return desired_string_load_kind; |
| 6238 | } |
| 6239 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6240 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6241 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6242 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6243 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6244 | if (load_kind == HLoadString::LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6245 | load_kind == HLoadString::LoadKind::kBootImageInternTable || |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6246 | load_kind == HLoadString::LoadKind::kBssEntry) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6247 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6248 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6249 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6250 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 6251 | } else { |
| 6252 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6253 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 6254 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6255 | // Rely on the pResolveString to save everything. |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6256 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6257 | InvokeRuntimeCallingConvention calling_convention; |
| 6258 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6259 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6260 | } else { |
| 6261 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6262 | } |
| 6263 | } |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6264 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6265 | } |
| 6266 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6267 | Label* CodeGeneratorX86::NewJitRootStringPatch(const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6268 | dex::StringIndex string_index, |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6269 | Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6270 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6271 | // Add a patch entry and return the label. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6272 | jit_string_patches_.emplace_back(dex_file, string_index.index_); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6273 | PatchInfo<Label>* info = &jit_string_patches_.back(); |
| 6274 | return &info->label; |
| 6275 | } |
| 6276 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6277 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6278 | // move. |
| 6279 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6280 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6281 | Location out_loc = locations->Out(); |
| 6282 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6283 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6284 | switch (load->GetLoadKind()) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6285 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6286 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6287 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6288 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6289 | codegen_->RecordBootStringPatch(load); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6290 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6291 | } |
| 6292 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6293 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6294 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 6295 | DCHECK_NE(address, 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6296 | __ movl(out, Immediate(address)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6297 | return; |
| 6298 | } |
| 6299 | case HLoadString::LoadKind::kBootImageInternTable: { |
| 6300 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 6301 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6302 | __ movl(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
| 6303 | codegen_->RecordBootStringPatch(load); |
| 6304 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6305 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6306 | case HLoadString::LoadKind::kBssEntry: { |
| 6307 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6308 | Address address = Address(method_address, CodeGeneratorX86::kDummy32BitOffset); |
| 6309 | Label* fixup_label = codegen_->NewStringBssEntryPatch(load); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6310 | // /* GcRoot<mirror::String> */ out = *address /* PC-relative */ |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6311 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6312 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadStringSlowPathX86(load); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6313 | codegen_->AddSlowPath(slow_path); |
| 6314 | __ testl(out, out); |
| 6315 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6316 | __ Bind(slow_path->GetExitLabel()); |
| 6317 | return; |
| 6318 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6319 | case HLoadString::LoadKind::kJitTableAddress: { |
| 6320 | Address address = Address::Absolute(CodeGeneratorX86::kDummy32BitOffset); |
| 6321 | Label* fixup_label = codegen_->NewJitRootStringPatch( |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6322 | load->GetDexFile(), load->GetStringIndex(), load->GetString()); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6323 | // /* GcRoot<mirror::String> */ out = *address |
| 6324 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
| 6325 | return; |
| 6326 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6327 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6328 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6329 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6330 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6331 | // 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] | 6332 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6333 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6334 | __ movl(calling_convention.GetRegisterAt(0), Immediate(load->GetStringIndex().index_)); |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6335 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 6336 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6337 | } |
| 6338 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6339 | static Address GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6340 | return Address::Absolute(Thread::ExceptionOffset<kX86PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6341 | } |
| 6342 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6343 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 6344 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6345 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6346 | locations->SetOut(Location::RequiresRegister()); |
| 6347 | } |
| 6348 | |
| 6349 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6350 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 6351 | } |
| 6352 | |
| 6353 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6354 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6355 | } |
| 6356 | |
| 6357 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6358 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6359 | } |
| 6360 | |
| 6361 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6362 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6363 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6364 | InvokeRuntimeCallingConvention calling_convention; |
| 6365 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6366 | } |
| 6367 | |
| 6368 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6369 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6370 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6371 | } |
| 6372 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6373 | // Temp is used for read barrier. |
| 6374 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 6375 | if (kEmitCompilerReadBarrier && |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6376 | !kUseBakerReadBarrier && |
| 6377 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6378 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6379 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 6380 | return 1; |
| 6381 | } |
| 6382 | return 0; |
| 6383 | } |
| 6384 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6385 | // 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] | 6386 | // interface pointer, one for loading the current interface. |
| 6387 | // The other checks have one temp for loading the object's class. |
| 6388 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 6389 | if (type_check_kind == TypeCheckKind::kInterfaceCheck && !kPoisonHeapReferences) { |
| 6390 | return 2; |
| 6391 | } |
| 6392 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6393 | } |
| 6394 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6395 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6396 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6397 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6398 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6399 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6400 | case TypeCheckKind::kExactCheck: |
| 6401 | case TypeCheckKind::kAbstractClassCheck: |
| 6402 | case TypeCheckKind::kClassHierarchyCheck: |
| 6403 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6404 | call_kind = |
| 6405 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6406 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6407 | break; |
| 6408 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6409 | case TypeCheckKind::kUnresolvedCheck: |
| 6410 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6411 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6412 | break; |
| 6413 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6414 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6415 | LocationSummary* locations = |
| 6416 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6417 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6418 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6419 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6420 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6421 | locations->SetInAt(1, Location::Any()); |
| 6422 | // Note that TypeCheckSlowPathX86 uses this "out" register too. |
| 6423 | locations->SetOut(Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6424 | // When read barriers are enabled, we need a temporary register for some cases. |
| 6425 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6426 | } |
| 6427 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6428 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6429 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6430 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6431 | Location obj_loc = locations->InAt(0); |
| 6432 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6433 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6434 | Location out_loc = locations->Out(); |
| 6435 | Register out = out_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6436 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 6437 | DCHECK_LE(num_temps, 1u); |
| 6438 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6439 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6440 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6441 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6442 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6443 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6444 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6445 | |
| 6446 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6447 | // Avoid null check if we know obj is not null. |
| 6448 | if (instruction->MustDoNullCheck()) { |
| 6449 | __ testl(obj, obj); |
| 6450 | __ j(kEqual, &zero); |
| 6451 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6452 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6453 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6454 | case TypeCheckKind::kExactCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6455 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6456 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6457 | out_loc, |
| 6458 | obj_loc, |
| 6459 | class_offset, |
| 6460 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6461 | if (cls.IsRegister()) { |
| 6462 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6463 | } else { |
| 6464 | DCHECK(cls.IsStackSlot()) << cls; |
| 6465 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6466 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6467 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6468 | // Classes must be equal for the instanceof to succeed. |
| 6469 | __ j(kNotEqual, &zero); |
| 6470 | __ movl(out, Immediate(1)); |
| 6471 | __ jmp(&done); |
| 6472 | break; |
| 6473 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6474 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6475 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6476 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6477 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6478 | out_loc, |
| 6479 | obj_loc, |
| 6480 | class_offset, |
| 6481 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6482 | // If the class is abstract, we eagerly fetch the super class of the |
| 6483 | // object to avoid doing a comparison we know will fail. |
| 6484 | NearLabel loop; |
| 6485 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6486 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6487 | GenerateReferenceLoadOneRegister(instruction, |
| 6488 | out_loc, |
| 6489 | super_offset, |
| 6490 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6491 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6492 | __ testl(out, out); |
| 6493 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6494 | __ j(kEqual, &done); |
| 6495 | if (cls.IsRegister()) { |
| 6496 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6497 | } else { |
| 6498 | DCHECK(cls.IsStackSlot()) << cls; |
| 6499 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6500 | } |
| 6501 | __ j(kNotEqual, &loop); |
| 6502 | __ movl(out, Immediate(1)); |
| 6503 | if (zero.IsLinked()) { |
| 6504 | __ jmp(&done); |
| 6505 | } |
| 6506 | break; |
| 6507 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6508 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6509 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6510 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6511 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6512 | out_loc, |
| 6513 | obj_loc, |
| 6514 | class_offset, |
| 6515 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6516 | // Walk over the class hierarchy to find a match. |
| 6517 | NearLabel loop, success; |
| 6518 | __ Bind(&loop); |
| 6519 | if (cls.IsRegister()) { |
| 6520 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6521 | } else { |
| 6522 | DCHECK(cls.IsStackSlot()) << cls; |
| 6523 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6524 | } |
| 6525 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6526 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6527 | GenerateReferenceLoadOneRegister(instruction, |
| 6528 | out_loc, |
| 6529 | super_offset, |
| 6530 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6531 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6532 | __ testl(out, out); |
| 6533 | __ j(kNotEqual, &loop); |
| 6534 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6535 | __ jmp(&done); |
| 6536 | __ Bind(&success); |
| 6537 | __ movl(out, Immediate(1)); |
| 6538 | if (zero.IsLinked()) { |
| 6539 | __ jmp(&done); |
| 6540 | } |
| 6541 | break; |
| 6542 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6543 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6544 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6545 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6546 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6547 | out_loc, |
| 6548 | obj_loc, |
| 6549 | class_offset, |
| 6550 | kCompilerReadBarrierOption); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6551 | // Do an exact check. |
| 6552 | NearLabel exact_check; |
| 6553 | if (cls.IsRegister()) { |
| 6554 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6555 | } else { |
| 6556 | DCHECK(cls.IsStackSlot()) << cls; |
| 6557 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6558 | } |
| 6559 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6560 | // 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] | 6561 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6562 | GenerateReferenceLoadOneRegister(instruction, |
| 6563 | out_loc, |
| 6564 | component_offset, |
| 6565 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6566 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6567 | __ testl(out, out); |
| 6568 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6569 | __ j(kEqual, &done); |
| 6570 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 6571 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6572 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6573 | __ movl(out, Immediate(1)); |
| 6574 | __ jmp(&done); |
| 6575 | break; |
| 6576 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6577 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6578 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6579 | // No read barrier since the slow path will retry upon failure. |
| 6580 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6581 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6582 | out_loc, |
| 6583 | obj_loc, |
| 6584 | class_offset, |
| 6585 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6586 | if (cls.IsRegister()) { |
| 6587 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6588 | } else { |
| 6589 | DCHECK(cls.IsStackSlot()) << cls; |
| 6590 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6591 | } |
| 6592 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6593 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
| 6594 | instruction, /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6595 | codegen_->AddSlowPath(slow_path); |
| 6596 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6597 | __ movl(out, Immediate(1)); |
| 6598 | if (zero.IsLinked()) { |
| 6599 | __ jmp(&done); |
| 6600 | } |
| 6601 | break; |
| 6602 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6603 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6604 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6605 | case TypeCheckKind::kInterfaceCheck: { |
| 6606 | // 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] | 6607 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6608 | // cases. |
| 6609 | // |
| 6610 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6611 | // entry point without resorting to a type checking slow path |
| 6612 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6613 | // require to assign fixed registers for the inputs of this |
| 6614 | // HInstanceOf instruction (following the runtime calling |
| 6615 | // convention), which might be cluttered by the potential first |
| 6616 | // read barrier emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6617 | // |
| 6618 | // TODO: Introduce a new runtime entry point taking the object |
| 6619 | // to test (instead of its class) as argument, and let it deal |
| 6620 | // with the read barrier issues. This will let us refactor this |
| 6621 | // case of the `switch` code as it was previously (with a direct |
| 6622 | // call to the runtime not using a type checking slow path). |
| 6623 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6624 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6625 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
| 6626 | instruction, /* is_fatal */ false); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6627 | codegen_->AddSlowPath(slow_path); |
| 6628 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6629 | if (zero.IsLinked()) { |
| 6630 | __ jmp(&done); |
| 6631 | } |
| 6632 | break; |
| 6633 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6634 | } |
| 6635 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6636 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6637 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6638 | __ xorl(out, out); |
| 6639 | } |
| 6640 | |
| 6641 | if (done.IsLinked()) { |
| 6642 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6643 | } |
| 6644 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6645 | if (slow_path != nullptr) { |
| 6646 | __ Bind(slow_path->GetExitLabel()); |
| 6647 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6648 | } |
| 6649 | |
Mathieu Chartier | 5ac321b | 2016-11-09 16:33:54 -0800 | [diff] [blame] | 6650 | static bool IsTypeCheckSlowPathFatal(TypeCheckKind type_check_kind, bool throws_into_catch) { |
| 6651 | switch (type_check_kind) { |
| 6652 | case TypeCheckKind::kExactCheck: |
| 6653 | case TypeCheckKind::kAbstractClassCheck: |
| 6654 | case TypeCheckKind::kClassHierarchyCheck: |
| 6655 | case TypeCheckKind::kArrayObjectCheck: |
| 6656 | return !throws_into_catch && !kEmitCompilerReadBarrier; |
| 6657 | case TypeCheckKind::kInterfaceCheck: |
| 6658 | return !throws_into_catch && !kEmitCompilerReadBarrier && !kPoisonHeapReferences; |
| 6659 | case TypeCheckKind::kArrayCheck: |
| 6660 | case TypeCheckKind::kUnresolvedCheck: |
| 6661 | return false; |
| 6662 | } |
| 6663 | LOG(FATAL) << "Unreachable"; |
| 6664 | UNREACHABLE(); |
| 6665 | } |
| 6666 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6667 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6668 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6669 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Mathieu Chartier | 5ac321b | 2016-11-09 16:33:54 -0800 | [diff] [blame] | 6670 | LocationSummary::CallKind call_kind = |
| 6671 | IsTypeCheckSlowPathFatal(type_check_kind, throws_into_catch) |
| 6672 | ? LocationSummary::kNoCall |
| 6673 | : LocationSummary::kCallOnSlowPath; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6674 | LocationSummary* locations = |
| 6675 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6676 | locations->SetInAt(0, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6677 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6678 | // Require a register for the interface check since there is a loop that compares the class to |
| 6679 | // a memory address. |
| 6680 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6681 | } else { |
| 6682 | locations->SetInAt(1, Location::Any()); |
| 6683 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6684 | // Note that TypeCheckSlowPathX86 uses this "temp" register too. |
| 6685 | locations->AddTemp(Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6686 | // When read barriers are enabled, we need an additional temporary register for some cases. |
| 6687 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
| 6688 | } |
| 6689 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6690 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6691 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6692 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6693 | Location obj_loc = locations->InAt(0); |
| 6694 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6695 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6696 | Location temp_loc = locations->GetTemp(0); |
| 6697 | Register temp = temp_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6698 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 6699 | DCHECK_GE(num_temps, 1u); |
| 6700 | DCHECK_LE(num_temps, 2u); |
| 6701 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 6702 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6703 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6704 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6705 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 6706 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 6707 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 6708 | const uint32_t object_array_data_offset = |
| 6709 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6710 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6711 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 6712 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 6713 | // read barriers is done for performance and code size reasons. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6714 | bool is_type_check_slow_path_fatal = |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6715 | IsTypeCheckSlowPathFatal(type_check_kind, instruction->CanThrowIntoCatchBlock()); |
| 6716 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6717 | SlowPathCode* type_check_slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6718 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
| 6719 | instruction, is_type_check_slow_path_fatal); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6720 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6721 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6722 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6723 | // Avoid null check if we know obj is not null. |
| 6724 | if (instruction->MustDoNullCheck()) { |
| 6725 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6726 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6727 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6728 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6729 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6730 | case TypeCheckKind::kExactCheck: |
| 6731 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6732 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6733 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6734 | temp_loc, |
| 6735 | obj_loc, |
| 6736 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6737 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6738 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6739 | if (cls.IsRegister()) { |
| 6740 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6741 | } else { |
| 6742 | DCHECK(cls.IsStackSlot()) << cls; |
| 6743 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6744 | } |
| 6745 | // Jump to slow path for throwing the exception or doing a |
| 6746 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6747 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6748 | break; |
| 6749 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6750 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6751 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6752 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6753 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6754 | temp_loc, |
| 6755 | obj_loc, |
| 6756 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6757 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6758 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6759 | // If the class is abstract, we eagerly fetch the super class of the |
| 6760 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6761 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6762 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6763 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6764 | GenerateReferenceLoadOneRegister(instruction, |
| 6765 | temp_loc, |
| 6766 | super_offset, |
| 6767 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6768 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6769 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6770 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 6771 | // exception. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6772 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6773 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6774 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6775 | // Otherwise, compare the classes |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6776 | if (cls.IsRegister()) { |
| 6777 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6778 | } else { |
| 6779 | DCHECK(cls.IsStackSlot()) << cls; |
| 6780 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6781 | } |
| 6782 | __ j(kNotEqual, &loop); |
| 6783 | break; |
| 6784 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6785 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6786 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6787 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6788 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6789 | temp_loc, |
| 6790 | obj_loc, |
| 6791 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6792 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6793 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6794 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6795 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6796 | __ Bind(&loop); |
| 6797 | if (cls.IsRegister()) { |
| 6798 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6799 | } else { |
| 6800 | DCHECK(cls.IsStackSlot()) << cls; |
| 6801 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6802 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6803 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6804 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6805 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6806 | GenerateReferenceLoadOneRegister(instruction, |
| 6807 | temp_loc, |
| 6808 | super_offset, |
| 6809 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6810 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6811 | |
| 6812 | // If the class reference currently in `temp` is not null, jump |
| 6813 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6814 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6815 | __ j(kNotZero, &loop); |
| 6816 | // Otherwise, jump to the slow path to throw the exception.; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6817 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6818 | break; |
| 6819 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6820 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6821 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6822 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6823 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6824 | temp_loc, |
| 6825 | obj_loc, |
| 6826 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6827 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6828 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6829 | // Do an exact check. |
| 6830 | if (cls.IsRegister()) { |
| 6831 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6832 | } else { |
| 6833 | DCHECK(cls.IsStackSlot()) << cls; |
| 6834 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6835 | } |
| 6836 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6837 | |
| 6838 | // 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] | 6839 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6840 | GenerateReferenceLoadOneRegister(instruction, |
| 6841 | temp_loc, |
| 6842 | component_offset, |
| 6843 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6844 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6845 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6846 | // If the component type is null (i.e. the object not an array), jump to the slow path to |
| 6847 | // throw the exception. Otherwise proceed with the check. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6848 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6849 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6850 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6851 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6852 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6853 | break; |
| 6854 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6855 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6856 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6857 | // 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] | 6858 | // We cannot directly call the CheckCast runtime entry point |
| 6859 | // without resorting to a type checking slow path here (i.e. by |
| 6860 | // calling InvokeRuntime directly), as it would require to |
| 6861 | // assign fixed registers for the inputs of this HInstanceOf |
| 6862 | // instruction (following the runtime calling convention), which |
| 6863 | // might be cluttered by the potential first read barrier |
| 6864 | // emission at the beginning of this method. |
| 6865 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6866 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6867 | |
| 6868 | case TypeCheckKind::kInterfaceCheck: { |
| 6869 | // Fast path for the interface check. Since we compare with a memory location in the inner |
| 6870 | // loop we would need to have cls poisoned. However unpoisoning cls would reset the |
| 6871 | // conditional flags and cause the conditional jump to be incorrect. Therefore we just jump |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6872 | // to the slow path if we are running under poisoning. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6873 | if (!kPoisonHeapReferences) { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6874 | // Try to avoid read barriers to improve the fast path. We can not get false positives by |
| 6875 | // doing this. |
| 6876 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6877 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6878 | temp_loc, |
| 6879 | obj_loc, |
| 6880 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6881 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6882 | |
| 6883 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 6884 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6885 | temp_loc, |
| 6886 | temp_loc, |
| 6887 | iftable_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6888 | kWithoutReadBarrier); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6889 | // Iftable is never null. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6890 | __ movl(maybe_temp2_loc.AsRegister<Register>(), Address(temp, array_length_offset)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6891 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6892 | NearLabel start_loop; |
| 6893 | __ Bind(&start_loop); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6894 | // Need to subtract first to handle the empty array case. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6895 | __ subl(maybe_temp2_loc.AsRegister<Register>(), Immediate(2)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6896 | __ j(kNegative, type_check_slow_path->GetEntryLabel()); |
| 6897 | // Go to next interface if the classes do not match. |
| 6898 | __ cmpl(cls.AsRegister<Register>(), |
| 6899 | CodeGeneratorX86::ArrayAddress(temp, |
| 6900 | maybe_temp2_loc, |
| 6901 | TIMES_4, |
| 6902 | object_array_data_offset)); |
| 6903 | __ j(kNotEqual, &start_loop); |
| 6904 | } else { |
| 6905 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6906 | } |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6907 | break; |
| 6908 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6909 | } |
| 6910 | __ Bind(&done); |
| 6911 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6912 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6913 | } |
| 6914 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6915 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6916 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6917 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6918 | InvokeRuntimeCallingConvention calling_convention; |
| 6919 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6920 | } |
| 6921 | |
| 6922 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6923 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject |
| 6924 | : kQuickUnlockObject, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6925 | instruction, |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6926 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6927 | if (instruction->IsEnter()) { |
| 6928 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6929 | } else { |
| 6930 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6931 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6932 | } |
| 6933 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6934 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6935 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6936 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6937 | |
| 6938 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6939 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6940 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6941 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 |
| 6942 | || instruction->GetResultType() == DataType::Type::kInt64); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6943 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6944 | locations->SetInAt(1, Location::Any()); |
| 6945 | locations->SetOut(Location::SameAsFirstInput()); |
| 6946 | } |
| 6947 | |
| 6948 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 6949 | HandleBitwiseOperation(instruction); |
| 6950 | } |
| 6951 | |
| 6952 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 6953 | HandleBitwiseOperation(instruction); |
| 6954 | } |
| 6955 | |
| 6956 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 6957 | HandleBitwiseOperation(instruction); |
| 6958 | } |
| 6959 | |
| 6960 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6961 | LocationSummary* locations = instruction->GetLocations(); |
| 6962 | Location first = locations->InAt(0); |
| 6963 | Location second = locations->InAt(1); |
| 6964 | DCHECK(first.Equals(locations->Out())); |
| 6965 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6966 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6967 | if (second.IsRegister()) { |
| 6968 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6969 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6970 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6971 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6972 | } else { |
| 6973 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6974 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6975 | } |
| 6976 | } else if (second.IsConstant()) { |
| 6977 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6978 | __ andl(first.AsRegister<Register>(), |
| 6979 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6980 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6981 | __ orl(first.AsRegister<Register>(), |
| 6982 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6983 | } else { |
| 6984 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6985 | __ xorl(first.AsRegister<Register>(), |
| 6986 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6987 | } |
| 6988 | } else { |
| 6989 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6990 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6991 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6992 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6993 | } else { |
| 6994 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6995 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6996 | } |
| 6997 | } |
| 6998 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6999 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7000 | if (second.IsRegisterPair()) { |
| 7001 | if (instruction->IsAnd()) { |
| 7002 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 7003 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 7004 | } else if (instruction->IsOr()) { |
| 7005 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 7006 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 7007 | } else { |
| 7008 | DCHECK(instruction->IsXor()); |
| 7009 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 7010 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 7011 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7012 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7013 | if (instruction->IsAnd()) { |
| 7014 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7015 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 7016 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7017 | } else if (instruction->IsOr()) { |
| 7018 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7019 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 7020 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7021 | } else { |
| 7022 | DCHECK(instruction->IsXor()); |
| 7023 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7024 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 7025 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7026 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7027 | } else { |
| 7028 | DCHECK(second.IsConstant()) << second; |
| 7029 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7030 | int32_t low_value = Low32Bits(value); |
| 7031 | int32_t high_value = High32Bits(value); |
| 7032 | Immediate low(low_value); |
| 7033 | Immediate high(high_value); |
| 7034 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 7035 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7036 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7037 | if (low_value == 0) { |
| 7038 | __ xorl(first_low, first_low); |
| 7039 | } else if (low_value != -1) { |
| 7040 | __ andl(first_low, low); |
| 7041 | } |
| 7042 | if (high_value == 0) { |
| 7043 | __ xorl(first_high, first_high); |
| 7044 | } else if (high_value != -1) { |
| 7045 | __ andl(first_high, high); |
| 7046 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7047 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7048 | if (low_value != 0) { |
| 7049 | __ orl(first_low, low); |
| 7050 | } |
| 7051 | if (high_value != 0) { |
| 7052 | __ orl(first_high, high); |
| 7053 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7054 | } else { |
| 7055 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7056 | if (low_value != 0) { |
| 7057 | __ xorl(first_low, low); |
| 7058 | } |
| 7059 | if (high_value != 0) { |
| 7060 | __ xorl(first_high, high); |
| 7061 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7062 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7063 | } |
| 7064 | } |
| 7065 | } |
| 7066 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7067 | void InstructionCodeGeneratorX86::GenerateReferenceLoadOneRegister( |
| 7068 | HInstruction* instruction, |
| 7069 | Location out, |
| 7070 | uint32_t offset, |
| 7071 | Location maybe_temp, |
| 7072 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7073 | Register out_reg = out.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7074 | if (read_barrier_option == kWithReadBarrier) { |
| 7075 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7076 | if (kUseBakerReadBarrier) { |
| 7077 | // Load with fast path based Baker's read barrier. |
| 7078 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7079 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7080 | instruction, out, out_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7081 | } else { |
| 7082 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7083 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7084 | // in the following move operation, as we will need it for the |
| 7085 | // read barrier below. |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7086 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7087 | __ movl(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7088 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7089 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7090 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7091 | } |
| 7092 | } else { |
| 7093 | // Plain load with no read barrier. |
| 7094 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7095 | __ movl(out_reg, Address(out_reg, offset)); |
| 7096 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7097 | } |
| 7098 | } |
| 7099 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7100 | void InstructionCodeGeneratorX86::GenerateReferenceLoadTwoRegisters( |
| 7101 | HInstruction* instruction, |
| 7102 | Location out, |
| 7103 | Location obj, |
| 7104 | uint32_t offset, |
| 7105 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7106 | Register out_reg = out.AsRegister<Register>(); |
| 7107 | Register obj_reg = obj.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7108 | if (read_barrier_option == kWithReadBarrier) { |
| 7109 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7110 | if (kUseBakerReadBarrier) { |
| 7111 | // Load with fast path based Baker's read barrier. |
| 7112 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7113 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7114 | instruction, out, obj_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7115 | } else { |
| 7116 | // Load with slow path based read barrier. |
| 7117 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7118 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7119 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 7120 | } |
| 7121 | } else { |
| 7122 | // Plain load with no read barrier. |
| 7123 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7124 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7125 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7126 | } |
| 7127 | } |
| 7128 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7129 | void InstructionCodeGeneratorX86::GenerateGcRootFieldLoad( |
| 7130 | HInstruction* instruction, |
| 7131 | Location root, |
| 7132 | const Address& address, |
| 7133 | Label* fixup_label, |
| 7134 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7135 | Register root_reg = root.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7136 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7137 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7138 | if (kUseBakerReadBarrier) { |
| 7139 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 7140 | // Baker's read barrier are used: |
| 7141 | // |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7142 | // root = obj.field; |
| 7143 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 7144 | // if (temp != null) { |
| 7145 | // root = temp(root) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7146 | // } |
| 7147 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7148 | // /* GcRoot<mirror::Object> */ root = *address |
| 7149 | __ movl(root_reg, address); |
| 7150 | if (fixup_label != nullptr) { |
| 7151 | __ Bind(fixup_label); |
| 7152 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7153 | static_assert( |
| 7154 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 7155 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 7156 | "have different sizes."); |
| 7157 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 7158 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 7159 | "have different sizes."); |
| 7160 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7161 | // Slow path marking the GC root `root`. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7162 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathX86( |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7163 | instruction, root, /* unpoison_ref_before_marking */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7164 | codegen_->AddSlowPath(slow_path); |
| 7165 | |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7166 | // Test the entrypoint (`Thread::Current()->pReadBarrierMarkReg ## root.reg()`). |
| 7167 | const int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 7168 | Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(root.reg()); |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7169 | __ fs()->cmpl(Address::Absolute(entry_point_offset), Immediate(0)); |
| 7170 | // The entrypoint is null when the GC is not marking. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7171 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 7172 | __ Bind(slow_path->GetExitLabel()); |
| 7173 | } else { |
| 7174 | // GC root loaded through a slow path for read barriers other |
| 7175 | // than Baker's. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7176 | // /* GcRoot<mirror::Object>* */ root = address |
| 7177 | __ leal(root_reg, address); |
| 7178 | if (fixup_label != nullptr) { |
| 7179 | __ Bind(fixup_label); |
| 7180 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7181 | // /* mirror::Object* */ root = root->Read() |
| 7182 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 7183 | } |
| 7184 | } else { |
| 7185 | // Plain GC root load with no read barrier. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7186 | // /* GcRoot<mirror::Object> */ root = *address |
| 7187 | __ movl(root_reg, address); |
| 7188 | if (fixup_label != nullptr) { |
| 7189 | __ Bind(fixup_label); |
| 7190 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7191 | // Note that GC roots are not affected by heap poisoning, thus we |
| 7192 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7193 | } |
| 7194 | } |
| 7195 | |
| 7196 | void CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7197 | Location ref, |
| 7198 | Register obj, |
| 7199 | uint32_t offset, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7200 | bool needs_null_check) { |
| 7201 | DCHECK(kEmitCompilerReadBarrier); |
| 7202 | DCHECK(kUseBakerReadBarrier); |
| 7203 | |
| 7204 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7205 | Address src(obj, offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7206 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7207 | } |
| 7208 | |
| 7209 | void CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7210 | Location ref, |
| 7211 | Register obj, |
| 7212 | uint32_t data_offset, |
| 7213 | Location index, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7214 | bool needs_null_check) { |
| 7215 | DCHECK(kEmitCompilerReadBarrier); |
| 7216 | DCHECK(kUseBakerReadBarrier); |
| 7217 | |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 7218 | static_assert( |
| 7219 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 7220 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7221 | // /* HeapReference<Object> */ ref = |
| 7222 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7223 | Address src = CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7224 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7225 | } |
| 7226 | |
| 7227 | void CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7228 | Location ref, |
| 7229 | Register obj, |
| 7230 | const Address& src, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7231 | bool needs_null_check, |
| 7232 | bool always_update_field, |
| 7233 | Register* temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7234 | DCHECK(kEmitCompilerReadBarrier); |
| 7235 | DCHECK(kUseBakerReadBarrier); |
| 7236 | |
| 7237 | // In slow path based read barriers, the read barrier call is |
| 7238 | // inserted after the original load. However, in fast path based |
| 7239 | // Baker's read barriers, we need to perform the load of |
| 7240 | // mirror::Object::monitor_ *before* the original reference load. |
| 7241 | // This load-load ordering is required by the read barrier. |
| 7242 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 7243 | // |
| 7244 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7245 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7246 | // HeapReference<Object> ref = *src; // Original reference load. |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7247 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7248 | // if (is_gray) { |
| 7249 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 7250 | // } |
| 7251 | // |
| 7252 | // Note: the original implementation in ReadBarrier::Barrier is |
| 7253 | // slightly more complex as: |
| 7254 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7255 | // the high-bits of rb_state, which are expected to be all zeroes |
| 7256 | // (we use CodeGeneratorX86::GenerateMemoryBarrier instead here, |
| 7257 | // which is a no-op thanks to the x86 memory model); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7258 | // - it performs additional checks that we do not do here for |
| 7259 | // performance reasons. |
| 7260 | |
| 7261 | Register ref_reg = ref.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7262 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 7263 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7264 | // 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] | 7265 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 7266 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7267 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 7268 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 7269 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 7270 | |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7271 | // if (rb_state == ReadBarrier::GrayState()) |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7272 | // ref = ReadBarrier::Mark(ref); |
| 7273 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 7274 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7275 | if (needs_null_check) { |
| 7276 | MaybeRecordImplicitNullCheck(instruction); |
| 7277 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7278 | |
| 7279 | // Load fence to prevent load-load reordering. |
| 7280 | // Note that this is a no-op, thanks to the x86 memory model. |
| 7281 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 7282 | |
| 7283 | // The actual reference load. |
| 7284 | // /* HeapReference<Object> */ ref = *src |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7285 | __ movl(ref_reg, src); // Flags are unaffected. |
| 7286 | |
| 7287 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 7288 | // Slow path marking the object `ref` when it is gray. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7289 | SlowPathCode* slow_path; |
| 7290 | if (always_update_field) { |
| 7291 | DCHECK(temp != nullptr); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7292 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkAndUpdateFieldSlowPathX86( |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7293 | instruction, ref, obj, src, /* unpoison_ref_before_marking */ true, *temp); |
| 7294 | } else { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7295 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkSlowPathX86( |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7296 | instruction, ref, /* unpoison_ref_before_marking */ true); |
| 7297 | } |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7298 | AddSlowPath(slow_path); |
| 7299 | |
| 7300 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 7301 | __ j(kNotZero, slow_path->GetEntryLabel()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7302 | |
| 7303 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7304 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7305 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7306 | __ Bind(slow_path->GetExitLabel()); |
| 7307 | } |
| 7308 | |
| 7309 | void CodeGeneratorX86::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7310 | Location out, |
| 7311 | Location ref, |
| 7312 | Location obj, |
| 7313 | uint32_t offset, |
| 7314 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7315 | DCHECK(kEmitCompilerReadBarrier); |
| 7316 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7317 | // Insert a slow path based read barrier *after* the reference load. |
| 7318 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7319 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7320 | // reference will be carried out by the runtime within the slow |
| 7321 | // path. |
| 7322 | // |
| 7323 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7324 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7325 | // not used by the artReadBarrierSlow entry point. |
| 7326 | // |
| 7327 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7328 | SlowPathCode* slow_path = new (GetScopedAllocator()) |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7329 | ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); |
| 7330 | AddSlowPath(slow_path); |
| 7331 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7332 | __ jmp(slow_path->GetEntryLabel()); |
| 7333 | __ Bind(slow_path->GetExitLabel()); |
| 7334 | } |
| 7335 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7336 | void CodeGeneratorX86::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 7337 | Location out, |
| 7338 | Location ref, |
| 7339 | Location obj, |
| 7340 | uint32_t offset, |
| 7341 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7342 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7343 | // Baker's read barriers shall be handled by the fast path |
| 7344 | // (CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier). |
| 7345 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7346 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7347 | // by the runtime within the slow path. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7348 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7349 | } else if (kPoisonHeapReferences) { |
| 7350 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 7351 | } |
| 7352 | } |
| 7353 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7354 | void CodeGeneratorX86::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7355 | Location out, |
| 7356 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7357 | DCHECK(kEmitCompilerReadBarrier); |
| 7358 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7359 | // Insert a slow path based read barrier *after* the GC root load. |
| 7360 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7361 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7362 | // not need to do anything special for this here. |
| 7363 | SlowPathCode* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7364 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathX86(instruction, out, root); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7365 | AddSlowPath(slow_path); |
| 7366 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7367 | __ jmp(slow_path->GetEntryLabel()); |
| 7368 | __ Bind(slow_path->GetExitLabel()); |
| 7369 | } |
| 7370 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7371 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7372 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7373 | LOG(FATAL) << "Unreachable"; |
| 7374 | } |
| 7375 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7376 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7377 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7378 | LOG(FATAL) << "Unreachable"; |
| 7379 | } |
| 7380 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7381 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7382 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7383 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7384 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7385 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7386 | } |
| 7387 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7388 | void InstructionCodeGeneratorX86::GenPackedSwitchWithCompares(Register value_reg, |
| 7389 | int32_t lower_bound, |
| 7390 | uint32_t num_entries, |
| 7391 | HBasicBlock* switch_block, |
| 7392 | HBasicBlock* default_block) { |
| 7393 | // Figure out the correct compare values and jump conditions. |
| 7394 | // Handle the first compare/branch as a special case because it might |
| 7395 | // jump to the default case. |
| 7396 | DCHECK_GT(num_entries, 2u); |
| 7397 | Condition first_condition; |
| 7398 | uint32_t index; |
| 7399 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 7400 | if (lower_bound != 0) { |
| 7401 | first_condition = kLess; |
| 7402 | __ cmpl(value_reg, Immediate(lower_bound)); |
| 7403 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 7404 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7405 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7406 | index = 1; |
| 7407 | } else { |
| 7408 | // Handle all the compare/jumps below. |
| 7409 | first_condition = kBelow; |
| 7410 | index = 0; |
| 7411 | } |
| 7412 | |
| 7413 | // Handle the rest of the compare/jumps. |
| 7414 | for (; index + 1 < num_entries; index += 2) { |
| 7415 | int32_t compare_to_value = lower_bound + index + 1; |
| 7416 | __ cmpl(value_reg, Immediate(compare_to_value)); |
| 7417 | // Jump to successors[index] if value < case_value[index]. |
| 7418 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 7419 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 7420 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 7421 | } |
| 7422 | |
| 7423 | if (index != num_entries) { |
| 7424 | // There are an odd number of entries. Handle the last one. |
| 7425 | DCHECK_EQ(index + 1, num_entries); |
| 7426 | __ cmpl(value_reg, Immediate(lower_bound + index)); |
| 7427 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7428 | } |
| 7429 | |
| 7430 | // And the default for any other value. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7431 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
| 7432 | __ jmp(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7433 | } |
| 7434 | } |
| 7435 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7436 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7437 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 7438 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 7439 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7440 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7441 | |
| 7442 | GenPackedSwitchWithCompares(value_reg, |
| 7443 | lower_bound, |
| 7444 | num_entries, |
| 7445 | switch_instr->GetBlock(), |
| 7446 | switch_instr->GetDefaultBlock()); |
| 7447 | } |
| 7448 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7449 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7450 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7451 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7452 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7453 | |
| 7454 | // Constant area pointer. |
| 7455 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7456 | |
| 7457 | // And the temporary we need. |
| 7458 | locations->AddTemp(Location::RequiresRegister()); |
| 7459 | } |
| 7460 | |
| 7461 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7462 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7463 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7464 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7465 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7466 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7467 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7468 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 7469 | GenPackedSwitchWithCompares(value_reg, |
| 7470 | lower_bound, |
| 7471 | num_entries, |
| 7472 | switch_instr->GetBlock(), |
| 7473 | default_block); |
| 7474 | return; |
| 7475 | } |
| 7476 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7477 | // Optimizing has a jump area. |
| 7478 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 7479 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 7480 | |
| 7481 | // Remove the bias, if needed. |
| 7482 | if (lower_bound != 0) { |
| 7483 | __ leal(temp_reg, Address(value_reg, -lower_bound)); |
| 7484 | value_reg = temp_reg; |
| 7485 | } |
| 7486 | |
| 7487 | // Is the value in range? |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7488 | DCHECK_GE(num_entries, 1u); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7489 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 7490 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| 7491 | |
| 7492 | // We are in the range of the table. |
| 7493 | // Load (target-constant_area) from the jump table, indexing by the value. |
| 7494 | __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); |
| 7495 | |
| 7496 | // Compute the actual target address by adding in constant_area. |
| 7497 | __ addl(temp_reg, constant_area); |
| 7498 | |
| 7499 | // And jump. |
| 7500 | __ jmp(temp_reg); |
| 7501 | } |
| 7502 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7503 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 7504 | HX86ComputeBaseMethodAddress* insn) { |
| 7505 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7506 | new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7507 | locations->SetOut(Location::RequiresRegister()); |
| 7508 | } |
| 7509 | |
| 7510 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 7511 | HX86ComputeBaseMethodAddress* insn) { |
| 7512 | LocationSummary* locations = insn->GetLocations(); |
| 7513 | Register reg = locations->Out().AsRegister<Register>(); |
| 7514 | |
| 7515 | // Generate call to next instruction. |
| 7516 | Label next_instruction; |
| 7517 | __ call(&next_instruction); |
| 7518 | __ Bind(&next_instruction); |
| 7519 | |
| 7520 | // Remember this offset for later use with constant area. |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7521 | codegen_->AddMethodAddressOffset(insn, GetAssembler()->CodeSize()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7522 | |
| 7523 | // Grab the return address off the stack. |
| 7524 | __ popl(reg); |
| 7525 | } |
| 7526 | |
| 7527 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 7528 | HX86LoadFromConstantTable* insn) { |
| 7529 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7530 | new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7531 | |
| 7532 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7533 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 7534 | |
| 7535 | // 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] | 7536 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7537 | return; |
| 7538 | } |
| 7539 | |
| 7540 | switch (insn->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7541 | case DataType::Type::kFloat32: |
| 7542 | case DataType::Type::kFloat64: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7543 | locations->SetOut(Location::RequiresFpuRegister()); |
| 7544 | break; |
| 7545 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7546 | case DataType::Type::kInt32: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7547 | locations->SetOut(Location::RequiresRegister()); |
| 7548 | break; |
| 7549 | |
| 7550 | default: |
| 7551 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7552 | } |
| 7553 | } |
| 7554 | |
| 7555 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 7556 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7557 | return; |
| 7558 | } |
| 7559 | |
| 7560 | LocationSummary* locations = insn->GetLocations(); |
| 7561 | Location out = locations->Out(); |
| 7562 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 7563 | HConstant *value = insn->GetConstant(); |
| 7564 | |
| 7565 | switch (insn->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7566 | case DataType::Type::kFloat32: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7567 | __ movss(out.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7568 | codegen_->LiteralFloatAddress( |
| 7569 | value->AsFloatConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7570 | break; |
| 7571 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7572 | case DataType::Type::kFloat64: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7573 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7574 | codegen_->LiteralDoubleAddress( |
| 7575 | value->AsDoubleConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7576 | break; |
| 7577 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7578 | case DataType::Type::kInt32: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7579 | __ movl(out.AsRegister<Register>(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7580 | codegen_->LiteralInt32Address( |
| 7581 | value->AsIntConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7582 | break; |
| 7583 | |
| 7584 | default: |
| 7585 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7586 | } |
| 7587 | } |
| 7588 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7589 | /** |
| 7590 | * Class to handle late fixup of offsets into constant area. |
| 7591 | */ |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 7592 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7593 | public: |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7594 | RIPFixup(CodeGeneratorX86& codegen, |
| 7595 | HX86ComputeBaseMethodAddress* base_method_address, |
| 7596 | size_t offset) |
| 7597 | : codegen_(&codegen), |
| 7598 | base_method_address_(base_method_address), |
| 7599 | offset_into_constant_area_(offset) {} |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7600 | |
| 7601 | protected: |
| 7602 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 7603 | |
| 7604 | CodeGeneratorX86* codegen_; |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7605 | HX86ComputeBaseMethodAddress* base_method_address_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7606 | |
| 7607 | private: |
| 7608 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 7609 | // Patch the correct offset for the instruction. The place to patch is the |
| 7610 | // last 4 bytes of the instruction. |
| 7611 | // The value to patch is the distance from the offset in the constant area |
| 7612 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7613 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7614 | int32_t relative_position = |
| 7615 | constant_offset - codegen_->GetMethodAddressOffset(base_method_address_); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7616 | |
| 7617 | // Patch in the right value. |
| 7618 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 7619 | } |
| 7620 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7621 | // Location in constant area that the fixup refers to. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7622 | int32_t offset_into_constant_area_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7623 | }; |
| 7624 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7625 | /** |
| 7626 | * Class to handle late fixup of offsets to a jump table that will be created in the |
| 7627 | * constant area. |
| 7628 | */ |
| 7629 | class JumpTableRIPFixup : public RIPFixup { |
| 7630 | public: |
| 7631 | JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7632 | : RIPFixup(codegen, switch_instr->GetBaseMethodAddress(), static_cast<size_t>(-1)), |
| 7633 | switch_instr_(switch_instr) {} |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7634 | |
| 7635 | void CreateJumpTable() { |
| 7636 | X86Assembler* assembler = codegen_->GetAssembler(); |
| 7637 | |
| 7638 | // Ensure that the reference to the jump table has the correct offset. |
| 7639 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 7640 | SetOffset(offset_in_constant_table); |
| 7641 | |
| 7642 | // The label values in the jump table are computed relative to the |
| 7643 | // instruction addressing the constant area. |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7644 | const int32_t relative_offset = codegen_->GetMethodAddressOffset(base_method_address_); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7645 | |
| 7646 | // Populate the jump table with the correct values for the jump table. |
| 7647 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 7648 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 7649 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 7650 | // The value that we want is the target offset - the position of the table. |
| 7651 | for (int32_t i = 0; i < num_entries; i++) { |
| 7652 | HBasicBlock* b = successors[i]; |
| 7653 | Label* l = codegen_->GetLabelOf(b); |
| 7654 | DCHECK(l->IsBound()); |
| 7655 | int32_t offset_to_block = l->Position() - relative_offset; |
| 7656 | assembler->AppendInt32(offset_to_block); |
| 7657 | } |
| 7658 | } |
| 7659 | |
| 7660 | private: |
| 7661 | const HX86PackedSwitch* switch_instr_; |
| 7662 | }; |
| 7663 | |
| 7664 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 7665 | // Generate the constant area if needed. |
| 7666 | X86Assembler* assembler = GetAssembler(); |
| 7667 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7668 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 7669 | // byte values. |
| 7670 | assembler->Align(4, 0); |
| 7671 | constant_area_start_ = assembler->CodeSize(); |
| 7672 | |
| 7673 | // Populate any jump tables. |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7674 | for (JumpTableRIPFixup* jump_table : fixups_to_jump_tables_) { |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7675 | jump_table->CreateJumpTable(); |
| 7676 | } |
| 7677 | |
| 7678 | // And now add the constant area to the generated code. |
| 7679 | assembler->AddConstantArea(); |
| 7680 | } |
| 7681 | |
| 7682 | // And finish up. |
| 7683 | CodeGenerator::Finalize(allocator); |
| 7684 | } |
| 7685 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7686 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, |
| 7687 | HX86ComputeBaseMethodAddress* method_base, |
| 7688 | Register reg) { |
| 7689 | AssemblerFixup* fixup = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7690 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddDouble(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7691 | return Address(reg, kDummy32BitOffset, fixup); |
| 7692 | } |
| 7693 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7694 | Address CodeGeneratorX86::LiteralFloatAddress(float v, |
| 7695 | HX86ComputeBaseMethodAddress* method_base, |
| 7696 | Register reg) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7697 | AssemblerFixup* fixup = |
| 7698 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddFloat(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7699 | return Address(reg, kDummy32BitOffset, fixup); |
| 7700 | } |
| 7701 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7702 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, |
| 7703 | HX86ComputeBaseMethodAddress* method_base, |
| 7704 | Register reg) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7705 | AssemblerFixup* fixup = |
| 7706 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddInt32(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7707 | return Address(reg, kDummy32BitOffset, fixup); |
| 7708 | } |
| 7709 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7710 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, |
| 7711 | HX86ComputeBaseMethodAddress* method_base, |
| 7712 | Register reg) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7713 | AssemblerFixup* fixup = |
| 7714 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddInt64(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7715 | return Address(reg, kDummy32BitOffset, fixup); |
| 7716 | } |
| 7717 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 7718 | void CodeGeneratorX86::Load32BitValue(Register dest, int32_t value) { |
| 7719 | if (value == 0) { |
| 7720 | __ xorl(dest, dest); |
| 7721 | } else { |
| 7722 | __ movl(dest, Immediate(value)); |
| 7723 | } |
| 7724 | } |
| 7725 | |
| 7726 | void CodeGeneratorX86::Compare32BitValue(Register dest, int32_t value) { |
| 7727 | if (value == 0) { |
| 7728 | __ testl(dest, dest); |
| 7729 | } else { |
| 7730 | __ cmpl(dest, Immediate(value)); |
| 7731 | } |
| 7732 | } |
| 7733 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7734 | void CodeGeneratorX86::GenerateIntCompare(Location lhs, Location rhs) { |
| 7735 | Register lhs_reg = lhs.AsRegister<Register>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7736 | GenerateIntCompare(lhs_reg, rhs); |
| 7737 | } |
| 7738 | |
| 7739 | void CodeGeneratorX86::GenerateIntCompare(Register lhs, Location rhs) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7740 | if (rhs.IsConstant()) { |
| 7741 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7742 | Compare32BitValue(lhs, value); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7743 | } else if (rhs.IsStackSlot()) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7744 | __ cmpl(lhs, Address(ESP, rhs.GetStackIndex())); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7745 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7746 | __ cmpl(lhs, rhs.AsRegister<Register>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7747 | } |
| 7748 | } |
| 7749 | |
| 7750 | Address CodeGeneratorX86::ArrayAddress(Register obj, |
| 7751 | Location index, |
| 7752 | ScaleFactor scale, |
| 7753 | uint32_t data_offset) { |
| 7754 | return index.IsConstant() ? |
| 7755 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) : |
| 7756 | Address(obj, index.AsRegister<Register>(), scale, data_offset); |
| 7757 | } |
| 7758 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7759 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, |
| 7760 | Register reg, |
| 7761 | Register value) { |
| 7762 | // Create a fixup to be used to create and address the jump table. |
| 7763 | JumpTableRIPFixup* table_fixup = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7764 | new (GetGraph()->GetAllocator()) JumpTableRIPFixup(*this, switch_instr); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7765 | |
| 7766 | // We have to populate the jump tables. |
| 7767 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7768 | |
| 7769 | // We want a scaled address, as we are extracting the correct offset from the table. |
| 7770 | return Address(reg, value, TIMES_4, kDummy32BitOffset, table_fixup); |
| 7771 | } |
| 7772 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7773 | // TODO: target as memory. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7774 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, DataType::Type type) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7775 | if (!target.IsValid()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7776 | DCHECK_EQ(type, DataType::Type::kVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7777 | return; |
| 7778 | } |
| 7779 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7780 | DCHECK_NE(type, DataType::Type::kVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7781 | |
| 7782 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 7783 | if (target.Equals(return_loc)) { |
| 7784 | return; |
| 7785 | } |
| 7786 | |
| 7787 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 7788 | // with the else branch. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7789 | if (type == DataType::Type::kInt64) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7790 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7791 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), DataType::Type::kInt32, nullptr); |
| 7792 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), DataType::Type::kInt32, nullptr); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7793 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7794 | } else { |
| 7795 | // Let the parallel move resolver take care of all of this. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7796 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7797 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 7798 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7799 | } |
| 7800 | } |
| 7801 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7802 | void CodeGeneratorX86::PatchJitRootUse(uint8_t* code, |
| 7803 | const uint8_t* roots_data, |
| 7804 | const PatchInfo<Label>& info, |
| 7805 | uint64_t index_in_table) const { |
| 7806 | uint32_t code_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 7807 | uintptr_t address = |
| 7808 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 7809 | typedef __attribute__((__aligned__(1))) uint32_t unaligned_uint32_t; |
| 7810 | reinterpret_cast<unaligned_uint32_t*>(code + code_offset)[0] = |
| 7811 | dchecked_integral_cast<uint32_t>(address); |
| 7812 | } |
| 7813 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7814 | void CodeGeneratorX86::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 7815 | for (const PatchInfo<Label>& info : jit_string_patches_) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7816 | StringReference string_reference(&info.dex_file, dex::StringIndex(info.index)); |
| 7817 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7818 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7819 | } |
| 7820 | |
| 7821 | for (const PatchInfo<Label>& info : jit_class_patches_) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7822 | TypeReference type_reference(&info.dex_file, dex::TypeIndex(info.index)); |
| 7823 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7824 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7825 | } |
| 7826 | } |
| 7827 | |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7828 | void LocationsBuilderX86::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 7829 | ATTRIBUTE_UNUSED) { |
| 7830 | LOG(FATAL) << "Unreachable"; |
| 7831 | } |
| 7832 | |
| 7833 | void InstructionCodeGeneratorX86::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 7834 | ATTRIBUTE_UNUSED) { |
| 7835 | LOG(FATAL) << "Unreachable"; |
| 7836 | } |
| 7837 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7838 | #undef __ |
| 7839 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7840 | } // namespace x86 |
| 7841 | } // namespace art |