Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "code_generator_x86.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 18 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 19 | #include "art_method.h" |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 20 | #include "class_table.h" |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 21 | #include "code_generator_utils.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 22 | #include "compiled_method.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 23 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 24 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 25 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 09659c2 | 2017-09-18 18:23:32 -0700 | [diff] [blame] | 26 | #include "heap_poisoning.h" |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 27 | #include "intrinsics.h" |
| 28 | #include "intrinsics_x86.h" |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 29 | #include "linker/linker_patch.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 30 | #include "lock_word.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 31 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 32 | #include "mirror/class-inl.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 33 | #include "thread.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 34 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 35 | #include "utils/stack_checks.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 36 | #include "utils/x86/assembler_x86.h" |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 37 | #include "utils/x86/managed_register_x86.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 38 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 39 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 40 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 41 | template<class MirrorType> |
| 42 | class GcRoot; |
| 43 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 44 | namespace x86 { |
| 45 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 46 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 47 | static constexpr Register kMethodRegisterArgument = EAX; |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 48 | static constexpr Register kCoreCalleeSaves[] = { EBP, ESI, EDI }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 49 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 50 | static constexpr int kC2ConditionMask = 0x400; |
| 51 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 52 | static constexpr int kFakeReturnRegister = Register(8); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 53 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 54 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 55 | #define __ down_cast<X86Assembler*>(codegen->GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 56 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86PointerSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 57 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 58 | class NullCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 59 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 60 | explicit NullCheckSlowPathX86(HNullCheck* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 61 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 62 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 63 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 64 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 65 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 66 | // Live registers will be restored in the catch block if caught. |
| 67 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 68 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 69 | x86_codegen->InvokeRuntime(kQuickThrowNullPointer, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 70 | instruction_, |
| 71 | instruction_->GetDexPc(), |
| 72 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 73 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 74 | } |
| 75 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 76 | bool IsFatal() const OVERRIDE { return true; } |
| 77 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 78 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86"; } |
| 79 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 80 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 81 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86); |
| 82 | }; |
| 83 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 84 | class DivZeroCheckSlowPathX86 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 85 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 86 | explicit DivZeroCheckSlowPathX86(HDivZeroCheck* instruction) : SlowPathCode(instruction) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 87 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 88 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 89 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 90 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 91 | x86_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 92 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 93 | } |
| 94 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 95 | bool IsFatal() const OVERRIDE { return true; } |
| 96 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 97 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86"; } |
| 98 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 99 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 100 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86); |
| 101 | }; |
| 102 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 103 | class DivRemMinusOneSlowPathX86 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 104 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 105 | DivRemMinusOneSlowPathX86(HInstruction* instruction, Register reg, bool is_div) |
| 106 | : SlowPathCode(instruction), reg_(reg), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 107 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 108 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 109 | __ Bind(GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 110 | if (is_div_) { |
| 111 | __ negl(reg_); |
| 112 | } else { |
| 113 | __ movl(reg_, Immediate(0)); |
| 114 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 115 | __ jmp(GetExitLabel()); |
| 116 | } |
| 117 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 118 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86"; } |
| 119 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 120 | private: |
| 121 | Register reg_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 122 | bool is_div_; |
| 123 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 124 | }; |
| 125 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 126 | class BoundsCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 127 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 128 | explicit BoundsCheckSlowPathX86(HBoundsCheck* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 129 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 130 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 131 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 132 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 133 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 134 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 135 | // move resolver. |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 136 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 137 | // Live registers will be restored in the catch block if caught. |
| 138 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 139 | } |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 140 | |
| 141 | // Are we using an array length from memory? |
| 142 | HInstruction* array_length = instruction_->InputAt(1); |
| 143 | Location length_loc = locations->InAt(1); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 144 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 145 | if (array_length->IsArrayLength() && array_length->IsEmittedAtUseSite()) { |
| 146 | // Load the array length into our temporary. |
Nicolas Geoffray | 0aff3a8 | 2017-10-13 13:12:36 +0100 | [diff] [blame] | 147 | HArrayLength* length = array_length->AsArrayLength(); |
| 148 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(length); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 149 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 150 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
| 151 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(1)); |
| 152 | // Check for conflicts with index. |
| 153 | if (length_loc.Equals(locations->InAt(0))) { |
| 154 | // We know we aren't using parameter 2. |
| 155 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(2)); |
| 156 | } |
| 157 | __ movl(length_loc.AsRegister<Register>(), array_len); |
Nicolas Geoffray | 0aff3a8 | 2017-10-13 13:12:36 +0100 | [diff] [blame] | 158 | if (mirror::kUseStringCompression && length->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 159 | __ shrl(length_loc.AsRegister<Register>(), Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 160 | } |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 161 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 162 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 163 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 164 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 165 | DataType::Type::kInt32, |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 166 | length_loc, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 167 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 168 | DataType::Type::kInt32); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 169 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 170 | ? kQuickThrowStringBounds |
| 171 | : kQuickThrowArrayBounds; |
| 172 | x86_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 173 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 174 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 175 | } |
| 176 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 177 | bool IsFatal() const OVERRIDE { return true; } |
| 178 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 179 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86"; } |
| 180 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 181 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 182 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86); |
| 183 | }; |
| 184 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 185 | class SuspendCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 186 | public: |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 187 | SuspendCheckSlowPathX86(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 188 | : SlowPathCode(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 189 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 190 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 191 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 192 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 193 | __ Bind(GetEntryLabel()); |
Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 194 | SaveLiveRegisters(codegen, locations); // Only saves full width XMM for SIMD. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 195 | x86_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 196 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 197 | RestoreLiveRegisters(codegen, locations); // Only restores full width XMM for SIMD. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 198 | if (successor_ == nullptr) { |
| 199 | __ jmp(GetReturnLabel()); |
| 200 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 201 | __ jmp(x86_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 202 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 203 | } |
| 204 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 205 | Label* GetReturnLabel() { |
| 206 | DCHECK(successor_ == nullptr); |
| 207 | return &return_label_; |
| 208 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 209 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 210 | HBasicBlock* GetSuccessor() const { |
| 211 | return successor_; |
| 212 | } |
| 213 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 214 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86"; } |
| 215 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 216 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 217 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 218 | Label return_label_; |
| 219 | |
| 220 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86); |
| 221 | }; |
| 222 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 223 | class LoadStringSlowPathX86 : public SlowPathCode { |
| 224 | public: |
| 225 | explicit LoadStringSlowPathX86(HLoadString* instruction): SlowPathCode(instruction) {} |
| 226 | |
| 227 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 228 | LocationSummary* locations = instruction_->GetLocations(); |
| 229 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 230 | |
| 231 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 232 | __ Bind(GetEntryLabel()); |
| 233 | SaveLiveRegisters(codegen, locations); |
| 234 | |
| 235 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 236 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 237 | __ movl(calling_convention.GetRegisterAt(0), Immediate(string_index.index_)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 238 | x86_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 239 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 240 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 241 | RestoreLiveRegisters(codegen, locations); |
| 242 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 243 | __ jmp(GetExitLabel()); |
| 244 | } |
| 245 | |
| 246 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86"; } |
| 247 | |
| 248 | private: |
| 249 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86); |
| 250 | }; |
| 251 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 252 | class LoadClassSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 253 | public: |
| 254 | LoadClassSlowPathX86(HLoadClass* cls, |
| 255 | HInstruction* at, |
| 256 | uint32_t dex_pc, |
| 257 | bool do_clinit) |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 258 | : SlowPathCode(at), cls_(cls), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 259 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 260 | } |
| 261 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 262 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 263 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 264 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 265 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 266 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 267 | |
| 268 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 269 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 270 | __ movl(calling_convention.GetRegisterAt(0), Immediate(type_index.index_)); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 271 | x86_codegen->InvokeRuntime(do_clinit_ ? kQuickInitializeStaticStorage |
| 272 | : kQuickInitializeType, |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 273 | instruction_, |
| 274 | dex_pc_, |
| 275 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 276 | if (do_clinit_) { |
| 277 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 278 | } else { |
| 279 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 280 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 281 | |
| 282 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 283 | Location out = locations->Out(); |
| 284 | if (out.IsValid()) { |
| 285 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 286 | x86_codegen->Move32(out, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 287 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 288 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 289 | __ jmp(GetExitLabel()); |
| 290 | } |
| 291 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 292 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86"; } |
| 293 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 294 | private: |
| 295 | // The class this slow path will load. |
| 296 | HLoadClass* const cls_; |
| 297 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 298 | // The dex PC of `at_`. |
| 299 | const uint32_t dex_pc_; |
| 300 | |
| 301 | // Whether to initialize the class. |
| 302 | const bool do_clinit_; |
| 303 | |
| 304 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86); |
| 305 | }; |
| 306 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 307 | class TypeCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 308 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 309 | TypeCheckSlowPathX86(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 310 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 311 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 312 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 313 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 314 | DCHECK(instruction_->IsCheckCast() |
| 315 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 316 | |
| 317 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 318 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 319 | |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 320 | if (kPoisonHeapReferences && |
| 321 | instruction_->IsCheckCast() && |
| 322 | instruction_->AsCheckCast()->GetTypeCheckKind() == TypeCheckKind::kInterfaceCheck) { |
| 323 | // First, unpoison the `cls` reference that was poisoned for direct memory comparison. |
| 324 | __ UnpoisonHeapReference(locations->InAt(1).AsRegister<Register>()); |
| 325 | } |
| 326 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 327 | if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 328 | SaveLiveRegisters(codegen, locations); |
| 329 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 330 | |
| 331 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 332 | // move resolver. |
| 333 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 334 | x86_codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 335 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 336 | DataType::Type::kReference, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 337 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 338 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 339 | DataType::Type::kReference); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 340 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 341 | x86_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 342 | instruction_, |
| 343 | instruction_->GetDexPc(), |
| 344 | this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 345 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 346 | } else { |
| 347 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 348 | x86_codegen->InvokeRuntime(kQuickCheckInstanceOf, |
| 349 | instruction_, |
| 350 | instruction_->GetDexPc(), |
| 351 | this); |
| 352 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 353 | } |
| 354 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 355 | if (!is_fatal_) { |
| 356 | if (instruction_->IsInstanceOf()) { |
| 357 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 358 | } |
| 359 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 360 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 361 | __ jmp(GetExitLabel()); |
| 362 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 363 | } |
| 364 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 365 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86"; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 366 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 367 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 368 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 369 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 370 | |
| 371 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86); |
| 372 | }; |
| 373 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 374 | class DeoptimizationSlowPathX86 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 375 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 376 | explicit DeoptimizationSlowPathX86(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 377 | : SlowPathCode(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 378 | |
| 379 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 380 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 381 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 382 | LocationSummary* locations = instruction_->GetLocations(); |
| 383 | SaveLiveRegisters(codegen, locations); |
| 384 | InvokeRuntimeCallingConvention calling_convention; |
| 385 | x86_codegen->Load32BitValue( |
| 386 | calling_convention.GetRegisterAt(0), |
| 387 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 388 | x86_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 389 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 390 | } |
| 391 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 392 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86"; } |
| 393 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 394 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 395 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86); |
| 396 | }; |
| 397 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 398 | class ArraySetSlowPathX86 : public SlowPathCode { |
| 399 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 400 | explicit ArraySetSlowPathX86(HInstruction* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 401 | |
| 402 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 403 | LocationSummary* locations = instruction_->GetLocations(); |
| 404 | __ Bind(GetEntryLabel()); |
| 405 | SaveLiveRegisters(codegen, locations); |
| 406 | |
| 407 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 408 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 409 | parallel_move.AddMove( |
| 410 | locations->InAt(0), |
| 411 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 412 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 413 | nullptr); |
| 414 | parallel_move.AddMove( |
| 415 | locations->InAt(1), |
| 416 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 417 | DataType::Type::kInt32, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 418 | nullptr); |
| 419 | parallel_move.AddMove( |
| 420 | locations->InAt(2), |
| 421 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 422 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 423 | nullptr); |
| 424 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 425 | |
| 426 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 427 | x86_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 428 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 429 | RestoreLiveRegisters(codegen, locations); |
| 430 | __ jmp(GetExitLabel()); |
| 431 | } |
| 432 | |
| 433 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86"; } |
| 434 | |
| 435 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 436 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86); |
| 437 | }; |
| 438 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 439 | // Slow path marking an object reference `ref` during a read |
| 440 | // barrier. The field `obj.field` in the object `obj` holding this |
| 441 | // reference does not get updated by this slow path after marking (see |
| 442 | // ReadBarrierMarkAndUpdateFieldSlowPathX86 below for that). |
| 443 | // |
| 444 | // This means that after the execution of this slow path, `ref` will |
| 445 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 446 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 447 | // probably still be a from-space reference (unless it gets updated by |
| 448 | // another thread, or if another thread installed another object |
| 449 | // reference (different from `ref`) in `obj.field`). |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 450 | class ReadBarrierMarkSlowPathX86 : public SlowPathCode { |
| 451 | public: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 452 | ReadBarrierMarkSlowPathX86(HInstruction* instruction, |
| 453 | Location ref, |
| 454 | bool unpoison_ref_before_marking) |
| 455 | : SlowPathCode(instruction), |
| 456 | ref_(ref), |
| 457 | unpoison_ref_before_marking_(unpoison_ref_before_marking) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 458 | DCHECK(kEmitCompilerReadBarrier); |
| 459 | } |
| 460 | |
| 461 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathX86"; } |
| 462 | |
| 463 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 464 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 465 | Register ref_reg = ref_.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 466 | DCHECK(locations->CanCall()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 467 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 468 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 469 | instruction_->IsStaticFieldGet() || |
| 470 | instruction_->IsArrayGet() || |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 471 | instruction_->IsArraySet() || |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 472 | instruction_->IsLoadClass() || |
| 473 | instruction_->IsLoadString() || |
| 474 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 475 | instruction_->IsCheckCast() || |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 476 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 477 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 478 | << "Unexpected instruction in read barrier marking slow path: " |
| 479 | << instruction_->DebugName(); |
| 480 | |
| 481 | __ Bind(GetEntryLabel()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 482 | if (unpoison_ref_before_marking_) { |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 483 | // Object* ref = ref_addr->AsMirrorPtr() |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 484 | __ MaybeUnpoisonHeapReference(ref_reg); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 485 | } |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 486 | // No need to save live registers; it's taken care of by the |
| 487 | // entrypoint. Also, there is no need to update the stack mask, |
| 488 | // as this runtime call will not trigger a garbage collection. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 489 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 490 | DCHECK_NE(ref_reg, ESP); |
| 491 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 492 | // "Compact" slow path, saving two moves. |
| 493 | // |
| 494 | // Instead of using the standard runtime calling convention (input |
| 495 | // and output in EAX): |
| 496 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 497 | // EAX <- ref |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 498 | // EAX <- ReadBarrierMark(EAX) |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 499 | // ref <- EAX |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 500 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 501 | // we just use rX (the register containing `ref`) as input and output |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 502 | // of a dedicated entrypoint: |
| 503 | // |
| 504 | // rX <- ReadBarrierMarkRegX(rX) |
| 505 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 506 | int32_t entry_point_offset = Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(ref_reg); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 507 | // This runtime call does not require a stack map. |
| 508 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 509 | __ jmp(GetExitLabel()); |
| 510 | } |
| 511 | |
| 512 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 513 | // The location (register) of the marked object reference. |
| 514 | const Location ref_; |
| 515 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 516 | const bool unpoison_ref_before_marking_; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 517 | |
| 518 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86); |
| 519 | }; |
| 520 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 521 | // Slow path marking an object reference `ref` during a read barrier, |
| 522 | // and if needed, atomically updating the field `obj.field` in the |
| 523 | // object `obj` holding this reference after marking (contrary to |
| 524 | // ReadBarrierMarkSlowPathX86 above, which never tries to update |
| 525 | // `obj.field`). |
| 526 | // |
| 527 | // This means that after the execution of this slow path, both `ref` |
| 528 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 529 | // hold the same to-space reference (unless another thread installed |
| 530 | // another object reference (different from `ref`) in `obj.field`). |
| 531 | class ReadBarrierMarkAndUpdateFieldSlowPathX86 : public SlowPathCode { |
| 532 | public: |
| 533 | ReadBarrierMarkAndUpdateFieldSlowPathX86(HInstruction* instruction, |
| 534 | Location ref, |
| 535 | Register obj, |
| 536 | const Address& field_addr, |
| 537 | bool unpoison_ref_before_marking, |
| 538 | Register temp) |
| 539 | : SlowPathCode(instruction), |
| 540 | ref_(ref), |
| 541 | obj_(obj), |
| 542 | field_addr_(field_addr), |
| 543 | unpoison_ref_before_marking_(unpoison_ref_before_marking), |
| 544 | temp_(temp) { |
| 545 | DCHECK(kEmitCompilerReadBarrier); |
| 546 | } |
| 547 | |
| 548 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkAndUpdateFieldSlowPathX86"; } |
| 549 | |
| 550 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 551 | LocationSummary* locations = instruction_->GetLocations(); |
| 552 | Register ref_reg = ref_.AsRegister<Register>(); |
| 553 | DCHECK(locations->CanCall()); |
| 554 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 555 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 556 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 557 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 558 | << instruction_->DebugName(); |
| 559 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 560 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 561 | |
| 562 | __ Bind(GetEntryLabel()); |
| 563 | if (unpoison_ref_before_marking_) { |
| 564 | // Object* ref = ref_addr->AsMirrorPtr() |
| 565 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 566 | } |
| 567 | |
| 568 | // Save the old (unpoisoned) reference. |
| 569 | __ movl(temp_, ref_reg); |
| 570 | |
| 571 | // No need to save live registers; it's taken care of by the |
| 572 | // entrypoint. Also, there is no need to update the stack mask, |
| 573 | // as this runtime call will not trigger a garbage collection. |
| 574 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 575 | DCHECK_NE(ref_reg, ESP); |
| 576 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
| 577 | // "Compact" slow path, saving two moves. |
| 578 | // |
| 579 | // Instead of using the standard runtime calling convention (input |
| 580 | // and output in EAX): |
| 581 | // |
| 582 | // EAX <- ref |
| 583 | // EAX <- ReadBarrierMark(EAX) |
| 584 | // ref <- EAX |
| 585 | // |
| 586 | // we just use rX (the register containing `ref`) as input and output |
| 587 | // of a dedicated entrypoint: |
| 588 | // |
| 589 | // rX <- ReadBarrierMarkRegX(rX) |
| 590 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 591 | int32_t entry_point_offset = Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(ref_reg); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 592 | // This runtime call does not require a stack map. |
| 593 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 594 | |
| 595 | // If the new reference is different from the old reference, |
| 596 | // update the field in the holder (`*field_addr`). |
| 597 | // |
| 598 | // Note that this field could also hold a different object, if |
| 599 | // another thread had concurrently changed it. In that case, the |
| 600 | // LOCK CMPXCHGL instruction in the compare-and-set (CAS) |
| 601 | // operation below would abort the CAS, leaving the field as-is. |
| 602 | NearLabel done; |
| 603 | __ cmpl(temp_, ref_reg); |
| 604 | __ j(kEqual, &done); |
| 605 | |
| 606 | // Update the the holder's field atomically. This may fail if |
| 607 | // mutator updates before us, but it's OK. This is achieved |
| 608 | // using a strong compare-and-set (CAS) operation with relaxed |
| 609 | // memory synchronization ordering, where the expected value is |
| 610 | // the old reference and the desired value is the new reference. |
| 611 | // This operation is implemented with a 32-bit LOCK CMPXLCHG |
| 612 | // instruction, which requires the expected value (the old |
| 613 | // reference) to be in EAX. Save EAX beforehand, and move the |
| 614 | // expected value (stored in `temp_`) into EAX. |
| 615 | __ pushl(EAX); |
| 616 | __ movl(EAX, temp_); |
| 617 | |
| 618 | // Convenience aliases. |
| 619 | Register base = obj_; |
| 620 | Register expected = EAX; |
| 621 | Register value = ref_reg; |
| 622 | |
| 623 | bool base_equals_value = (base == value); |
| 624 | if (kPoisonHeapReferences) { |
| 625 | if (base_equals_value) { |
| 626 | // If `base` and `value` are the same register location, move |
| 627 | // `value` to a temporary register. This way, poisoning |
| 628 | // `value` won't invalidate `base`. |
| 629 | value = temp_; |
| 630 | __ movl(value, base); |
| 631 | } |
| 632 | |
| 633 | // Check that the register allocator did not assign the location |
| 634 | // of `expected` (EAX) to `value` nor to `base`, so that heap |
| 635 | // poisoning (when enabled) works as intended below. |
| 636 | // - If `value` were equal to `expected`, both references would |
| 637 | // be poisoned twice, meaning they would not be poisoned at |
| 638 | // all, as heap poisoning uses address negation. |
| 639 | // - If `base` were equal to `expected`, poisoning `expected` |
| 640 | // would invalidate `base`. |
| 641 | DCHECK_NE(value, expected); |
| 642 | DCHECK_NE(base, expected); |
| 643 | |
| 644 | __ PoisonHeapReference(expected); |
| 645 | __ PoisonHeapReference(value); |
| 646 | } |
| 647 | |
| 648 | __ LockCmpxchgl(field_addr_, value); |
| 649 | |
| 650 | // If heap poisoning is enabled, we need to unpoison the values |
| 651 | // that were poisoned earlier. |
| 652 | if (kPoisonHeapReferences) { |
| 653 | if (base_equals_value) { |
| 654 | // `value` has been moved to a temporary register, no need |
| 655 | // to unpoison it. |
| 656 | } else { |
| 657 | __ UnpoisonHeapReference(value); |
| 658 | } |
| 659 | // No need to unpoison `expected` (EAX), as it is be overwritten below. |
| 660 | } |
| 661 | |
| 662 | // Restore EAX. |
| 663 | __ popl(EAX); |
| 664 | |
| 665 | __ Bind(&done); |
| 666 | __ jmp(GetExitLabel()); |
| 667 | } |
| 668 | |
| 669 | private: |
| 670 | // The location (register) of the marked object reference. |
| 671 | const Location ref_; |
| 672 | // The register containing the object holding the marked object reference field. |
| 673 | const Register obj_; |
| 674 | // The address of the marked reference field. The base of this address must be `obj_`. |
| 675 | const Address field_addr_; |
| 676 | |
| 677 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 678 | const bool unpoison_ref_before_marking_; |
| 679 | |
| 680 | const Register temp_; |
| 681 | |
| 682 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathX86); |
| 683 | }; |
| 684 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 685 | // Slow path generating a read barrier for a heap reference. |
| 686 | class ReadBarrierForHeapReferenceSlowPathX86 : public SlowPathCode { |
| 687 | public: |
| 688 | ReadBarrierForHeapReferenceSlowPathX86(HInstruction* instruction, |
| 689 | Location out, |
| 690 | Location ref, |
| 691 | Location obj, |
| 692 | uint32_t offset, |
| 693 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 694 | : SlowPathCode(instruction), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 695 | out_(out), |
| 696 | ref_(ref), |
| 697 | obj_(obj), |
| 698 | offset_(offset), |
| 699 | index_(index) { |
| 700 | DCHECK(kEmitCompilerReadBarrier); |
| 701 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 702 | // has been overwritten by (or after) the heap object reference load |
| 703 | // to be instrumented, e.g.: |
| 704 | // |
| 705 | // __ movl(out, Address(out, offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 706 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 707 | // |
| 708 | // In that case, we have lost the information about the original |
| 709 | // object, and the emitted read barrier cannot work properly. |
| 710 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 711 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 712 | } |
| 713 | |
| 714 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 715 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 716 | LocationSummary* locations = instruction_->GetLocations(); |
| 717 | Register reg_out = out_.AsRegister<Register>(); |
| 718 | DCHECK(locations->CanCall()); |
| 719 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 720 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 721 | instruction_->IsStaticFieldGet() || |
| 722 | instruction_->IsArrayGet() || |
| 723 | instruction_->IsInstanceOf() || |
| 724 | instruction_->IsCheckCast() || |
Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 725 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 726 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 727 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 728 | |
| 729 | __ Bind(GetEntryLabel()); |
| 730 | SaveLiveRegisters(codegen, locations); |
| 731 | |
| 732 | // We may have to change the index's value, but as `index_` is a |
| 733 | // constant member (like other "inputs" of this slow path), |
| 734 | // introduce a copy of it, `index`. |
| 735 | Location index = index_; |
| 736 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 737 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 738 | if (instruction_->IsArrayGet()) { |
| 739 | // Compute the actual memory offset and store it in `index`. |
| 740 | Register index_reg = index_.AsRegister<Register>(); |
| 741 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 742 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 743 | // We are about to change the value of `index_reg` (see the |
| 744 | // calls to art::x86::X86Assembler::shll and |
| 745 | // art::x86::X86Assembler::AddImmediate below), but it has |
| 746 | // not been saved by the previous call to |
| 747 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 748 | // callee-save register -- |
| 749 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 750 | // callee-save registers, as it has been designed with the |
| 751 | // assumption that callee-save registers are supposed to be |
| 752 | // handled by the called function. So, as a callee-save |
| 753 | // register, `index_reg` _would_ eventually be saved onto |
| 754 | // the stack, but it would be too late: we would have |
| 755 | // changed its value earlier. Therefore, we manually save |
| 756 | // it here into another freely available register, |
| 757 | // `free_reg`, chosen of course among the caller-save |
| 758 | // registers (as a callee-save `free_reg` register would |
| 759 | // exhibit the same problem). |
| 760 | // |
| 761 | // Note we could have requested a temporary register from |
| 762 | // the register allocator instead; but we prefer not to, as |
| 763 | // this is a slow path, and we know we can find a |
| 764 | // caller-save register that is available. |
| 765 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 766 | __ movl(free_reg, index_reg); |
| 767 | index_reg = free_reg; |
| 768 | index = Location::RegisterLocation(index_reg); |
| 769 | } else { |
| 770 | // The initial register stored in `index_` has already been |
| 771 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 772 | // (as it is not a callee-save register), so we can freely |
| 773 | // use it. |
| 774 | } |
| 775 | // Shifting the index value contained in `index_reg` by the scale |
| 776 | // factor (2) cannot overflow in practice, as the runtime is |
| 777 | // unable to allocate object arrays with a size larger than |
| 778 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 779 | __ shll(index_reg, Immediate(TIMES_4)); |
| 780 | static_assert( |
| 781 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 782 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 783 | __ AddImmediate(index_reg, Immediate(offset_)); |
| 784 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 785 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 786 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 787 | // (as in the case of ArrayGet), as it is actually an offset |
| 788 | // to an object field within an object. |
| 789 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 790 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 791 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 792 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 793 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 794 | DCHECK_EQ(offset_, 0U); |
| 795 | DCHECK(index_.IsRegisterPair()); |
| 796 | // UnsafeGet's offset location is a register pair, the low |
| 797 | // part contains the correct offset. |
| 798 | index = index_.ToLow(); |
| 799 | } |
| 800 | } |
| 801 | |
| 802 | // We're moving two or three locations to locations that could |
| 803 | // overlap, so we need a parallel move resolver. |
| 804 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 805 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 806 | parallel_move.AddMove(ref_, |
| 807 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 808 | DataType::Type::kReference, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 809 | nullptr); |
| 810 | parallel_move.AddMove(obj_, |
| 811 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 812 | DataType::Type::kReference, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 813 | nullptr); |
| 814 | if (index.IsValid()) { |
| 815 | parallel_move.AddMove(index, |
| 816 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 817 | DataType::Type::kInt32, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 818 | nullptr); |
| 819 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 820 | } else { |
| 821 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 822 | __ movl(calling_convention.GetRegisterAt(2), Immediate(offset_)); |
| 823 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 824 | x86_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 825 | CheckEntrypointTypes< |
| 826 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 827 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 828 | |
| 829 | RestoreLiveRegisters(codegen, locations); |
| 830 | __ jmp(GetExitLabel()); |
| 831 | } |
| 832 | |
| 833 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathX86"; } |
| 834 | |
| 835 | private: |
| 836 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 837 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 838 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 839 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 840 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 841 | return static_cast<Register>(i); |
| 842 | } |
| 843 | } |
| 844 | // We shall never fail to find a free caller-save register, as |
| 845 | // there are more than two core caller-save registers on x86 |
| 846 | // (meaning it is possible to find one which is different from |
| 847 | // `ref` and `obj`). |
| 848 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 849 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 850 | UNREACHABLE(); |
| 851 | } |
| 852 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 853 | const Location out_; |
| 854 | const Location ref_; |
| 855 | const Location obj_; |
| 856 | const uint32_t offset_; |
| 857 | // An additional location containing an index to an array. |
| 858 | // Only used for HArrayGet and the UnsafeGetObject & |
| 859 | // UnsafeGetObjectVolatile intrinsics. |
| 860 | const Location index_; |
| 861 | |
| 862 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86); |
| 863 | }; |
| 864 | |
| 865 | // Slow path generating a read barrier for a GC root. |
| 866 | class ReadBarrierForRootSlowPathX86 : public SlowPathCode { |
| 867 | public: |
| 868 | ReadBarrierForRootSlowPathX86(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 869 | : SlowPathCode(instruction), out_(out), root_(root) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 870 | DCHECK(kEmitCompilerReadBarrier); |
| 871 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 872 | |
| 873 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 874 | LocationSummary* locations = instruction_->GetLocations(); |
| 875 | Register reg_out = out_.AsRegister<Register>(); |
| 876 | DCHECK(locations->CanCall()); |
| 877 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 878 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 879 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 880 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 881 | |
| 882 | __ Bind(GetEntryLabel()); |
| 883 | SaveLiveRegisters(codegen, locations); |
| 884 | |
| 885 | InvokeRuntimeCallingConvention calling_convention; |
| 886 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 887 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 888 | x86_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 889 | instruction_, |
| 890 | instruction_->GetDexPc(), |
| 891 | this); |
| 892 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 893 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 894 | |
| 895 | RestoreLiveRegisters(codegen, locations); |
| 896 | __ jmp(GetExitLabel()); |
| 897 | } |
| 898 | |
| 899 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathX86"; } |
| 900 | |
| 901 | private: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 902 | const Location out_; |
| 903 | const Location root_; |
| 904 | |
| 905 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86); |
| 906 | }; |
| 907 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 908 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 909 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 910 | #define __ down_cast<X86Assembler*>(GetAssembler())-> // NOLINT |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 911 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 912 | inline Condition X86Condition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 913 | switch (cond) { |
| 914 | case kCondEQ: return kEqual; |
| 915 | case kCondNE: return kNotEqual; |
| 916 | case kCondLT: return kLess; |
| 917 | case kCondLE: return kLessEqual; |
| 918 | case kCondGT: return kGreater; |
| 919 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 920 | case kCondB: return kBelow; |
| 921 | case kCondBE: return kBelowEqual; |
| 922 | case kCondA: return kAbove; |
| 923 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 924 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 925 | LOG(FATAL) << "Unreachable"; |
| 926 | UNREACHABLE(); |
| 927 | } |
| 928 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 929 | // Maps signed condition to unsigned condition and FP condition to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 930 | inline Condition X86UnsignedOrFPCondition(IfCondition cond) { |
| 931 | switch (cond) { |
| 932 | case kCondEQ: return kEqual; |
| 933 | case kCondNE: return kNotEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 934 | // Signed to unsigned, and FP to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 935 | case kCondLT: return kBelow; |
| 936 | case kCondLE: return kBelowEqual; |
| 937 | case kCondGT: return kAbove; |
| 938 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 939 | // Unsigned remain unchanged. |
| 940 | case kCondB: return kBelow; |
| 941 | case kCondBE: return kBelowEqual; |
| 942 | case kCondA: return kAbove; |
| 943 | case kCondAE: return kAboveEqual; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 944 | } |
| 945 | LOG(FATAL) << "Unreachable"; |
| 946 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 947 | } |
| 948 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 949 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 950 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 951 | } |
| 952 | |
| 953 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 954 | stream << XmmRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 955 | } |
| 956 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 957 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 958 | __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); |
| 959 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 960 | } |
| 961 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 962 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 963 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); |
| 964 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 965 | } |
| 966 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 967 | size_t CodeGeneratorX86::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 968 | if (GetGraph()->HasSIMD()) { |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 969 | __ movups(Address(ESP, stack_index), XmmRegister(reg_id)); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 970 | } else { |
| 971 | __ movsd(Address(ESP, stack_index), XmmRegister(reg_id)); |
| 972 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 973 | return GetFloatingPointSpillSlotSize(); |
| 974 | } |
| 975 | |
| 976 | size_t CodeGeneratorX86::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 977 | if (GetGraph()->HasSIMD()) { |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 978 | __ movups(XmmRegister(reg_id), Address(ESP, stack_index)); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 979 | } else { |
| 980 | __ movsd(XmmRegister(reg_id), Address(ESP, stack_index)); |
| 981 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 982 | return GetFloatingPointSpillSlotSize(); |
| 983 | } |
| 984 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 985 | void CodeGeneratorX86::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 986 | HInstruction* instruction, |
| 987 | uint32_t dex_pc, |
| 988 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 989 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 990 | GenerateInvokeRuntime(GetThreadOffset<kX86PointerSize>(entrypoint).Int32Value()); |
| 991 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 992 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 993 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 994 | } |
| 995 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 996 | void CodeGeneratorX86::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 997 | HInstruction* instruction, |
| 998 | SlowPathCode* slow_path) { |
| 999 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1000 | GenerateInvokeRuntime(entry_point_offset); |
| 1001 | } |
| 1002 | |
| 1003 | void CodeGeneratorX86::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1004 | __ fs()->call(Address::Absolute(entry_point_offset)); |
| 1005 | } |
| 1006 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1007 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1008 | const X86InstructionSetFeatures& isa_features, |
| 1009 | const CompilerOptions& compiler_options, |
| 1010 | OptimizingCompilerStats* stats) |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1011 | : CodeGenerator(graph, |
| 1012 | kNumberOfCpuRegisters, |
| 1013 | kNumberOfXmmRegisters, |
| 1014 | kNumberOfRegisterPairs, |
| 1015 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1016 | arraysize(kCoreCalleeSaves)) |
| 1017 | | (1 << kFakeReturnRegister), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1018 | 0, |
| 1019 | compiler_options, |
| 1020 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1021 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1022 | location_builder_(graph, this), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1023 | instruction_visitor_(graph, this), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1024 | move_resolver_(graph->GetAllocator(), this), |
| 1025 | assembler_(graph->GetAllocator()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1026 | isa_features_(isa_features), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1027 | boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1028 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1029 | boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1030 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1031 | string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1032 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1033 | jit_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1034 | jit_class_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1035 | constant_area_start_(-1), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1036 | fixups_to_jump_tables_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1037 | method_address_offset_(std::less<uint32_t>(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1038 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1039 | // Use a fake return address register to mimic Quick. |
| 1040 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1041 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1042 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1043 | void CodeGeneratorX86::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1044 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1045 | blocked_core_registers_[ESP] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1046 | } |
| 1047 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1048 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1049 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1050 | assembler_(codegen->GetAssembler()), |
| 1051 | codegen_(codegen) {} |
| 1052 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1053 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1054 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1055 | } |
| 1056 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1057 | void CodeGeneratorX86::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1058 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1059 | __ Bind(&frame_entry_label_); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1060 | bool skip_overflow_check = |
| 1061 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1062 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 1063 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1064 | if (!skip_overflow_check) { |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1065 | size_t reserved_bytes = GetStackOverflowReservedBytes(InstructionSet::kX86); |
| 1066 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(reserved_bytes))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1067 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 1068 | } |
| 1069 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1070 | if (HasEmptyFrame()) { |
| 1071 | return; |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1072 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1073 | |
| 1074 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 1075 | Register reg = kCoreCalleeSaves[i]; |
| 1076 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1077 | __ pushl(reg); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1078 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 1079 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1080 | } |
| 1081 | } |
| 1082 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1083 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1084 | __ subl(ESP, Immediate(adjust)); |
| 1085 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1086 | // Save the current method if we need it. Note that we do not |
| 1087 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1088 | // in the SSA graph. |
| 1089 | if (RequiresCurrentMethod()) { |
| 1090 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
| 1091 | } |
Nicolas Geoffray | f789353 | 2017-06-15 12:34:36 +0100 | [diff] [blame] | 1092 | |
| 1093 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1094 | // Initialize should_deoptimize flag to 0. |
| 1095 | __ movl(Address(ESP, GetStackOffsetOfShouldDeoptimizeFlag()), Immediate(0)); |
| 1096 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1097 | } |
| 1098 | |
| 1099 | void CodeGeneratorX86::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1100 | __ cfi().RememberState(); |
| 1101 | if (!HasEmptyFrame()) { |
| 1102 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1103 | __ addl(ESP, Immediate(adjust)); |
| 1104 | __ cfi().AdjustCFAOffset(-adjust); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1105 | |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1106 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1107 | Register reg = kCoreCalleeSaves[i]; |
| 1108 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1109 | __ popl(reg); |
| 1110 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 1111 | __ cfi().Restore(DWARFReg(reg)); |
| 1112 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1113 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1114 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1115 | __ ret(); |
| 1116 | __ cfi().RestoreState(); |
| 1117 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1118 | } |
| 1119 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1120 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 1121 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1122 | } |
| 1123 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1124 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(DataType::Type type) const { |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1125 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1126 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1127 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1128 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1129 | case DataType::Type::kInt8: |
| 1130 | case DataType::Type::kUint16: |
| 1131 | case DataType::Type::kInt16: |
| 1132 | case DataType::Type::kInt32: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1133 | return Location::RegisterLocation(EAX); |
| 1134 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1135 | case DataType::Type::kInt64: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1136 | return Location::RegisterPairLocation(EAX, EDX); |
| 1137 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1138 | case DataType::Type::kVoid: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1139 | return Location::NoLocation(); |
| 1140 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1141 | case DataType::Type::kFloat64: |
| 1142 | case DataType::Type::kFloat32: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1143 | return Location::FpuRegisterLocation(XMM0); |
| 1144 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1145 | |
| 1146 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1147 | } |
| 1148 | |
| 1149 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 1150 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1151 | } |
| 1152 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1153 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(DataType::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1154 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1155 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1156 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1157 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1158 | case DataType::Type::kInt8: |
| 1159 | case DataType::Type::kUint16: |
| 1160 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1161 | case DataType::Type::kInt32: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1162 | uint32_t index = gp_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1163 | stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1164 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1165 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1166 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1167 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1168 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1169 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1170 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1171 | case DataType::Type::kInt64: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1172 | uint32_t index = gp_index_; |
| 1173 | gp_index_ += 2; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1174 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1175 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1176 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 1177 | calling_convention.GetRegisterPairAt(index)); |
| 1178 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1179 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1180 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1181 | } |
| 1182 | } |
| 1183 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1184 | case DataType::Type::kFloat32: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1185 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1186 | stack_index_++; |
| 1187 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1188 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1189 | } else { |
| 1190 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1191 | } |
| 1192 | } |
| 1193 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1194 | case DataType::Type::kFloat64: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1195 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1196 | stack_index_ += 2; |
| 1197 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1198 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1199 | } else { |
| 1200 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1201 | } |
| 1202 | } |
| 1203 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1204 | case DataType::Type::kVoid: |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1205 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1206 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1207 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1208 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1209 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1210 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1211 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 1212 | if (source.Equals(destination)) { |
| 1213 | return; |
| 1214 | } |
| 1215 | if (destination.IsRegister()) { |
| 1216 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1217 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1218 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1219 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1220 | } else { |
| 1221 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1222 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1223 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1224 | } else if (destination.IsFpuRegister()) { |
| 1225 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1226 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1227 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1228 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1229 | } else { |
| 1230 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1231 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1232 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1233 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1234 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1235 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1236 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1237 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1238 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1239 | } else if (source.IsConstant()) { |
| 1240 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1241 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1242 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1243 | } else { |
| 1244 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1245 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 1246 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1247 | } |
| 1248 | } |
| 1249 | } |
| 1250 | |
| 1251 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 1252 | if (source.Equals(destination)) { |
| 1253 | return; |
| 1254 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1255 | if (destination.IsRegisterPair()) { |
| 1256 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1257 | EmitParallelMoves( |
| 1258 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1259 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1260 | DataType::Type::kInt32, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1261 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1262 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1263 | DataType::Type::kInt32); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1264 | } else if (source.IsFpuRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1265 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 1266 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 1267 | __ psrlq(src_reg, Immediate(32)); |
| 1268 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1269 | } else { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1270 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1271 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1272 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 1273 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1274 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 1275 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1276 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1277 | if (source.IsFpuRegister()) { |
| 1278 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 1279 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1280 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1281 | } else if (source.IsRegisterPair()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1282 | size_t elem_size = DataType::Size(DataType::Type::kInt32); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1283 | // Create stack space for 2 elements. |
| 1284 | __ subl(ESP, Immediate(2 * elem_size)); |
| 1285 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 1286 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 1287 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 1288 | // And remove the temporary stack space we allocated. |
| 1289 | __ addl(ESP, Immediate(2 * elem_size)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1290 | } else { |
| 1291 | LOG(FATAL) << "Unimplemented"; |
| 1292 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1293 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1294 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1295 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1296 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1297 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1298 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1299 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1300 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1301 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1302 | } else if (source.IsConstant()) { |
| 1303 | HConstant* constant = source.GetConstant(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1304 | DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant()); |
| 1305 | int64_t value = GetInt64ValueOf(constant); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1306 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1307 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
| 1308 | Immediate(High32Bits(value))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1309 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1310 | DCHECK(source.IsDoubleStackSlot()) << source; |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1311 | EmitParallelMoves( |
| 1312 | Location::StackSlot(source.GetStackIndex()), |
| 1313 | Location::StackSlot(destination.GetStackIndex()), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1314 | DataType::Type::kInt32, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1315 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1316 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1317 | DataType::Type::kInt32); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1318 | } |
| 1319 | } |
| 1320 | } |
| 1321 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1322 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { |
| 1323 | DCHECK(location.IsRegister()); |
| 1324 | __ movl(location.AsRegister<Register>(), Immediate(value)); |
| 1325 | } |
| 1326 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1327 | void CodeGeneratorX86::MoveLocation(Location dst, Location src, DataType::Type dst_type) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1328 | HParallelMove move(GetGraph()->GetAllocator()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1329 | if (dst_type == DataType::Type::kInt64 && !src.IsConstant() && !src.IsFpuRegister()) { |
| 1330 | move.AddMove(src.ToLow(), dst.ToLow(), DataType::Type::kInt32, nullptr); |
| 1331 | move.AddMove(src.ToHigh(), dst.ToHigh(), DataType::Type::kInt32, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1332 | } else { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1333 | move.AddMove(src, dst, dst_type, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1334 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1335 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1336 | } |
| 1337 | |
| 1338 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1339 | if (location.IsRegister()) { |
| 1340 | locations->AddTemp(location); |
| 1341 | } else if (location.IsRegisterPair()) { |
| 1342 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1343 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1344 | } else { |
| 1345 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1346 | } |
| 1347 | } |
| 1348 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1349 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1350 | DCHECK(!successor->IsExitBlock()); |
| 1351 | |
| 1352 | HBasicBlock* block = got->GetBlock(); |
| 1353 | HInstruction* previous = got->GetPrevious(); |
| 1354 | |
| 1355 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1356 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1357 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1358 | return; |
| 1359 | } |
| 1360 | |
| 1361 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1362 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1363 | } |
| 1364 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1365 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1366 | } |
| 1367 | } |
| 1368 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1369 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 1370 | got->SetLocations(nullptr); |
| 1371 | } |
| 1372 | |
| 1373 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 1374 | HandleGoto(got, got->GetSuccessor()); |
| 1375 | } |
| 1376 | |
| 1377 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1378 | try_boundary->SetLocations(nullptr); |
| 1379 | } |
| 1380 | |
| 1381 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1382 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1383 | if (!successor->IsExitBlock()) { |
| 1384 | HandleGoto(try_boundary, successor); |
| 1385 | } |
| 1386 | } |
| 1387 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1388 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1389 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1390 | } |
| 1391 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1392 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1393 | } |
| 1394 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1395 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1396 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1397 | LabelType* true_label, |
| 1398 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1399 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1400 | __ j(kUnordered, true_label); |
| 1401 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1402 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1403 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1404 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1405 | } |
| 1406 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1407 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1408 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1409 | LabelType* true_label, |
| 1410 | LabelType* false_label) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1411 | LocationSummary* locations = cond->GetLocations(); |
| 1412 | Location left = locations->InAt(0); |
| 1413 | Location right = locations->InAt(1); |
| 1414 | IfCondition if_cond = cond->GetCondition(); |
| 1415 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1416 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1417 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1418 | IfCondition true_high_cond = if_cond; |
| 1419 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1420 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); // unsigned on lower part |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1421 | |
| 1422 | // Set the conditions for the test, remembering that == needs to be |
| 1423 | // decided using the low words. |
| 1424 | switch (if_cond) { |
| 1425 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1426 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1427 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1428 | break; |
| 1429 | case kCondLT: |
| 1430 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1431 | break; |
| 1432 | case kCondLE: |
| 1433 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1434 | break; |
| 1435 | case kCondGT: |
| 1436 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1437 | break; |
| 1438 | case kCondGE: |
| 1439 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1440 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1441 | case kCondB: |
| 1442 | false_high_cond = kCondA; |
| 1443 | break; |
| 1444 | case kCondBE: |
| 1445 | true_high_cond = kCondB; |
| 1446 | break; |
| 1447 | case kCondA: |
| 1448 | false_high_cond = kCondB; |
| 1449 | break; |
| 1450 | case kCondAE: |
| 1451 | true_high_cond = kCondA; |
| 1452 | break; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1453 | } |
| 1454 | |
| 1455 | if (right.IsConstant()) { |
| 1456 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1457 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1458 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1459 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1460 | codegen_->Compare32BitValue(left_high, val_high); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1461 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1462 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1463 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1464 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1465 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1466 | __ j(X86Condition(true_high_cond), true_label); |
| 1467 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1468 | } |
| 1469 | // Must be equal high, so compare the lows. |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1470 | codegen_->Compare32BitValue(left_low, val_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1471 | } else if (right.IsRegisterPair()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1472 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1473 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1474 | |
| 1475 | __ cmpl(left_high, right_high); |
| 1476 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1477 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1478 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1479 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1480 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1481 | __ j(X86Condition(true_high_cond), true_label); |
| 1482 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1483 | } |
| 1484 | // Must be equal high, so compare the lows. |
| 1485 | __ cmpl(left_low, right_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1486 | } else { |
| 1487 | DCHECK(right.IsDoubleStackSlot()); |
| 1488 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
| 1489 | if (if_cond == kCondNE) { |
| 1490 | __ j(X86Condition(true_high_cond), true_label); |
| 1491 | } else if (if_cond == kCondEQ) { |
| 1492 | __ j(X86Condition(false_high_cond), false_label); |
| 1493 | } else { |
| 1494 | __ j(X86Condition(true_high_cond), true_label); |
| 1495 | __ j(X86Condition(false_high_cond), false_label); |
| 1496 | } |
| 1497 | // Must be equal high, so compare the lows. |
| 1498 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1499 | } |
| 1500 | // The last comparison might be unsigned. |
| 1501 | __ j(final_condition, true_label); |
| 1502 | } |
| 1503 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1504 | void InstructionCodeGeneratorX86::GenerateFPCompare(Location lhs, |
| 1505 | Location rhs, |
| 1506 | HInstruction* insn, |
| 1507 | bool is_double) { |
| 1508 | HX86LoadFromConstantTable* const_area = insn->InputAt(1)->AsX86LoadFromConstantTable(); |
| 1509 | if (is_double) { |
| 1510 | if (rhs.IsFpuRegister()) { |
| 1511 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1512 | } else if (const_area != nullptr) { |
| 1513 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1514 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), |
| 1515 | codegen_->LiteralDoubleAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1516 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 1517 | const_area->GetBaseMethodAddress(), |
| 1518 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1519 | } else { |
| 1520 | DCHECK(rhs.IsDoubleStackSlot()); |
| 1521 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1522 | } |
| 1523 | } else { |
| 1524 | if (rhs.IsFpuRegister()) { |
| 1525 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1526 | } else if (const_area != nullptr) { |
| 1527 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1528 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), |
| 1529 | codegen_->LiteralFloatAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1530 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 1531 | const_area->GetBaseMethodAddress(), |
| 1532 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1533 | } else { |
| 1534 | DCHECK(rhs.IsStackSlot()); |
| 1535 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1536 | } |
| 1537 | } |
| 1538 | } |
| 1539 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1540 | template<class LabelType> |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1541 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1542 | LabelType* true_target_in, |
| 1543 | LabelType* false_target_in) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1544 | // Generated branching requires both targets to be explicit. If either of the |
| 1545 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1546 | LabelType fallthrough_target; |
| 1547 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1548 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1549 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1550 | LocationSummary* locations = condition->GetLocations(); |
| 1551 | Location left = locations->InAt(0); |
| 1552 | Location right = locations->InAt(1); |
| 1553 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1554 | DataType::Type type = condition->InputAt(0)->GetType(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1555 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1556 | case DataType::Type::kInt64: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1557 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1558 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1559 | case DataType::Type::kFloat32: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1560 | GenerateFPCompare(left, right, condition, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1561 | GenerateFPJumps(condition, true_target, false_target); |
| 1562 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1563 | case DataType::Type::kFloat64: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1564 | GenerateFPCompare(left, right, condition, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1565 | GenerateFPJumps(condition, true_target, false_target); |
| 1566 | break; |
| 1567 | default: |
| 1568 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1569 | } |
| 1570 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1571 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1572 | __ jmp(false_target); |
| 1573 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1574 | |
| 1575 | if (fallthrough_target.IsLinked()) { |
| 1576 | __ Bind(&fallthrough_target); |
| 1577 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1578 | } |
| 1579 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1580 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1581 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1582 | // are set only strictly before `branch`. We can't use the eflags on long/FP |
| 1583 | // conditions if they are materialized due to the complex branching. |
| 1584 | return cond->IsCondition() && |
| 1585 | cond->GetNext() == branch && |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1586 | cond->InputAt(0)->GetType() != DataType::Type::kInt64 && |
| 1587 | !DataType::IsFloatingPointType(cond->InputAt(0)->GetType()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1588 | } |
| 1589 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1590 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1591 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1592 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1593 | LabelType* true_target, |
| 1594 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1595 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1596 | |
| 1597 | if (true_target == nullptr && false_target == nullptr) { |
| 1598 | // Nothing to do. The code always falls through. |
| 1599 | return; |
| 1600 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1601 | // Constant condition, statically compared against "true" (integer value 1). |
| 1602 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1603 | if (true_target != nullptr) { |
| 1604 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1605 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1606 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1607 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1608 | if (false_target != nullptr) { |
| 1609 | __ jmp(false_target); |
| 1610 | } |
| 1611 | } |
| 1612 | return; |
| 1613 | } |
| 1614 | |
| 1615 | // The following code generates these patterns: |
| 1616 | // (1) true_target == nullptr && false_target != nullptr |
| 1617 | // - opposite condition true => branch to false_target |
| 1618 | // (2) true_target != nullptr && false_target == nullptr |
| 1619 | // - condition true => branch to true_target |
| 1620 | // (3) true_target != nullptr && false_target != nullptr |
| 1621 | // - condition true => branch to true_target |
| 1622 | // - branch to false_target |
| 1623 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1624 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1625 | if (true_target == nullptr) { |
| 1626 | __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1627 | } else { |
| 1628 | __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); |
| 1629 | } |
| 1630 | } else { |
| 1631 | // Materialized condition, compare against 0. |
| 1632 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1633 | if (lhs.IsRegister()) { |
| 1634 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1635 | } else { |
| 1636 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1637 | } |
| 1638 | if (true_target == nullptr) { |
| 1639 | __ j(kEqual, false_target); |
| 1640 | } else { |
| 1641 | __ j(kNotEqual, true_target); |
| 1642 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1643 | } |
| 1644 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1645 | // Condition has not been materialized, use its inputs as the comparison and |
| 1646 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1647 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1648 | |
| 1649 | // If this is a long or FP comparison that has been folded into |
| 1650 | // the HCondition, generate the comparison directly. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1651 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 1652 | if (type == DataType::Type::kInt64 || DataType::IsFloatingPointType(type)) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1653 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1654 | return; |
| 1655 | } |
| 1656 | |
| 1657 | Location lhs = condition->GetLocations()->InAt(0); |
| 1658 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1659 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition). |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1660 | codegen_->GenerateIntCompare(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1661 | if (true_target == nullptr) { |
| 1662 | __ j(X86Condition(condition->GetOppositeCondition()), false_target); |
| 1663 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1664 | __ j(X86Condition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1665 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1666 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1667 | |
| 1668 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1669 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1670 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1671 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1672 | } |
| 1673 | } |
| 1674 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1675 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1676 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1677 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1678 | locations->SetInAt(0, Location::Any()); |
| 1679 | } |
| 1680 | } |
| 1681 | |
| 1682 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1683 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1684 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1685 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1686 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1687 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1688 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1689 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1690 | } |
| 1691 | |
| 1692 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1693 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1694 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 1695 | InvokeRuntimeCallingConvention calling_convention; |
| 1696 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 1697 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1698 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1699 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1700 | locations->SetInAt(0, Location::Any()); |
| 1701 | } |
| 1702 | } |
| 1703 | |
| 1704 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1705 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1706 | GenerateTestAndBranch<Label>(deoptimize, |
| 1707 | /* condition_input_index */ 0, |
| 1708 | slow_path->GetEntryLabel(), |
| 1709 | /* false_target */ nullptr); |
| 1710 | } |
| 1711 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1712 | void LocationsBuilderX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1713 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1714 | LocationSummary(flag, LocationSummary::kNoCall); |
| 1715 | locations->SetOut(Location::RequiresRegister()); |
| 1716 | } |
| 1717 | |
| 1718 | void InstructionCodeGeneratorX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1719 | __ movl(flag->GetLocations()->Out().AsRegister<Register>(), |
| 1720 | Address(ESP, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1721 | } |
| 1722 | |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1723 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1724 | // There are no conditional move instructions for XMMs. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1725 | if (DataType::IsFloatingPointType(select->GetType())) { |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1726 | return false; |
| 1727 | } |
| 1728 | |
| 1729 | // A FP condition doesn't generate the single CC that we need. |
| 1730 | // In 32 bit mode, a long condition doesn't generate a single CC either. |
| 1731 | HInstruction* condition = select->GetCondition(); |
| 1732 | if (condition->IsCondition()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1733 | DataType::Type compare_type = condition->InputAt(0)->GetType(); |
| 1734 | if (compare_type == DataType::Type::kInt64 || |
| 1735 | DataType::IsFloatingPointType(compare_type)) { |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1736 | return false; |
| 1737 | } |
| 1738 | } |
| 1739 | |
| 1740 | // We can generate a CMOV for this Select. |
| 1741 | return true; |
| 1742 | } |
| 1743 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1744 | void LocationsBuilderX86::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1745 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1746 | if (DataType::IsFloatingPointType(select->GetType())) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1747 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1748 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1749 | } else { |
| 1750 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1751 | if (SelectCanUseCMOV(select)) { |
| 1752 | if (select->InputAt(1)->IsConstant()) { |
| 1753 | // Cmov can't handle a constant value. |
| 1754 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1755 | } else { |
| 1756 | locations->SetInAt(1, Location::Any()); |
| 1757 | } |
| 1758 | } else { |
| 1759 | locations->SetInAt(1, Location::Any()); |
| 1760 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1761 | } |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1762 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1763 | locations->SetInAt(2, Location::RequiresRegister()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1764 | } |
| 1765 | locations->SetOut(Location::SameAsFirstInput()); |
| 1766 | } |
| 1767 | |
| 1768 | void InstructionCodeGeneratorX86::VisitSelect(HSelect* select) { |
| 1769 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1770 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1771 | if (SelectCanUseCMOV(select)) { |
| 1772 | // If both the condition and the source types are integer, we can generate |
| 1773 | // a CMOV to implement Select. |
| 1774 | |
| 1775 | HInstruction* select_condition = select->GetCondition(); |
| 1776 | Condition cond = kNotEqual; |
| 1777 | |
| 1778 | // Figure out how to test the 'condition'. |
| 1779 | if (select_condition->IsCondition()) { |
| 1780 | HCondition* condition = select_condition->AsCondition(); |
| 1781 | if (!condition->IsEmittedAtUseSite()) { |
| 1782 | // This was a previously materialized condition. |
| 1783 | // Can we use the existing condition code? |
| 1784 | if (AreEflagsSetFrom(condition, select)) { |
| 1785 | // Materialization was the previous instruction. Condition codes are right. |
| 1786 | cond = X86Condition(condition->GetCondition()); |
| 1787 | } else { |
| 1788 | // No, we have to recreate the condition code. |
| 1789 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1790 | __ testl(cond_reg, cond_reg); |
| 1791 | } |
| 1792 | } else { |
| 1793 | // We can't handle FP or long here. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1794 | DCHECK_NE(condition->InputAt(0)->GetType(), DataType::Type::kInt64); |
| 1795 | DCHECK(!DataType::IsFloatingPointType(condition->InputAt(0)->GetType())); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1796 | LocationSummary* cond_locations = condition->GetLocations(); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1797 | codegen_->GenerateIntCompare(cond_locations->InAt(0), cond_locations->InAt(1)); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1798 | cond = X86Condition(condition->GetCondition()); |
| 1799 | } |
| 1800 | } else { |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 1801 | // Must be a Boolean condition, which needs to be compared to 0. |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1802 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1803 | __ testl(cond_reg, cond_reg); |
| 1804 | } |
| 1805 | |
| 1806 | // If the condition is true, overwrite the output, which already contains false. |
| 1807 | Location false_loc = locations->InAt(0); |
| 1808 | Location true_loc = locations->InAt(1); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1809 | if (select->GetType() == DataType::Type::kInt64) { |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1810 | // 64 bit conditional move. |
| 1811 | Register false_high = false_loc.AsRegisterPairHigh<Register>(); |
| 1812 | Register false_low = false_loc.AsRegisterPairLow<Register>(); |
| 1813 | if (true_loc.IsRegisterPair()) { |
| 1814 | __ cmovl(cond, false_high, true_loc.AsRegisterPairHigh<Register>()); |
| 1815 | __ cmovl(cond, false_low, true_loc.AsRegisterPairLow<Register>()); |
| 1816 | } else { |
| 1817 | __ cmovl(cond, false_high, Address(ESP, true_loc.GetHighStackIndex(kX86WordSize))); |
| 1818 | __ cmovl(cond, false_low, Address(ESP, true_loc.GetStackIndex())); |
| 1819 | } |
| 1820 | } else { |
| 1821 | // 32 bit conditional move. |
| 1822 | Register false_reg = false_loc.AsRegister<Register>(); |
| 1823 | if (true_loc.IsRegister()) { |
| 1824 | __ cmovl(cond, false_reg, true_loc.AsRegister<Register>()); |
| 1825 | } else { |
| 1826 | __ cmovl(cond, false_reg, Address(ESP, true_loc.GetStackIndex())); |
| 1827 | } |
| 1828 | } |
| 1829 | } else { |
| 1830 | NearLabel false_target; |
| 1831 | GenerateTestAndBranch<NearLabel>( |
| 1832 | select, /* condition_input_index */ 2, /* true_target */ nullptr, &false_target); |
| 1833 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1834 | __ Bind(&false_target); |
| 1835 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1836 | } |
| 1837 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1838 | void LocationsBuilderX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1839 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1840 | } |
| 1841 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1842 | void InstructionCodeGeneratorX86::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1843 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1844 | } |
| 1845 | |
| 1846 | void CodeGeneratorX86::GenerateNop() { |
| 1847 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1848 | } |
| 1849 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1850 | void LocationsBuilderX86::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1851 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1852 | new (GetGraph()->GetAllocator()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1853 | // Handle the long/FP comparisons made in instruction simplification. |
| 1854 | switch (cond->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1855 | case DataType::Type::kInt64: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1856 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1857 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1858 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1859 | locations->SetOut(Location::RequiresRegister()); |
| 1860 | } |
| 1861 | break; |
| 1862 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1863 | case DataType::Type::kFloat32: |
| 1864 | case DataType::Type::kFloat64: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1865 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1866 | if (cond->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 1867 | DCHECK(cond->InputAt(1)->IsEmittedAtUseSite()); |
| 1868 | } else if (cond->InputAt(1)->IsConstant()) { |
| 1869 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1870 | } else { |
| 1871 | locations->SetInAt(1, Location::Any()); |
| 1872 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1873 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1874 | locations->SetOut(Location::RequiresRegister()); |
| 1875 | } |
| 1876 | break; |
| 1877 | } |
| 1878 | default: |
| 1879 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1880 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1881 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1882 | // We need a byte register. |
| 1883 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1884 | } |
| 1885 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1886 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1887 | } |
| 1888 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1889 | void InstructionCodeGeneratorX86::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1890 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1891 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1892 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1893 | |
| 1894 | LocationSummary* locations = cond->GetLocations(); |
| 1895 | Location lhs = locations->InAt(0); |
| 1896 | Location rhs = locations->InAt(1); |
| 1897 | Register reg = locations->Out().AsRegister<Register>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1898 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1899 | |
| 1900 | switch (cond->InputAt(0)->GetType()) { |
| 1901 | default: { |
| 1902 | // Integer case. |
| 1903 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 1904 | // Clear output register: setb only sets the low byte. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1905 | __ xorl(reg, reg); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1906 | codegen_->GenerateIntCompare(lhs, rhs); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1907 | __ setb(X86Condition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1908 | return; |
| 1909 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1910 | case DataType::Type::kInt64: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1911 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1912 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1913 | case DataType::Type::kFloat32: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1914 | GenerateFPCompare(lhs, rhs, cond, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1915 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1916 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1917 | case DataType::Type::kFloat64: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1918 | GenerateFPCompare(lhs, rhs, cond, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1919 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1920 | break; |
| 1921 | } |
| 1922 | |
| 1923 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1924 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1925 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1926 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1927 | __ Bind(&false_label); |
| 1928 | __ xorl(reg, reg); |
| 1929 | __ jmp(&done_label); |
| 1930 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1931 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1932 | __ Bind(&true_label); |
| 1933 | __ movl(reg, Immediate(1)); |
| 1934 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1935 | } |
| 1936 | |
| 1937 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1938 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1939 | } |
| 1940 | |
| 1941 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1942 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1943 | } |
| 1944 | |
| 1945 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1946 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1947 | } |
| 1948 | |
| 1949 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1950 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1951 | } |
| 1952 | |
| 1953 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1954 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1955 | } |
| 1956 | |
| 1957 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1958 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1959 | } |
| 1960 | |
| 1961 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1962 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1963 | } |
| 1964 | |
| 1965 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1966 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1967 | } |
| 1968 | |
| 1969 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1970 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1971 | } |
| 1972 | |
| 1973 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1974 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1975 | } |
| 1976 | |
| 1977 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1978 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1979 | } |
| 1980 | |
| 1981 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1982 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1983 | } |
| 1984 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1985 | void LocationsBuilderX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1986 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1987 | } |
| 1988 | |
| 1989 | void InstructionCodeGeneratorX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1990 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1991 | } |
| 1992 | |
| 1993 | void LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1994 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1995 | } |
| 1996 | |
| 1997 | void InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1998 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1999 | } |
| 2000 | |
| 2001 | void LocationsBuilderX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2002 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2003 | } |
| 2004 | |
| 2005 | void InstructionCodeGeneratorX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2006 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2007 | } |
| 2008 | |
| 2009 | void LocationsBuilderX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2010 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2011 | } |
| 2012 | |
| 2013 | void InstructionCodeGeneratorX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2014 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2015 | } |
| 2016 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2017 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2018 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2019 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2020 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2021 | } |
| 2022 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2023 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2024 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2025 | } |
| 2026 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2027 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 2028 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2029 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2030 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2031 | } |
| 2032 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2033 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2034 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2035 | } |
| 2036 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2037 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2038 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2039 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2040 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2041 | } |
| 2042 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2043 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2044 | // Will be generated at use site. |
| 2045 | } |
| 2046 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2047 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 2048 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2049 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2050 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2051 | } |
| 2052 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2053 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2054 | // Will be generated at use site. |
| 2055 | } |
| 2056 | |
| 2057 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2058 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2059 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2060 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2061 | } |
| 2062 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2063 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2064 | // Will be generated at use site. |
| 2065 | } |
| 2066 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2067 | void LocationsBuilderX86::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 2068 | constructor_fence->SetLocations(nullptr); |
| 2069 | } |
| 2070 | |
| 2071 | void InstructionCodeGeneratorX86::VisitConstructorFence( |
| 2072 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 2073 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 2074 | } |
| 2075 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2076 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2077 | memory_barrier->SetLocations(nullptr); |
| 2078 | } |
| 2079 | |
| 2080 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 2081 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2082 | } |
| 2083 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2084 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2085 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2086 | } |
| 2087 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2088 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2089 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2090 | } |
| 2091 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2092 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2093 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2094 | new (GetGraph()->GetAllocator()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2095 | switch (ret->InputAt(0)->GetType()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2096 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2097 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2098 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2099 | case DataType::Type::kInt8: |
| 2100 | case DataType::Type::kUint16: |
| 2101 | case DataType::Type::kInt16: |
| 2102 | case DataType::Type::kInt32: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2103 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2104 | break; |
| 2105 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2106 | case DataType::Type::kInt64: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2107 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2108 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2109 | break; |
| 2110 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2111 | case DataType::Type::kFloat32: |
| 2112 | case DataType::Type::kFloat64: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2113 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2114 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2115 | break; |
| 2116 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2117 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2118 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2119 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2120 | } |
| 2121 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2122 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2123 | if (kIsDebugBuild) { |
| 2124 | switch (ret->InputAt(0)->GetType()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2125 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2126 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2127 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2128 | case DataType::Type::kInt8: |
| 2129 | case DataType::Type::kUint16: |
| 2130 | case DataType::Type::kInt16: |
| 2131 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2132 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2133 | break; |
| 2134 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2135 | case DataType::Type::kInt64: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2136 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 2137 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2138 | break; |
| 2139 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2140 | case DataType::Type::kFloat32: |
| 2141 | case DataType::Type::kFloat64: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2142 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2143 | break; |
| 2144 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2145 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2146 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2147 | } |
| 2148 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2149 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2150 | } |
| 2151 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2152 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2153 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2154 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2155 | // the method_idx. |
| 2156 | HandleInvoke(invoke); |
| 2157 | } |
| 2158 | |
| 2159 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2160 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2161 | } |
| 2162 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2163 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2164 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2165 | // art::PrepareForRegisterAllocation. |
| 2166 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2167 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2168 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2169 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 2170 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeMethodLoadKind()) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 2171 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2172 | } |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2173 | return; |
| 2174 | } |
| 2175 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2176 | HandleInvoke(invoke); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2177 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2178 | // 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] | 2179 | if (invoke->HasPcRelativeMethodLoadKind()) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2180 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2181 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2182 | } |
| 2183 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2184 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 2185 | if (invoke->GetLocations()->Intrinsified()) { |
| 2186 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 2187 | intrinsic.Dispatch(invoke); |
| 2188 | return true; |
| 2189 | } |
| 2190 | return false; |
| 2191 | } |
| 2192 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2193 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2194 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2195 | // art::PrepareForRegisterAllocation. |
| 2196 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2197 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2198 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2199 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2200 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2201 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2202 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2203 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2204 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2205 | } |
| 2206 | |
| 2207 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 2208 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 2209 | if (intrinsic.TryDispatch(invoke)) { |
| 2210 | return; |
| 2211 | } |
| 2212 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2213 | HandleInvoke(invoke); |
| 2214 | } |
| 2215 | |
| 2216 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2217 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2218 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2219 | } |
| 2220 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2221 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2222 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2223 | return; |
| 2224 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2225 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2226 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2227 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2228 | } |
| 2229 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2230 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2231 | // This call to HandleInvoke allocates a temporary (core) register |
| 2232 | // which is also used to transfer the hidden argument from FP to |
| 2233 | // core register. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2234 | HandleInvoke(invoke); |
| 2235 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2236 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2237 | } |
| 2238 | |
| 2239 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2240 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2241 | LocationSummary* locations = invoke->GetLocations(); |
| 2242 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2243 | XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2244 | Location receiver = locations->InAt(0); |
| 2245 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2246 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2247 | // Set the hidden argument. This is safe to do this here, as XMM7 |
| 2248 | // won't be modified thereafter, before the `call` instruction. |
| 2249 | DCHECK_EQ(XMM7, hidden_reg); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2250 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2251 | __ movd(hidden_reg, temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2252 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2253 | if (receiver.IsStackSlot()) { |
| 2254 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2255 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2256 | __ movl(temp, Address(temp, class_offset)); |
| 2257 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2258 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2259 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2260 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2261 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2262 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2263 | // emit a read barrier for the previous class reference load. |
| 2264 | // However this is not required in practice, as this is an |
| 2265 | // intermediate/temporary reference and because the current |
| 2266 | // concurrent copying collector keeps the from-space memory |
| 2267 | // intact/accessible until the end of the marking phase (the |
| 2268 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2269 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2270 | // temp = temp->GetAddressOfIMT() |
| 2271 | __ movl(temp, |
| 2272 | Address(temp, mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2273 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2274 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2275 | invoke->GetImtIndex(), kX86PointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2276 | __ movl(temp, Address(temp, method_offset)); |
| 2277 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2278 | __ call(Address(temp, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2279 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2280 | |
| 2281 | DCHECK(!codegen_->IsLeafMethod()); |
| 2282 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2283 | } |
| 2284 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2285 | void LocationsBuilderX86::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2286 | HandleInvoke(invoke); |
| 2287 | } |
| 2288 | |
| 2289 | void InstructionCodeGeneratorX86::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2290 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 2291 | } |
| 2292 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2293 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 2294 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2295 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2296 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2297 | case DataType::Type::kInt32: |
| 2298 | case DataType::Type::kInt64: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2299 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2300 | locations->SetOut(Location::SameAsFirstInput()); |
| 2301 | break; |
| 2302 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2303 | case DataType::Type::kFloat32: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2304 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2305 | locations->SetOut(Location::SameAsFirstInput()); |
| 2306 | locations->AddTemp(Location::RequiresRegister()); |
| 2307 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2308 | break; |
| 2309 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2310 | case DataType::Type::kFloat64: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2311 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2312 | locations->SetOut(Location::SameAsFirstInput()); |
| 2313 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2314 | break; |
| 2315 | |
| 2316 | default: |
| 2317 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2318 | } |
| 2319 | } |
| 2320 | |
| 2321 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 2322 | LocationSummary* locations = neg->GetLocations(); |
| 2323 | Location out = locations->Out(); |
| 2324 | Location in = locations->InAt(0); |
| 2325 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2326 | case DataType::Type::kInt32: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2327 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2328 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2329 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2330 | break; |
| 2331 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2332 | case DataType::Type::kInt64: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2333 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2334 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2335 | __ negl(out.AsRegisterPairLow<Register>()); |
| 2336 | // Negation is similar to subtraction from zero. The least |
| 2337 | // significant byte triggers a borrow when it is different from |
| 2338 | // zero; to take it into account, add 1 to the most significant |
| 2339 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 2340 | // operation. |
| 2341 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2342 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 2343 | break; |
| 2344 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2345 | case DataType::Type::kFloat32: { |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2346 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2347 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 2348 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2349 | // Implement float negation with an exclusive or with value |
| 2350 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2351 | // single-precision floating-point number). |
| 2352 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 2353 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2354 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2355 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2356 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2357 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2358 | case DataType::Type::kFloat64: { |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2359 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2360 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2361 | // Implement double negation with an exclusive or with value |
| 2362 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 2363 | // a double-precision floating-point number). |
| 2364 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2365 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2366 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2367 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2368 | |
| 2369 | default: |
| 2370 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2371 | } |
| 2372 | } |
| 2373 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2374 | void LocationsBuilderX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2375 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2376 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2377 | DCHECK(DataType::IsFloatingPointType(neg->GetType())); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2378 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2379 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2380 | locations->SetOut(Location::SameAsFirstInput()); |
| 2381 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2382 | } |
| 2383 | |
| 2384 | void InstructionCodeGeneratorX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2385 | LocationSummary* locations = neg->GetLocations(); |
| 2386 | Location out = locations->Out(); |
| 2387 | DCHECK(locations->InAt(0).Equals(out)); |
| 2388 | |
| 2389 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 2390 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2391 | if (neg->GetType() == DataType::Type::kFloat32) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 2392 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x80000000), |
| 2393 | neg->GetBaseMethodAddress(), |
| 2394 | constant_area)); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2395 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| 2396 | } else { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 2397 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000), |
| 2398 | neg->GetBaseMethodAddress(), |
| 2399 | constant_area)); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2400 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| 2401 | } |
| 2402 | } |
| 2403 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2404 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2405 | DataType::Type result_type = conversion->GetResultType(); |
| 2406 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2407 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 2408 | << input_type << " -> " << result_type; |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2409 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2410 | // The float-to-long and double-to-long type conversions rely on a |
| 2411 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2412 | LocationSummary::CallKind call_kind = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2413 | ((input_type == DataType::Type::kFloat32 || input_type == DataType::Type::kFloat64) |
| 2414 | && result_type == DataType::Type::kInt64) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2415 | ? LocationSummary::kCallOnMainOnly |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2416 | : LocationSummary::kNoCall; |
| 2417 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2418 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, call_kind); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2419 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2420 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2421 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2422 | case DataType::Type::kInt8: |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2423 | switch (input_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2424 | case DataType::Type::kUint8: |
| 2425 | case DataType::Type::kInt8: |
| 2426 | case DataType::Type::kUint16: |
| 2427 | case DataType::Type::kInt16: |
| 2428 | case DataType::Type::kInt32: |
| 2429 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 2430 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2431 | // the validation of the linear scan implementation |
| 2432 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2433 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2434 | case DataType::Type::kInt64: { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2435 | HInstruction* input = conversion->InputAt(0); |
| 2436 | Location input_location = input->IsConstant() |
| 2437 | ? Location::ConstantLocation(input->AsConstant()) |
| 2438 | : Location::RegisterPairLocation(EAX, EDX); |
| 2439 | locations->SetInAt(0, input_location); |
| 2440 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2441 | // the validation of the linear scan implementation |
| 2442 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2443 | break; |
| 2444 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2445 | |
| 2446 | default: |
| 2447 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2448 | << " to " << result_type; |
| 2449 | } |
| 2450 | break; |
| 2451 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2452 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2453 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2454 | DCHECK(DataType::IsIntegralType(input_type)) << input_type; |
| 2455 | locations->SetInAt(0, Location::Any()); |
| 2456 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2457 | break; |
| 2458 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2459 | case DataType::Type::kInt32: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2460 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2461 | case DataType::Type::kInt64: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2462 | locations->SetInAt(0, Location::Any()); |
| 2463 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2464 | break; |
| 2465 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2466 | case DataType::Type::kFloat32: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2467 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2468 | locations->SetOut(Location::RequiresRegister()); |
| 2469 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2470 | break; |
| 2471 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2472 | case DataType::Type::kFloat64: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2473 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2474 | locations->SetOut(Location::RequiresRegister()); |
| 2475 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2476 | break; |
| 2477 | |
| 2478 | default: |
| 2479 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2480 | << " to " << result_type; |
| 2481 | } |
| 2482 | break; |
| 2483 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2484 | case DataType::Type::kInt64: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2485 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2486 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2487 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2488 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2489 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2490 | case DataType::Type::kInt16: |
| 2491 | case DataType::Type::kInt32: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2492 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 2493 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2494 | break; |
| 2495 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2496 | case DataType::Type::kFloat32: |
| 2497 | case DataType::Type::kFloat64: { |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2498 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2499 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 2500 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 2501 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2502 | // The runtime helper puts the result in EAX, EDX. |
| 2503 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2504 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2505 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2506 | |
| 2507 | default: |
| 2508 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2509 | << " to " << result_type; |
| 2510 | } |
| 2511 | break; |
| 2512 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2513 | case DataType::Type::kFloat32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2514 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2515 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2516 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2517 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2518 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2519 | case DataType::Type::kInt16: |
| 2520 | case DataType::Type::kInt32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2521 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2522 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2523 | break; |
| 2524 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2525 | case DataType::Type::kInt64: |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2526 | locations->SetInAt(0, Location::Any()); |
| 2527 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2528 | break; |
| 2529 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2530 | case DataType::Type::kFloat64: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2531 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2532 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2533 | break; |
| 2534 | |
| 2535 | default: |
| 2536 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2537 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 2538 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2539 | break; |
| 2540 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2541 | case DataType::Type::kFloat64: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2542 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2543 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2544 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2545 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2546 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2547 | case DataType::Type::kInt16: |
| 2548 | case DataType::Type::kInt32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2549 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2550 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2551 | break; |
| 2552 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2553 | case DataType::Type::kInt64: |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2554 | locations->SetInAt(0, Location::Any()); |
| 2555 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2556 | break; |
| 2557 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2558 | case DataType::Type::kFloat32: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2559 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2560 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2561 | break; |
| 2562 | |
| 2563 | default: |
| 2564 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2565 | << " to " << result_type; |
| 2566 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2567 | break; |
| 2568 | |
| 2569 | default: |
| 2570 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2571 | << " to " << result_type; |
| 2572 | } |
| 2573 | } |
| 2574 | |
| 2575 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 2576 | LocationSummary* locations = conversion->GetLocations(); |
| 2577 | Location out = locations->Out(); |
| 2578 | Location in = locations->InAt(0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2579 | DataType::Type result_type = conversion->GetResultType(); |
| 2580 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2581 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 2582 | << input_type << " -> " << result_type; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2583 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2584 | case DataType::Type::kUint8: |
| 2585 | switch (input_type) { |
| 2586 | case DataType::Type::kInt8: |
| 2587 | case DataType::Type::kUint16: |
| 2588 | case DataType::Type::kInt16: |
| 2589 | case DataType::Type::kInt32: |
| 2590 | if (in.IsRegister()) { |
| 2591 | __ movzxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
| 2592 | } else { |
| 2593 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2594 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2595 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint8_t>(value))); |
| 2596 | } |
| 2597 | break; |
| 2598 | case DataType::Type::kInt64: |
| 2599 | if (in.IsRegisterPair()) { |
| 2600 | __ movzxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 2601 | } else { |
| 2602 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2603 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2604 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint8_t>(value))); |
| 2605 | } |
| 2606 | break; |
| 2607 | |
| 2608 | default: |
| 2609 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2610 | << " to " << result_type; |
| 2611 | } |
| 2612 | break; |
| 2613 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2614 | case DataType::Type::kInt8: |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2615 | switch (input_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2616 | case DataType::Type::kUint8: |
| 2617 | case DataType::Type::kUint16: |
| 2618 | case DataType::Type::kInt16: |
| 2619 | case DataType::Type::kInt32: |
| 2620 | if (in.IsRegister()) { |
| 2621 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
| 2622 | } else { |
| 2623 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2624 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2625 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2626 | } |
| 2627 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2628 | case DataType::Type::kInt64: |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2629 | if (in.IsRegisterPair()) { |
| 2630 | __ movsxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 2631 | } else { |
| 2632 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2633 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2634 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2635 | } |
| 2636 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2637 | |
| 2638 | default: |
| 2639 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2640 | << " to " << result_type; |
| 2641 | } |
| 2642 | break; |
| 2643 | |
| 2644 | case DataType::Type::kUint16: |
| 2645 | switch (input_type) { |
| 2646 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2647 | case DataType::Type::kInt16: |
| 2648 | case DataType::Type::kInt32: |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2649 | if (in.IsRegister()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2650 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
| 2651 | } else if (in.IsStackSlot()) { |
| 2652 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2653 | } else { |
| 2654 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2655 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2656 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
| 2657 | } |
| 2658 | break; |
| 2659 | case DataType::Type::kInt64: |
| 2660 | if (in.IsRegisterPair()) { |
| 2661 | __ movzxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2662 | } else if (in.IsDoubleStackSlot()) { |
| 2663 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2664 | } else { |
| 2665 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2666 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2667 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2668 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2669 | break; |
| 2670 | |
| 2671 | default: |
| 2672 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2673 | << " to " << result_type; |
| 2674 | } |
| 2675 | break; |
| 2676 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2677 | case DataType::Type::kInt16: |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2678 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2679 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2680 | case DataType::Type::kInt32: |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2681 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2682 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2683 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2684 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2685 | } else { |
| 2686 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2687 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2688 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2689 | } |
| 2690 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2691 | case DataType::Type::kInt64: |
| 2692 | if (in.IsRegisterPair()) { |
| 2693 | __ movsxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2694 | } else if (in.IsDoubleStackSlot()) { |
| 2695 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2696 | } else { |
| 2697 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2698 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2699 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
| 2700 | } |
| 2701 | break; |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2702 | |
| 2703 | default: |
| 2704 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2705 | << " to " << result_type; |
| 2706 | } |
| 2707 | break; |
| 2708 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2709 | case DataType::Type::kInt32: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2710 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2711 | case DataType::Type::kInt64: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2712 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2713 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2714 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2715 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2716 | } else { |
| 2717 | DCHECK(in.IsConstant()); |
| 2718 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2719 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2720 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2721 | } |
| 2722 | break; |
| 2723 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2724 | case DataType::Type::kFloat32: { |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2725 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2726 | Register output = out.AsRegister<Register>(); |
| 2727 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2728 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2729 | |
| 2730 | __ movl(output, Immediate(kPrimIntMax)); |
| 2731 | // temp = int-to-float(output) |
| 2732 | __ cvtsi2ss(temp, output); |
| 2733 | // if input >= temp goto done |
| 2734 | __ comiss(input, temp); |
| 2735 | __ j(kAboveEqual, &done); |
| 2736 | // if input == NaN goto nan |
| 2737 | __ j(kUnordered, &nan); |
| 2738 | // output = float-to-int-truncate(input) |
| 2739 | __ cvttss2si(output, input); |
| 2740 | __ jmp(&done); |
| 2741 | __ Bind(&nan); |
| 2742 | // output = 0 |
| 2743 | __ xorl(output, output); |
| 2744 | __ Bind(&done); |
| 2745 | break; |
| 2746 | } |
| 2747 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2748 | case DataType::Type::kFloat64: { |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2749 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2750 | Register output = out.AsRegister<Register>(); |
| 2751 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2752 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2753 | |
| 2754 | __ movl(output, Immediate(kPrimIntMax)); |
| 2755 | // temp = int-to-double(output) |
| 2756 | __ cvtsi2sd(temp, output); |
| 2757 | // if input >= temp goto done |
| 2758 | __ comisd(input, temp); |
| 2759 | __ j(kAboveEqual, &done); |
| 2760 | // if input == NaN goto nan |
| 2761 | __ j(kUnordered, &nan); |
| 2762 | // output = double-to-int-truncate(input) |
| 2763 | __ cvttsd2si(output, input); |
| 2764 | __ jmp(&done); |
| 2765 | __ Bind(&nan); |
| 2766 | // output = 0 |
| 2767 | __ xorl(output, output); |
| 2768 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2769 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2770 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2771 | |
| 2772 | default: |
| 2773 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2774 | << " to " << result_type; |
| 2775 | } |
| 2776 | break; |
| 2777 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2778 | case DataType::Type::kInt64: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2779 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2780 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2781 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2782 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2783 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2784 | case DataType::Type::kInt16: |
| 2785 | case DataType::Type::kInt32: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2786 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2787 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2788 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2789 | __ cdq(); |
| 2790 | break; |
| 2791 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2792 | case DataType::Type::kFloat32: |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2793 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2794 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2795 | break; |
| 2796 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2797 | case DataType::Type::kFloat64: |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2798 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2799 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2800 | break; |
| 2801 | |
| 2802 | default: |
| 2803 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2804 | << " to " << result_type; |
| 2805 | } |
| 2806 | break; |
| 2807 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2808 | case DataType::Type::kFloat32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2809 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2810 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2811 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2812 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2813 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2814 | case DataType::Type::kInt16: |
| 2815 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2816 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2817 | break; |
| 2818 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2819 | case DataType::Type::kInt64: { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2820 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2821 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2822 | // Create stack space for the call to |
| 2823 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2824 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2825 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2826 | adjustment = DataType::Size(DataType::Type::kInt64); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2827 | __ subl(ESP, Immediate(adjustment)); |
| 2828 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2829 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2830 | // Load the value to the FP stack, using temporaries if needed. |
| 2831 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2832 | |
| 2833 | if (out.IsStackSlot()) { |
| 2834 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2835 | } else { |
| 2836 | __ fstps(Address(ESP, 0)); |
| 2837 | Location stack_temp = Location::StackSlot(0); |
| 2838 | codegen_->Move32(out, stack_temp); |
| 2839 | } |
| 2840 | |
| 2841 | // Remove the temporary stack space we allocated. |
| 2842 | if (adjustment != 0) { |
| 2843 | __ addl(ESP, Immediate(adjustment)); |
| 2844 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2845 | break; |
| 2846 | } |
| 2847 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2848 | case DataType::Type::kFloat64: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2849 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2850 | break; |
| 2851 | |
| 2852 | default: |
| 2853 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2854 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 2855 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2856 | break; |
| 2857 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2858 | case DataType::Type::kFloat64: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2859 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2860 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2861 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2862 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2863 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2864 | case DataType::Type::kInt16: |
| 2865 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2866 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2867 | break; |
| 2868 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2869 | case DataType::Type::kInt64: { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2870 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2871 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2872 | // Create stack space for the call to |
| 2873 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2874 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2875 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2876 | adjustment = DataType::Size(DataType::Type::kInt64); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2877 | __ subl(ESP, Immediate(adjustment)); |
| 2878 | } |
| 2879 | |
| 2880 | // Load the value to the FP stack, using temporaries if needed. |
| 2881 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2882 | |
| 2883 | if (out.IsDoubleStackSlot()) { |
| 2884 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2885 | } else { |
| 2886 | __ fstpl(Address(ESP, 0)); |
| 2887 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2888 | codegen_->Move64(out, stack_temp); |
| 2889 | } |
| 2890 | |
| 2891 | // Remove the temporary stack space we allocated. |
| 2892 | if (adjustment != 0) { |
| 2893 | __ addl(ESP, Immediate(adjustment)); |
| 2894 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2895 | break; |
| 2896 | } |
| 2897 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2898 | case DataType::Type::kFloat32: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2899 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2900 | break; |
| 2901 | |
| 2902 | default: |
| 2903 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2904 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 2905 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2906 | break; |
| 2907 | |
| 2908 | default: |
| 2909 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2910 | << " to " << result_type; |
| 2911 | } |
| 2912 | } |
| 2913 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2914 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2915 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2916 | new (GetGraph()->GetAllocator()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2917 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2918 | case DataType::Type::kInt32: { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2919 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2920 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2921 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2922 | break; |
| 2923 | } |
| 2924 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2925 | case DataType::Type::kInt64: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2926 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2927 | locations->SetInAt(1, Location::Any()); |
| 2928 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2929 | break; |
| 2930 | } |
| 2931 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2932 | case DataType::Type::kFloat32: |
| 2933 | case DataType::Type::kFloat64: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2934 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2935 | if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2936 | DCHECK(add->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2937 | } else if (add->InputAt(1)->IsConstant()) { |
| 2938 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2939 | } else { |
| 2940 | locations->SetInAt(1, Location::Any()); |
| 2941 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2942 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2943 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2944 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2945 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2946 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2947 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2948 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2949 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2950 | } |
| 2951 | |
| 2952 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 2953 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2954 | Location first = locations->InAt(0); |
| 2955 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2956 | Location out = locations->Out(); |
| 2957 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2958 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2959 | case DataType::Type::kInt32: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2960 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2961 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2962 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2963 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2964 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2965 | } else { |
| 2966 | __ leal(out.AsRegister<Register>(), Address( |
| 2967 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 2968 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2969 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2970 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2971 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2972 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 2973 | } else { |
| 2974 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 2975 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2976 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2977 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2978 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2979 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2980 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2981 | } |
| 2982 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2983 | case DataType::Type::kInt64: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2984 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2985 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2986 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2987 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2988 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 2989 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2990 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2991 | } else { |
| 2992 | DCHECK(second.IsConstant()) << second; |
| 2993 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2994 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2995 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2996 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2997 | break; |
| 2998 | } |
| 2999 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3000 | case DataType::Type::kFloat32: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3001 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3002 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3003 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3004 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3005 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3006 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 3007 | codegen_->LiteralFloatAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3008 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3009 | const_area->GetBaseMethodAddress(), |
| 3010 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3011 | } else { |
| 3012 | DCHECK(second.IsStackSlot()); |
| 3013 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3014 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3015 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3016 | } |
| 3017 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3018 | case DataType::Type::kFloat64: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3019 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3020 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3021 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3022 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3023 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3024 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 3025 | codegen_->LiteralDoubleAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3026 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3027 | const_area->GetBaseMethodAddress(), |
| 3028 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3029 | } else { |
| 3030 | DCHECK(second.IsDoubleStackSlot()); |
| 3031 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3032 | } |
| 3033 | break; |
| 3034 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3035 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3036 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3037 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3038 | } |
| 3039 | } |
| 3040 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3041 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3042 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3043 | new (GetGraph()->GetAllocator()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3044 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3045 | case DataType::Type::kInt32: |
| 3046 | case DataType::Type::kInt64: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3047 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3048 | locations->SetInAt(1, Location::Any()); |
| 3049 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3050 | break; |
| 3051 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3052 | case DataType::Type::kFloat32: |
| 3053 | case DataType::Type::kFloat64: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3054 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3055 | if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3056 | DCHECK(sub->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3057 | } else if (sub->InputAt(1)->IsConstant()) { |
| 3058 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3059 | } else { |
| 3060 | locations->SetInAt(1, Location::Any()); |
| 3061 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3062 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3063 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3064 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3065 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3066 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3067 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3068 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3069 | } |
| 3070 | |
| 3071 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 3072 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3073 | Location first = locations->InAt(0); |
| 3074 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3075 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3076 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3077 | case DataType::Type::kInt32: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3078 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3079 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3080 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3081 | __ subl(first.AsRegister<Register>(), |
| 3082 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3083 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3084 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3085 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3086 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3087 | } |
| 3088 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3089 | case DataType::Type::kInt64: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3090 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3091 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3092 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3093 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3094 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3095 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 3096 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3097 | } else { |
| 3098 | DCHECK(second.IsConstant()) << second; |
| 3099 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3100 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 3101 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3102 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3103 | break; |
| 3104 | } |
| 3105 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3106 | case DataType::Type::kFloat32: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3107 | if (second.IsFpuRegister()) { |
| 3108 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3109 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3110 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3111 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3112 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3113 | codegen_->LiteralFloatAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3114 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3115 | const_area->GetBaseMethodAddress(), |
| 3116 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3117 | } else { |
| 3118 | DCHECK(second.IsStackSlot()); |
| 3119 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3120 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3121 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3122 | } |
| 3123 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3124 | case DataType::Type::kFloat64: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3125 | if (second.IsFpuRegister()) { |
| 3126 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3127 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3128 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3129 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3130 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3131 | codegen_->LiteralDoubleAddress( |
| 3132 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3133 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3134 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3135 | } else { |
| 3136 | DCHECK(second.IsDoubleStackSlot()); |
| 3137 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3138 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3139 | break; |
| 3140 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3141 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3142 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3143 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3144 | } |
| 3145 | } |
| 3146 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3147 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 3148 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3149 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3150 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3151 | case DataType::Type::kInt32: |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3152 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3153 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3154 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3155 | // Can use 3 operand multiply. |
| 3156 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3157 | } else { |
| 3158 | locations->SetOut(Location::SameAsFirstInput()); |
| 3159 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3160 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3161 | case DataType::Type::kInt64: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3162 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3163 | locations->SetInAt(1, Location::Any()); |
| 3164 | locations->SetOut(Location::SameAsFirstInput()); |
| 3165 | // Needed for imul on 32bits with 64bits output. |
| 3166 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 3167 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 3168 | break; |
| 3169 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3170 | case DataType::Type::kFloat32: |
| 3171 | case DataType::Type::kFloat64: { |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3172 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3173 | if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3174 | DCHECK(mul->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3175 | } else if (mul->InputAt(1)->IsConstant()) { |
| 3176 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3177 | } else { |
| 3178 | locations->SetInAt(1, Location::Any()); |
| 3179 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3180 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3181 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3182 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3183 | |
| 3184 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3185 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3186 | } |
| 3187 | } |
| 3188 | |
| 3189 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 3190 | LocationSummary* locations = mul->GetLocations(); |
| 3191 | Location first = locations->InAt(0); |
| 3192 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3193 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3194 | |
| 3195 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3196 | case DataType::Type::kInt32: |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3197 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3198 | // problems where the output may not be the same as the first operand. |
| 3199 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3200 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3201 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 3202 | } else if (second.IsRegister()) { |
| 3203 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3204 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3205 | } else { |
| 3206 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3207 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3208 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3209 | } |
| 3210 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3211 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3212 | case DataType::Type::kInt64: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3213 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 3214 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3215 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 3216 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3217 | |
| 3218 | DCHECK_EQ(EAX, eax); |
| 3219 | DCHECK_EQ(EDX, edx); |
| 3220 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3221 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3222 | // output: in1 |
| 3223 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3224 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3225 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3226 | if (second.IsConstant()) { |
| 3227 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3228 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3229 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3230 | int32_t low_value = Low32Bits(value); |
| 3231 | int32_t high_value = High32Bits(value); |
| 3232 | Immediate low(low_value); |
| 3233 | Immediate high(high_value); |
| 3234 | |
| 3235 | __ movl(eax, high); |
| 3236 | // eax <- in1.lo * in2.hi |
| 3237 | __ imull(eax, in1_lo); |
| 3238 | // in1.hi <- in1.hi * in2.lo |
| 3239 | __ imull(in1_hi, low); |
| 3240 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3241 | __ addl(in1_hi, eax); |
| 3242 | // move in2_lo to eax to prepare for double precision |
| 3243 | __ movl(eax, low); |
| 3244 | // edx:eax <- in1.lo * in2.lo |
| 3245 | __ mull(in1_lo); |
| 3246 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3247 | __ addl(in1_hi, edx); |
| 3248 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3249 | __ movl(in1_lo, eax); |
| 3250 | } else if (second.IsRegisterPair()) { |
| 3251 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3252 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3253 | |
| 3254 | __ movl(eax, in2_hi); |
| 3255 | // eax <- in1.lo * in2.hi |
| 3256 | __ imull(eax, in1_lo); |
| 3257 | // in1.hi <- in1.hi * in2.lo |
| 3258 | __ imull(in1_hi, in2_lo); |
| 3259 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3260 | __ addl(in1_hi, eax); |
| 3261 | // move in1_lo to eax to prepare for double precision |
| 3262 | __ movl(eax, in1_lo); |
| 3263 | // edx:eax <- in1.lo * in2.lo |
| 3264 | __ mull(in2_lo); |
| 3265 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3266 | __ addl(in1_hi, edx); |
| 3267 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3268 | __ movl(in1_lo, eax); |
| 3269 | } else { |
| 3270 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 3271 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 3272 | Address in2_lo(ESP, second.GetStackIndex()); |
| 3273 | |
| 3274 | __ movl(eax, in2_hi); |
| 3275 | // eax <- in1.lo * in2.hi |
| 3276 | __ imull(eax, in1_lo); |
| 3277 | // in1.hi <- in1.hi * in2.lo |
| 3278 | __ imull(in1_hi, in2_lo); |
| 3279 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3280 | __ addl(in1_hi, eax); |
| 3281 | // move in1_lo to eax to prepare for double precision |
| 3282 | __ movl(eax, in1_lo); |
| 3283 | // edx:eax <- in1.lo * in2.lo |
| 3284 | __ mull(in2_lo); |
| 3285 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3286 | __ addl(in1_hi, edx); |
| 3287 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3288 | __ movl(in1_lo, eax); |
| 3289 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3290 | |
| 3291 | break; |
| 3292 | } |
| 3293 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3294 | case DataType::Type::kFloat32: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3295 | DCHECK(first.Equals(locations->Out())); |
| 3296 | if (second.IsFpuRegister()) { |
| 3297 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3298 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3299 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3300 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3301 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3302 | codegen_->LiteralFloatAddress( |
| 3303 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3304 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3305 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3306 | } else { |
| 3307 | DCHECK(second.IsStackSlot()); |
| 3308 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3309 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3310 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3311 | } |
| 3312 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3313 | case DataType::Type::kFloat64: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3314 | DCHECK(first.Equals(locations->Out())); |
| 3315 | if (second.IsFpuRegister()) { |
| 3316 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3317 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3318 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3319 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3320 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3321 | codegen_->LiteralDoubleAddress( |
| 3322 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3323 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3324 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3325 | } else { |
| 3326 | DCHECK(second.IsDoubleStackSlot()); |
| 3327 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3328 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3329 | break; |
| 3330 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3331 | |
| 3332 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3333 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3334 | } |
| 3335 | } |
| 3336 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3337 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 3338 | uint32_t temp_offset, |
| 3339 | uint32_t stack_adjustment, |
| 3340 | bool is_fp, |
| 3341 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3342 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3343 | DCHECK(!is_wide); |
| 3344 | if (is_fp) { |
| 3345 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3346 | } else { |
| 3347 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3348 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3349 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3350 | DCHECK(is_wide); |
| 3351 | if (is_fp) { |
| 3352 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3353 | } else { |
| 3354 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3355 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3356 | } else { |
| 3357 | // 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] | 3358 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3359 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3360 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3361 | if (is_fp) { |
| 3362 | __ flds(Address(ESP, temp_offset)); |
| 3363 | } else { |
| 3364 | __ filds(Address(ESP, temp_offset)); |
| 3365 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3366 | } else { |
| 3367 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3368 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3369 | if (is_fp) { |
| 3370 | __ fldl(Address(ESP, temp_offset)); |
| 3371 | } else { |
| 3372 | __ fildl(Address(ESP, temp_offset)); |
| 3373 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3374 | } |
| 3375 | } |
| 3376 | } |
| 3377 | |
| 3378 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3379 | DataType::Type type = rem->GetResultType(); |
| 3380 | bool is_float = type == DataType::Type::kFloat32; |
| 3381 | size_t elem_size = DataType::Size(type); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3382 | LocationSummary* locations = rem->GetLocations(); |
| 3383 | Location first = locations->InAt(0); |
| 3384 | Location second = locations->InAt(1); |
| 3385 | Location out = locations->Out(); |
| 3386 | |
| 3387 | // Create stack space for 2 elements. |
| 3388 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3389 | __ subl(ESP, Immediate(2 * elem_size)); |
| 3390 | |
| 3391 | // 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] | 3392 | const bool is_wide = !is_float; |
| 3393 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); |
| 3394 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3395 | |
| 3396 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3397 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3398 | __ Bind(&retry); |
| 3399 | __ fprem(); |
| 3400 | |
| 3401 | // Move FP status to AX. |
| 3402 | __ fstsw(); |
| 3403 | |
| 3404 | // And see if the argument reduction is complete. This is signaled by the |
| 3405 | // C2 FPU flag bit set to 0. |
| 3406 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 3407 | __ j(kNotEqual, &retry); |
| 3408 | |
| 3409 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3410 | // Store FP top of stack to real stack. |
| 3411 | if (is_float) { |
| 3412 | __ fsts(Address(ESP, 0)); |
| 3413 | } else { |
| 3414 | __ fstl(Address(ESP, 0)); |
| 3415 | } |
| 3416 | |
| 3417 | // Pop the 2 items from the FP stack. |
| 3418 | __ fucompp(); |
| 3419 | |
| 3420 | // Load the value from the stack into an XMM register. |
| 3421 | DCHECK(out.IsFpuRegister()) << out; |
| 3422 | if (is_float) { |
| 3423 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3424 | } else { |
| 3425 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3426 | } |
| 3427 | |
| 3428 | // And remove the temporary stack space we allocated. |
| 3429 | __ addl(ESP, Immediate(2 * elem_size)); |
| 3430 | } |
| 3431 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3432 | |
| 3433 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3434 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3435 | |
| 3436 | LocationSummary* locations = instruction->GetLocations(); |
| 3437 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3438 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3439 | |
| 3440 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3441 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3442 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3443 | |
| 3444 | DCHECK(imm == 1 || imm == -1); |
| 3445 | |
| 3446 | if (instruction->IsRem()) { |
| 3447 | __ xorl(out_register, out_register); |
| 3448 | } else { |
| 3449 | __ movl(out_register, input_register); |
| 3450 | if (imm == -1) { |
| 3451 | __ negl(out_register); |
| 3452 | } |
| 3453 | } |
| 3454 | } |
| 3455 | |
| 3456 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3457 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3458 | LocationSummary* locations = instruction->GetLocations(); |
| 3459 | |
| 3460 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3461 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3462 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3463 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3464 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3465 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3466 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 3467 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3468 | __ leal(num, Address(input_register, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3469 | __ testl(input_register, input_register); |
| 3470 | __ cmovl(kGreaterEqual, num, input_register); |
| 3471 | int shift = CTZ(imm); |
| 3472 | __ sarl(num, Immediate(shift)); |
| 3473 | |
| 3474 | if (imm < 0) { |
| 3475 | __ negl(num); |
| 3476 | } |
| 3477 | |
| 3478 | __ movl(out_register, num); |
| 3479 | } |
| 3480 | |
| 3481 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3482 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3483 | |
| 3484 | LocationSummary* locations = instruction->GetLocations(); |
| 3485 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 3486 | |
| 3487 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 3488 | Register out = locations->Out().AsRegister<Register>(); |
| 3489 | Register num; |
| 3490 | Register edx; |
| 3491 | |
| 3492 | if (instruction->IsDiv()) { |
| 3493 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 3494 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 3495 | } else { |
| 3496 | edx = locations->Out().AsRegister<Register>(); |
| 3497 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 3498 | } |
| 3499 | |
| 3500 | DCHECK_EQ(EAX, eax); |
| 3501 | DCHECK_EQ(EDX, edx); |
| 3502 | if (instruction->IsDiv()) { |
| 3503 | DCHECK_EQ(EAX, out); |
| 3504 | } else { |
| 3505 | DCHECK_EQ(EDX, out); |
| 3506 | } |
| 3507 | |
| 3508 | int64_t magic; |
| 3509 | int shift; |
| 3510 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3511 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3512 | // Save the numerator. |
| 3513 | __ movl(num, eax); |
| 3514 | |
| 3515 | // EAX = magic |
| 3516 | __ movl(eax, Immediate(magic)); |
| 3517 | |
| 3518 | // EDX:EAX = magic * numerator |
| 3519 | __ imull(num); |
| 3520 | |
| 3521 | if (imm > 0 && magic < 0) { |
| 3522 | // EDX += num |
| 3523 | __ addl(edx, num); |
| 3524 | } else if (imm < 0 && magic > 0) { |
| 3525 | __ subl(edx, num); |
| 3526 | } |
| 3527 | |
| 3528 | // Shift if needed. |
| 3529 | if (shift != 0) { |
| 3530 | __ sarl(edx, Immediate(shift)); |
| 3531 | } |
| 3532 | |
| 3533 | // EDX += 1 if EDX < 0 |
| 3534 | __ movl(eax, edx); |
| 3535 | __ shrl(edx, Immediate(31)); |
| 3536 | __ addl(edx, eax); |
| 3537 | |
| 3538 | if (instruction->IsRem()) { |
| 3539 | __ movl(eax, num); |
| 3540 | __ imull(edx, Immediate(imm)); |
| 3541 | __ subl(eax, edx); |
| 3542 | __ movl(edx, eax); |
| 3543 | } else { |
| 3544 | __ movl(eax, edx); |
| 3545 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3546 | } |
| 3547 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3548 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3549 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3550 | |
| 3551 | LocationSummary* locations = instruction->GetLocations(); |
| 3552 | Location out = locations->Out(); |
| 3553 | Location first = locations->InAt(0); |
| 3554 | Location second = locations->InAt(1); |
| 3555 | bool is_div = instruction->IsDiv(); |
| 3556 | |
| 3557 | switch (instruction->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3558 | case DataType::Type::kInt32: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3559 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 3560 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3561 | |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3562 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3563 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3564 | |
| 3565 | if (imm == 0) { |
| 3566 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 3567 | } else if (imm == 1 || imm == -1) { |
| 3568 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3569 | } else if (is_div && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3570 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3571 | } else { |
| 3572 | DCHECK(imm <= -2 || imm >= 2); |
| 3573 | GenerateDivRemWithAnyConstant(instruction); |
| 3574 | } |
| 3575 | } else { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3576 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) DivRemMinusOneSlowPathX86( |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3577 | instruction, out.AsRegister<Register>(), is_div); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3578 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3579 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3580 | Register second_reg = second.AsRegister<Register>(); |
| 3581 | // 0x80000000/-1 triggers an arithmetic exception! |
| 3582 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 3583 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3584 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3585 | __ cmpl(second_reg, Immediate(-1)); |
| 3586 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3587 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3588 | // edx:eax <- sign-extended of eax |
| 3589 | __ cdq(); |
| 3590 | // eax = quotient, edx = remainder |
| 3591 | __ idivl(second_reg); |
| 3592 | __ Bind(slow_path->GetExitLabel()); |
| 3593 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3594 | break; |
| 3595 | } |
| 3596 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3597 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3598 | InvokeRuntimeCallingConvention calling_convention; |
| 3599 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3600 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3601 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3602 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3603 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 3604 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 3605 | |
| 3606 | if (is_div) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3607 | codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3608 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3609 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3610 | codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3611 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3612 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3613 | break; |
| 3614 | } |
| 3615 | |
| 3616 | default: |
| 3617 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 3618 | } |
| 3619 | } |
| 3620 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3621 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3622 | LocationSummary::CallKind call_kind = (div->GetResultType() == DataType::Type::kInt64) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3623 | ? LocationSummary::kCallOnMainOnly |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3624 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3625 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(div, call_kind); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3626 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3627 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3628 | case DataType::Type::kInt32: { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3629 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3630 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3631 | locations->SetOut(Location::SameAsFirstInput()); |
| 3632 | // Intel uses edx:eax as the dividend. |
| 3633 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3634 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3635 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 3636 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3637 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3638 | locations->AddTemp(Location::RequiresRegister()); |
| 3639 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3640 | break; |
| 3641 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3642 | case DataType::Type::kInt64: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3643 | InvokeRuntimeCallingConvention calling_convention; |
| 3644 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3645 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3646 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3647 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3648 | // Runtime helper puts the result in EAX, EDX. |
| 3649 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3650 | break; |
| 3651 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3652 | case DataType::Type::kFloat32: |
| 3653 | case DataType::Type::kFloat64: { |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3654 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3655 | if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3656 | DCHECK(div->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3657 | } else if (div->InputAt(1)->IsConstant()) { |
| 3658 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3659 | } else { |
| 3660 | locations->SetInAt(1, Location::Any()); |
| 3661 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3662 | locations->SetOut(Location::SameAsFirstInput()); |
| 3663 | break; |
| 3664 | } |
| 3665 | |
| 3666 | default: |
| 3667 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3668 | } |
| 3669 | } |
| 3670 | |
| 3671 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 3672 | LocationSummary* locations = div->GetLocations(); |
| 3673 | Location first = locations->InAt(0); |
| 3674 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3675 | |
| 3676 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3677 | case DataType::Type::kInt32: |
| 3678 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3679 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3680 | break; |
| 3681 | } |
| 3682 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3683 | case DataType::Type::kFloat32: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3684 | if (second.IsFpuRegister()) { |
| 3685 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3686 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3687 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3688 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3689 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3690 | codegen_->LiteralFloatAddress( |
| 3691 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3692 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3693 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3694 | } else { |
| 3695 | DCHECK(second.IsStackSlot()); |
| 3696 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3697 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3698 | break; |
| 3699 | } |
| 3700 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3701 | case DataType::Type::kFloat64: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3702 | if (second.IsFpuRegister()) { |
| 3703 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3704 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3705 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3706 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3707 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3708 | codegen_->LiteralDoubleAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3709 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3710 | const_area->GetBaseMethodAddress(), |
| 3711 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3712 | } else { |
| 3713 | DCHECK(second.IsDoubleStackSlot()); |
| 3714 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3715 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3716 | break; |
| 3717 | } |
| 3718 | |
| 3719 | default: |
| 3720 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3721 | } |
| 3722 | } |
| 3723 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3724 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3725 | DataType::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3726 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3727 | LocationSummary::CallKind call_kind = (rem->GetResultType() == DataType::Type::kInt64) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3728 | ? LocationSummary::kCallOnMainOnly |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3729 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3730 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3731 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3732 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3733 | case DataType::Type::kInt32: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3734 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3735 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3736 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3737 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3738 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 3739 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3740 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3741 | locations->AddTemp(Location::RequiresRegister()); |
| 3742 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3743 | break; |
| 3744 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3745 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3746 | InvokeRuntimeCallingConvention calling_convention; |
| 3747 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3748 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3749 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3750 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3751 | // Runtime helper puts the result in EAX, EDX. |
| 3752 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3753 | break; |
| 3754 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3755 | case DataType::Type::kFloat64: |
| 3756 | case DataType::Type::kFloat32: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3757 | locations->SetInAt(0, Location::Any()); |
| 3758 | locations->SetInAt(1, Location::Any()); |
| 3759 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3760 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3761 | break; |
| 3762 | } |
| 3763 | |
| 3764 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3765 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3766 | } |
| 3767 | } |
| 3768 | |
| 3769 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3770 | DataType::Type type = rem->GetResultType(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3771 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3772 | case DataType::Type::kInt32: |
| 3773 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3774 | GenerateDivRemIntegral(rem); |
| 3775 | break; |
| 3776 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3777 | case DataType::Type::kFloat32: |
| 3778 | case DataType::Type::kFloat64: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3779 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3780 | break; |
| 3781 | } |
| 3782 | default: |
| 3783 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3784 | } |
| 3785 | } |
| 3786 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3787 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3788 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3789 | switch (instruction->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3790 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3791 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3792 | case DataType::Type::kInt8: |
| 3793 | case DataType::Type::kUint16: |
| 3794 | case DataType::Type::kInt16: |
| 3795 | case DataType::Type::kInt32: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3796 | locations->SetInAt(0, Location::Any()); |
| 3797 | break; |
| 3798 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3799 | case DataType::Type::kInt64: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3800 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 3801 | if (!instruction->IsConstant()) { |
| 3802 | locations->AddTemp(Location::RequiresRegister()); |
| 3803 | } |
| 3804 | break; |
| 3805 | } |
| 3806 | default: |
| 3807 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3808 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3809 | } |
| 3810 | |
| 3811 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3812 | SlowPathCode* slow_path = |
| 3813 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathX86(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3814 | codegen_->AddSlowPath(slow_path); |
| 3815 | |
| 3816 | LocationSummary* locations = instruction->GetLocations(); |
| 3817 | Location value = locations->InAt(0); |
| 3818 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3819 | switch (instruction->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3820 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3821 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3822 | case DataType::Type::kInt8: |
| 3823 | case DataType::Type::kUint16: |
| 3824 | case DataType::Type::kInt16: |
| 3825 | case DataType::Type::kInt32: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3826 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3827 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3828 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3829 | } else if (value.IsStackSlot()) { |
| 3830 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 3831 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3832 | } else { |
| 3833 | DCHECK(value.IsConstant()) << value; |
| 3834 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 3835 | __ jmp(slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3836 | } |
| 3837 | } |
| 3838 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3839 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3840 | case DataType::Type::kInt64: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3841 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3842 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3843 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 3844 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 3845 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3846 | } else { |
| 3847 | DCHECK(value.IsConstant()) << value; |
| 3848 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3849 | __ jmp(slow_path->GetEntryLabel()); |
| 3850 | } |
| 3851 | } |
| 3852 | break; |
| 3853 | } |
| 3854 | default: |
| 3855 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3856 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3857 | } |
| 3858 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3859 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 3860 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3861 | |
| 3862 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3863 | new (GetGraph()->GetAllocator()) LocationSummary(op, LocationSummary::kNoCall); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3864 | |
| 3865 | switch (op->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3866 | case DataType::Type::kInt32: |
| 3867 | case DataType::Type::kInt64: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3868 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3869 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3870 | // The shift count needs to be in CL or a constant. |
| 3871 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3872 | locations->SetOut(Location::SameAsFirstInput()); |
| 3873 | break; |
| 3874 | } |
| 3875 | default: |
| 3876 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3877 | } |
| 3878 | } |
| 3879 | |
| 3880 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 3881 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3882 | |
| 3883 | LocationSummary* locations = op->GetLocations(); |
| 3884 | Location first = locations->InAt(0); |
| 3885 | Location second = locations->InAt(1); |
| 3886 | DCHECK(first.Equals(locations->Out())); |
| 3887 | |
| 3888 | switch (op->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3889 | case DataType::Type::kInt32: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3890 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3891 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3892 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3893 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3894 | DCHECK_EQ(ECX, second_reg); |
| 3895 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3896 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3897 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3898 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3899 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3900 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3901 | } |
| 3902 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3903 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3904 | if (shift == 0) { |
| 3905 | return; |
| 3906 | } |
| 3907 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3908 | if (op->IsShl()) { |
| 3909 | __ shll(first_reg, imm); |
| 3910 | } else if (op->IsShr()) { |
| 3911 | __ sarl(first_reg, imm); |
| 3912 | } else { |
| 3913 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3914 | } |
| 3915 | } |
| 3916 | break; |
| 3917 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3918 | case DataType::Type::kInt64: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3919 | if (second.IsRegister()) { |
| 3920 | Register second_reg = second.AsRegister<Register>(); |
| 3921 | DCHECK_EQ(ECX, second_reg); |
| 3922 | if (op->IsShl()) { |
| 3923 | GenerateShlLong(first, second_reg); |
| 3924 | } else if (op->IsShr()) { |
| 3925 | GenerateShrLong(first, second_reg); |
| 3926 | } else { |
| 3927 | GenerateUShrLong(first, second_reg); |
| 3928 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3929 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3930 | // Shift by a constant. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3931 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3932 | // Nothing to do if the shift is 0, as the input is already the output. |
| 3933 | if (shift != 0) { |
| 3934 | if (op->IsShl()) { |
| 3935 | GenerateShlLong(first, shift); |
| 3936 | } else if (op->IsShr()) { |
| 3937 | GenerateShrLong(first, shift); |
| 3938 | } else { |
| 3939 | GenerateUShrLong(first, shift); |
| 3940 | } |
| 3941 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3942 | } |
| 3943 | break; |
| 3944 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3945 | default: |
| 3946 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3947 | } |
| 3948 | } |
| 3949 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3950 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 3951 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3952 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 3953 | if (shift == 1) { |
| 3954 | // This is just an addition. |
| 3955 | __ addl(low, low); |
| 3956 | __ adcl(high, high); |
| 3957 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3958 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 3959 | codegen_->EmitParallelMoves( |
| 3960 | loc.ToLow(), |
| 3961 | loc.ToHigh(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3962 | DataType::Type::kInt32, |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3963 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3964 | loc.ToLow(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3965 | DataType::Type::kInt32); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3966 | } else if (shift > 32) { |
| 3967 | // Low part becomes 0. High part is low part << (shift-32). |
| 3968 | __ movl(high, low); |
| 3969 | __ shll(high, Immediate(shift - 32)); |
| 3970 | __ xorl(low, low); |
| 3971 | } else { |
| 3972 | // Between 1 and 31. |
| 3973 | __ shld(high, low, Immediate(shift)); |
| 3974 | __ shll(low, Immediate(shift)); |
| 3975 | } |
| 3976 | } |
| 3977 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3978 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3979 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3980 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 3981 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 3982 | __ testl(shifter, Immediate(32)); |
| 3983 | __ j(kEqual, &done); |
| 3984 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 3985 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 3986 | __ Bind(&done); |
| 3987 | } |
| 3988 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3989 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 3990 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3991 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3992 | if (shift == 32) { |
| 3993 | // Need to copy the sign. |
| 3994 | DCHECK_NE(low, high); |
| 3995 | __ movl(low, high); |
| 3996 | __ sarl(high, Immediate(31)); |
| 3997 | } else if (shift > 32) { |
| 3998 | DCHECK_NE(low, high); |
| 3999 | // High part becomes sign. Low part is shifted by shift - 32. |
| 4000 | __ movl(low, high); |
| 4001 | __ sarl(high, Immediate(31)); |
| 4002 | __ sarl(low, Immediate(shift - 32)); |
| 4003 | } else { |
| 4004 | // Between 1 and 31. |
| 4005 | __ shrd(low, high, Immediate(shift)); |
| 4006 | __ sarl(high, Immediate(shift)); |
| 4007 | } |
| 4008 | } |
| 4009 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4010 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4011 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4012 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4013 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4014 | __ testl(shifter, Immediate(32)); |
| 4015 | __ j(kEqual, &done); |
| 4016 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4017 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 4018 | __ Bind(&done); |
| 4019 | } |
| 4020 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4021 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 4022 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4023 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 4024 | if (shift == 32) { |
| 4025 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 4026 | codegen_->EmitParallelMoves( |
| 4027 | loc.ToHigh(), |
| 4028 | loc.ToLow(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4029 | DataType::Type::kInt32, |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4030 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 4031 | loc.ToHigh(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4032 | DataType::Type::kInt32); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4033 | } else if (shift > 32) { |
| 4034 | // Low part is high >> (shift - 32). High part becomes 0. |
| 4035 | __ movl(low, high); |
| 4036 | __ shrl(low, Immediate(shift - 32)); |
| 4037 | __ xorl(high, high); |
| 4038 | } else { |
| 4039 | // Between 1 and 31. |
| 4040 | __ shrd(low, high, Immediate(shift)); |
| 4041 | __ shrl(high, Immediate(shift)); |
| 4042 | } |
| 4043 | } |
| 4044 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4045 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4046 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4047 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4048 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4049 | __ testl(shifter, Immediate(32)); |
| 4050 | __ j(kEqual, &done); |
| 4051 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4052 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 4053 | __ Bind(&done); |
| 4054 | } |
| 4055 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4056 | void LocationsBuilderX86::VisitRor(HRor* ror) { |
| 4057 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4058 | new (GetGraph()->GetAllocator()) LocationSummary(ror, LocationSummary::kNoCall); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4059 | |
| 4060 | switch (ror->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4061 | case DataType::Type::kInt64: |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4062 | // Add the temporary needed. |
| 4063 | locations->AddTemp(Location::RequiresRegister()); |
| 4064 | FALLTHROUGH_INTENDED; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4065 | case DataType::Type::kInt32: |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4066 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4067 | // The shift count needs to be in CL (unless it is a constant). |
| 4068 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); |
| 4069 | locations->SetOut(Location::SameAsFirstInput()); |
| 4070 | break; |
| 4071 | default: |
| 4072 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4073 | UNREACHABLE(); |
| 4074 | } |
| 4075 | } |
| 4076 | |
| 4077 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { |
| 4078 | LocationSummary* locations = ror->GetLocations(); |
| 4079 | Location first = locations->InAt(0); |
| 4080 | Location second = locations->InAt(1); |
| 4081 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4082 | if (ror->GetResultType() == DataType::Type::kInt32) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4083 | Register first_reg = first.AsRegister<Register>(); |
| 4084 | if (second.IsRegister()) { |
| 4085 | Register second_reg = second.AsRegister<Register>(); |
| 4086 | __ rorl(first_reg, second_reg); |
| 4087 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4088 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4089 | __ rorl(first_reg, imm); |
| 4090 | } |
| 4091 | return; |
| 4092 | } |
| 4093 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4094 | DCHECK_EQ(ror->GetResultType(), DataType::Type::kInt64); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4095 | Register first_reg_lo = first.AsRegisterPairLow<Register>(); |
| 4096 | Register first_reg_hi = first.AsRegisterPairHigh<Register>(); |
| 4097 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 4098 | if (second.IsRegister()) { |
| 4099 | Register second_reg = second.AsRegister<Register>(); |
| 4100 | DCHECK_EQ(second_reg, ECX); |
| 4101 | __ movl(temp_reg, first_reg_hi); |
| 4102 | __ shrd(first_reg_hi, first_reg_lo, second_reg); |
| 4103 | __ shrd(first_reg_lo, temp_reg, second_reg); |
| 4104 | __ movl(temp_reg, first_reg_hi); |
| 4105 | __ testl(second_reg, Immediate(32)); |
| 4106 | __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); |
| 4107 | __ cmovl(kNotEqual, first_reg_lo, temp_reg); |
| 4108 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4109 | int32_t shift_amt = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4110 | if (shift_amt == 0) { |
| 4111 | // Already fine. |
| 4112 | return; |
| 4113 | } |
| 4114 | if (shift_amt == 32) { |
| 4115 | // Just swap. |
| 4116 | __ movl(temp_reg, first_reg_lo); |
| 4117 | __ movl(first_reg_lo, first_reg_hi); |
| 4118 | __ movl(first_reg_hi, temp_reg); |
| 4119 | return; |
| 4120 | } |
| 4121 | |
| 4122 | Immediate imm(shift_amt); |
| 4123 | // Save the constents of the low value. |
| 4124 | __ movl(temp_reg, first_reg_lo); |
| 4125 | |
| 4126 | // Shift right into low, feeding bits from high. |
| 4127 | __ shrd(first_reg_lo, first_reg_hi, imm); |
| 4128 | |
| 4129 | // Shift right into high, feeding bits from the original low. |
| 4130 | __ shrd(first_reg_hi, temp_reg, imm); |
| 4131 | |
| 4132 | // Swap if needed. |
| 4133 | if (shift_amt > 32) { |
| 4134 | __ movl(temp_reg, first_reg_lo); |
| 4135 | __ movl(first_reg_lo, first_reg_hi); |
| 4136 | __ movl(first_reg_hi, temp_reg); |
| 4137 | } |
| 4138 | } |
| 4139 | } |
| 4140 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4141 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 4142 | HandleShift(shl); |
| 4143 | } |
| 4144 | |
| 4145 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 4146 | HandleShift(shl); |
| 4147 | } |
| 4148 | |
| 4149 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 4150 | HandleShift(shr); |
| 4151 | } |
| 4152 | |
| 4153 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 4154 | HandleShift(shr); |
| 4155 | } |
| 4156 | |
| 4157 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 4158 | HandleShift(ushr); |
| 4159 | } |
| 4160 | |
| 4161 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 4162 | HandleShift(ushr); |
| 4163 | } |
| 4164 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4165 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4166 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4167 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4168 | locations->SetOut(Location::RegisterLocation(EAX)); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4169 | if (instruction->IsStringAlloc()) { |
| 4170 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4171 | } else { |
| 4172 | InvokeRuntimeCallingConvention calling_convention; |
| 4173 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4174 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4175 | } |
| 4176 | |
| 4177 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4178 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4179 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4180 | if (instruction->IsStringAlloc()) { |
| 4181 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4182 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4183 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4184 | __ fs()->movl(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString))); |
| 4185 | __ call(Address(temp, code_offset.Int32Value())); |
| 4186 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4187 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 4188 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 4189 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4190 | DCHECK(!codegen_->IsLeafMethod()); |
| 4191 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4192 | } |
| 4193 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4194 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4195 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4196 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4197 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 4198 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4199 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4200 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4201 | } |
| 4202 | |
| 4203 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4204 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4205 | // of poisoning the reference. |
Nicolas Geoffray | d095844 | 2017-01-30 14:57:16 +0000 | [diff] [blame] | 4206 | QuickEntrypointEnum entrypoint = |
| 4207 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 4208 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4209 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4210 | DCHECK(!codegen_->IsLeafMethod()); |
| 4211 | } |
| 4212 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4213 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4214 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4215 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4216 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4217 | if (location.IsStackSlot()) { |
| 4218 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4219 | } else if (location.IsDoubleStackSlot()) { |
| 4220 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4221 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4222 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4223 | } |
| 4224 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4225 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 4226 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 4227 | } |
| 4228 | |
| 4229 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4230 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4231 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4232 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4233 | } |
| 4234 | |
| 4235 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4236 | } |
| 4237 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4238 | void LocationsBuilderX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4239 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4240 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4241 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4242 | locations->SetOut(Location::RequiresRegister()); |
| 4243 | } |
| 4244 | |
| 4245 | void InstructionCodeGeneratorX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4246 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4247 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4248 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4249 | instruction->GetIndex(), kX86PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4250 | __ movl(locations->Out().AsRegister<Register>(), |
| 4251 | Address(locations->InAt(0).AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4252 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4253 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4254 | instruction->GetIndex(), kX86PointerSize)); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4255 | __ movl(locations->Out().AsRegister<Register>(), |
| 4256 | Address(locations->InAt(0).AsRegister<Register>(), |
| 4257 | mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
| 4258 | // temp = temp->GetImtEntryAt(method_offset); |
| 4259 | __ movl(locations->Out().AsRegister<Register>(), |
| 4260 | Address(locations->Out().AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4261 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4262 | } |
| 4263 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4264 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4265 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4266 | new (GetGraph()->GetAllocator()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4267 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4268 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4269 | } |
| 4270 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4271 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 4272 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4273 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4274 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4275 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4276 | switch (not_->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4277 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4278 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4279 | break; |
| 4280 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4281 | case DataType::Type::kInt64: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4282 | __ notl(out.AsRegisterPairLow<Register>()); |
| 4283 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4284 | break; |
| 4285 | |
| 4286 | default: |
| 4287 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4288 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4289 | } |
| 4290 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4291 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4292 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4293 | new (GetGraph()->GetAllocator()) LocationSummary(bool_not, LocationSummary::kNoCall); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4294 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4295 | locations->SetOut(Location::SameAsFirstInput()); |
| 4296 | } |
| 4297 | |
| 4298 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4299 | LocationSummary* locations = bool_not->GetLocations(); |
| 4300 | Location in = locations->InAt(0); |
| 4301 | Location out = locations->Out(); |
| 4302 | DCHECK(in.Equals(out)); |
| 4303 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 4304 | } |
| 4305 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4306 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4307 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4308 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4309 | switch (compare->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4310 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4311 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4312 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4313 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4314 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4315 | case DataType::Type::kInt32: |
| 4316 | case DataType::Type::kInt64: { |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4317 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4318 | locations->SetInAt(1, Location::Any()); |
| 4319 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4320 | break; |
| 4321 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4322 | case DataType::Type::kFloat32: |
| 4323 | case DataType::Type::kFloat64: { |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4324 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4325 | if (compare->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4326 | DCHECK(compare->InputAt(1)->IsEmittedAtUseSite()); |
| 4327 | } else if (compare->InputAt(1)->IsConstant()) { |
| 4328 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4329 | } else { |
| 4330 | locations->SetInAt(1, Location::Any()); |
| 4331 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4332 | locations->SetOut(Location::RequiresRegister()); |
| 4333 | break; |
| 4334 | } |
| 4335 | default: |
| 4336 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4337 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4338 | } |
| 4339 | |
| 4340 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4341 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4342 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4343 | Location left = locations->InAt(0); |
| 4344 | Location right = locations->InAt(1); |
| 4345 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4346 | NearLabel less, greater, done; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4347 | Condition less_cond = kLess; |
| 4348 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4349 | switch (compare->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4350 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4351 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4352 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4353 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4354 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4355 | case DataType::Type::kInt32: { |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 4356 | codegen_->GenerateIntCompare(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4357 | break; |
| 4358 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4359 | case DataType::Type::kInt64: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4360 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 4361 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 4362 | int32_t val_low = 0; |
| 4363 | int32_t val_high = 0; |
| 4364 | bool right_is_const = false; |
| 4365 | |
| 4366 | if (right.IsConstant()) { |
| 4367 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 4368 | right_is_const = true; |
| 4369 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 4370 | val_low = Low32Bits(val); |
| 4371 | val_high = High32Bits(val); |
| 4372 | } |
| 4373 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4374 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4375 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4376 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4377 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4378 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4379 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4380 | codegen_->Compare32BitValue(left_high, val_high); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4381 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4382 | __ j(kLess, &less); // Signed compare. |
| 4383 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4384 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4385 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4386 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4387 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4388 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4389 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4390 | codegen_->Compare32BitValue(left_low, val_low); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4391 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4392 | less_cond = kBelow; // for CF (unsigned). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4393 | break; |
| 4394 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4395 | case DataType::Type::kFloat32: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4396 | GenerateFPCompare(left, right, compare, false); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4397 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4398 | less_cond = kBelow; // for CF (floats). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4399 | break; |
| 4400 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4401 | case DataType::Type::kFloat64: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4402 | GenerateFPCompare(left, right, compare, true); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4403 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4404 | less_cond = kBelow; // for CF (floats). |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4405 | break; |
| 4406 | } |
| 4407 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4408 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4409 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4410 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4411 | __ movl(out, Immediate(0)); |
| 4412 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4413 | __ j(less_cond, &less); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4414 | |
| 4415 | __ Bind(&greater); |
| 4416 | __ movl(out, Immediate(1)); |
| 4417 | __ jmp(&done); |
| 4418 | |
| 4419 | __ Bind(&less); |
| 4420 | __ movl(out, Immediate(-1)); |
| 4421 | |
| 4422 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4423 | } |
| 4424 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4425 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4426 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4427 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4428 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4429 | locations->SetInAt(i, Location::Any()); |
| 4430 | } |
| 4431 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4432 | } |
| 4433 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4434 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4435 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4436 | } |
| 4437 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4438 | void CodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4439 | /* |
| 4440 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 4441 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 4442 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4443 | */ |
| 4444 | switch (kind) { |
| 4445 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4446 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4447 | break; |
| 4448 | } |
| 4449 | case MemBarrierKind::kAnyStore: |
| 4450 | case MemBarrierKind::kLoadAny: |
| 4451 | case MemBarrierKind::kStoreStore: { |
| 4452 | // nop |
| 4453 | break; |
| 4454 | } |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4455 | case MemBarrierKind::kNTStoreStore: |
| 4456 | // Non-Temporal Store/Store needs an explicit fence. |
| 4457 | MemoryFence(/* non-temporal */ true); |
| 4458 | break; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4459 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4460 | } |
| 4461 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4462 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( |
| 4463 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4464 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4465 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4466 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4467 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4468 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 4469 | Register temp) { |
| 4470 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4471 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4472 | if (!invoke->GetLocations()->Intrinsified()) { |
| 4473 | return location.AsRegister<Register>(); |
| 4474 | } |
| 4475 | // For intrinsics we allow any location, so it may be on the stack. |
| 4476 | if (!location.IsRegister()) { |
| 4477 | __ movl(temp, Address(ESP, location.GetStackIndex())); |
| 4478 | return temp; |
| 4479 | } |
| 4480 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 4481 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 4482 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 4483 | // simple and more robust approach rather that trying to determine if that's the case. |
| 4484 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
Vladimir Marko | 4ee8e29 | 2017-06-02 15:39:30 +0000 | [diff] [blame] | 4485 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 4486 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 4487 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 4488 | __ movl(temp, Address(ESP, stack_offset)); |
| 4489 | return temp; |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4490 | } |
| 4491 | return location.AsRegister<Register>(); |
| 4492 | } |
| 4493 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4494 | void CodeGeneratorX86::GenerateStaticOrDirectCall( |
| 4495 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4496 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4497 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4498 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4499 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4500 | uint32_t offset = |
| 4501 | GetThreadOffset<kX86PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 4502 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4503 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4504 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4505 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4506 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4507 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4508 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 4509 | DCHECK(GetCompilerOptions().IsBootImage()); |
| 4510 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4511 | temp.AsRegister<Register>()); |
| 4512 | __ leal(temp.AsRegister<Register>(), Address(base_reg, CodeGeneratorX86::kDummy32BitOffset)); |
| 4513 | RecordBootMethodPatch(invoke); |
| 4514 | break; |
| 4515 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4516 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4517 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 4518 | break; |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4519 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4520 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4521 | temp.AsRegister<Register>()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4522 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4523 | // Bind a new fixup label at the end of the "movl" insn. |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4524 | __ Bind(NewMethodBssEntryPatch( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4525 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(), |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4526 | MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()))); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4527 | break; |
| 4528 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4529 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 4530 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 4531 | return; // No code pointer retrieval; the runtime performs the call directly. |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4532 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4533 | } |
| 4534 | |
| 4535 | switch (invoke->GetCodePtrLocation()) { |
| 4536 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 4537 | __ call(GetFrameEntryLabel()); |
| 4538 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4539 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4540 | // (callee_method + offset_of_quick_compiled_code)() |
| 4541 | __ call(Address(callee_method.AsRegister<Register>(), |
| 4542 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4543 | kX86PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4544 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4545 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4546 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4547 | |
| 4548 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4549 | } |
| 4550 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4551 | void CodeGeneratorX86::GenerateVirtualCall( |
| 4552 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4553 | Register temp = temp_in.AsRegister<Register>(); |
| 4554 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4555 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4556 | |
| 4557 | // Use the calling convention instead of the location of the receiver, as |
| 4558 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4559 | // slow path, the arguments have been moved to the right place, so here we are |
| 4560 | // guaranteed that the receiver is the first register of the calling convention. |
| 4561 | InvokeDexCallingConvention calling_convention; |
| 4562 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4563 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4564 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4565 | __ movl(temp, Address(receiver, class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4566 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4567 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4568 | // emit a read barrier for the previous class reference load. |
| 4569 | // However this is not required in practice, as this is an |
| 4570 | // intermediate/temporary reference and because the current |
| 4571 | // concurrent copying collector keeps the from-space memory |
| 4572 | // intact/accessible until the end of the marking phase (the |
| 4573 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4574 | __ MaybeUnpoisonHeapReference(temp); |
| 4575 | // temp = temp->GetMethodAt(method_offset); |
| 4576 | __ movl(temp, Address(temp, method_offset)); |
| 4577 | // call temp->GetEntryPoint(); |
| 4578 | __ call(Address( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4579 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4580 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4581 | } |
| 4582 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4583 | void CodeGeneratorX86::RecordBootMethodPatch(HInvokeStaticOrDirect* invoke) { |
| 4584 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 4585 | HX86ComputeBaseMethodAddress* address = |
| 4586 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
| 4587 | boot_image_method_patches_.emplace_back(address, |
| 4588 | *invoke->GetTargetMethod().dex_file, |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 4589 | invoke->GetTargetMethod().index); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4590 | __ Bind(&boot_image_method_patches_.back().label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4591 | } |
| 4592 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4593 | Label* CodeGeneratorX86::NewMethodBssEntryPatch( |
| 4594 | HX86ComputeBaseMethodAddress* method_address, |
| 4595 | MethodReference target_method) { |
| 4596 | // Add the patch entry and bind its label at the end of the instruction. |
| 4597 | method_bss_entry_patches_.emplace_back(method_address, |
| 4598 | *target_method.dex_file, |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 4599 | target_method.index); |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4600 | return &method_bss_entry_patches_.back().label; |
| 4601 | } |
| 4602 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4603 | void CodeGeneratorX86::RecordBootTypePatch(HLoadClass* load_class) { |
Vladimir Marko | 00916b9 | 2017-05-17 17:45:45 +0100 | [diff] [blame] | 4604 | HX86ComputeBaseMethodAddress* address = load_class->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4605 | boot_image_type_patches_.emplace_back(address, |
| 4606 | load_class->GetDexFile(), |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4607 | load_class->GetTypeIndex().index_); |
| 4608 | __ Bind(&boot_image_type_patches_.back().label); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4609 | } |
| 4610 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4611 | Label* CodeGeneratorX86::NewTypeBssEntryPatch(HLoadClass* load_class) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4612 | HX86ComputeBaseMethodAddress* address = |
| 4613 | load_class->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 4614 | type_bss_entry_patches_.emplace_back( |
| 4615 | address, load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4616 | return &type_bss_entry_patches_.back().label; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4617 | } |
| 4618 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4619 | void CodeGeneratorX86::RecordBootStringPatch(HLoadString* load_string) { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4620 | HX86ComputeBaseMethodAddress* address = load_string->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 4621 | string_patches_.emplace_back(address, |
| 4622 | load_string->GetDexFile(), |
| 4623 | load_string->GetStringIndex().index_); |
| 4624 | __ Bind(&string_patches_.back().label); |
| 4625 | } |
| 4626 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4627 | Label* CodeGeneratorX86::NewStringBssEntryPatch(HLoadString* load_string) { |
| 4628 | DCHECK(!GetCompilerOptions().IsBootImage()); |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4629 | HX86ComputeBaseMethodAddress* address = |
| 4630 | load_string->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4631 | string_bss_entry_patches_.emplace_back( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4632 | address, load_string->GetDexFile(), load_string->GetStringIndex().index_); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4633 | return &string_bss_entry_patches_.back().label; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4634 | } |
| 4635 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4636 | // The label points to the end of the "movl" or another instruction but the literal offset |
| 4637 | // for method patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 4638 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
| 4639 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4640 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4641 | inline void CodeGeneratorX86::EmitPcRelativeLinkerPatches( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4642 | const ArenaDeque<X86PcRelativePatchInfo>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4643 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4644 | for (const X86PcRelativePatchInfo& info : infos) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4645 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4646 | linker_patches->push_back(Factory( |
| 4647 | literal_offset, &info.dex_file, GetMethodAddressOffset(info.method_address), info.index)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4648 | } |
| 4649 | } |
| 4650 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4651 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4652 | DCHECK(linker_patches->empty()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4653 | size_t size = |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4654 | boot_image_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4655 | method_bss_entry_patches_.size() + |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4656 | boot_image_type_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4657 | type_bss_entry_patches_.size() + |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4658 | string_patches_.size() + |
| 4659 | string_bss_entry_patches_.size(); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4660 | linker_patches->reserve(size); |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 4661 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4662 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
| 4663 | boot_image_method_patches_, linker_patches); |
| 4664 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
| 4665 | boot_image_type_patches_, linker_patches); |
| 4666 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
| 4667 | string_patches_, linker_patches); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4668 | } else { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4669 | DCHECK(boot_image_method_patches_.empty()); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4670 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeClassTablePatch>( |
| 4671 | boot_image_type_patches_, linker_patches); |
| 4672 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringInternTablePatch>( |
| 4673 | string_patches_, linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4674 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4675 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 4676 | method_bss_entry_patches_, linker_patches); |
| 4677 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 4678 | type_bss_entry_patches_, linker_patches); |
| 4679 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 4680 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4681 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4682 | } |
| 4683 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4684 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 4685 | Register card, |
| 4686 | Register object, |
| 4687 | Register value, |
| 4688 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4689 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4690 | if (value_can_be_null) { |
| 4691 | __ testl(value, value); |
| 4692 | __ j(kEqual, &is_null); |
| 4693 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4694 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86PointerSize>().Int32Value())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4695 | __ movl(temp, object); |
| 4696 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4697 | __ movb(Address(temp, card, TIMES_1, 0), |
| 4698 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4699 | if (value_can_be_null) { |
| 4700 | __ Bind(&is_null); |
| 4701 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4702 | } |
| 4703 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4704 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4705 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4706 | |
| 4707 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4708 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4709 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4710 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 4711 | kEmitCompilerReadBarrier |
| 4712 | ? LocationSummary::kCallOnSlowPath |
| 4713 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4714 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4715 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4716 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4717 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4718 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4719 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4720 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4721 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4722 | // The output overlaps in case of long: we don't want the low move |
| 4723 | // to overwrite the object's location. Likewise, in the case of |
| 4724 | // an object field get with read barriers enabled, we do not want |
| 4725 | // the move to overwrite the object's location, as we need it to emit |
| 4726 | // the read barrier. |
| 4727 | locations->SetOut( |
| 4728 | Location::RequiresRegister(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4729 | (object_field_get_with_read_barrier || instruction->GetType() == DataType::Type::kInt64) ? |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4730 | Location::kOutputOverlap : |
| 4731 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4732 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4733 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4734 | if (field_info.IsVolatile() && (field_info.GetFieldType() == DataType::Type::kInt64)) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4735 | // Long values can be loaded atomically into an XMM using movsd. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4736 | // So we use an XMM register as a temp to achieve atomicity (first |
| 4737 | // load the temp into the XMM and then copy the XMM into the |
| 4738 | // output, 32 bits at a time). |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4739 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4740 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4741 | } |
| 4742 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4743 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 4744 | const FieldInfo& field_info) { |
| 4745 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4746 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4747 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4748 | Location base_loc = locations->InAt(0); |
| 4749 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4750 | Location out = locations->Out(); |
| 4751 | bool is_volatile = field_info.IsVolatile(); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4752 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 4753 | DataType::Type load_type = instruction->GetType(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4754 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4755 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4756 | switch (load_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4757 | case DataType::Type::kBool: |
| 4758 | case DataType::Type::kUint8: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4759 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4760 | break; |
| 4761 | } |
| 4762 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4763 | case DataType::Type::kInt8: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4764 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4765 | break; |
| 4766 | } |
| 4767 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4768 | case DataType::Type::kUint16: { |
| 4769 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4770 | break; |
| 4771 | } |
| 4772 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4773 | case DataType::Type::kInt16: { |
| 4774 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4775 | break; |
| 4776 | } |
| 4777 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4778 | case DataType::Type::kInt32: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4779 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4780 | break; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4781 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4782 | case DataType::Type::kReference: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4783 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4784 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4785 | // Note that a potential implicit null check is handled in this |
| 4786 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 4787 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 4788 | instruction, out, base, offset, /* needs_null_check */ true); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4789 | if (is_volatile) { |
| 4790 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4791 | } |
| 4792 | } else { |
| 4793 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| 4794 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4795 | if (is_volatile) { |
| 4796 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4797 | } |
| 4798 | // If read barriers are enabled, emit read barriers other than |
| 4799 | // Baker's using a slow path (and also unpoison the loaded |
| 4800 | // reference, if heap poisoning is enabled). |
| 4801 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4802 | } |
| 4803 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4804 | } |
| 4805 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4806 | case DataType::Type::kInt64: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4807 | if (is_volatile) { |
| 4808 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4809 | __ movsd(temp, 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 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 4812 | __ psrlq(temp, Immediate(32)); |
| 4813 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 4814 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4815 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4816 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4817 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4818 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 4819 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4820 | break; |
| 4821 | } |
| 4822 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4823 | case DataType::Type::kFloat32: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4824 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4825 | break; |
| 4826 | } |
| 4827 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4828 | case DataType::Type::kFloat64: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4829 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4830 | break; |
| 4831 | } |
| 4832 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4833 | case DataType::Type::kVoid: |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4834 | LOG(FATAL) << "Unreachable type " << load_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4835 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4836 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4837 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4838 | if (load_type == DataType::Type::kReference || load_type == DataType::Type::kInt64) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4839 | // Potential implicit null checks, in the case of reference or |
| 4840 | // long fields, are handled in the previous switch statement. |
| 4841 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4842 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4843 | } |
| 4844 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4845 | if (is_volatile) { |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4846 | if (load_type == DataType::Type::kReference) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4847 | // Memory barriers, in the case of references, are also handled |
| 4848 | // in the previous switch statement. |
| 4849 | } else { |
| 4850 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4851 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4852 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4853 | } |
| 4854 | |
| 4855 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4856 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4857 | |
| 4858 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4859 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4860 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4861 | bool is_volatile = field_info.IsVolatile(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4862 | DataType::Type field_type = field_info.GetFieldType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4863 | bool is_byte_type = DataType::Size(field_type) == 1u; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4864 | |
| 4865 | // The register allocator does not support multiple |
| 4866 | // inputs that die at entry with one in a specific register. |
| 4867 | if (is_byte_type) { |
| 4868 | // Ensure the value is in a byte register. |
| 4869 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4870 | } else if (DataType::IsFloatingPointType(field_type)) { |
| 4871 | if (is_volatile && field_type == DataType::Type::kFloat64) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4872 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4873 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4874 | } else { |
| 4875 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4876 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4877 | } else if (is_volatile && field_type == DataType::Type::kInt64) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4878 | // 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] | 4879 | locations->SetInAt(1, Location::RequiresRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4880 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4881 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 4882 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 4883 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 4884 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 4885 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 4886 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4887 | locations->AddTemp(Location::RequiresFpuRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4888 | } else { |
| 4889 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4890 | |
| 4891 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4892 | // Temporary registers for the write barrier. |
| 4893 | locations->AddTemp(Location::RequiresRegister()); // May be used for reference poisoning too. |
| 4894 | // Ensure the card is in a byte register. |
| 4895 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 4896 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4897 | } |
| 4898 | } |
| 4899 | |
| 4900 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4901 | const FieldInfo& field_info, |
| 4902 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4903 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4904 | |
| 4905 | LocationSummary* locations = instruction->GetLocations(); |
| 4906 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 4907 | Location value = locations->InAt(1); |
| 4908 | bool is_volatile = field_info.IsVolatile(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4909 | DataType::Type field_type = field_info.GetFieldType(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4910 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4911 | bool needs_write_barrier = |
| 4912 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4913 | |
| 4914 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4915 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4916 | } |
| 4917 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4918 | bool maybe_record_implicit_null_check_done = false; |
| 4919 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4920 | switch (field_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4921 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4922 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4923 | case DataType::Type::kInt8: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4924 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 4925 | break; |
| 4926 | } |
| 4927 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4928 | case DataType::Type::kUint16: |
| 4929 | case DataType::Type::kInt16: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4930 | if (value.IsConstant()) { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 4931 | __ movw(Address(base, offset), |
| 4932 | Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4933 | } else { |
| 4934 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 4935 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4936 | break; |
| 4937 | } |
| 4938 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4939 | case DataType::Type::kInt32: |
| 4940 | case DataType::Type::kReference: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4941 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4942 | // Note that in the case where `value` is a null reference, |
| 4943 | // we do not enter this block, as the reference does not |
| 4944 | // need poisoning. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4945 | DCHECK_EQ(field_type, DataType::Type::kReference); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4946 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4947 | __ movl(temp, value.AsRegister<Register>()); |
| 4948 | __ PoisonHeapReference(temp); |
| 4949 | __ movl(Address(base, offset), temp); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4950 | } else if (value.IsConstant()) { |
| 4951 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4952 | __ movl(Address(base, offset), Immediate(v)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4953 | } else { |
Nicolas Geoffray | 0397163 | 2016-03-17 10:44:24 +0000 | [diff] [blame] | 4954 | DCHECK(value.IsRegister()) << value; |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4955 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 4956 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4957 | break; |
| 4958 | } |
| 4959 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4960 | case DataType::Type::kInt64: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4961 | if (is_volatile) { |
| 4962 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4963 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 4964 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 4965 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 4966 | __ punpckldq(temp1, temp2); |
| 4967 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4968 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4969 | } else if (value.IsConstant()) { |
| 4970 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4971 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4972 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4973 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4974 | } else { |
| 4975 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4976 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4977 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 4978 | } |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4979 | maybe_record_implicit_null_check_done = true; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4980 | break; |
| 4981 | } |
| 4982 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4983 | case DataType::Type::kFloat32: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4984 | if (value.IsConstant()) { |
| 4985 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4986 | __ movl(Address(base, offset), Immediate(v)); |
| 4987 | } else { |
| 4988 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4989 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4990 | break; |
| 4991 | } |
| 4992 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4993 | case DataType::Type::kFloat64: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4994 | if (value.IsConstant()) { |
| 4995 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4996 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4997 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4998 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
| 4999 | maybe_record_implicit_null_check_done = true; |
| 5000 | } else { |
| 5001 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 5002 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5003 | break; |
| 5004 | } |
| 5005 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5006 | case DataType::Type::kVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5007 | LOG(FATAL) << "Unreachable type " << field_type; |
| 5008 | UNREACHABLE(); |
| 5009 | } |
| 5010 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5011 | if (!maybe_record_implicit_null_check_done) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5012 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5013 | } |
| 5014 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5015 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5016 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5017 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5018 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5019 | } |
| 5020 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5021 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5022 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5023 | } |
| 5024 | } |
| 5025 | |
| 5026 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5027 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5028 | } |
| 5029 | |
| 5030 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5031 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5032 | } |
| 5033 | |
| 5034 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 5035 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5036 | } |
| 5037 | |
| 5038 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5039 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5040 | } |
| 5041 | |
| 5042 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5043 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5044 | } |
| 5045 | |
| 5046 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5047 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5048 | } |
| 5049 | |
| 5050 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5051 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5052 | } |
| 5053 | |
| 5054 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5055 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5056 | } |
| 5057 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5058 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 5059 | HUnresolvedInstanceFieldGet* instruction) { |
| 5060 | FieldAccessCallingConventionX86 calling_convention; |
| 5061 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5062 | instruction, instruction->GetFieldType(), calling_convention); |
| 5063 | } |
| 5064 | |
| 5065 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 5066 | HUnresolvedInstanceFieldGet* instruction) { |
| 5067 | FieldAccessCallingConventionX86 calling_convention; |
| 5068 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5069 | instruction->GetFieldType(), |
| 5070 | instruction->GetFieldIndex(), |
| 5071 | instruction->GetDexPc(), |
| 5072 | calling_convention); |
| 5073 | } |
| 5074 | |
| 5075 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 5076 | HUnresolvedInstanceFieldSet* instruction) { |
| 5077 | FieldAccessCallingConventionX86 calling_convention; |
| 5078 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5079 | instruction, instruction->GetFieldType(), calling_convention); |
| 5080 | } |
| 5081 | |
| 5082 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 5083 | HUnresolvedInstanceFieldSet* instruction) { |
| 5084 | FieldAccessCallingConventionX86 calling_convention; |
| 5085 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5086 | instruction->GetFieldType(), |
| 5087 | instruction->GetFieldIndex(), |
| 5088 | instruction->GetDexPc(), |
| 5089 | calling_convention); |
| 5090 | } |
| 5091 | |
| 5092 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 5093 | HUnresolvedStaticFieldGet* instruction) { |
| 5094 | FieldAccessCallingConventionX86 calling_convention; |
| 5095 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5096 | instruction, instruction->GetFieldType(), calling_convention); |
| 5097 | } |
| 5098 | |
| 5099 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 5100 | HUnresolvedStaticFieldGet* instruction) { |
| 5101 | FieldAccessCallingConventionX86 calling_convention; |
| 5102 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5103 | instruction->GetFieldType(), |
| 5104 | instruction->GetFieldIndex(), |
| 5105 | instruction->GetDexPc(), |
| 5106 | calling_convention); |
| 5107 | } |
| 5108 | |
| 5109 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 5110 | HUnresolvedStaticFieldSet* instruction) { |
| 5111 | FieldAccessCallingConventionX86 calling_convention; |
| 5112 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5113 | instruction, instruction->GetFieldType(), calling_convention); |
| 5114 | } |
| 5115 | |
| 5116 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 5117 | HUnresolvedStaticFieldSet* instruction) { |
| 5118 | FieldAccessCallingConventionX86 calling_convention; |
| 5119 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5120 | instruction->GetFieldType(), |
| 5121 | instruction->GetFieldIndex(), |
| 5122 | instruction->GetDexPc(), |
| 5123 | calling_convention); |
| 5124 | } |
| 5125 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5126 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5127 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5128 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 5129 | ? Location::RequiresRegister() |
| 5130 | : Location::Any(); |
| 5131 | locations->SetInAt(0, loc); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5132 | } |
| 5133 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5134 | void CodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5135 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5136 | return; |
| 5137 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5138 | LocationSummary* locations = instruction->GetLocations(); |
| 5139 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5140 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5141 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5142 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5143 | } |
| 5144 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5145 | void CodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5146 | SlowPathCode* slow_path = new (GetScopedAllocator()) NullCheckSlowPathX86(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5147 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5148 | |
| 5149 | LocationSummary* locations = instruction->GetLocations(); |
| 5150 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5151 | |
| 5152 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 5153 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5154 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5155 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5156 | } else { |
| 5157 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5158 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5159 | __ jmp(slow_path->GetEntryLabel()); |
| 5160 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5161 | } |
| 5162 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5163 | } |
| 5164 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5165 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5166 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5167 | } |
| 5168 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5169 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5170 | bool object_array_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5171 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5172 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5173 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 5174 | object_array_get_with_read_barrier |
| 5175 | ? LocationSummary::kCallOnSlowPath |
| 5176 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5177 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5178 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5179 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5180 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5181 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5182 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5183 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5184 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5185 | // The output overlaps in case of long: we don't want the low move |
| 5186 | // to overwrite the array's location. Likewise, in the case of an |
| 5187 | // object array get with read barriers enabled, we do not want the |
| 5188 | // move to overwrite the array's location, as we need it to emit |
| 5189 | // the read barrier. |
| 5190 | locations->SetOut( |
| 5191 | Location::RequiresRegister(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5192 | (instruction->GetType() == DataType::Type::kInt64 || object_array_get_with_read_barrier) |
| 5193 | ? Location::kOutputOverlap |
| 5194 | : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5195 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5196 | } |
| 5197 | |
| 5198 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 5199 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5200 | Location obj_loc = locations->InAt(0); |
| 5201 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5202 | Location index = locations->InAt(1); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5203 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5204 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5205 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5206 | DataType::Type type = instruction->GetType(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5207 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5208 | case DataType::Type::kBool: |
| 5209 | case DataType::Type::kUint8: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5210 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5211 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5212 | break; |
| 5213 | } |
| 5214 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5215 | case DataType::Type::kInt8: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5216 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5217 | __ movsxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5218 | break; |
| 5219 | } |
| 5220 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5221 | case DataType::Type::kUint16: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5222 | Register out = out_loc.AsRegister<Register>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5223 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5224 | // Branch cases into compressed and uncompressed for each index's type. |
| 5225 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 5226 | NearLabel done, not_compressed; |
Vladimir Marko | 3c89d42 | 2017-02-17 11:30:23 +0000 | [diff] [blame] | 5227 | __ testb(Address(obj, count_offset), Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5228 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5229 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 5230 | "Expecting 0=compressed, 1=uncompressed"); |
| 5231 | __ j(kNotZero, ¬_compressed); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5232 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| 5233 | __ jmp(&done); |
| 5234 | __ Bind(¬_compressed); |
| 5235 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5236 | __ Bind(&done); |
| 5237 | } else { |
| 5238 | // Common case for charAt of array of char or when string compression's |
| 5239 | // feature is turned off. |
| 5240 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5241 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5242 | break; |
| 5243 | } |
| 5244 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5245 | case DataType::Type::kInt16: { |
| 5246 | Register out = out_loc.AsRegister<Register>(); |
| 5247 | __ movsxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5248 | break; |
| 5249 | } |
| 5250 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5251 | case DataType::Type::kInt32: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5252 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5253 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5254 | break; |
| 5255 | } |
| 5256 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5257 | case DataType::Type::kReference: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5258 | static_assert( |
| 5259 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5260 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5261 | // /* HeapReference<Object> */ out = |
| 5262 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5263 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5264 | // Note that a potential implicit null check is handled in this |
| 5265 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 5266 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5267 | instruction, out_loc, obj, data_offset, index, /* needs_null_check */ true); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5268 | } else { |
| 5269 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5270 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| 5271 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5272 | // If read barriers are enabled, emit read barriers other than |
| 5273 | // Baker's using a slow path (and also unpoison the loaded |
| 5274 | // reference, if heap poisoning is enabled). |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5275 | if (index.IsConstant()) { |
| 5276 | uint32_t offset = |
| 5277 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5278 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5279 | } else { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5280 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5281 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5282 | } |
| 5283 | } |
| 5284 | break; |
| 5285 | } |
| 5286 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5287 | case DataType::Type::kInt64: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5288 | DCHECK_NE(obj, out_loc.AsRegisterPairLow<Register>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5289 | __ movl(out_loc.AsRegisterPairLow<Register>(), |
| 5290 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
| 5291 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5292 | __ movl(out_loc.AsRegisterPairHigh<Register>(), |
| 5293 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5294 | break; |
| 5295 | } |
| 5296 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5297 | case DataType::Type::kFloat32: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5298 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5299 | __ movss(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5300 | break; |
| 5301 | } |
| 5302 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5303 | case DataType::Type::kFloat64: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5304 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5305 | __ movsd(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5306 | break; |
| 5307 | } |
| 5308 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5309 | case DataType::Type::kVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5310 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5311 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5312 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5313 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5314 | if (type == DataType::Type::kReference || type == DataType::Type::kInt64) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5315 | // Potential implicit null checks, in the case of reference or |
| 5316 | // long arrays, are handled in the previous switch statement. |
| 5317 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5318 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5319 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5320 | } |
| 5321 | |
| 5322 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5323 | DataType::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5324 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5325 | bool needs_write_barrier = |
| 5326 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5327 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5328 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5329 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5330 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 5331 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5332 | LocationSummary::kCallOnSlowPath : |
| 5333 | LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5334 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5335 | bool is_byte_type = DataType::Size(value_type) == 1u; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5336 | // We need the inputs to be different than the output in case of long operation. |
| 5337 | // In case of a byte operation, the register allocator does not support multiple |
| 5338 | // inputs that die at entry with one in a specific register. |
| 5339 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5340 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5341 | if (is_byte_type) { |
| 5342 | // Ensure the value is in a byte register. |
| 5343 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5344 | } else if (DataType::IsFloatingPointType(value_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5345 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5346 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5347 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 5348 | } |
| 5349 | if (needs_write_barrier) { |
| 5350 | // Temporary registers for the write barrier. |
| 5351 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 5352 | // Ensure the card is in a byte register. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5353 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5354 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5355 | } |
| 5356 | |
| 5357 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 5358 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5359 | Location array_loc = locations->InAt(0); |
| 5360 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5361 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5362 | Location value = locations->InAt(2); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5363 | DataType::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5364 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5365 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5366 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5367 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5368 | bool needs_write_barrier = |
| 5369 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5370 | |
| 5371 | switch (value_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5372 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5373 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5374 | case DataType::Type::kInt8: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5375 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5376 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_1, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5377 | if (value.IsRegister()) { |
| 5378 | __ movb(address, value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5379 | } else { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5380 | __ movb(address, Immediate(CodeGenerator::GetInt8ValueOf(value.GetConstant()))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5381 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5382 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5383 | break; |
| 5384 | } |
| 5385 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5386 | case DataType::Type::kUint16: |
| 5387 | case DataType::Type::kInt16: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5388 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5389 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_2, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5390 | if (value.IsRegister()) { |
| 5391 | __ movw(address, value.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5392 | } else { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5393 | __ movw(address, Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5394 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5395 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5396 | break; |
| 5397 | } |
| 5398 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5399 | case DataType::Type::kReference: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5400 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5401 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5402 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5403 | if (!value.IsRegister()) { |
| 5404 | // Just setting null. |
| 5405 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5406 | DCHECK(value.IsConstant()) << value; |
| 5407 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5408 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5409 | DCHECK(!needs_write_barrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5410 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5411 | break; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5412 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5413 | |
| 5414 | DCHECK(needs_write_barrier); |
| 5415 | Register register_value = value.AsRegister<Register>(); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5416 | // We cannot use a NearLabel for `done`, as its range may be too |
| 5417 | // short when Baker read barriers are enabled. |
| 5418 | Label done; |
| 5419 | NearLabel not_null, do_put; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5420 | SlowPathCode* slow_path = nullptr; |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5421 | Location temp_loc = locations->GetTemp(0); |
| 5422 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5423 | if (may_need_runtime_call_for_type_check) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5424 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathX86(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5425 | codegen_->AddSlowPath(slow_path); |
| 5426 | if (instruction->GetValueCanBeNull()) { |
| 5427 | __ testl(register_value, register_value); |
| 5428 | __ j(kNotEqual, ¬_null); |
| 5429 | __ movl(address, Immediate(0)); |
| 5430 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5431 | __ jmp(&done); |
| 5432 | __ Bind(¬_null); |
| 5433 | } |
| 5434 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5435 | // Note that when Baker read barriers are enabled, the type |
| 5436 | // checks are performed without read barriers. This is fine, |
| 5437 | // even in the case where a class object is in the from-space |
| 5438 | // after the flip, as a comparison involving such a type would |
| 5439 | // not produce a false positive; it may of course produce a |
| 5440 | // false negative, in which case we would take the ArraySet |
| 5441 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5442 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5443 | // /* HeapReference<Class> */ temp = array->klass_ |
| 5444 | __ movl(temp, Address(array, class_offset)); |
| 5445 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5446 | __ MaybeUnpoisonHeapReference(temp); |
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 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5449 | __ movl(temp, Address(temp, component_offset)); |
| 5450 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 5451 | // nor the object reference in `register_value->klass`, as |
| 5452 | // we are comparing two poisoned references. |
| 5453 | __ cmpl(temp, Address(register_value, class_offset)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5454 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5455 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5456 | __ j(kEqual, &do_put); |
| 5457 | // If heap poisoning is enabled, the `temp` reference has |
| 5458 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5459 | __ MaybeUnpoisonHeapReference(temp); |
| 5460 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5461 | // If heap poisoning is enabled, no need to unpoison the |
| 5462 | // heap reference loaded below, as it is only used for a |
| 5463 | // comparison with null. |
| 5464 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 5465 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5466 | __ Bind(&do_put); |
| 5467 | } else { |
| 5468 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5469 | } |
| 5470 | } |
| 5471 | |
| 5472 | if (kPoisonHeapReferences) { |
| 5473 | __ movl(temp, register_value); |
| 5474 | __ PoisonHeapReference(temp); |
| 5475 | __ movl(address, temp); |
| 5476 | } else { |
| 5477 | __ movl(address, register_value); |
| 5478 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5479 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5480 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5481 | } |
| 5482 | |
| 5483 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 5484 | codegen_->MarkGCCard( |
| 5485 | temp, card, array, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); |
| 5486 | __ Bind(&done); |
| 5487 | |
| 5488 | if (slow_path != nullptr) { |
| 5489 | __ Bind(slow_path->GetExitLabel()); |
| 5490 | } |
| 5491 | |
| 5492 | break; |
| 5493 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5494 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5495 | case DataType::Type::kInt32: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5496 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5497 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5498 | if (value.IsRegister()) { |
| 5499 | __ movl(address, value.AsRegister<Register>()); |
| 5500 | } else { |
| 5501 | DCHECK(value.IsConstant()) << value; |
| 5502 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5503 | __ movl(address, Immediate(v)); |
| 5504 | } |
| 5505 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5506 | break; |
| 5507 | } |
| 5508 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5509 | case DataType::Type::kInt64: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5510 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5511 | if (value.IsRegisterPair()) { |
| 5512 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 5513 | value.AsRegisterPairLow<Register>()); |
| 5514 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5515 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 5516 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5517 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5518 | DCHECK(value.IsConstant()); |
| 5519 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
| 5520 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 5521 | Immediate(Low32Bits(val))); |
| 5522 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5523 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 5524 | Immediate(High32Bits(val))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5525 | } |
| 5526 | break; |
| 5527 | } |
| 5528 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5529 | case DataType::Type::kFloat32: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5530 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5531 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5532 | if (value.IsFpuRegister()) { |
| 5533 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5534 | } else { |
| 5535 | DCHECK(value.IsConstant()); |
| 5536 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 5537 | __ movl(address, Immediate(v)); |
| 5538 | } |
| 5539 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5540 | break; |
| 5541 | } |
| 5542 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5543 | case DataType::Type::kFloat64: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5544 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5545 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5546 | if (value.IsFpuRegister()) { |
| 5547 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5548 | } else { |
| 5549 | DCHECK(value.IsConstant()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5550 | Address address_hi = |
| 5551 | CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset + kX86WordSize); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5552 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 5553 | __ movl(address, Immediate(Low32Bits(v))); |
| 5554 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5555 | __ movl(address_hi, Immediate(High32Bits(v))); |
| 5556 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5557 | break; |
| 5558 | } |
| 5559 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5560 | case DataType::Type::kVoid: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5561 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5562 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5563 | } |
| 5564 | } |
| 5565 | |
| 5566 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5567 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5568 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5569 | if (!instruction->IsEmittedAtUseSite()) { |
| 5570 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5571 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5572 | } |
| 5573 | |
| 5574 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5575 | if (instruction->IsEmittedAtUseSite()) { |
| 5576 | return; |
| 5577 | } |
| 5578 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5579 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5580 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5581 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5582 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5583 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5584 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5585 | // Mask out most significant bit in case the array is String's array of char. |
| 5586 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5587 | __ shrl(out, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5588 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5589 | } |
| 5590 | |
| 5591 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5592 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5593 | InvokeRuntimeCallingConvention calling_convention; |
| 5594 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5595 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5596 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5597 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5598 | HInstruction* length = instruction->InputAt(1); |
| 5599 | if (!length->IsEmittedAtUseSite()) { |
| 5600 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5601 | } |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5602 | // Need register to see array's length. |
| 5603 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5604 | locations->AddTemp(Location::RequiresRegister()); |
| 5605 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5606 | } |
| 5607 | |
| 5608 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5609 | const bool is_string_compressed_char_at = |
| 5610 | mirror::kUseStringCompression && instruction->IsStringCharAt(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5611 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5612 | Location index_loc = locations->InAt(0); |
| 5613 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5614 | SlowPathCode* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5615 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathX86(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5616 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5617 | if (length_loc.IsConstant()) { |
| 5618 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5619 | if (index_loc.IsConstant()) { |
| 5620 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5621 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5622 | if (index < 0 || index >= length) { |
| 5623 | codegen_->AddSlowPath(slow_path); |
| 5624 | __ jmp(slow_path->GetEntryLabel()); |
| 5625 | } else { |
| 5626 | // Some optimization after BCE may have generated this, and we should not |
| 5627 | // generate a bounds check if it is a valid range. |
| 5628 | } |
| 5629 | return; |
| 5630 | } |
| 5631 | |
| 5632 | // We have to reverse the jump condition because the length is the constant. |
| 5633 | Register index_reg = index_loc.AsRegister<Register>(); |
| 5634 | __ cmpl(index_reg, Immediate(length)); |
| 5635 | codegen_->AddSlowPath(slow_path); |
| 5636 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5637 | } else { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5638 | HInstruction* array_length = instruction->InputAt(1); |
| 5639 | if (array_length->IsEmittedAtUseSite()) { |
| 5640 | // Address the length field in the array. |
| 5641 | DCHECK(array_length->IsArrayLength()); |
| 5642 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 5643 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 5644 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5645 | if (is_string_compressed_char_at) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5646 | // TODO: if index_loc.IsConstant(), compare twice the index (to compensate for |
| 5647 | // the string compression flag) with the in-memory length and avoid the temporary. |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5648 | Register length_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 5649 | __ movl(length_reg, array_len); |
| 5650 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5651 | __ shrl(length_reg, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5652 | codegen_->GenerateIntCompare(length_reg, index_loc); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5653 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5654 | // Checking bounds for general case: |
| 5655 | // Array of char or string's array with feature compression off. |
| 5656 | if (index_loc.IsConstant()) { |
| 5657 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5658 | __ cmpl(array_len, Immediate(value)); |
| 5659 | } else { |
| 5660 | __ cmpl(array_len, index_loc.AsRegister<Register>()); |
| 5661 | } |
| 5662 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5663 | } |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5664 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5665 | codegen_->GenerateIntCompare(length_loc, index_loc); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5666 | } |
| 5667 | codegen_->AddSlowPath(slow_path); |
| 5668 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5669 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5670 | } |
| 5671 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5672 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5673 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5674 | } |
| 5675 | |
| 5676 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 5677 | if (instruction->GetNext()->IsSuspendCheck() && |
| 5678 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 5679 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 5680 | // The back edge will generate the suspend check. |
| 5681 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 5682 | } |
| 5683 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5684 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5685 | } |
| 5686 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5687 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5688 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5689 | instruction, LocationSummary::kCallOnSlowPath); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 5690 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 5691 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 5692 | // registers in full width (since the runtime only saves/restores lower part). |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5693 | locations->SetCustomSlowPathCallerSaves( |
| 5694 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5695 | } |
| 5696 | |
| 5697 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5698 | HBasicBlock* block = instruction->GetBlock(); |
| 5699 | if (block->GetLoopInformation() != nullptr) { |
| 5700 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5701 | // The back edge will generate the suspend check. |
| 5702 | return; |
| 5703 | } |
| 5704 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5705 | // The goto will generate the suspend check. |
| 5706 | return; |
| 5707 | } |
| 5708 | GenerateSuspendCheck(instruction, nullptr); |
| 5709 | } |
| 5710 | |
| 5711 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5712 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5713 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5714 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 5715 | if (slow_path == nullptr) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5716 | slow_path = |
| 5717 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathX86(instruction, successor); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5718 | instruction->SetSlowPath(slow_path); |
| 5719 | codegen_->AddSlowPath(slow_path); |
| 5720 | if (successor != nullptr) { |
| 5721 | DCHECK(successor->IsLoopHeader()); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5722 | } |
| 5723 | } else { |
| 5724 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5725 | } |
| 5726 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5727 | __ fs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86PointerSize>().Int32Value()), |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5728 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5729 | if (successor == nullptr) { |
| 5730 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5731 | __ Bind(slow_path->GetReturnLabel()); |
| 5732 | } else { |
| 5733 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5734 | __ jmp(slow_path->GetEntryLabel()); |
| 5735 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5736 | } |
| 5737 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5738 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 5739 | return codegen_->GetAssembler(); |
| 5740 | } |
| 5741 | |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5742 | void ParallelMoveResolverX86::MoveMemoryToMemory(int dst, int src, int number_of_words) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5743 | ScratchRegisterScope ensure_scratch( |
| 5744 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5745 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5746 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5747 | |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5748 | // Now that temp register is available (possibly spilled), move blocks of memory. |
| 5749 | for (int i = 0; i < number_of_words; i++) { |
| 5750 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5751 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 5752 | stack_offset += kX86WordSize; |
| 5753 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5754 | } |
| 5755 | |
| 5756 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5757 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5758 | Location source = move->GetSource(); |
| 5759 | Location destination = move->GetDestination(); |
| 5760 | |
| 5761 | if (source.IsRegister()) { |
| 5762 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5763 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5764 | } else if (destination.IsFpuRegister()) { |
| 5765 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5766 | } else { |
| 5767 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5768 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5769 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5770 | } else if (source.IsRegisterPair()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5771 | size_t elem_size = DataType::Size(DataType::Type::kInt32); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5772 | // Create stack space for 2 elements. |
| 5773 | __ subl(ESP, Immediate(2 * elem_size)); |
| 5774 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 5775 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 5776 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 5777 | // And remove the temporary stack space we allocated. |
| 5778 | __ addl(ESP, Immediate(2 * elem_size)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5779 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5780 | if (destination.IsRegister()) { |
| 5781 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
| 5782 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5783 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5784 | } else if (destination.IsRegisterPair()) { |
| 5785 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 5786 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 5787 | __ psrlq(src_reg, Immediate(32)); |
| 5788 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5789 | } else if (destination.IsStackSlot()) { |
| 5790 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5791 | } else if (destination.IsDoubleStackSlot()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5792 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5793 | } else { |
| 5794 | DCHECK(destination.IsSIMDStackSlot()); |
| 5795 | __ movups(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5796 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5797 | } else if (source.IsStackSlot()) { |
| 5798 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5799 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5800 | } else if (destination.IsFpuRegister()) { |
| 5801 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5802 | } else { |
| 5803 | DCHECK(destination.IsStackSlot()); |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5804 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 1); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5805 | } |
| 5806 | } else if (source.IsDoubleStackSlot()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5807 | if (destination.IsRegisterPair()) { |
| 5808 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 5809 | __ movl(destination.AsRegisterPairHigh<Register>(), |
| 5810 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 5811 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5812 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 5813 | } else { |
| 5814 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5815 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 2); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5816 | } |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5817 | } else if (source.IsSIMDStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5818 | if (destination.IsFpuRegister()) { |
| 5819 | __ movups(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 5820 | } else { |
| 5821 | DCHECK(destination.IsSIMDStackSlot()); |
| 5822 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 4); |
| 5823 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5824 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5825 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5826 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5827 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5828 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5829 | if (value == 0) { |
| 5830 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5831 | } else { |
| 5832 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 5833 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5834 | } else { |
| 5835 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5836 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5837 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5838 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5839 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5840 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5841 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5842 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5843 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5844 | if (value == 0) { |
| 5845 | // Easy handling of 0.0. |
| 5846 | __ xorps(dest, dest); |
| 5847 | } else { |
| 5848 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5849 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5850 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5851 | __ movl(temp, Immediate(value)); |
| 5852 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5853 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5854 | } else { |
| 5855 | DCHECK(destination.IsStackSlot()) << destination; |
| 5856 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 5857 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5858 | } else if (constant->IsLongConstant()) { |
| 5859 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5860 | int32_t low_value = Low32Bits(value); |
| 5861 | int32_t high_value = High32Bits(value); |
| 5862 | Immediate low(low_value); |
| 5863 | Immediate high(high_value); |
| 5864 | if (destination.IsDoubleStackSlot()) { |
| 5865 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5866 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5867 | } else { |
| 5868 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 5869 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 5870 | } |
| 5871 | } else { |
| 5872 | DCHECK(constant->IsDoubleConstant()); |
| 5873 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5874 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5875 | int32_t low_value = Low32Bits(value); |
| 5876 | int32_t high_value = High32Bits(value); |
| 5877 | Immediate low(low_value); |
| 5878 | Immediate high(high_value); |
| 5879 | if (destination.IsFpuRegister()) { |
| 5880 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5881 | if (value == 0) { |
| 5882 | // Easy handling of 0.0. |
| 5883 | __ xorpd(dest, dest); |
| 5884 | } else { |
| 5885 | __ pushl(high); |
| 5886 | __ pushl(low); |
| 5887 | __ movsd(dest, Address(ESP, 0)); |
| 5888 | __ addl(ESP, Immediate(8)); |
| 5889 | } |
| 5890 | } else { |
| 5891 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5892 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5893 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5894 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5895 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5896 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5897 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5898 | } |
| 5899 | } |
| 5900 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 5901 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5902 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 5903 | ScratchRegisterScope ensure_scratch( |
| 5904 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 5905 | |
| 5906 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5907 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 5908 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 5909 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5910 | } |
| 5911 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5912 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5913 | ScratchRegisterScope ensure_scratch( |
| 5914 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5915 | |
| 5916 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5917 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5918 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 5919 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 5920 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5921 | } |
| 5922 | |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5923 | void ParallelMoveResolverX86::Exchange128(XmmRegister reg, int mem) { |
| 5924 | size_t extra_slot = 4 * kX86WordSize; |
| 5925 | __ subl(ESP, Immediate(extra_slot)); |
| 5926 | __ movups(Address(ESP, 0), XmmRegister(reg)); |
| 5927 | ExchangeMemory(0, mem + extra_slot, 4); |
| 5928 | __ movups(XmmRegister(reg), Address(ESP, 0)); |
| 5929 | __ addl(ESP, Immediate(extra_slot)); |
| 5930 | } |
| 5931 | |
| 5932 | void ParallelMoveResolverX86::ExchangeMemory(int mem1, int mem2, int number_of_words) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5933 | ScratchRegisterScope ensure_scratch1( |
| 5934 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5935 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5936 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 5937 | ScratchRegisterScope ensure_scratch2( |
| 5938 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5939 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5940 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 5941 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5942 | |
| 5943 | // Now that temp registers are available (possibly spilled), exchange blocks of memory. |
| 5944 | for (int i = 0; i < number_of_words; i++) { |
| 5945 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 5946 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 5947 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 5948 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
| 5949 | stack_offset += kX86WordSize; |
| 5950 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5951 | } |
| 5952 | |
| 5953 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5954 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5955 | Location source = move->GetSource(); |
| 5956 | Location destination = move->GetDestination(); |
| 5957 | |
| 5958 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 5959 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 5960 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5961 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5962 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5963 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5964 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5965 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5966 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5967 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5968 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5969 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 1); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5970 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 5971 | // Use XOR Swap algorithm to avoid a temporary. |
| 5972 | DCHECK_NE(source.reg(), destination.reg()); |
| 5973 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5974 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5975 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5976 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 5977 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 5978 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 5979 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5980 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 5981 | // Take advantage of the 16 bytes in the XMM register. |
| 5982 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 5983 | Address stack(ESP, destination.GetStackIndex()); |
| 5984 | // Load the double into the high doubleword. |
| 5985 | __ movhpd(reg, stack); |
| 5986 | |
| 5987 | // Store the low double into the destination. |
| 5988 | __ movsd(stack, reg); |
| 5989 | |
| 5990 | // Move the high double to the low double. |
| 5991 | __ psrldq(reg, Immediate(8)); |
| 5992 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 5993 | // Take advantage of the 16 bytes in the XMM register. |
| 5994 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 5995 | Address stack(ESP, source.GetStackIndex()); |
| 5996 | // Load the double into the high doubleword. |
| 5997 | __ movhpd(reg, stack); |
| 5998 | |
| 5999 | // Store the low double into the destination. |
| 6000 | __ movsd(stack, reg); |
| 6001 | |
| 6002 | // Move the high double to the low double. |
| 6003 | __ psrldq(reg, Immediate(8)); |
| 6004 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6005 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 2); |
| 6006 | } else if (source.IsSIMDStackSlot() && destination.IsSIMDStackSlot()) { |
| 6007 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 4); |
| 6008 | } else if (source.IsFpuRegister() && destination.IsSIMDStackSlot()) { |
| 6009 | Exchange128(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 6010 | } else if (destination.IsFpuRegister() && source.IsSIMDStackSlot()) { |
| 6011 | Exchange128(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6012 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6013 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6014 | } |
| 6015 | } |
| 6016 | |
| 6017 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 6018 | __ pushl(static_cast<Register>(reg)); |
| 6019 | } |
| 6020 | |
| 6021 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 6022 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6023 | } |
| 6024 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6025 | HLoadClass::LoadKind CodeGeneratorX86::GetSupportedLoadClassKind( |
| 6026 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6027 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6028 | case HLoadClass::LoadKind::kInvalid: |
| 6029 | LOG(FATAL) << "UNREACHABLE"; |
| 6030 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6031 | case HLoadClass::LoadKind::kReferrersClass: |
| 6032 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6033 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6034 | case HLoadClass::LoadKind::kBootImageClassTable: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6035 | case HLoadClass::LoadKind::kBssEntry: |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6036 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6037 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6038 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6039 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6040 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6041 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6042 | case HLoadClass::LoadKind::kRuntimeCall: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6043 | break; |
| 6044 | } |
| 6045 | return desired_class_load_kind; |
| 6046 | } |
| 6047 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6048 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6049 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6050 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6051 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6052 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6053 | cls, |
| 6054 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6055 | Location::RegisterLocation(EAX)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6056 | DCHECK_EQ(calling_convention.GetRegisterAt(0), EAX); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6057 | return; |
| 6058 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6059 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6060 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6061 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 6062 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6063 | ? LocationSummary::kCallOnSlowPath |
| 6064 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6065 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6066 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6067 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6068 | } |
| 6069 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6070 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6071 | load_kind == HLoadClass::LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6072 | load_kind == HLoadClass::LoadKind::kBootImageClassTable || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6073 | load_kind == HLoadClass::LoadKind::kBssEntry) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6074 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6075 | } |
| 6076 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6077 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 6078 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 6079 | // Rely on the type resolution and/or initialization to save everything. |
| 6080 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6081 | InvokeRuntimeCallingConvention calling_convention; |
| 6082 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6083 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6084 | } else { |
| 6085 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6086 | } |
| 6087 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6088 | } |
| 6089 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6090 | Label* CodeGeneratorX86::NewJitRootClassPatch(const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6091 | dex::TypeIndex type_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6092 | Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6093 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6094 | // Add a patch entry and return the label. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6095 | jit_class_patches_.emplace_back(dex_file, type_index.index_); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6096 | PatchInfo<Label>* info = &jit_class_patches_.back(); |
| 6097 | return &info->label; |
| 6098 | } |
| 6099 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6100 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6101 | // move. |
| 6102 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6103 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6104 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6105 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6106 | return; |
| 6107 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6108 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6109 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6110 | LocationSummary* locations = cls->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6111 | Location out_loc = locations->Out(); |
| 6112 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6113 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6114 | bool generate_null_check = false; |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6115 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 6116 | ? kWithoutReadBarrier |
| 6117 | : kCompilerReadBarrierOption; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6118 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6119 | case HLoadClass::LoadKind::kReferrersClass: { |
| 6120 | DCHECK(!cls->CanCallRuntime()); |
| 6121 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 6122 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6123 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 6124 | GenerateGcRootFieldLoad( |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6125 | cls, |
| 6126 | out_loc, |
| 6127 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 6128 | /* fixup_label */ nullptr, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6129 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6130 | break; |
| 6131 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6132 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6133 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6134 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6135 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6136 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 6137 | codegen_->RecordBootTypePatch(cls); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6138 | break; |
| 6139 | } |
| 6140 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6141 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6142 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6143 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 6144 | DCHECK_NE(address, 0u); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6145 | __ movl(out, Immediate(address)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6146 | break; |
| 6147 | } |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6148 | case HLoadClass::LoadKind::kBootImageClassTable: { |
| 6149 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 6150 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6151 | __ movl(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
| 6152 | codegen_->RecordBootTypePatch(cls); |
| 6153 | // Extract the reference from the slot data, i.e. clear the hash bits. |
| 6154 | int32_t masked_hash = ClassTable::TableSlot::MaskHash( |
| 6155 | ComputeModifiedUtf8Hash(cls->GetDexFile().StringByTypeIdx(cls->GetTypeIndex()))); |
| 6156 | if (masked_hash != 0) { |
| 6157 | __ subl(out, Immediate(masked_hash)); |
| 6158 | } |
| 6159 | break; |
| 6160 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6161 | case HLoadClass::LoadKind::kBssEntry: { |
| 6162 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6163 | Address address(method_address, CodeGeneratorX86::kDummy32BitOffset); |
| 6164 | Label* fixup_label = codegen_->NewTypeBssEntryPatch(cls); |
| 6165 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
| 6166 | generate_null_check = true; |
| 6167 | break; |
| 6168 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6169 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 6170 | Address address = Address::Absolute(CodeGeneratorX86::kDummy32BitOffset); |
| 6171 | Label* fixup_label = codegen_->NewJitRootClassPatch( |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6172 | cls->GetDexFile(), cls->GetTypeIndex(), cls->GetClass()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6173 | // /* GcRoot<mirror::Class> */ out = *address |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6174 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6175 | break; |
| 6176 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6177 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6178 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6179 | LOG(FATAL) << "UNREACHABLE"; |
| 6180 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6181 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6182 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6183 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6184 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6185 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6186 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 6187 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6188 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6189 | if (generate_null_check) { |
| 6190 | __ testl(out, out); |
| 6191 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6192 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6193 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6194 | if (cls->MustGenerateClinitCheck()) { |
| 6195 | GenerateClassInitializationCheck(slow_path, out); |
| 6196 | } else { |
| 6197 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6198 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6199 | } |
| 6200 | } |
| 6201 | |
| 6202 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 6203 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6204 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6205 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6206 | if (check->HasUses()) { |
| 6207 | locations->SetOut(Location::SameAsFirstInput()); |
| 6208 | } |
| 6209 | } |
| 6210 | |
| 6211 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6212 | // We assume the class to not be null. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6213 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6214 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6215 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6216 | GenerateClassInitializationCheck(slow_path, |
| 6217 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6218 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6219 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6220 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6221 | SlowPathCode* slow_path, Register class_reg) { |
Igor Murashkin | 86083f7 | 2017-10-27 10:59:04 -0700 | [diff] [blame] | 6222 | __ cmpb(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 6223 | Immediate(enum_cast<>(ClassStatus::kInitialized))); |
| 6224 | __ j(kBelow, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6225 | __ Bind(slow_path->GetExitLabel()); |
| 6226 | // No need for memory fence, thanks to the X86 memory model. |
| 6227 | } |
| 6228 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6229 | HLoadString::LoadKind CodeGeneratorX86::GetSupportedLoadStringKind( |
| 6230 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6231 | switch (desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6232 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6233 | case HLoadString::LoadKind::kBootImageInternTable: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6234 | case HLoadString::LoadKind::kBssEntry: |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6235 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6236 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6237 | case HLoadString::LoadKind::kJitTableAddress: |
| 6238 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6239 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6240 | case HLoadString::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6241 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6242 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6243 | } |
| 6244 | return desired_string_load_kind; |
| 6245 | } |
| 6246 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6247 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6248 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6249 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6250 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6251 | if (load_kind == HLoadString::LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6252 | load_kind == HLoadString::LoadKind::kBootImageInternTable || |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6253 | load_kind == HLoadString::LoadKind::kBssEntry) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6254 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6255 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6256 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6257 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 6258 | } else { |
| 6259 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6260 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 6261 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6262 | // Rely on the pResolveString to save everything. |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6263 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6264 | InvokeRuntimeCallingConvention calling_convention; |
| 6265 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6266 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6267 | } else { |
| 6268 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6269 | } |
| 6270 | } |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6271 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6272 | } |
| 6273 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6274 | Label* CodeGeneratorX86::NewJitRootStringPatch(const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6275 | dex::StringIndex string_index, |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6276 | Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6277 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6278 | // Add a patch entry and return the label. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6279 | jit_string_patches_.emplace_back(dex_file, string_index.index_); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6280 | PatchInfo<Label>* info = &jit_string_patches_.back(); |
| 6281 | return &info->label; |
| 6282 | } |
| 6283 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6284 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6285 | // move. |
| 6286 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6287 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6288 | Location out_loc = locations->Out(); |
| 6289 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6290 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6291 | switch (load->GetLoadKind()) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6292 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6293 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6294 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6295 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6296 | codegen_->RecordBootStringPatch(load); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6297 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6298 | } |
| 6299 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6300 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6301 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 6302 | DCHECK_NE(address, 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6303 | __ movl(out, Immediate(address)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6304 | return; |
| 6305 | } |
| 6306 | case HLoadString::LoadKind::kBootImageInternTable: { |
| 6307 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 6308 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6309 | __ movl(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
| 6310 | codegen_->RecordBootStringPatch(load); |
| 6311 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6312 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6313 | case HLoadString::LoadKind::kBssEntry: { |
| 6314 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6315 | Address address = Address(method_address, CodeGeneratorX86::kDummy32BitOffset); |
| 6316 | Label* fixup_label = codegen_->NewStringBssEntryPatch(load); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6317 | // /* GcRoot<mirror::String> */ out = *address /* PC-relative */ |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6318 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6319 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadStringSlowPathX86(load); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6320 | codegen_->AddSlowPath(slow_path); |
| 6321 | __ testl(out, out); |
| 6322 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6323 | __ Bind(slow_path->GetExitLabel()); |
| 6324 | return; |
| 6325 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6326 | case HLoadString::LoadKind::kJitTableAddress: { |
| 6327 | Address address = Address::Absolute(CodeGeneratorX86::kDummy32BitOffset); |
| 6328 | Label* fixup_label = codegen_->NewJitRootStringPatch( |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6329 | load->GetDexFile(), load->GetStringIndex(), load->GetString()); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6330 | // /* GcRoot<mirror::String> */ out = *address |
| 6331 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
| 6332 | return; |
| 6333 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6334 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6335 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6336 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6337 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6338 | // 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] | 6339 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6340 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6341 | __ movl(calling_convention.GetRegisterAt(0), Immediate(load->GetStringIndex().index_)); |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6342 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 6343 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6344 | } |
| 6345 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6346 | static Address GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6347 | return Address::Absolute(Thread::ExceptionOffset<kX86PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6348 | } |
| 6349 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6350 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 6351 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6352 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6353 | locations->SetOut(Location::RequiresRegister()); |
| 6354 | } |
| 6355 | |
| 6356 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6357 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 6358 | } |
| 6359 | |
| 6360 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6361 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6362 | } |
| 6363 | |
| 6364 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6365 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6366 | } |
| 6367 | |
| 6368 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6369 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6370 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6371 | InvokeRuntimeCallingConvention calling_convention; |
| 6372 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6373 | } |
| 6374 | |
| 6375 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6376 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6377 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6378 | } |
| 6379 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6380 | // Temp is used for read barrier. |
| 6381 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 6382 | if (kEmitCompilerReadBarrier && |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6383 | !kUseBakerReadBarrier && |
| 6384 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6385 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6386 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 6387 | return 1; |
| 6388 | } |
| 6389 | return 0; |
| 6390 | } |
| 6391 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6392 | // 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] | 6393 | // interface pointer, one for loading the current interface. |
| 6394 | // The other checks have one temp for loading the object's class. |
| 6395 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 6396 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6397 | return 2; |
| 6398 | } |
| 6399 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6400 | } |
| 6401 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6402 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6403 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6404 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6405 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6406 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6407 | case TypeCheckKind::kExactCheck: |
| 6408 | case TypeCheckKind::kAbstractClassCheck: |
| 6409 | case TypeCheckKind::kClassHierarchyCheck: |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6410 | case TypeCheckKind::kArrayObjectCheck: { |
| 6411 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 6412 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 6413 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6414 | break; |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6415 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6416 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6417 | case TypeCheckKind::kUnresolvedCheck: |
| 6418 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6419 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6420 | break; |
| 6421 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6422 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6423 | LocationSummary* locations = |
| 6424 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6425 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6426 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6427 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6428 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6429 | locations->SetInAt(1, Location::Any()); |
| 6430 | // Note that TypeCheckSlowPathX86 uses this "out" register too. |
| 6431 | locations->SetOut(Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6432 | // When read barriers are enabled, we need a temporary register for some cases. |
| 6433 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6434 | } |
| 6435 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6436 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6437 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6438 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6439 | Location obj_loc = locations->InAt(0); |
| 6440 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6441 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6442 | Location out_loc = locations->Out(); |
| 6443 | Register out = out_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6444 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 6445 | DCHECK_LE(num_temps, 1u); |
| 6446 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6447 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6448 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6449 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6450 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6451 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6452 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6453 | |
| 6454 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6455 | // Avoid null check if we know obj is not null. |
| 6456 | if (instruction->MustDoNullCheck()) { |
| 6457 | __ testl(obj, obj); |
| 6458 | __ j(kEqual, &zero); |
| 6459 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6460 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6461 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6462 | case TypeCheckKind::kExactCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6463 | ReadBarrierOption read_barrier_option = |
| 6464 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6465 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6466 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6467 | out_loc, |
| 6468 | obj_loc, |
| 6469 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6470 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6471 | if (cls.IsRegister()) { |
| 6472 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6473 | } else { |
| 6474 | DCHECK(cls.IsStackSlot()) << cls; |
| 6475 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6476 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6477 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6478 | // Classes must be equal for the instanceof to succeed. |
| 6479 | __ j(kNotEqual, &zero); |
| 6480 | __ movl(out, Immediate(1)); |
| 6481 | __ jmp(&done); |
| 6482 | break; |
| 6483 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6484 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6485 | case TypeCheckKind::kAbstractClassCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6486 | ReadBarrierOption read_barrier_option = |
| 6487 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6488 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6489 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6490 | out_loc, |
| 6491 | obj_loc, |
| 6492 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6493 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6494 | // If the class is abstract, we eagerly fetch the super class of the |
| 6495 | // object to avoid doing a comparison we know will fail. |
| 6496 | NearLabel loop; |
| 6497 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6498 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6499 | GenerateReferenceLoadOneRegister(instruction, |
| 6500 | out_loc, |
| 6501 | super_offset, |
| 6502 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6503 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6504 | __ testl(out, out); |
| 6505 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6506 | __ j(kEqual, &done); |
| 6507 | if (cls.IsRegister()) { |
| 6508 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6509 | } else { |
| 6510 | DCHECK(cls.IsStackSlot()) << cls; |
| 6511 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6512 | } |
| 6513 | __ j(kNotEqual, &loop); |
| 6514 | __ movl(out, Immediate(1)); |
| 6515 | if (zero.IsLinked()) { |
| 6516 | __ jmp(&done); |
| 6517 | } |
| 6518 | break; |
| 6519 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6520 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6521 | case TypeCheckKind::kClassHierarchyCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6522 | ReadBarrierOption read_barrier_option = |
| 6523 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6524 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6525 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6526 | out_loc, |
| 6527 | obj_loc, |
| 6528 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6529 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6530 | // Walk over the class hierarchy to find a match. |
| 6531 | NearLabel loop, success; |
| 6532 | __ Bind(&loop); |
| 6533 | if (cls.IsRegister()) { |
| 6534 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6535 | } else { |
| 6536 | DCHECK(cls.IsStackSlot()) << cls; |
| 6537 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6538 | } |
| 6539 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6540 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6541 | GenerateReferenceLoadOneRegister(instruction, |
| 6542 | out_loc, |
| 6543 | super_offset, |
| 6544 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6545 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6546 | __ testl(out, out); |
| 6547 | __ j(kNotEqual, &loop); |
| 6548 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6549 | __ jmp(&done); |
| 6550 | __ Bind(&success); |
| 6551 | __ movl(out, Immediate(1)); |
| 6552 | if (zero.IsLinked()) { |
| 6553 | __ jmp(&done); |
| 6554 | } |
| 6555 | break; |
| 6556 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6557 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6558 | case TypeCheckKind::kArrayObjectCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6559 | ReadBarrierOption read_barrier_option = |
| 6560 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6561 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6562 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6563 | out_loc, |
| 6564 | obj_loc, |
| 6565 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6566 | read_barrier_option); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6567 | // Do an exact check. |
| 6568 | NearLabel exact_check; |
| 6569 | if (cls.IsRegister()) { |
| 6570 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6571 | } else { |
| 6572 | DCHECK(cls.IsStackSlot()) << cls; |
| 6573 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6574 | } |
| 6575 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6576 | // 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] | 6577 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6578 | GenerateReferenceLoadOneRegister(instruction, |
| 6579 | out_loc, |
| 6580 | component_offset, |
| 6581 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6582 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6583 | __ testl(out, out); |
| 6584 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6585 | __ j(kEqual, &done); |
| 6586 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 6587 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6588 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6589 | __ movl(out, Immediate(1)); |
| 6590 | __ jmp(&done); |
| 6591 | break; |
| 6592 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6593 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6594 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6595 | // No read barrier since the slow path will retry upon failure. |
| 6596 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6597 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6598 | out_loc, |
| 6599 | obj_loc, |
| 6600 | class_offset, |
| 6601 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6602 | if (cls.IsRegister()) { |
| 6603 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6604 | } else { |
| 6605 | DCHECK(cls.IsStackSlot()) << cls; |
| 6606 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6607 | } |
| 6608 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6609 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
| 6610 | instruction, /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6611 | codegen_->AddSlowPath(slow_path); |
| 6612 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6613 | __ movl(out, Immediate(1)); |
| 6614 | if (zero.IsLinked()) { |
| 6615 | __ jmp(&done); |
| 6616 | } |
| 6617 | break; |
| 6618 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6619 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6620 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6621 | case TypeCheckKind::kInterfaceCheck: { |
| 6622 | // 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] | 6623 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6624 | // cases. |
| 6625 | // |
| 6626 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6627 | // entry point without resorting to a type checking slow path |
| 6628 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6629 | // require to assign fixed registers for the inputs of this |
| 6630 | // HInstanceOf instruction (following the runtime calling |
| 6631 | // convention), which might be cluttered by the potential first |
| 6632 | // read barrier emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6633 | // |
| 6634 | // TODO: Introduce a new runtime entry point taking the object |
| 6635 | // to test (instead of its class) as argument, and let it deal |
| 6636 | // with the read barrier issues. This will let us refactor this |
| 6637 | // case of the `switch` code as it was previously (with a direct |
| 6638 | // call to the runtime not using a type checking slow path). |
| 6639 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6640 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6641 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
| 6642 | instruction, /* is_fatal */ false); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6643 | codegen_->AddSlowPath(slow_path); |
| 6644 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6645 | if (zero.IsLinked()) { |
| 6646 | __ jmp(&done); |
| 6647 | } |
| 6648 | break; |
| 6649 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6650 | } |
| 6651 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6652 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6653 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6654 | __ xorl(out, out); |
| 6655 | } |
| 6656 | |
| 6657 | if (done.IsLinked()) { |
| 6658 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6659 | } |
| 6660 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6661 | if (slow_path != nullptr) { |
| 6662 | __ Bind(slow_path->GetExitLabel()); |
| 6663 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6664 | } |
| 6665 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6666 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6667 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6668 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6669 | LocationSummary* locations = |
| 6670 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6671 | locations->SetInAt(0, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6672 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6673 | // Require a register for the interface check since there is a loop that compares the class to |
| 6674 | // a memory address. |
| 6675 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6676 | } else { |
| 6677 | locations->SetInAt(1, Location::Any()); |
| 6678 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6679 | // Note that TypeCheckSlowPathX86 uses this "temp" register too. |
| 6680 | locations->AddTemp(Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6681 | // When read barriers are enabled, we need an additional temporary register for some cases. |
| 6682 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
| 6683 | } |
| 6684 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6685 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6686 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6687 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6688 | Location obj_loc = locations->InAt(0); |
| 6689 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6690 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6691 | Location temp_loc = locations->GetTemp(0); |
| 6692 | Register temp = temp_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6693 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 6694 | DCHECK_GE(num_temps, 1u); |
| 6695 | DCHECK_LE(num_temps, 2u); |
| 6696 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 6697 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6698 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6699 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6700 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 6701 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 6702 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 6703 | const uint32_t object_array_data_offset = |
| 6704 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6705 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6706 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6707 | SlowPathCode* type_check_slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6708 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
| 6709 | instruction, is_type_check_slow_path_fatal); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6710 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6711 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6712 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6713 | // Avoid null check if we know obj is not null. |
| 6714 | if (instruction->MustDoNullCheck()) { |
| 6715 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6716 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6717 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6718 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6719 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6720 | case TypeCheckKind::kExactCheck: |
| 6721 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6722 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6723 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6724 | temp_loc, |
| 6725 | obj_loc, |
| 6726 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6727 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6728 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6729 | if (cls.IsRegister()) { |
| 6730 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6731 | } else { |
| 6732 | DCHECK(cls.IsStackSlot()) << cls; |
| 6733 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6734 | } |
| 6735 | // Jump to slow path for throwing the exception or doing a |
| 6736 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6737 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6738 | break; |
| 6739 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6740 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6741 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6742 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6743 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6744 | temp_loc, |
| 6745 | obj_loc, |
| 6746 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6747 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6748 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6749 | // If the class is abstract, we eagerly fetch the super class of the |
| 6750 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6751 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6752 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6753 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6754 | GenerateReferenceLoadOneRegister(instruction, |
| 6755 | temp_loc, |
| 6756 | super_offset, |
| 6757 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6758 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6759 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6760 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 6761 | // exception. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6762 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6763 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6764 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6765 | // Otherwise, compare the classes |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6766 | if (cls.IsRegister()) { |
| 6767 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6768 | } else { |
| 6769 | DCHECK(cls.IsStackSlot()) << cls; |
| 6770 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6771 | } |
| 6772 | __ j(kNotEqual, &loop); |
| 6773 | break; |
| 6774 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6775 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6776 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6777 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6778 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6779 | temp_loc, |
| 6780 | obj_loc, |
| 6781 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6782 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6783 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6784 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6785 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6786 | __ Bind(&loop); |
| 6787 | if (cls.IsRegister()) { |
| 6788 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6789 | } else { |
| 6790 | DCHECK(cls.IsStackSlot()) << cls; |
| 6791 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6792 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6793 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6794 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6795 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6796 | GenerateReferenceLoadOneRegister(instruction, |
| 6797 | temp_loc, |
| 6798 | super_offset, |
| 6799 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6800 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6801 | |
| 6802 | // If the class reference currently in `temp` is not null, jump |
| 6803 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6804 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6805 | __ j(kNotZero, &loop); |
| 6806 | // Otherwise, jump to the slow path to throw the exception.; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6807 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6808 | break; |
| 6809 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6810 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6811 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6812 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6813 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6814 | temp_loc, |
| 6815 | obj_loc, |
| 6816 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6817 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6818 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6819 | // Do an exact check. |
| 6820 | if (cls.IsRegister()) { |
| 6821 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6822 | } else { |
| 6823 | DCHECK(cls.IsStackSlot()) << cls; |
| 6824 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6825 | } |
| 6826 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6827 | |
| 6828 | // 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] | 6829 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6830 | GenerateReferenceLoadOneRegister(instruction, |
| 6831 | temp_loc, |
| 6832 | component_offset, |
| 6833 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6834 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6835 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6836 | // If the component type is null (i.e. the object not an array), jump to the slow path to |
| 6837 | // throw the exception. Otherwise proceed with the check. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6838 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6839 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6840 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6841 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6842 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6843 | break; |
| 6844 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6845 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6846 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6847 | // 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] | 6848 | // We cannot directly call the CheckCast runtime entry point |
| 6849 | // without resorting to a type checking slow path here (i.e. by |
| 6850 | // calling InvokeRuntime directly), as it would require to |
| 6851 | // assign fixed registers for the inputs of this HInstanceOf |
| 6852 | // instruction (following the runtime calling convention), which |
| 6853 | // might be cluttered by the potential first read barrier |
| 6854 | // emission at the beginning of this method. |
| 6855 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6856 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6857 | |
| 6858 | case TypeCheckKind::kInterfaceCheck: { |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 6859 | // Fast path for the interface check. Try to avoid read barriers to improve the fast path. |
| 6860 | // We can not get false positives by doing this. |
| 6861 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6862 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6863 | temp_loc, |
| 6864 | obj_loc, |
| 6865 | class_offset, |
| 6866 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6867 | |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 6868 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 6869 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6870 | temp_loc, |
| 6871 | temp_loc, |
| 6872 | iftable_offset, |
| 6873 | kWithoutReadBarrier); |
| 6874 | // Iftable is never null. |
| 6875 | __ movl(maybe_temp2_loc.AsRegister<Register>(), Address(temp, array_length_offset)); |
| 6876 | // Maybe poison the `cls` for direct comparison with memory. |
| 6877 | __ MaybePoisonHeapReference(cls.AsRegister<Register>()); |
| 6878 | // Loop through the iftable and check if any class matches. |
| 6879 | NearLabel start_loop; |
| 6880 | __ Bind(&start_loop); |
| 6881 | // Need to subtract first to handle the empty array case. |
| 6882 | __ subl(maybe_temp2_loc.AsRegister<Register>(), Immediate(2)); |
| 6883 | __ j(kNegative, type_check_slow_path->GetEntryLabel()); |
| 6884 | // Go to next interface if the classes do not match. |
| 6885 | __ cmpl(cls.AsRegister<Register>(), |
| 6886 | CodeGeneratorX86::ArrayAddress(temp, |
| 6887 | maybe_temp2_loc, |
| 6888 | TIMES_4, |
| 6889 | object_array_data_offset)); |
| 6890 | __ j(kNotEqual, &start_loop); |
| 6891 | // If `cls` was poisoned above, unpoison it. |
| 6892 | __ MaybeUnpoisonHeapReference(cls.AsRegister<Register>()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6893 | break; |
| 6894 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6895 | } |
| 6896 | __ Bind(&done); |
| 6897 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6898 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6899 | } |
| 6900 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6901 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6902 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6903 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6904 | InvokeRuntimeCallingConvention calling_convention; |
| 6905 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6906 | } |
| 6907 | |
| 6908 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6909 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject |
| 6910 | : kQuickUnlockObject, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6911 | instruction, |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6912 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6913 | if (instruction->IsEnter()) { |
| 6914 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6915 | } else { |
| 6916 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6917 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6918 | } |
| 6919 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6920 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6921 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6922 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6923 | |
| 6924 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6925 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6926 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6927 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 |
| 6928 | || instruction->GetResultType() == DataType::Type::kInt64); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6929 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6930 | locations->SetInAt(1, Location::Any()); |
| 6931 | locations->SetOut(Location::SameAsFirstInput()); |
| 6932 | } |
| 6933 | |
| 6934 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 6935 | HandleBitwiseOperation(instruction); |
| 6936 | } |
| 6937 | |
| 6938 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 6939 | HandleBitwiseOperation(instruction); |
| 6940 | } |
| 6941 | |
| 6942 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 6943 | HandleBitwiseOperation(instruction); |
| 6944 | } |
| 6945 | |
| 6946 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6947 | LocationSummary* locations = instruction->GetLocations(); |
| 6948 | Location first = locations->InAt(0); |
| 6949 | Location second = locations->InAt(1); |
| 6950 | DCHECK(first.Equals(locations->Out())); |
| 6951 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6952 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6953 | if (second.IsRegister()) { |
| 6954 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6955 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6956 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6957 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6958 | } else { |
| 6959 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6960 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6961 | } |
| 6962 | } else if (second.IsConstant()) { |
| 6963 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6964 | __ andl(first.AsRegister<Register>(), |
| 6965 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6966 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6967 | __ orl(first.AsRegister<Register>(), |
| 6968 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6969 | } else { |
| 6970 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6971 | __ xorl(first.AsRegister<Register>(), |
| 6972 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6973 | } |
| 6974 | } else { |
| 6975 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6976 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6977 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6978 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6979 | } else { |
| 6980 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6981 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6982 | } |
| 6983 | } |
| 6984 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6985 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6986 | if (second.IsRegisterPair()) { |
| 6987 | if (instruction->IsAnd()) { |
| 6988 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6989 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6990 | } else if (instruction->IsOr()) { |
| 6991 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6992 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6993 | } else { |
| 6994 | DCHECK(instruction->IsXor()); |
| 6995 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6996 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6997 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6998 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6999 | if (instruction->IsAnd()) { |
| 7000 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7001 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 7002 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7003 | } else if (instruction->IsOr()) { |
| 7004 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7005 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 7006 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7007 | } else { |
| 7008 | DCHECK(instruction->IsXor()); |
| 7009 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7010 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 7011 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7012 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7013 | } else { |
| 7014 | DCHECK(second.IsConstant()) << second; |
| 7015 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7016 | int32_t low_value = Low32Bits(value); |
| 7017 | int32_t high_value = High32Bits(value); |
| 7018 | Immediate low(low_value); |
| 7019 | Immediate high(high_value); |
| 7020 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 7021 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7022 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7023 | if (low_value == 0) { |
| 7024 | __ xorl(first_low, first_low); |
| 7025 | } else if (low_value != -1) { |
| 7026 | __ andl(first_low, low); |
| 7027 | } |
| 7028 | if (high_value == 0) { |
| 7029 | __ xorl(first_high, first_high); |
| 7030 | } else if (high_value != -1) { |
| 7031 | __ andl(first_high, high); |
| 7032 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7033 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7034 | if (low_value != 0) { |
| 7035 | __ orl(first_low, low); |
| 7036 | } |
| 7037 | if (high_value != 0) { |
| 7038 | __ orl(first_high, high); |
| 7039 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7040 | } else { |
| 7041 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7042 | if (low_value != 0) { |
| 7043 | __ xorl(first_low, low); |
| 7044 | } |
| 7045 | if (high_value != 0) { |
| 7046 | __ xorl(first_high, high); |
| 7047 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7048 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7049 | } |
| 7050 | } |
| 7051 | } |
| 7052 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7053 | void InstructionCodeGeneratorX86::GenerateReferenceLoadOneRegister( |
| 7054 | HInstruction* instruction, |
| 7055 | Location out, |
| 7056 | uint32_t offset, |
| 7057 | Location maybe_temp, |
| 7058 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7059 | Register out_reg = out.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7060 | if (read_barrier_option == kWithReadBarrier) { |
| 7061 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7062 | if (kUseBakerReadBarrier) { |
| 7063 | // Load with fast path based Baker's read barrier. |
| 7064 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7065 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7066 | instruction, out, out_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7067 | } else { |
| 7068 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7069 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7070 | // in the following move operation, as we will need it for the |
| 7071 | // read barrier below. |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7072 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7073 | __ movl(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7074 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7075 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7076 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7077 | } |
| 7078 | } else { |
| 7079 | // Plain load with no read barrier. |
| 7080 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7081 | __ movl(out_reg, Address(out_reg, offset)); |
| 7082 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7083 | } |
| 7084 | } |
| 7085 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7086 | void InstructionCodeGeneratorX86::GenerateReferenceLoadTwoRegisters( |
| 7087 | HInstruction* instruction, |
| 7088 | Location out, |
| 7089 | Location obj, |
| 7090 | uint32_t offset, |
| 7091 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7092 | Register out_reg = out.AsRegister<Register>(); |
| 7093 | Register obj_reg = obj.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7094 | if (read_barrier_option == kWithReadBarrier) { |
| 7095 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7096 | if (kUseBakerReadBarrier) { |
| 7097 | // Load with fast path based Baker's read barrier. |
| 7098 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7099 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7100 | instruction, out, obj_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7101 | } else { |
| 7102 | // Load with slow path based read barrier. |
| 7103 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7104 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7105 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 7106 | } |
| 7107 | } else { |
| 7108 | // Plain load with no read barrier. |
| 7109 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7110 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7111 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7112 | } |
| 7113 | } |
| 7114 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7115 | void InstructionCodeGeneratorX86::GenerateGcRootFieldLoad( |
| 7116 | HInstruction* instruction, |
| 7117 | Location root, |
| 7118 | const Address& address, |
| 7119 | Label* fixup_label, |
| 7120 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7121 | Register root_reg = root.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7122 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7123 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7124 | if (kUseBakerReadBarrier) { |
| 7125 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 7126 | // Baker's read barrier are used: |
| 7127 | // |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7128 | // root = obj.field; |
| 7129 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 7130 | // if (temp != null) { |
| 7131 | // root = temp(root) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7132 | // } |
| 7133 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7134 | // /* GcRoot<mirror::Object> */ root = *address |
| 7135 | __ movl(root_reg, address); |
| 7136 | if (fixup_label != nullptr) { |
| 7137 | __ Bind(fixup_label); |
| 7138 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7139 | static_assert( |
| 7140 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 7141 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 7142 | "have different sizes."); |
| 7143 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 7144 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 7145 | "have different sizes."); |
| 7146 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7147 | // Slow path marking the GC root `root`. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7148 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathX86( |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7149 | instruction, root, /* unpoison_ref_before_marking */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7150 | codegen_->AddSlowPath(slow_path); |
| 7151 | |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7152 | // Test the entrypoint (`Thread::Current()->pReadBarrierMarkReg ## root.reg()`). |
| 7153 | const int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 7154 | Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(root.reg()); |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7155 | __ fs()->cmpl(Address::Absolute(entry_point_offset), Immediate(0)); |
| 7156 | // The entrypoint is null when the GC is not marking. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7157 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 7158 | __ Bind(slow_path->GetExitLabel()); |
| 7159 | } else { |
| 7160 | // GC root loaded through a slow path for read barriers other |
| 7161 | // than Baker's. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7162 | // /* GcRoot<mirror::Object>* */ root = address |
| 7163 | __ leal(root_reg, address); |
| 7164 | if (fixup_label != nullptr) { |
| 7165 | __ Bind(fixup_label); |
| 7166 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7167 | // /* mirror::Object* */ root = root->Read() |
| 7168 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 7169 | } |
| 7170 | } else { |
| 7171 | // Plain GC root load with no read barrier. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7172 | // /* GcRoot<mirror::Object> */ root = *address |
| 7173 | __ movl(root_reg, address); |
| 7174 | if (fixup_label != nullptr) { |
| 7175 | __ Bind(fixup_label); |
| 7176 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7177 | // Note that GC roots are not affected by heap poisoning, thus we |
| 7178 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7179 | } |
| 7180 | } |
| 7181 | |
| 7182 | void CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7183 | Location ref, |
| 7184 | Register obj, |
| 7185 | uint32_t offset, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7186 | bool needs_null_check) { |
| 7187 | DCHECK(kEmitCompilerReadBarrier); |
| 7188 | DCHECK(kUseBakerReadBarrier); |
| 7189 | |
| 7190 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7191 | Address src(obj, offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7192 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7193 | } |
| 7194 | |
| 7195 | void CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7196 | Location ref, |
| 7197 | Register obj, |
| 7198 | uint32_t data_offset, |
| 7199 | Location index, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7200 | bool needs_null_check) { |
| 7201 | DCHECK(kEmitCompilerReadBarrier); |
| 7202 | DCHECK(kUseBakerReadBarrier); |
| 7203 | |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 7204 | static_assert( |
| 7205 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 7206 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7207 | // /* HeapReference<Object> */ ref = |
| 7208 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7209 | Address src = CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7210 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7211 | } |
| 7212 | |
| 7213 | void CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7214 | Location ref, |
| 7215 | Register obj, |
| 7216 | const Address& src, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7217 | bool needs_null_check, |
| 7218 | bool always_update_field, |
| 7219 | Register* temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7220 | DCHECK(kEmitCompilerReadBarrier); |
| 7221 | DCHECK(kUseBakerReadBarrier); |
| 7222 | |
| 7223 | // In slow path based read barriers, the read barrier call is |
| 7224 | // inserted after the original load. However, in fast path based |
| 7225 | // Baker's read barriers, we need to perform the load of |
| 7226 | // mirror::Object::monitor_ *before* the original reference load. |
| 7227 | // This load-load ordering is required by the read barrier. |
| 7228 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 7229 | // |
| 7230 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7231 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7232 | // HeapReference<Object> ref = *src; // Original reference load. |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7233 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7234 | // if (is_gray) { |
| 7235 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 7236 | // } |
| 7237 | // |
| 7238 | // Note: the original implementation in ReadBarrier::Barrier is |
| 7239 | // slightly more complex as: |
| 7240 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7241 | // the high-bits of rb_state, which are expected to be all zeroes |
| 7242 | // (we use CodeGeneratorX86::GenerateMemoryBarrier instead here, |
| 7243 | // which is a no-op thanks to the x86 memory model); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7244 | // - it performs additional checks that we do not do here for |
| 7245 | // performance reasons. |
| 7246 | |
| 7247 | Register ref_reg = ref.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7248 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 7249 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7250 | // 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] | 7251 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 7252 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7253 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 7254 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 7255 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 7256 | |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7257 | // if (rb_state == ReadBarrier::GrayState()) |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7258 | // ref = ReadBarrier::Mark(ref); |
| 7259 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 7260 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7261 | if (needs_null_check) { |
| 7262 | MaybeRecordImplicitNullCheck(instruction); |
| 7263 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7264 | |
| 7265 | // Load fence to prevent load-load reordering. |
| 7266 | // Note that this is a no-op, thanks to the x86 memory model. |
| 7267 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 7268 | |
| 7269 | // The actual reference load. |
| 7270 | // /* HeapReference<Object> */ ref = *src |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7271 | __ movl(ref_reg, src); // Flags are unaffected. |
| 7272 | |
| 7273 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 7274 | // Slow path marking the object `ref` when it is gray. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7275 | SlowPathCode* slow_path; |
| 7276 | if (always_update_field) { |
| 7277 | DCHECK(temp != nullptr); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7278 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkAndUpdateFieldSlowPathX86( |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7279 | instruction, ref, obj, src, /* unpoison_ref_before_marking */ true, *temp); |
| 7280 | } else { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7281 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkSlowPathX86( |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7282 | instruction, ref, /* unpoison_ref_before_marking */ true); |
| 7283 | } |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7284 | AddSlowPath(slow_path); |
| 7285 | |
| 7286 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 7287 | __ j(kNotZero, slow_path->GetEntryLabel()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7288 | |
| 7289 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7290 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7291 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7292 | __ Bind(slow_path->GetExitLabel()); |
| 7293 | } |
| 7294 | |
| 7295 | void CodeGeneratorX86::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7296 | Location out, |
| 7297 | Location ref, |
| 7298 | Location obj, |
| 7299 | uint32_t offset, |
| 7300 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7301 | DCHECK(kEmitCompilerReadBarrier); |
| 7302 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7303 | // Insert a slow path based read barrier *after* the reference load. |
| 7304 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7305 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7306 | // reference will be carried out by the runtime within the slow |
| 7307 | // path. |
| 7308 | // |
| 7309 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7310 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7311 | // not used by the artReadBarrierSlow entry point. |
| 7312 | // |
| 7313 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7314 | SlowPathCode* slow_path = new (GetScopedAllocator()) |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7315 | ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); |
| 7316 | AddSlowPath(slow_path); |
| 7317 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7318 | __ jmp(slow_path->GetEntryLabel()); |
| 7319 | __ Bind(slow_path->GetExitLabel()); |
| 7320 | } |
| 7321 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7322 | void CodeGeneratorX86::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 7323 | Location out, |
| 7324 | Location ref, |
| 7325 | Location obj, |
| 7326 | uint32_t offset, |
| 7327 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7328 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7329 | // Baker's read barriers shall be handled by the fast path |
| 7330 | // (CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier). |
| 7331 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7332 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7333 | // by the runtime within the slow path. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7334 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7335 | } else if (kPoisonHeapReferences) { |
| 7336 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 7337 | } |
| 7338 | } |
| 7339 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7340 | void CodeGeneratorX86::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7341 | Location out, |
| 7342 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7343 | DCHECK(kEmitCompilerReadBarrier); |
| 7344 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7345 | // Insert a slow path based read barrier *after* the GC root load. |
| 7346 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7347 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7348 | // not need to do anything special for this here. |
| 7349 | SlowPathCode* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7350 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathX86(instruction, out, root); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7351 | AddSlowPath(slow_path); |
| 7352 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7353 | __ jmp(slow_path->GetEntryLabel()); |
| 7354 | __ Bind(slow_path->GetExitLabel()); |
| 7355 | } |
| 7356 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7357 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7358 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7359 | LOG(FATAL) << "Unreachable"; |
| 7360 | } |
| 7361 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7362 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7363 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7364 | LOG(FATAL) << "Unreachable"; |
| 7365 | } |
| 7366 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7367 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7368 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7369 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7370 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7371 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7372 | } |
| 7373 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7374 | void InstructionCodeGeneratorX86::GenPackedSwitchWithCompares(Register value_reg, |
| 7375 | int32_t lower_bound, |
| 7376 | uint32_t num_entries, |
| 7377 | HBasicBlock* switch_block, |
| 7378 | HBasicBlock* default_block) { |
| 7379 | // Figure out the correct compare values and jump conditions. |
| 7380 | // Handle the first compare/branch as a special case because it might |
| 7381 | // jump to the default case. |
| 7382 | DCHECK_GT(num_entries, 2u); |
| 7383 | Condition first_condition; |
| 7384 | uint32_t index; |
| 7385 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 7386 | if (lower_bound != 0) { |
| 7387 | first_condition = kLess; |
| 7388 | __ cmpl(value_reg, Immediate(lower_bound)); |
| 7389 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 7390 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7391 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7392 | index = 1; |
| 7393 | } else { |
| 7394 | // Handle all the compare/jumps below. |
| 7395 | first_condition = kBelow; |
| 7396 | index = 0; |
| 7397 | } |
| 7398 | |
| 7399 | // Handle the rest of the compare/jumps. |
| 7400 | for (; index + 1 < num_entries; index += 2) { |
| 7401 | int32_t compare_to_value = lower_bound + index + 1; |
| 7402 | __ cmpl(value_reg, Immediate(compare_to_value)); |
| 7403 | // Jump to successors[index] if value < case_value[index]. |
| 7404 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 7405 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 7406 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 7407 | } |
| 7408 | |
| 7409 | if (index != num_entries) { |
| 7410 | // There are an odd number of entries. Handle the last one. |
| 7411 | DCHECK_EQ(index + 1, num_entries); |
| 7412 | __ cmpl(value_reg, Immediate(lower_bound + index)); |
| 7413 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7414 | } |
| 7415 | |
| 7416 | // And the default for any other value. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7417 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
| 7418 | __ jmp(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7419 | } |
| 7420 | } |
| 7421 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7422 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7423 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 7424 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 7425 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7426 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7427 | |
| 7428 | GenPackedSwitchWithCompares(value_reg, |
| 7429 | lower_bound, |
| 7430 | num_entries, |
| 7431 | switch_instr->GetBlock(), |
| 7432 | switch_instr->GetDefaultBlock()); |
| 7433 | } |
| 7434 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7435 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7436 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7437 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7438 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7439 | |
| 7440 | // Constant area pointer. |
| 7441 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7442 | |
| 7443 | // And the temporary we need. |
| 7444 | locations->AddTemp(Location::RequiresRegister()); |
| 7445 | } |
| 7446 | |
| 7447 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7448 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7449 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7450 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7451 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7452 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7453 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7454 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 7455 | GenPackedSwitchWithCompares(value_reg, |
| 7456 | lower_bound, |
| 7457 | num_entries, |
| 7458 | switch_instr->GetBlock(), |
| 7459 | default_block); |
| 7460 | return; |
| 7461 | } |
| 7462 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7463 | // Optimizing has a jump area. |
| 7464 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 7465 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 7466 | |
| 7467 | // Remove the bias, if needed. |
| 7468 | if (lower_bound != 0) { |
| 7469 | __ leal(temp_reg, Address(value_reg, -lower_bound)); |
| 7470 | value_reg = temp_reg; |
| 7471 | } |
| 7472 | |
| 7473 | // Is the value in range? |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7474 | DCHECK_GE(num_entries, 1u); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7475 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 7476 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| 7477 | |
| 7478 | // We are in the range of the table. |
| 7479 | // Load (target-constant_area) from the jump table, indexing by the value. |
| 7480 | __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); |
| 7481 | |
| 7482 | // Compute the actual target address by adding in constant_area. |
| 7483 | __ addl(temp_reg, constant_area); |
| 7484 | |
| 7485 | // And jump. |
| 7486 | __ jmp(temp_reg); |
| 7487 | } |
| 7488 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7489 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 7490 | HX86ComputeBaseMethodAddress* insn) { |
| 7491 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7492 | new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7493 | locations->SetOut(Location::RequiresRegister()); |
| 7494 | } |
| 7495 | |
| 7496 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 7497 | HX86ComputeBaseMethodAddress* insn) { |
| 7498 | LocationSummary* locations = insn->GetLocations(); |
| 7499 | Register reg = locations->Out().AsRegister<Register>(); |
| 7500 | |
| 7501 | // Generate call to next instruction. |
| 7502 | Label next_instruction; |
| 7503 | __ call(&next_instruction); |
| 7504 | __ Bind(&next_instruction); |
| 7505 | |
| 7506 | // Remember this offset for later use with constant area. |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7507 | codegen_->AddMethodAddressOffset(insn, GetAssembler()->CodeSize()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7508 | |
| 7509 | // Grab the return address off the stack. |
| 7510 | __ popl(reg); |
| 7511 | } |
| 7512 | |
| 7513 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 7514 | HX86LoadFromConstantTable* insn) { |
| 7515 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7516 | new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7517 | |
| 7518 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7519 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 7520 | |
| 7521 | // 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] | 7522 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7523 | return; |
| 7524 | } |
| 7525 | |
| 7526 | switch (insn->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7527 | case DataType::Type::kFloat32: |
| 7528 | case DataType::Type::kFloat64: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7529 | locations->SetOut(Location::RequiresFpuRegister()); |
| 7530 | break; |
| 7531 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7532 | case DataType::Type::kInt32: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7533 | locations->SetOut(Location::RequiresRegister()); |
| 7534 | break; |
| 7535 | |
| 7536 | default: |
| 7537 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7538 | } |
| 7539 | } |
| 7540 | |
| 7541 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 7542 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7543 | return; |
| 7544 | } |
| 7545 | |
| 7546 | LocationSummary* locations = insn->GetLocations(); |
| 7547 | Location out = locations->Out(); |
| 7548 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 7549 | HConstant *value = insn->GetConstant(); |
| 7550 | |
| 7551 | switch (insn->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7552 | case DataType::Type::kFloat32: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7553 | __ movss(out.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7554 | codegen_->LiteralFloatAddress( |
| 7555 | value->AsFloatConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7556 | break; |
| 7557 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7558 | case DataType::Type::kFloat64: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7559 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7560 | codegen_->LiteralDoubleAddress( |
| 7561 | value->AsDoubleConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7562 | break; |
| 7563 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7564 | case DataType::Type::kInt32: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7565 | __ movl(out.AsRegister<Register>(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7566 | codegen_->LiteralInt32Address( |
| 7567 | value->AsIntConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7568 | break; |
| 7569 | |
| 7570 | default: |
| 7571 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7572 | } |
| 7573 | } |
| 7574 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7575 | /** |
| 7576 | * Class to handle late fixup of offsets into constant area. |
| 7577 | */ |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 7578 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7579 | public: |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7580 | RIPFixup(CodeGeneratorX86& codegen, |
| 7581 | HX86ComputeBaseMethodAddress* base_method_address, |
| 7582 | size_t offset) |
| 7583 | : codegen_(&codegen), |
| 7584 | base_method_address_(base_method_address), |
| 7585 | offset_into_constant_area_(offset) {} |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7586 | |
| 7587 | protected: |
| 7588 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 7589 | |
| 7590 | CodeGeneratorX86* codegen_; |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7591 | HX86ComputeBaseMethodAddress* base_method_address_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7592 | |
| 7593 | private: |
| 7594 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 7595 | // Patch the correct offset for the instruction. The place to patch is the |
| 7596 | // last 4 bytes of the instruction. |
| 7597 | // The value to patch is the distance from the offset in the constant area |
| 7598 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7599 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7600 | int32_t relative_position = |
| 7601 | constant_offset - codegen_->GetMethodAddressOffset(base_method_address_); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7602 | |
| 7603 | // Patch in the right value. |
| 7604 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 7605 | } |
| 7606 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7607 | // Location in constant area that the fixup refers to. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7608 | int32_t offset_into_constant_area_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7609 | }; |
| 7610 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7611 | /** |
| 7612 | * Class to handle late fixup of offsets to a jump table that will be created in the |
| 7613 | * constant area. |
| 7614 | */ |
| 7615 | class JumpTableRIPFixup : public RIPFixup { |
| 7616 | public: |
| 7617 | JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7618 | : RIPFixup(codegen, switch_instr->GetBaseMethodAddress(), static_cast<size_t>(-1)), |
| 7619 | switch_instr_(switch_instr) {} |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7620 | |
| 7621 | void CreateJumpTable() { |
| 7622 | X86Assembler* assembler = codegen_->GetAssembler(); |
| 7623 | |
| 7624 | // Ensure that the reference to the jump table has the correct offset. |
| 7625 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 7626 | SetOffset(offset_in_constant_table); |
| 7627 | |
| 7628 | // The label values in the jump table are computed relative to the |
| 7629 | // instruction addressing the constant area. |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7630 | const int32_t relative_offset = codegen_->GetMethodAddressOffset(base_method_address_); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7631 | |
| 7632 | // Populate the jump table with the correct values for the jump table. |
| 7633 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 7634 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 7635 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 7636 | // The value that we want is the target offset - the position of the table. |
| 7637 | for (int32_t i = 0; i < num_entries; i++) { |
| 7638 | HBasicBlock* b = successors[i]; |
| 7639 | Label* l = codegen_->GetLabelOf(b); |
| 7640 | DCHECK(l->IsBound()); |
| 7641 | int32_t offset_to_block = l->Position() - relative_offset; |
| 7642 | assembler->AppendInt32(offset_to_block); |
| 7643 | } |
| 7644 | } |
| 7645 | |
| 7646 | private: |
| 7647 | const HX86PackedSwitch* switch_instr_; |
| 7648 | }; |
| 7649 | |
| 7650 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 7651 | // Generate the constant area if needed. |
| 7652 | X86Assembler* assembler = GetAssembler(); |
| 7653 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7654 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 7655 | // byte values. |
| 7656 | assembler->Align(4, 0); |
| 7657 | constant_area_start_ = assembler->CodeSize(); |
| 7658 | |
| 7659 | // Populate any jump tables. |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7660 | for (JumpTableRIPFixup* jump_table : fixups_to_jump_tables_) { |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7661 | jump_table->CreateJumpTable(); |
| 7662 | } |
| 7663 | |
| 7664 | // And now add the constant area to the generated code. |
| 7665 | assembler->AddConstantArea(); |
| 7666 | } |
| 7667 | |
| 7668 | // And finish up. |
| 7669 | CodeGenerator::Finalize(allocator); |
| 7670 | } |
| 7671 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7672 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, |
| 7673 | HX86ComputeBaseMethodAddress* method_base, |
| 7674 | Register reg) { |
| 7675 | AssemblerFixup* fixup = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7676 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddDouble(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7677 | return Address(reg, kDummy32BitOffset, fixup); |
| 7678 | } |
| 7679 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7680 | Address CodeGeneratorX86::LiteralFloatAddress(float v, |
| 7681 | HX86ComputeBaseMethodAddress* method_base, |
| 7682 | Register reg) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7683 | AssemblerFixup* fixup = |
| 7684 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddFloat(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7685 | return Address(reg, kDummy32BitOffset, fixup); |
| 7686 | } |
| 7687 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7688 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, |
| 7689 | HX86ComputeBaseMethodAddress* method_base, |
| 7690 | Register reg) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7691 | AssemblerFixup* fixup = |
| 7692 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddInt32(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7693 | return Address(reg, kDummy32BitOffset, fixup); |
| 7694 | } |
| 7695 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7696 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, |
| 7697 | HX86ComputeBaseMethodAddress* method_base, |
| 7698 | Register reg) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7699 | AssemblerFixup* fixup = |
| 7700 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddInt64(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7701 | return Address(reg, kDummy32BitOffset, fixup); |
| 7702 | } |
| 7703 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 7704 | void CodeGeneratorX86::Load32BitValue(Register dest, int32_t value) { |
| 7705 | if (value == 0) { |
| 7706 | __ xorl(dest, dest); |
| 7707 | } else { |
| 7708 | __ movl(dest, Immediate(value)); |
| 7709 | } |
| 7710 | } |
| 7711 | |
| 7712 | void CodeGeneratorX86::Compare32BitValue(Register dest, int32_t value) { |
| 7713 | if (value == 0) { |
| 7714 | __ testl(dest, dest); |
| 7715 | } else { |
| 7716 | __ cmpl(dest, Immediate(value)); |
| 7717 | } |
| 7718 | } |
| 7719 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7720 | void CodeGeneratorX86::GenerateIntCompare(Location lhs, Location rhs) { |
| 7721 | Register lhs_reg = lhs.AsRegister<Register>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7722 | GenerateIntCompare(lhs_reg, rhs); |
| 7723 | } |
| 7724 | |
| 7725 | void CodeGeneratorX86::GenerateIntCompare(Register lhs, Location rhs) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7726 | if (rhs.IsConstant()) { |
| 7727 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7728 | Compare32BitValue(lhs, value); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7729 | } else if (rhs.IsStackSlot()) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7730 | __ cmpl(lhs, Address(ESP, rhs.GetStackIndex())); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7731 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7732 | __ cmpl(lhs, rhs.AsRegister<Register>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7733 | } |
| 7734 | } |
| 7735 | |
| 7736 | Address CodeGeneratorX86::ArrayAddress(Register obj, |
| 7737 | Location index, |
| 7738 | ScaleFactor scale, |
| 7739 | uint32_t data_offset) { |
| 7740 | return index.IsConstant() ? |
| 7741 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) : |
| 7742 | Address(obj, index.AsRegister<Register>(), scale, data_offset); |
| 7743 | } |
| 7744 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7745 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, |
| 7746 | Register reg, |
| 7747 | Register value) { |
| 7748 | // Create a fixup to be used to create and address the jump table. |
| 7749 | JumpTableRIPFixup* table_fixup = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7750 | new (GetGraph()->GetAllocator()) JumpTableRIPFixup(*this, switch_instr); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7751 | |
| 7752 | // We have to populate the jump tables. |
| 7753 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7754 | |
| 7755 | // We want a scaled address, as we are extracting the correct offset from the table. |
| 7756 | return Address(reg, value, TIMES_4, kDummy32BitOffset, table_fixup); |
| 7757 | } |
| 7758 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7759 | // TODO: target as memory. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7760 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, DataType::Type type) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7761 | if (!target.IsValid()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7762 | DCHECK_EQ(type, DataType::Type::kVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7763 | return; |
| 7764 | } |
| 7765 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7766 | DCHECK_NE(type, DataType::Type::kVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7767 | |
| 7768 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 7769 | if (target.Equals(return_loc)) { |
| 7770 | return; |
| 7771 | } |
| 7772 | |
| 7773 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 7774 | // with the else branch. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7775 | if (type == DataType::Type::kInt64) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7776 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7777 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), DataType::Type::kInt32, nullptr); |
| 7778 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), DataType::Type::kInt32, nullptr); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7779 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7780 | } else { |
| 7781 | // Let the parallel move resolver take care of all of this. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7782 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7783 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 7784 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7785 | } |
| 7786 | } |
| 7787 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7788 | void CodeGeneratorX86::PatchJitRootUse(uint8_t* code, |
| 7789 | const uint8_t* roots_data, |
| 7790 | const PatchInfo<Label>& info, |
| 7791 | uint64_t index_in_table) const { |
| 7792 | uint32_t code_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 7793 | uintptr_t address = |
| 7794 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 7795 | typedef __attribute__((__aligned__(1))) uint32_t unaligned_uint32_t; |
| 7796 | reinterpret_cast<unaligned_uint32_t*>(code + code_offset)[0] = |
| 7797 | dchecked_integral_cast<uint32_t>(address); |
| 7798 | } |
| 7799 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7800 | void CodeGeneratorX86::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 7801 | for (const PatchInfo<Label>& info : jit_string_patches_) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7802 | StringReference string_reference(&info.dex_file, dex::StringIndex(info.index)); |
| 7803 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7804 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7805 | } |
| 7806 | |
| 7807 | for (const PatchInfo<Label>& info : jit_class_patches_) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7808 | TypeReference type_reference(&info.dex_file, dex::TypeIndex(info.index)); |
| 7809 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7810 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7811 | } |
| 7812 | } |
| 7813 | |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7814 | void LocationsBuilderX86::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 7815 | ATTRIBUTE_UNUSED) { |
| 7816 | LOG(FATAL) << "Unreachable"; |
| 7817 | } |
| 7818 | |
| 7819 | void InstructionCodeGeneratorX86::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 7820 | ATTRIBUTE_UNUSED) { |
| 7821 | LOG(FATAL) << "Unreachable"; |
| 7822 | } |
| 7823 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7824 | #undef __ |
| 7825 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7826 | } // namespace x86 |
| 7827 | } // namespace art |