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 | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame^] | 1064 | if (GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 1065 | __ addw(Address(kMethodRegisterArgument, ArtMethod::HotnessCountOffset().Int32Value()), |
| 1066 | Immediate(1)); |
| 1067 | } |
| 1068 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1069 | if (!skip_overflow_check) { |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1070 | size_t reserved_bytes = GetStackOverflowReservedBytes(InstructionSet::kX86); |
| 1071 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(reserved_bytes))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1072 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 1073 | } |
| 1074 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1075 | if (HasEmptyFrame()) { |
| 1076 | return; |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1077 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1078 | |
| 1079 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 1080 | Register reg = kCoreCalleeSaves[i]; |
| 1081 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1082 | __ pushl(reg); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1083 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 1084 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1085 | } |
| 1086 | } |
| 1087 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1088 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1089 | __ subl(ESP, Immediate(adjust)); |
| 1090 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1091 | // Save the current method if we need it. Note that we do not |
| 1092 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1093 | // in the SSA graph. |
| 1094 | if (RequiresCurrentMethod()) { |
| 1095 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
| 1096 | } |
Nicolas Geoffray | f789353 | 2017-06-15 12:34:36 +0100 | [diff] [blame] | 1097 | |
| 1098 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1099 | // Initialize should_deoptimize flag to 0. |
| 1100 | __ movl(Address(ESP, GetStackOffsetOfShouldDeoptimizeFlag()), Immediate(0)); |
| 1101 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1102 | } |
| 1103 | |
| 1104 | void CodeGeneratorX86::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1105 | __ cfi().RememberState(); |
| 1106 | if (!HasEmptyFrame()) { |
| 1107 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1108 | __ addl(ESP, Immediate(adjust)); |
| 1109 | __ cfi().AdjustCFAOffset(-adjust); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1110 | |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1111 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1112 | Register reg = kCoreCalleeSaves[i]; |
| 1113 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1114 | __ popl(reg); |
| 1115 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 1116 | __ cfi().Restore(DWARFReg(reg)); |
| 1117 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1118 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1119 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1120 | __ ret(); |
| 1121 | __ cfi().RestoreState(); |
| 1122 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1123 | } |
| 1124 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1125 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 1126 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1127 | } |
| 1128 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1129 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(DataType::Type type) const { |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1130 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1131 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1132 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1133 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1134 | case DataType::Type::kInt8: |
| 1135 | case DataType::Type::kUint16: |
| 1136 | case DataType::Type::kInt16: |
| 1137 | case DataType::Type::kInt32: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1138 | return Location::RegisterLocation(EAX); |
| 1139 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1140 | case DataType::Type::kInt64: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1141 | return Location::RegisterPairLocation(EAX, EDX); |
| 1142 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1143 | case DataType::Type::kVoid: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1144 | return Location::NoLocation(); |
| 1145 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1146 | case DataType::Type::kFloat64: |
| 1147 | case DataType::Type::kFloat32: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1148 | return Location::FpuRegisterLocation(XMM0); |
| 1149 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1150 | |
| 1151 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1152 | } |
| 1153 | |
| 1154 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 1155 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1156 | } |
| 1157 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1158 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(DataType::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1159 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1160 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1161 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1162 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1163 | case DataType::Type::kInt8: |
| 1164 | case DataType::Type::kUint16: |
| 1165 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1166 | case DataType::Type::kInt32: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1167 | uint32_t index = gp_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1168 | stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1169 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1170 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1171 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1172 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1173 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1174 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1175 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1176 | case DataType::Type::kInt64: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1177 | uint32_t index = gp_index_; |
| 1178 | gp_index_ += 2; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1179 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1180 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1181 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 1182 | calling_convention.GetRegisterPairAt(index)); |
| 1183 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1184 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1185 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1186 | } |
| 1187 | } |
| 1188 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1189 | case DataType::Type::kFloat32: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1190 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1191 | stack_index_++; |
| 1192 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1193 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1194 | } else { |
| 1195 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1196 | } |
| 1197 | } |
| 1198 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1199 | case DataType::Type::kFloat64: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1200 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1201 | stack_index_ += 2; |
| 1202 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1203 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1204 | } else { |
| 1205 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1206 | } |
| 1207 | } |
| 1208 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1209 | case DataType::Type::kVoid: |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1210 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1211 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1212 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1213 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1214 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1215 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1216 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 1217 | if (source.Equals(destination)) { |
| 1218 | return; |
| 1219 | } |
| 1220 | if (destination.IsRegister()) { |
| 1221 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1222 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1223 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1224 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1225 | } else { |
| 1226 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1227 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1228 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1229 | } else if (destination.IsFpuRegister()) { |
| 1230 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1231 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1232 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1233 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1234 | } else { |
| 1235 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1236 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1237 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1238 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1239 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1240 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1241 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1242 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1243 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1244 | } else if (source.IsConstant()) { |
| 1245 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1246 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1247 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1248 | } else { |
| 1249 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1250 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 1251 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1252 | } |
| 1253 | } |
| 1254 | } |
| 1255 | |
| 1256 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 1257 | if (source.Equals(destination)) { |
| 1258 | return; |
| 1259 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1260 | if (destination.IsRegisterPair()) { |
| 1261 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1262 | EmitParallelMoves( |
| 1263 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1264 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1265 | DataType::Type::kInt32, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1266 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1267 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1268 | DataType::Type::kInt32); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1269 | } else if (source.IsFpuRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1270 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 1271 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 1272 | __ psrlq(src_reg, Immediate(32)); |
| 1273 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1274 | } else { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1275 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1276 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1277 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 1278 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1279 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 1280 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1281 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1282 | if (source.IsFpuRegister()) { |
| 1283 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 1284 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1285 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1286 | } else if (source.IsRegisterPair()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1287 | size_t elem_size = DataType::Size(DataType::Type::kInt32); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1288 | // Create stack space for 2 elements. |
| 1289 | __ subl(ESP, Immediate(2 * elem_size)); |
| 1290 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 1291 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 1292 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 1293 | // And remove the temporary stack space we allocated. |
| 1294 | __ addl(ESP, Immediate(2 * elem_size)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1295 | } else { |
| 1296 | LOG(FATAL) << "Unimplemented"; |
| 1297 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1298 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1299 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1300 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1301 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1302 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1303 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1304 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1305 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1306 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1307 | } else if (source.IsConstant()) { |
| 1308 | HConstant* constant = source.GetConstant(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1309 | DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant()); |
| 1310 | int64_t value = GetInt64ValueOf(constant); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1311 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1312 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
| 1313 | Immediate(High32Bits(value))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1314 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1315 | DCHECK(source.IsDoubleStackSlot()) << source; |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1316 | EmitParallelMoves( |
| 1317 | Location::StackSlot(source.GetStackIndex()), |
| 1318 | Location::StackSlot(destination.GetStackIndex()), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1319 | DataType::Type::kInt32, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1320 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1321 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1322 | DataType::Type::kInt32); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1323 | } |
| 1324 | } |
| 1325 | } |
| 1326 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1327 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { |
| 1328 | DCHECK(location.IsRegister()); |
| 1329 | __ movl(location.AsRegister<Register>(), Immediate(value)); |
| 1330 | } |
| 1331 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1332 | void CodeGeneratorX86::MoveLocation(Location dst, Location src, DataType::Type dst_type) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1333 | HParallelMove move(GetGraph()->GetAllocator()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1334 | if (dst_type == DataType::Type::kInt64 && !src.IsConstant() && !src.IsFpuRegister()) { |
| 1335 | move.AddMove(src.ToLow(), dst.ToLow(), DataType::Type::kInt32, nullptr); |
| 1336 | move.AddMove(src.ToHigh(), dst.ToHigh(), DataType::Type::kInt32, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1337 | } else { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1338 | move.AddMove(src, dst, dst_type, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1339 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1340 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1341 | } |
| 1342 | |
| 1343 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1344 | if (location.IsRegister()) { |
| 1345 | locations->AddTemp(location); |
| 1346 | } else if (location.IsRegisterPair()) { |
| 1347 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1348 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1349 | } else { |
| 1350 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1351 | } |
| 1352 | } |
| 1353 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1354 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 1355 | if (successor->IsExitBlock()) { |
| 1356 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 1357 | return; // no code needed |
| 1358 | } |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1359 | |
| 1360 | HBasicBlock* block = got->GetBlock(); |
| 1361 | HInstruction* previous = got->GetPrevious(); |
| 1362 | |
| 1363 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1364 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame^] | 1365 | if (codegen_->GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 1366 | __ pushl(EAX); |
| 1367 | __ movl(EAX, Address(ESP, kX86WordSize)); |
| 1368 | __ addw(Address(EAX, ArtMethod::HotnessCountOffset().Int32Value()), Immediate(1)); |
| 1369 | __ popl(EAX); |
| 1370 | } |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1371 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1372 | return; |
| 1373 | } |
| 1374 | |
| 1375 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1376 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1377 | } |
| 1378 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1379 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1380 | } |
| 1381 | } |
| 1382 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1383 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 1384 | got->SetLocations(nullptr); |
| 1385 | } |
| 1386 | |
| 1387 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 1388 | HandleGoto(got, got->GetSuccessor()); |
| 1389 | } |
| 1390 | |
| 1391 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1392 | try_boundary->SetLocations(nullptr); |
| 1393 | } |
| 1394 | |
| 1395 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1396 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1397 | if (!successor->IsExitBlock()) { |
| 1398 | HandleGoto(try_boundary, successor); |
| 1399 | } |
| 1400 | } |
| 1401 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1402 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1403 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1404 | } |
| 1405 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1406 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1407 | } |
| 1408 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1409 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1410 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1411 | LabelType* true_label, |
| 1412 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1413 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1414 | __ j(kUnordered, true_label); |
| 1415 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1416 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1417 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1418 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1419 | } |
| 1420 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1421 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1422 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1423 | LabelType* true_label, |
| 1424 | LabelType* false_label) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1425 | LocationSummary* locations = cond->GetLocations(); |
| 1426 | Location left = locations->InAt(0); |
| 1427 | Location right = locations->InAt(1); |
| 1428 | IfCondition if_cond = cond->GetCondition(); |
| 1429 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1430 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1431 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1432 | IfCondition true_high_cond = if_cond; |
| 1433 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1434 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); // unsigned on lower part |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1435 | |
| 1436 | // Set the conditions for the test, remembering that == needs to be |
| 1437 | // decided using the low words. |
| 1438 | switch (if_cond) { |
| 1439 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1440 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1441 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1442 | break; |
| 1443 | case kCondLT: |
| 1444 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1445 | break; |
| 1446 | case kCondLE: |
| 1447 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1448 | break; |
| 1449 | case kCondGT: |
| 1450 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1451 | break; |
| 1452 | case kCondGE: |
| 1453 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1454 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1455 | case kCondB: |
| 1456 | false_high_cond = kCondA; |
| 1457 | break; |
| 1458 | case kCondBE: |
| 1459 | true_high_cond = kCondB; |
| 1460 | break; |
| 1461 | case kCondA: |
| 1462 | false_high_cond = kCondB; |
| 1463 | break; |
| 1464 | case kCondAE: |
| 1465 | true_high_cond = kCondA; |
| 1466 | break; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1467 | } |
| 1468 | |
| 1469 | if (right.IsConstant()) { |
| 1470 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1471 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1472 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1473 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1474 | codegen_->Compare32BitValue(left_high, val_high); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1475 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1476 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1477 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1478 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1479 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1480 | __ j(X86Condition(true_high_cond), true_label); |
| 1481 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1482 | } |
| 1483 | // Must be equal high, so compare the lows. |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1484 | codegen_->Compare32BitValue(left_low, val_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1485 | } else if (right.IsRegisterPair()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1486 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1487 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1488 | |
| 1489 | __ cmpl(left_high, right_high); |
| 1490 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1491 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1492 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1493 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1494 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1495 | __ j(X86Condition(true_high_cond), true_label); |
| 1496 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1497 | } |
| 1498 | // Must be equal high, so compare the lows. |
| 1499 | __ cmpl(left_low, right_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1500 | } else { |
| 1501 | DCHECK(right.IsDoubleStackSlot()); |
| 1502 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
| 1503 | if (if_cond == kCondNE) { |
| 1504 | __ j(X86Condition(true_high_cond), true_label); |
| 1505 | } else if (if_cond == kCondEQ) { |
| 1506 | __ j(X86Condition(false_high_cond), false_label); |
| 1507 | } else { |
| 1508 | __ j(X86Condition(true_high_cond), true_label); |
| 1509 | __ j(X86Condition(false_high_cond), false_label); |
| 1510 | } |
| 1511 | // Must be equal high, so compare the lows. |
| 1512 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1513 | } |
| 1514 | // The last comparison might be unsigned. |
| 1515 | __ j(final_condition, true_label); |
| 1516 | } |
| 1517 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1518 | void InstructionCodeGeneratorX86::GenerateFPCompare(Location lhs, |
| 1519 | Location rhs, |
| 1520 | HInstruction* insn, |
| 1521 | bool is_double) { |
| 1522 | HX86LoadFromConstantTable* const_area = insn->InputAt(1)->AsX86LoadFromConstantTable(); |
| 1523 | if (is_double) { |
| 1524 | if (rhs.IsFpuRegister()) { |
| 1525 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1526 | } else if (const_area != nullptr) { |
| 1527 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1528 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), |
| 1529 | codegen_->LiteralDoubleAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1530 | const_area->GetConstant()->AsDoubleConstant()->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.IsDoubleStackSlot()); |
| 1535 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1536 | } |
| 1537 | } else { |
| 1538 | if (rhs.IsFpuRegister()) { |
| 1539 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1540 | } else if (const_area != nullptr) { |
| 1541 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1542 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), |
| 1543 | codegen_->LiteralFloatAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1544 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 1545 | const_area->GetBaseMethodAddress(), |
| 1546 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1547 | } else { |
| 1548 | DCHECK(rhs.IsStackSlot()); |
| 1549 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1550 | } |
| 1551 | } |
| 1552 | } |
| 1553 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1554 | template<class LabelType> |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1555 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1556 | LabelType* true_target_in, |
| 1557 | LabelType* false_target_in) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1558 | // Generated branching requires both targets to be explicit. If either of the |
| 1559 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1560 | LabelType fallthrough_target; |
| 1561 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1562 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1563 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1564 | LocationSummary* locations = condition->GetLocations(); |
| 1565 | Location left = locations->InAt(0); |
| 1566 | Location right = locations->InAt(1); |
| 1567 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1568 | DataType::Type type = condition->InputAt(0)->GetType(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1569 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1570 | case DataType::Type::kInt64: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1571 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1572 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1573 | case DataType::Type::kFloat32: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1574 | GenerateFPCompare(left, right, condition, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1575 | GenerateFPJumps(condition, true_target, false_target); |
| 1576 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1577 | case DataType::Type::kFloat64: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1578 | GenerateFPCompare(left, right, condition, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1579 | GenerateFPJumps(condition, true_target, false_target); |
| 1580 | break; |
| 1581 | default: |
| 1582 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1583 | } |
| 1584 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1585 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1586 | __ jmp(false_target); |
| 1587 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1588 | |
| 1589 | if (fallthrough_target.IsLinked()) { |
| 1590 | __ Bind(&fallthrough_target); |
| 1591 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1592 | } |
| 1593 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1594 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1595 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1596 | // are set only strictly before `branch`. We can't use the eflags on long/FP |
| 1597 | // conditions if they are materialized due to the complex branching. |
| 1598 | return cond->IsCondition() && |
| 1599 | cond->GetNext() == branch && |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1600 | cond->InputAt(0)->GetType() != DataType::Type::kInt64 && |
| 1601 | !DataType::IsFloatingPointType(cond->InputAt(0)->GetType()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1602 | } |
| 1603 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1604 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1605 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1606 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1607 | LabelType* true_target, |
| 1608 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1609 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1610 | |
| 1611 | if (true_target == nullptr && false_target == nullptr) { |
| 1612 | // Nothing to do. The code always falls through. |
| 1613 | return; |
| 1614 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1615 | // Constant condition, statically compared against "true" (integer value 1). |
| 1616 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1617 | if (true_target != nullptr) { |
| 1618 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1619 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1620 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1621 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1622 | if (false_target != nullptr) { |
| 1623 | __ jmp(false_target); |
| 1624 | } |
| 1625 | } |
| 1626 | return; |
| 1627 | } |
| 1628 | |
| 1629 | // The following code generates these patterns: |
| 1630 | // (1) true_target == nullptr && false_target != nullptr |
| 1631 | // - opposite condition true => branch to false_target |
| 1632 | // (2) true_target != nullptr && false_target == nullptr |
| 1633 | // - condition true => branch to true_target |
| 1634 | // (3) true_target != nullptr && false_target != nullptr |
| 1635 | // - condition true => branch to true_target |
| 1636 | // - branch to false_target |
| 1637 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1638 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1639 | if (true_target == nullptr) { |
| 1640 | __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1641 | } else { |
| 1642 | __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); |
| 1643 | } |
| 1644 | } else { |
| 1645 | // Materialized condition, compare against 0. |
| 1646 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1647 | if (lhs.IsRegister()) { |
| 1648 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1649 | } else { |
| 1650 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1651 | } |
| 1652 | if (true_target == nullptr) { |
| 1653 | __ j(kEqual, false_target); |
| 1654 | } else { |
| 1655 | __ j(kNotEqual, true_target); |
| 1656 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1657 | } |
| 1658 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1659 | // Condition has not been materialized, use its inputs as the comparison and |
| 1660 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1661 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1662 | |
| 1663 | // If this is a long or FP comparison that has been folded into |
| 1664 | // the HCondition, generate the comparison directly. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1665 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 1666 | if (type == DataType::Type::kInt64 || DataType::IsFloatingPointType(type)) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1667 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1668 | return; |
| 1669 | } |
| 1670 | |
| 1671 | Location lhs = condition->GetLocations()->InAt(0); |
| 1672 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1673 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition). |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1674 | codegen_->GenerateIntCompare(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1675 | if (true_target == nullptr) { |
| 1676 | __ j(X86Condition(condition->GetOppositeCondition()), false_target); |
| 1677 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1678 | __ j(X86Condition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1679 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1680 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1681 | |
| 1682 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1683 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1684 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1685 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1686 | } |
| 1687 | } |
| 1688 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1689 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1690 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1691 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1692 | locations->SetInAt(0, Location::Any()); |
| 1693 | } |
| 1694 | } |
| 1695 | |
| 1696 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1697 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1698 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1699 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1700 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1701 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1702 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1703 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1704 | } |
| 1705 | |
| 1706 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1707 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1708 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 1709 | InvokeRuntimeCallingConvention calling_convention; |
| 1710 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 1711 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1712 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1713 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1714 | locations->SetInAt(0, Location::Any()); |
| 1715 | } |
| 1716 | } |
| 1717 | |
| 1718 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1719 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1720 | GenerateTestAndBranch<Label>(deoptimize, |
| 1721 | /* condition_input_index */ 0, |
| 1722 | slow_path->GetEntryLabel(), |
| 1723 | /* false_target */ nullptr); |
| 1724 | } |
| 1725 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1726 | void LocationsBuilderX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1727 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1728 | LocationSummary(flag, LocationSummary::kNoCall); |
| 1729 | locations->SetOut(Location::RequiresRegister()); |
| 1730 | } |
| 1731 | |
| 1732 | void InstructionCodeGeneratorX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1733 | __ movl(flag->GetLocations()->Out().AsRegister<Register>(), |
| 1734 | Address(ESP, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1735 | } |
| 1736 | |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1737 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1738 | // There are no conditional move instructions for XMMs. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1739 | if (DataType::IsFloatingPointType(select->GetType())) { |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1740 | return false; |
| 1741 | } |
| 1742 | |
| 1743 | // A FP condition doesn't generate the single CC that we need. |
| 1744 | // In 32 bit mode, a long condition doesn't generate a single CC either. |
| 1745 | HInstruction* condition = select->GetCondition(); |
| 1746 | if (condition->IsCondition()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1747 | DataType::Type compare_type = condition->InputAt(0)->GetType(); |
| 1748 | if (compare_type == DataType::Type::kInt64 || |
| 1749 | DataType::IsFloatingPointType(compare_type)) { |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1750 | return false; |
| 1751 | } |
| 1752 | } |
| 1753 | |
| 1754 | // We can generate a CMOV for this Select. |
| 1755 | return true; |
| 1756 | } |
| 1757 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1758 | void LocationsBuilderX86::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1759 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1760 | if (DataType::IsFloatingPointType(select->GetType())) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1761 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1762 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1763 | } else { |
| 1764 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1765 | if (SelectCanUseCMOV(select)) { |
| 1766 | if (select->InputAt(1)->IsConstant()) { |
| 1767 | // Cmov can't handle a constant value. |
| 1768 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1769 | } else { |
| 1770 | locations->SetInAt(1, Location::Any()); |
| 1771 | } |
| 1772 | } else { |
| 1773 | locations->SetInAt(1, Location::Any()); |
| 1774 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1775 | } |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1776 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1777 | locations->SetInAt(2, Location::RequiresRegister()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1778 | } |
| 1779 | locations->SetOut(Location::SameAsFirstInput()); |
| 1780 | } |
| 1781 | |
| 1782 | void InstructionCodeGeneratorX86::VisitSelect(HSelect* select) { |
| 1783 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1784 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1785 | if (SelectCanUseCMOV(select)) { |
| 1786 | // If both the condition and the source types are integer, we can generate |
| 1787 | // a CMOV to implement Select. |
| 1788 | |
| 1789 | HInstruction* select_condition = select->GetCondition(); |
| 1790 | Condition cond = kNotEqual; |
| 1791 | |
| 1792 | // Figure out how to test the 'condition'. |
| 1793 | if (select_condition->IsCondition()) { |
| 1794 | HCondition* condition = select_condition->AsCondition(); |
| 1795 | if (!condition->IsEmittedAtUseSite()) { |
| 1796 | // This was a previously materialized condition. |
| 1797 | // Can we use the existing condition code? |
| 1798 | if (AreEflagsSetFrom(condition, select)) { |
| 1799 | // Materialization was the previous instruction. Condition codes are right. |
| 1800 | cond = X86Condition(condition->GetCondition()); |
| 1801 | } else { |
| 1802 | // No, we have to recreate the condition code. |
| 1803 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1804 | __ testl(cond_reg, cond_reg); |
| 1805 | } |
| 1806 | } else { |
| 1807 | // We can't handle FP or long here. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1808 | DCHECK_NE(condition->InputAt(0)->GetType(), DataType::Type::kInt64); |
| 1809 | DCHECK(!DataType::IsFloatingPointType(condition->InputAt(0)->GetType())); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1810 | LocationSummary* cond_locations = condition->GetLocations(); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1811 | codegen_->GenerateIntCompare(cond_locations->InAt(0), cond_locations->InAt(1)); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1812 | cond = X86Condition(condition->GetCondition()); |
| 1813 | } |
| 1814 | } else { |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 1815 | // Must be a Boolean condition, which needs to be compared to 0. |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1816 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1817 | __ testl(cond_reg, cond_reg); |
| 1818 | } |
| 1819 | |
| 1820 | // If the condition is true, overwrite the output, which already contains false. |
| 1821 | Location false_loc = locations->InAt(0); |
| 1822 | Location true_loc = locations->InAt(1); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1823 | if (select->GetType() == DataType::Type::kInt64) { |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1824 | // 64 bit conditional move. |
| 1825 | Register false_high = false_loc.AsRegisterPairHigh<Register>(); |
| 1826 | Register false_low = false_loc.AsRegisterPairLow<Register>(); |
| 1827 | if (true_loc.IsRegisterPair()) { |
| 1828 | __ cmovl(cond, false_high, true_loc.AsRegisterPairHigh<Register>()); |
| 1829 | __ cmovl(cond, false_low, true_loc.AsRegisterPairLow<Register>()); |
| 1830 | } else { |
| 1831 | __ cmovl(cond, false_high, Address(ESP, true_loc.GetHighStackIndex(kX86WordSize))); |
| 1832 | __ cmovl(cond, false_low, Address(ESP, true_loc.GetStackIndex())); |
| 1833 | } |
| 1834 | } else { |
| 1835 | // 32 bit conditional move. |
| 1836 | Register false_reg = false_loc.AsRegister<Register>(); |
| 1837 | if (true_loc.IsRegister()) { |
| 1838 | __ cmovl(cond, false_reg, true_loc.AsRegister<Register>()); |
| 1839 | } else { |
| 1840 | __ cmovl(cond, false_reg, Address(ESP, true_loc.GetStackIndex())); |
| 1841 | } |
| 1842 | } |
| 1843 | } else { |
| 1844 | NearLabel false_target; |
| 1845 | GenerateTestAndBranch<NearLabel>( |
| 1846 | select, /* condition_input_index */ 2, /* true_target */ nullptr, &false_target); |
| 1847 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1848 | __ Bind(&false_target); |
| 1849 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1850 | } |
| 1851 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1852 | void LocationsBuilderX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1853 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1854 | } |
| 1855 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1856 | void InstructionCodeGeneratorX86::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1857 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1858 | } |
| 1859 | |
| 1860 | void CodeGeneratorX86::GenerateNop() { |
| 1861 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1862 | } |
| 1863 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1864 | void LocationsBuilderX86::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1865 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1866 | new (GetGraph()->GetAllocator()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1867 | // Handle the long/FP comparisons made in instruction simplification. |
| 1868 | switch (cond->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1869 | case DataType::Type::kInt64: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1870 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1871 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1872 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1873 | locations->SetOut(Location::RequiresRegister()); |
| 1874 | } |
| 1875 | break; |
| 1876 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1877 | case DataType::Type::kFloat32: |
| 1878 | case DataType::Type::kFloat64: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1879 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1880 | if (cond->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 1881 | DCHECK(cond->InputAt(1)->IsEmittedAtUseSite()); |
| 1882 | } else if (cond->InputAt(1)->IsConstant()) { |
| 1883 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1884 | } else { |
| 1885 | locations->SetInAt(1, Location::Any()); |
| 1886 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1887 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1888 | locations->SetOut(Location::RequiresRegister()); |
| 1889 | } |
| 1890 | break; |
| 1891 | } |
| 1892 | default: |
| 1893 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1894 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1895 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1896 | // We need a byte register. |
| 1897 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1898 | } |
| 1899 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1900 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1901 | } |
| 1902 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1903 | void InstructionCodeGeneratorX86::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1904 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1905 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1906 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1907 | |
| 1908 | LocationSummary* locations = cond->GetLocations(); |
| 1909 | Location lhs = locations->InAt(0); |
| 1910 | Location rhs = locations->InAt(1); |
| 1911 | Register reg = locations->Out().AsRegister<Register>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1912 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1913 | |
| 1914 | switch (cond->InputAt(0)->GetType()) { |
| 1915 | default: { |
| 1916 | // Integer case. |
| 1917 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 1918 | // Clear output register: setb only sets the low byte. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1919 | __ xorl(reg, reg); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1920 | codegen_->GenerateIntCompare(lhs, rhs); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1921 | __ setb(X86Condition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1922 | return; |
| 1923 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1924 | case DataType::Type::kInt64: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1925 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1926 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1927 | case DataType::Type::kFloat32: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1928 | GenerateFPCompare(lhs, rhs, cond, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1929 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1930 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1931 | case DataType::Type::kFloat64: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1932 | GenerateFPCompare(lhs, rhs, cond, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1933 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1934 | break; |
| 1935 | } |
| 1936 | |
| 1937 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1938 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1939 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1940 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1941 | __ Bind(&false_label); |
| 1942 | __ xorl(reg, reg); |
| 1943 | __ jmp(&done_label); |
| 1944 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1945 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1946 | __ Bind(&true_label); |
| 1947 | __ movl(reg, Immediate(1)); |
| 1948 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1949 | } |
| 1950 | |
| 1951 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1952 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1953 | } |
| 1954 | |
| 1955 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1956 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1957 | } |
| 1958 | |
| 1959 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1960 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1961 | } |
| 1962 | |
| 1963 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1964 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1965 | } |
| 1966 | |
| 1967 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1968 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1969 | } |
| 1970 | |
| 1971 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1972 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1973 | } |
| 1974 | |
| 1975 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1976 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1977 | } |
| 1978 | |
| 1979 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1980 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1981 | } |
| 1982 | |
| 1983 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1984 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1985 | } |
| 1986 | |
| 1987 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1988 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1989 | } |
| 1990 | |
| 1991 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1992 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1993 | } |
| 1994 | |
| 1995 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1996 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1997 | } |
| 1998 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1999 | void LocationsBuilderX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2000 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2001 | } |
| 2002 | |
| 2003 | void InstructionCodeGeneratorX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2004 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2005 | } |
| 2006 | |
| 2007 | void LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2008 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2009 | } |
| 2010 | |
| 2011 | void InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2012 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2013 | } |
| 2014 | |
| 2015 | void LocationsBuilderX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2016 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2017 | } |
| 2018 | |
| 2019 | void InstructionCodeGeneratorX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2020 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2021 | } |
| 2022 | |
| 2023 | void LocationsBuilderX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2024 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2025 | } |
| 2026 | |
| 2027 | void InstructionCodeGeneratorX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2028 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2029 | } |
| 2030 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2031 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2032 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2033 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2034 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2035 | } |
| 2036 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2037 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2038 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2039 | } |
| 2040 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2041 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 2042 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2043 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2044 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2045 | } |
| 2046 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2047 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2048 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2049 | } |
| 2050 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2051 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2052 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2053 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2054 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2055 | } |
| 2056 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2057 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2058 | // Will be generated at use site. |
| 2059 | } |
| 2060 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2061 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 2062 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2063 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2064 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2065 | } |
| 2066 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2067 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2068 | // Will be generated at use site. |
| 2069 | } |
| 2070 | |
| 2071 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2072 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2073 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2074 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2075 | } |
| 2076 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2077 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2078 | // Will be generated at use site. |
| 2079 | } |
| 2080 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2081 | void LocationsBuilderX86::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 2082 | constructor_fence->SetLocations(nullptr); |
| 2083 | } |
| 2084 | |
| 2085 | void InstructionCodeGeneratorX86::VisitConstructorFence( |
| 2086 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 2087 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 2088 | } |
| 2089 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2090 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2091 | memory_barrier->SetLocations(nullptr); |
| 2092 | } |
| 2093 | |
| 2094 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 2095 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2096 | } |
| 2097 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2098 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2099 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2100 | } |
| 2101 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2102 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2103 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2104 | } |
| 2105 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2106 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2107 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2108 | new (GetGraph()->GetAllocator()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2109 | switch (ret->InputAt(0)->GetType()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2110 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2111 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2112 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2113 | case DataType::Type::kInt8: |
| 2114 | case DataType::Type::kUint16: |
| 2115 | case DataType::Type::kInt16: |
| 2116 | case DataType::Type::kInt32: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2117 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2118 | break; |
| 2119 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2120 | case DataType::Type::kInt64: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2121 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2122 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2123 | break; |
| 2124 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2125 | case DataType::Type::kFloat32: |
| 2126 | case DataType::Type::kFloat64: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2127 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2128 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2129 | break; |
| 2130 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2131 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2132 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2133 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2134 | } |
| 2135 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2136 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2137 | if (kIsDebugBuild) { |
| 2138 | switch (ret->InputAt(0)->GetType()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2139 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2140 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2141 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2142 | case DataType::Type::kInt8: |
| 2143 | case DataType::Type::kUint16: |
| 2144 | case DataType::Type::kInt16: |
| 2145 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2146 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2147 | break; |
| 2148 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2149 | case DataType::Type::kInt64: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2150 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 2151 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2152 | break; |
| 2153 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2154 | case DataType::Type::kFloat32: |
| 2155 | case DataType::Type::kFloat64: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2156 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2157 | break; |
| 2158 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2159 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2160 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2161 | } |
| 2162 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2163 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2164 | } |
| 2165 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2166 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2167 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2168 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2169 | // the method_idx. |
| 2170 | HandleInvoke(invoke); |
| 2171 | } |
| 2172 | |
| 2173 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2174 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2175 | } |
| 2176 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2177 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2178 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2179 | // art::PrepareForRegisterAllocation. |
| 2180 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2181 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2182 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2183 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 2184 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeMethodLoadKind()) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 2185 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2186 | } |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2187 | return; |
| 2188 | } |
| 2189 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2190 | HandleInvoke(invoke); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2191 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2192 | // 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] | 2193 | if (invoke->HasPcRelativeMethodLoadKind()) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2194 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2195 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2196 | } |
| 2197 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2198 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 2199 | if (invoke->GetLocations()->Intrinsified()) { |
| 2200 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 2201 | intrinsic.Dispatch(invoke); |
| 2202 | return true; |
| 2203 | } |
| 2204 | return false; |
| 2205 | } |
| 2206 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2207 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2208 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2209 | // art::PrepareForRegisterAllocation. |
| 2210 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2211 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2212 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2213 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2214 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2215 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2216 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2217 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2218 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2219 | } |
| 2220 | |
| 2221 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 2222 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 2223 | if (intrinsic.TryDispatch(invoke)) { |
| 2224 | return; |
| 2225 | } |
| 2226 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2227 | HandleInvoke(invoke); |
| 2228 | } |
| 2229 | |
| 2230 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2231 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2232 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2233 | } |
| 2234 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2235 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2236 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2237 | return; |
| 2238 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2239 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2240 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2241 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2242 | } |
| 2243 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2244 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2245 | // This call to HandleInvoke allocates a temporary (core) register |
| 2246 | // which is also used to transfer the hidden argument from FP to |
| 2247 | // core register. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2248 | HandleInvoke(invoke); |
| 2249 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2250 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2251 | } |
| 2252 | |
| 2253 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2254 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2255 | LocationSummary* locations = invoke->GetLocations(); |
| 2256 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2257 | XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2258 | Location receiver = locations->InAt(0); |
| 2259 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2260 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2261 | // Set the hidden argument. This is safe to do this here, as XMM7 |
| 2262 | // won't be modified thereafter, before the `call` instruction. |
| 2263 | DCHECK_EQ(XMM7, hidden_reg); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2264 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2265 | __ movd(hidden_reg, temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2266 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2267 | if (receiver.IsStackSlot()) { |
| 2268 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2269 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2270 | __ movl(temp, Address(temp, class_offset)); |
| 2271 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2272 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2273 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2274 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2275 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2276 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2277 | // emit a read barrier for the previous class reference load. |
| 2278 | // However this is not required in practice, as this is an |
| 2279 | // intermediate/temporary reference and because the current |
| 2280 | // concurrent copying collector keeps the from-space memory |
| 2281 | // intact/accessible until the end of the marking phase (the |
| 2282 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2283 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2284 | // temp = temp->GetAddressOfIMT() |
| 2285 | __ movl(temp, |
| 2286 | Address(temp, mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2287 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2288 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2289 | invoke->GetImtIndex(), kX86PointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2290 | __ movl(temp, Address(temp, method_offset)); |
| 2291 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2292 | __ call(Address(temp, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2293 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2294 | |
| 2295 | DCHECK(!codegen_->IsLeafMethod()); |
| 2296 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2297 | } |
| 2298 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2299 | void LocationsBuilderX86::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2300 | HandleInvoke(invoke); |
| 2301 | } |
| 2302 | |
| 2303 | void InstructionCodeGeneratorX86::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2304 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 2305 | } |
| 2306 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2307 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 2308 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2309 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2310 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2311 | case DataType::Type::kInt32: |
| 2312 | case DataType::Type::kInt64: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2313 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2314 | locations->SetOut(Location::SameAsFirstInput()); |
| 2315 | break; |
| 2316 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2317 | case DataType::Type::kFloat32: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2318 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2319 | locations->SetOut(Location::SameAsFirstInput()); |
| 2320 | locations->AddTemp(Location::RequiresRegister()); |
| 2321 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2322 | break; |
| 2323 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2324 | case DataType::Type::kFloat64: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2325 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2326 | locations->SetOut(Location::SameAsFirstInput()); |
| 2327 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2328 | break; |
| 2329 | |
| 2330 | default: |
| 2331 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2332 | } |
| 2333 | } |
| 2334 | |
| 2335 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 2336 | LocationSummary* locations = neg->GetLocations(); |
| 2337 | Location out = locations->Out(); |
| 2338 | Location in = locations->InAt(0); |
| 2339 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2340 | case DataType::Type::kInt32: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2341 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2342 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2343 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2344 | break; |
| 2345 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2346 | case DataType::Type::kInt64: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2347 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2348 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2349 | __ negl(out.AsRegisterPairLow<Register>()); |
| 2350 | // Negation is similar to subtraction from zero. The least |
| 2351 | // significant byte triggers a borrow when it is different from |
| 2352 | // zero; to take it into account, add 1 to the most significant |
| 2353 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 2354 | // operation. |
| 2355 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2356 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 2357 | break; |
| 2358 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2359 | case DataType::Type::kFloat32: { |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2360 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2361 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 2362 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2363 | // Implement float negation with an exclusive or with value |
| 2364 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2365 | // single-precision floating-point number). |
| 2366 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 2367 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2368 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2369 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2370 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2371 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2372 | case DataType::Type::kFloat64: { |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2373 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2374 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2375 | // Implement double negation with an exclusive or with value |
| 2376 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 2377 | // a double-precision floating-point number). |
| 2378 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2379 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2380 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2381 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2382 | |
| 2383 | default: |
| 2384 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2385 | } |
| 2386 | } |
| 2387 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2388 | void LocationsBuilderX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2389 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2390 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2391 | DCHECK(DataType::IsFloatingPointType(neg->GetType())); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2392 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2393 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2394 | locations->SetOut(Location::SameAsFirstInput()); |
| 2395 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2396 | } |
| 2397 | |
| 2398 | void InstructionCodeGeneratorX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2399 | LocationSummary* locations = neg->GetLocations(); |
| 2400 | Location out = locations->Out(); |
| 2401 | DCHECK(locations->InAt(0).Equals(out)); |
| 2402 | |
| 2403 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 2404 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2405 | if (neg->GetType() == DataType::Type::kFloat32) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 2406 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x80000000), |
| 2407 | neg->GetBaseMethodAddress(), |
| 2408 | constant_area)); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2409 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| 2410 | } else { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 2411 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000), |
| 2412 | neg->GetBaseMethodAddress(), |
| 2413 | constant_area)); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2414 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| 2415 | } |
| 2416 | } |
| 2417 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2418 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2419 | DataType::Type result_type = conversion->GetResultType(); |
| 2420 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2421 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 2422 | << input_type << " -> " << result_type; |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2423 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2424 | // The float-to-long and double-to-long type conversions rely on a |
| 2425 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2426 | LocationSummary::CallKind call_kind = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2427 | ((input_type == DataType::Type::kFloat32 || input_type == DataType::Type::kFloat64) |
| 2428 | && result_type == DataType::Type::kInt64) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2429 | ? LocationSummary::kCallOnMainOnly |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2430 | : LocationSummary::kNoCall; |
| 2431 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2432 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, call_kind); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2433 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2434 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2435 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2436 | case DataType::Type::kInt8: |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2437 | switch (input_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2438 | case DataType::Type::kUint8: |
| 2439 | case DataType::Type::kInt8: |
| 2440 | case DataType::Type::kUint16: |
| 2441 | case DataType::Type::kInt16: |
| 2442 | case DataType::Type::kInt32: |
| 2443 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 2444 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2445 | // the validation of the linear scan implementation |
| 2446 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2447 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2448 | case DataType::Type::kInt64: { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2449 | HInstruction* input = conversion->InputAt(0); |
| 2450 | Location input_location = input->IsConstant() |
| 2451 | ? Location::ConstantLocation(input->AsConstant()) |
| 2452 | : Location::RegisterPairLocation(EAX, EDX); |
| 2453 | locations->SetInAt(0, input_location); |
| 2454 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2455 | // the validation of the linear scan implementation |
| 2456 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2457 | break; |
| 2458 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2459 | |
| 2460 | default: |
| 2461 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2462 | << " to " << result_type; |
| 2463 | } |
| 2464 | break; |
| 2465 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2466 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2467 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2468 | DCHECK(DataType::IsIntegralType(input_type)) << input_type; |
| 2469 | locations->SetInAt(0, Location::Any()); |
| 2470 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2471 | break; |
| 2472 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2473 | case DataType::Type::kInt32: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2474 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2475 | case DataType::Type::kInt64: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2476 | locations->SetInAt(0, Location::Any()); |
| 2477 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2478 | break; |
| 2479 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2480 | case DataType::Type::kFloat32: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2481 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2482 | locations->SetOut(Location::RequiresRegister()); |
| 2483 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2484 | break; |
| 2485 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2486 | case DataType::Type::kFloat64: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2487 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2488 | locations->SetOut(Location::RequiresRegister()); |
| 2489 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2490 | break; |
| 2491 | |
| 2492 | default: |
| 2493 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2494 | << " to " << result_type; |
| 2495 | } |
| 2496 | break; |
| 2497 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2498 | case DataType::Type::kInt64: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2499 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2500 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2501 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2502 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2503 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2504 | case DataType::Type::kInt16: |
| 2505 | case DataType::Type::kInt32: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2506 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 2507 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2508 | break; |
| 2509 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2510 | case DataType::Type::kFloat32: |
| 2511 | case DataType::Type::kFloat64: { |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2512 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2513 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 2514 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 2515 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2516 | // The runtime helper puts the result in EAX, EDX. |
| 2517 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2518 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2519 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2520 | |
| 2521 | default: |
| 2522 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2523 | << " to " << result_type; |
| 2524 | } |
| 2525 | break; |
| 2526 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2527 | case DataType::Type::kFloat32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2528 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2529 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2530 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2531 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2532 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2533 | case DataType::Type::kInt16: |
| 2534 | case DataType::Type::kInt32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2535 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2536 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2537 | break; |
| 2538 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2539 | case DataType::Type::kInt64: |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2540 | locations->SetInAt(0, Location::Any()); |
| 2541 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2542 | break; |
| 2543 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2544 | case DataType::Type::kFloat64: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2545 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2546 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2547 | break; |
| 2548 | |
| 2549 | default: |
| 2550 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2551 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 2552 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2553 | break; |
| 2554 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2555 | case DataType::Type::kFloat64: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2556 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2557 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2558 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2559 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2560 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2561 | case DataType::Type::kInt16: |
| 2562 | case DataType::Type::kInt32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2563 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2564 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2565 | break; |
| 2566 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2567 | case DataType::Type::kInt64: |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2568 | locations->SetInAt(0, Location::Any()); |
| 2569 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2570 | break; |
| 2571 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2572 | case DataType::Type::kFloat32: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2573 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2574 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2575 | break; |
| 2576 | |
| 2577 | default: |
| 2578 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2579 | << " to " << result_type; |
| 2580 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2581 | break; |
| 2582 | |
| 2583 | default: |
| 2584 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2585 | << " to " << result_type; |
| 2586 | } |
| 2587 | } |
| 2588 | |
| 2589 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 2590 | LocationSummary* locations = conversion->GetLocations(); |
| 2591 | Location out = locations->Out(); |
| 2592 | Location in = locations->InAt(0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2593 | DataType::Type result_type = conversion->GetResultType(); |
| 2594 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2595 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 2596 | << input_type << " -> " << result_type; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2597 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2598 | case DataType::Type::kUint8: |
| 2599 | switch (input_type) { |
| 2600 | case DataType::Type::kInt8: |
| 2601 | case DataType::Type::kUint16: |
| 2602 | case DataType::Type::kInt16: |
| 2603 | case DataType::Type::kInt32: |
| 2604 | if (in.IsRegister()) { |
| 2605 | __ movzxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
| 2606 | } else { |
| 2607 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2608 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2609 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint8_t>(value))); |
| 2610 | } |
| 2611 | break; |
| 2612 | case DataType::Type::kInt64: |
| 2613 | if (in.IsRegisterPair()) { |
| 2614 | __ movzxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 2615 | } else { |
| 2616 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2617 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2618 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint8_t>(value))); |
| 2619 | } |
| 2620 | break; |
| 2621 | |
| 2622 | default: |
| 2623 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2624 | << " to " << result_type; |
| 2625 | } |
| 2626 | break; |
| 2627 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2628 | case DataType::Type::kInt8: |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2629 | switch (input_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2630 | case DataType::Type::kUint8: |
| 2631 | case DataType::Type::kUint16: |
| 2632 | case DataType::Type::kInt16: |
| 2633 | case DataType::Type::kInt32: |
| 2634 | if (in.IsRegister()) { |
| 2635 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
| 2636 | } else { |
| 2637 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2638 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2639 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2640 | } |
| 2641 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2642 | case DataType::Type::kInt64: |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2643 | if (in.IsRegisterPair()) { |
| 2644 | __ movsxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 2645 | } else { |
| 2646 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2647 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2648 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2649 | } |
| 2650 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2651 | |
| 2652 | default: |
| 2653 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2654 | << " to " << result_type; |
| 2655 | } |
| 2656 | break; |
| 2657 | |
| 2658 | case DataType::Type::kUint16: |
| 2659 | switch (input_type) { |
| 2660 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2661 | case DataType::Type::kInt16: |
| 2662 | case DataType::Type::kInt32: |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2663 | if (in.IsRegister()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2664 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
| 2665 | } else if (in.IsStackSlot()) { |
| 2666 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2667 | } else { |
| 2668 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2669 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2670 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
| 2671 | } |
| 2672 | break; |
| 2673 | case DataType::Type::kInt64: |
| 2674 | if (in.IsRegisterPair()) { |
| 2675 | __ movzxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2676 | } else if (in.IsDoubleStackSlot()) { |
| 2677 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2678 | } else { |
| 2679 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2680 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2681 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2682 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2683 | break; |
| 2684 | |
| 2685 | default: |
| 2686 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2687 | << " to " << result_type; |
| 2688 | } |
| 2689 | break; |
| 2690 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2691 | case DataType::Type::kInt16: |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2692 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2693 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2694 | case DataType::Type::kInt32: |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2695 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2696 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2697 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2698 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2699 | } else { |
| 2700 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2701 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2702 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2703 | } |
| 2704 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2705 | case DataType::Type::kInt64: |
| 2706 | if (in.IsRegisterPair()) { |
| 2707 | __ movsxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2708 | } else if (in.IsDoubleStackSlot()) { |
| 2709 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2710 | } else { |
| 2711 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2712 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2713 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
| 2714 | } |
| 2715 | break; |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2716 | |
| 2717 | default: |
| 2718 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2719 | << " to " << result_type; |
| 2720 | } |
| 2721 | break; |
| 2722 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2723 | case DataType::Type::kInt32: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2724 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2725 | case DataType::Type::kInt64: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2726 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2727 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2728 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2729 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2730 | } else { |
| 2731 | DCHECK(in.IsConstant()); |
| 2732 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2733 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2734 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2735 | } |
| 2736 | break; |
| 2737 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2738 | case DataType::Type::kFloat32: { |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2739 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2740 | Register output = out.AsRegister<Register>(); |
| 2741 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2742 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2743 | |
| 2744 | __ movl(output, Immediate(kPrimIntMax)); |
| 2745 | // temp = int-to-float(output) |
| 2746 | __ cvtsi2ss(temp, output); |
| 2747 | // if input >= temp goto done |
| 2748 | __ comiss(input, temp); |
| 2749 | __ j(kAboveEqual, &done); |
| 2750 | // if input == NaN goto nan |
| 2751 | __ j(kUnordered, &nan); |
| 2752 | // output = float-to-int-truncate(input) |
| 2753 | __ cvttss2si(output, input); |
| 2754 | __ jmp(&done); |
| 2755 | __ Bind(&nan); |
| 2756 | // output = 0 |
| 2757 | __ xorl(output, output); |
| 2758 | __ Bind(&done); |
| 2759 | break; |
| 2760 | } |
| 2761 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2762 | case DataType::Type::kFloat64: { |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2763 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2764 | Register output = out.AsRegister<Register>(); |
| 2765 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2766 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2767 | |
| 2768 | __ movl(output, Immediate(kPrimIntMax)); |
| 2769 | // temp = int-to-double(output) |
| 2770 | __ cvtsi2sd(temp, output); |
| 2771 | // if input >= temp goto done |
| 2772 | __ comisd(input, temp); |
| 2773 | __ j(kAboveEqual, &done); |
| 2774 | // if input == NaN goto nan |
| 2775 | __ j(kUnordered, &nan); |
| 2776 | // output = double-to-int-truncate(input) |
| 2777 | __ cvttsd2si(output, input); |
| 2778 | __ jmp(&done); |
| 2779 | __ Bind(&nan); |
| 2780 | // output = 0 |
| 2781 | __ xorl(output, output); |
| 2782 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2783 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2784 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2785 | |
| 2786 | default: |
| 2787 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2788 | << " to " << result_type; |
| 2789 | } |
| 2790 | break; |
| 2791 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2792 | case DataType::Type::kInt64: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2793 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2794 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2795 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2796 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2797 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2798 | case DataType::Type::kInt16: |
| 2799 | case DataType::Type::kInt32: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2800 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2801 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2802 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2803 | __ cdq(); |
| 2804 | break; |
| 2805 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2806 | case DataType::Type::kFloat32: |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2807 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2808 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2809 | break; |
| 2810 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2811 | case DataType::Type::kFloat64: |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2812 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2813 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2814 | break; |
| 2815 | |
| 2816 | default: |
| 2817 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2818 | << " to " << result_type; |
| 2819 | } |
| 2820 | break; |
| 2821 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2822 | case DataType::Type::kFloat32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2823 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2824 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2825 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2826 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2827 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2828 | case DataType::Type::kInt16: |
| 2829 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2830 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2831 | break; |
| 2832 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2833 | case DataType::Type::kInt64: { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2834 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2835 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2836 | // Create stack space for the call to |
| 2837 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2838 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2839 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2840 | adjustment = DataType::Size(DataType::Type::kInt64); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2841 | __ subl(ESP, Immediate(adjustment)); |
| 2842 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2843 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2844 | // Load the value to the FP stack, using temporaries if needed. |
| 2845 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2846 | |
| 2847 | if (out.IsStackSlot()) { |
| 2848 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2849 | } else { |
| 2850 | __ fstps(Address(ESP, 0)); |
| 2851 | Location stack_temp = Location::StackSlot(0); |
| 2852 | codegen_->Move32(out, stack_temp); |
| 2853 | } |
| 2854 | |
| 2855 | // Remove the temporary stack space we allocated. |
| 2856 | if (adjustment != 0) { |
| 2857 | __ addl(ESP, Immediate(adjustment)); |
| 2858 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2859 | break; |
| 2860 | } |
| 2861 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2862 | case DataType::Type::kFloat64: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2863 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2864 | break; |
| 2865 | |
| 2866 | default: |
| 2867 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2868 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 2869 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2870 | break; |
| 2871 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2872 | case DataType::Type::kFloat64: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2873 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2874 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2875 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2876 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2877 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2878 | case DataType::Type::kInt16: |
| 2879 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2880 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2881 | break; |
| 2882 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2883 | case DataType::Type::kInt64: { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2884 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2885 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2886 | // Create stack space for the call to |
| 2887 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2888 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2889 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2890 | adjustment = DataType::Size(DataType::Type::kInt64); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2891 | __ subl(ESP, Immediate(adjustment)); |
| 2892 | } |
| 2893 | |
| 2894 | // Load the value to the FP stack, using temporaries if needed. |
| 2895 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2896 | |
| 2897 | if (out.IsDoubleStackSlot()) { |
| 2898 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2899 | } else { |
| 2900 | __ fstpl(Address(ESP, 0)); |
| 2901 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2902 | codegen_->Move64(out, stack_temp); |
| 2903 | } |
| 2904 | |
| 2905 | // Remove the temporary stack space we allocated. |
| 2906 | if (adjustment != 0) { |
| 2907 | __ addl(ESP, Immediate(adjustment)); |
| 2908 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2909 | break; |
| 2910 | } |
| 2911 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2912 | case DataType::Type::kFloat32: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2913 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2914 | break; |
| 2915 | |
| 2916 | default: |
| 2917 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2918 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 2919 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2920 | break; |
| 2921 | |
| 2922 | default: |
| 2923 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2924 | << " to " << result_type; |
| 2925 | } |
| 2926 | } |
| 2927 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2928 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2929 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2930 | new (GetGraph()->GetAllocator()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2931 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2932 | case DataType::Type::kInt32: { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2933 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2934 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2935 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2936 | break; |
| 2937 | } |
| 2938 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2939 | case DataType::Type::kInt64: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2940 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2941 | locations->SetInAt(1, Location::Any()); |
| 2942 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2943 | break; |
| 2944 | } |
| 2945 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2946 | case DataType::Type::kFloat32: |
| 2947 | case DataType::Type::kFloat64: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2948 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2949 | if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2950 | DCHECK(add->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2951 | } else if (add->InputAt(1)->IsConstant()) { |
| 2952 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2953 | } else { |
| 2954 | locations->SetInAt(1, Location::Any()); |
| 2955 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2956 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2957 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2958 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2959 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2960 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2961 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2962 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2963 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2964 | } |
| 2965 | |
| 2966 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 2967 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2968 | Location first = locations->InAt(0); |
| 2969 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2970 | Location out = locations->Out(); |
| 2971 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2972 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2973 | case DataType::Type::kInt32: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2974 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2975 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2976 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2977 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2978 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2979 | } else { |
| 2980 | __ leal(out.AsRegister<Register>(), Address( |
| 2981 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 2982 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2983 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2984 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2985 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2986 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 2987 | } else { |
| 2988 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 2989 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2990 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2991 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2992 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2993 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2994 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2995 | } |
| 2996 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2997 | case DataType::Type::kInt64: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2998 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2999 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3000 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3001 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3002 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 3003 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3004 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3005 | } else { |
| 3006 | DCHECK(second.IsConstant()) << second; |
| 3007 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3008 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 3009 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3010 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3011 | break; |
| 3012 | } |
| 3013 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3014 | case DataType::Type::kFloat32: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3015 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3016 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3017 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3018 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3019 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3020 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 3021 | codegen_->LiteralFloatAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3022 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3023 | const_area->GetBaseMethodAddress(), |
| 3024 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3025 | } else { |
| 3026 | DCHECK(second.IsStackSlot()); |
| 3027 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3028 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3029 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3030 | } |
| 3031 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3032 | case DataType::Type::kFloat64: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3033 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3034 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3035 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3036 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3037 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3038 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 3039 | codegen_->LiteralDoubleAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3040 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3041 | const_area->GetBaseMethodAddress(), |
| 3042 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3043 | } else { |
| 3044 | DCHECK(second.IsDoubleStackSlot()); |
| 3045 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3046 | } |
| 3047 | break; |
| 3048 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3049 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3050 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3051 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3052 | } |
| 3053 | } |
| 3054 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3055 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3056 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3057 | new (GetGraph()->GetAllocator()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3058 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3059 | case DataType::Type::kInt32: |
| 3060 | case DataType::Type::kInt64: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3061 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3062 | locations->SetInAt(1, Location::Any()); |
| 3063 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3064 | break; |
| 3065 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3066 | case DataType::Type::kFloat32: |
| 3067 | case DataType::Type::kFloat64: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3068 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3069 | if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3070 | DCHECK(sub->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3071 | } else if (sub->InputAt(1)->IsConstant()) { |
| 3072 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3073 | } else { |
| 3074 | locations->SetInAt(1, Location::Any()); |
| 3075 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3076 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3077 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3078 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3079 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3080 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3081 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3082 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3083 | } |
| 3084 | |
| 3085 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 3086 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3087 | Location first = locations->InAt(0); |
| 3088 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3089 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3090 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3091 | case DataType::Type::kInt32: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3092 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3093 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3094 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3095 | __ subl(first.AsRegister<Register>(), |
| 3096 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3097 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3098 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3099 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3100 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3101 | } |
| 3102 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3103 | case DataType::Type::kInt64: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3104 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3105 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3106 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3107 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3108 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3109 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 3110 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3111 | } else { |
| 3112 | DCHECK(second.IsConstant()) << second; |
| 3113 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3114 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 3115 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3116 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3117 | break; |
| 3118 | } |
| 3119 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3120 | case DataType::Type::kFloat32: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3121 | if (second.IsFpuRegister()) { |
| 3122 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3123 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3124 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3125 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3126 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3127 | codegen_->LiteralFloatAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3128 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3129 | const_area->GetBaseMethodAddress(), |
| 3130 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3131 | } else { |
| 3132 | DCHECK(second.IsStackSlot()); |
| 3133 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3134 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3135 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3136 | } |
| 3137 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3138 | case DataType::Type::kFloat64: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3139 | if (second.IsFpuRegister()) { |
| 3140 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3141 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3142 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3143 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3144 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3145 | codegen_->LiteralDoubleAddress( |
| 3146 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3147 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3148 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3149 | } else { |
| 3150 | DCHECK(second.IsDoubleStackSlot()); |
| 3151 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3152 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3153 | break; |
| 3154 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3155 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3156 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3157 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3158 | } |
| 3159 | } |
| 3160 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3161 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 3162 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3163 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3164 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3165 | case DataType::Type::kInt32: |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3166 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3167 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3168 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3169 | // Can use 3 operand multiply. |
| 3170 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3171 | } else { |
| 3172 | locations->SetOut(Location::SameAsFirstInput()); |
| 3173 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3174 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3175 | case DataType::Type::kInt64: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3176 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3177 | locations->SetInAt(1, Location::Any()); |
| 3178 | locations->SetOut(Location::SameAsFirstInput()); |
| 3179 | // Needed for imul on 32bits with 64bits output. |
| 3180 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 3181 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 3182 | break; |
| 3183 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3184 | case DataType::Type::kFloat32: |
| 3185 | case DataType::Type::kFloat64: { |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3186 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3187 | if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3188 | DCHECK(mul->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3189 | } else if (mul->InputAt(1)->IsConstant()) { |
| 3190 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3191 | } else { |
| 3192 | locations->SetInAt(1, Location::Any()); |
| 3193 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3194 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3195 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3196 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3197 | |
| 3198 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3199 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3200 | } |
| 3201 | } |
| 3202 | |
| 3203 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 3204 | LocationSummary* locations = mul->GetLocations(); |
| 3205 | Location first = locations->InAt(0); |
| 3206 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3207 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3208 | |
| 3209 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3210 | case DataType::Type::kInt32: |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3211 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3212 | // problems where the output may not be the same as the first operand. |
| 3213 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3214 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3215 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 3216 | } else if (second.IsRegister()) { |
| 3217 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3218 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3219 | } else { |
| 3220 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3221 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3222 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3223 | } |
| 3224 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3225 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3226 | case DataType::Type::kInt64: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3227 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 3228 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3229 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 3230 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3231 | |
| 3232 | DCHECK_EQ(EAX, eax); |
| 3233 | DCHECK_EQ(EDX, edx); |
| 3234 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3235 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3236 | // output: in1 |
| 3237 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3238 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3239 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3240 | if (second.IsConstant()) { |
| 3241 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3242 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3243 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3244 | int32_t low_value = Low32Bits(value); |
| 3245 | int32_t high_value = High32Bits(value); |
| 3246 | Immediate low(low_value); |
| 3247 | Immediate high(high_value); |
| 3248 | |
| 3249 | __ movl(eax, high); |
| 3250 | // eax <- in1.lo * in2.hi |
| 3251 | __ imull(eax, in1_lo); |
| 3252 | // in1.hi <- in1.hi * in2.lo |
| 3253 | __ imull(in1_hi, low); |
| 3254 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3255 | __ addl(in1_hi, eax); |
| 3256 | // move in2_lo to eax to prepare for double precision |
| 3257 | __ movl(eax, low); |
| 3258 | // edx:eax <- in1.lo * in2.lo |
| 3259 | __ mull(in1_lo); |
| 3260 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3261 | __ addl(in1_hi, edx); |
| 3262 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3263 | __ movl(in1_lo, eax); |
| 3264 | } else if (second.IsRegisterPair()) { |
| 3265 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3266 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3267 | |
| 3268 | __ movl(eax, in2_hi); |
| 3269 | // eax <- in1.lo * in2.hi |
| 3270 | __ imull(eax, in1_lo); |
| 3271 | // in1.hi <- in1.hi * in2.lo |
| 3272 | __ imull(in1_hi, in2_lo); |
| 3273 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3274 | __ addl(in1_hi, eax); |
| 3275 | // move in1_lo to eax to prepare for double precision |
| 3276 | __ movl(eax, in1_lo); |
| 3277 | // edx:eax <- in1.lo * in2.lo |
| 3278 | __ mull(in2_lo); |
| 3279 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3280 | __ addl(in1_hi, edx); |
| 3281 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3282 | __ movl(in1_lo, eax); |
| 3283 | } else { |
| 3284 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 3285 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 3286 | Address in2_lo(ESP, second.GetStackIndex()); |
| 3287 | |
| 3288 | __ movl(eax, in2_hi); |
| 3289 | // eax <- in1.lo * in2.hi |
| 3290 | __ imull(eax, in1_lo); |
| 3291 | // in1.hi <- in1.hi * in2.lo |
| 3292 | __ imull(in1_hi, in2_lo); |
| 3293 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3294 | __ addl(in1_hi, eax); |
| 3295 | // move in1_lo to eax to prepare for double precision |
| 3296 | __ movl(eax, in1_lo); |
| 3297 | // edx:eax <- in1.lo * in2.lo |
| 3298 | __ mull(in2_lo); |
| 3299 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3300 | __ addl(in1_hi, edx); |
| 3301 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3302 | __ movl(in1_lo, eax); |
| 3303 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3304 | |
| 3305 | break; |
| 3306 | } |
| 3307 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3308 | case DataType::Type::kFloat32: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3309 | DCHECK(first.Equals(locations->Out())); |
| 3310 | if (second.IsFpuRegister()) { |
| 3311 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3312 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3313 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3314 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3315 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3316 | codegen_->LiteralFloatAddress( |
| 3317 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3318 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3319 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3320 | } else { |
| 3321 | DCHECK(second.IsStackSlot()); |
| 3322 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3323 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3324 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3325 | } |
| 3326 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3327 | case DataType::Type::kFloat64: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3328 | DCHECK(first.Equals(locations->Out())); |
| 3329 | if (second.IsFpuRegister()) { |
| 3330 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3331 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3332 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3333 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3334 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3335 | codegen_->LiteralDoubleAddress( |
| 3336 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3337 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3338 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3339 | } else { |
| 3340 | DCHECK(second.IsDoubleStackSlot()); |
| 3341 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3342 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3343 | break; |
| 3344 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3345 | |
| 3346 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3347 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3348 | } |
| 3349 | } |
| 3350 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3351 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 3352 | uint32_t temp_offset, |
| 3353 | uint32_t stack_adjustment, |
| 3354 | bool is_fp, |
| 3355 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3356 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3357 | DCHECK(!is_wide); |
| 3358 | if (is_fp) { |
| 3359 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3360 | } else { |
| 3361 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3362 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3363 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3364 | DCHECK(is_wide); |
| 3365 | if (is_fp) { |
| 3366 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3367 | } else { |
| 3368 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3369 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3370 | } else { |
| 3371 | // 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] | 3372 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3373 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3374 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3375 | if (is_fp) { |
| 3376 | __ flds(Address(ESP, temp_offset)); |
| 3377 | } else { |
| 3378 | __ filds(Address(ESP, temp_offset)); |
| 3379 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3380 | } else { |
| 3381 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3382 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3383 | if (is_fp) { |
| 3384 | __ fldl(Address(ESP, temp_offset)); |
| 3385 | } else { |
| 3386 | __ fildl(Address(ESP, temp_offset)); |
| 3387 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3388 | } |
| 3389 | } |
| 3390 | } |
| 3391 | |
| 3392 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3393 | DataType::Type type = rem->GetResultType(); |
| 3394 | bool is_float = type == DataType::Type::kFloat32; |
| 3395 | size_t elem_size = DataType::Size(type); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3396 | LocationSummary* locations = rem->GetLocations(); |
| 3397 | Location first = locations->InAt(0); |
| 3398 | Location second = locations->InAt(1); |
| 3399 | Location out = locations->Out(); |
| 3400 | |
| 3401 | // Create stack space for 2 elements. |
| 3402 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3403 | __ subl(ESP, Immediate(2 * elem_size)); |
| 3404 | |
| 3405 | // 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] | 3406 | const bool is_wide = !is_float; |
| 3407 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); |
| 3408 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3409 | |
| 3410 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3411 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3412 | __ Bind(&retry); |
| 3413 | __ fprem(); |
| 3414 | |
| 3415 | // Move FP status to AX. |
| 3416 | __ fstsw(); |
| 3417 | |
| 3418 | // And see if the argument reduction is complete. This is signaled by the |
| 3419 | // C2 FPU flag bit set to 0. |
| 3420 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 3421 | __ j(kNotEqual, &retry); |
| 3422 | |
| 3423 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3424 | // Store FP top of stack to real stack. |
| 3425 | if (is_float) { |
| 3426 | __ fsts(Address(ESP, 0)); |
| 3427 | } else { |
| 3428 | __ fstl(Address(ESP, 0)); |
| 3429 | } |
| 3430 | |
| 3431 | // Pop the 2 items from the FP stack. |
| 3432 | __ fucompp(); |
| 3433 | |
| 3434 | // Load the value from the stack into an XMM register. |
| 3435 | DCHECK(out.IsFpuRegister()) << out; |
| 3436 | if (is_float) { |
| 3437 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3438 | } else { |
| 3439 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3440 | } |
| 3441 | |
| 3442 | // And remove the temporary stack space we allocated. |
| 3443 | __ addl(ESP, Immediate(2 * elem_size)); |
| 3444 | } |
| 3445 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3446 | |
| 3447 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3448 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3449 | |
| 3450 | LocationSummary* locations = instruction->GetLocations(); |
| 3451 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3452 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3453 | |
| 3454 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3455 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3456 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3457 | |
| 3458 | DCHECK(imm == 1 || imm == -1); |
| 3459 | |
| 3460 | if (instruction->IsRem()) { |
| 3461 | __ xorl(out_register, out_register); |
| 3462 | } else { |
| 3463 | __ movl(out_register, input_register); |
| 3464 | if (imm == -1) { |
| 3465 | __ negl(out_register); |
| 3466 | } |
| 3467 | } |
| 3468 | } |
| 3469 | |
| 3470 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3471 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3472 | LocationSummary* locations = instruction->GetLocations(); |
| 3473 | |
| 3474 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3475 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3476 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3477 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3478 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3479 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3480 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 3481 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3482 | __ leal(num, Address(input_register, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3483 | __ testl(input_register, input_register); |
| 3484 | __ cmovl(kGreaterEqual, num, input_register); |
| 3485 | int shift = CTZ(imm); |
| 3486 | __ sarl(num, Immediate(shift)); |
| 3487 | |
| 3488 | if (imm < 0) { |
| 3489 | __ negl(num); |
| 3490 | } |
| 3491 | |
| 3492 | __ movl(out_register, num); |
| 3493 | } |
| 3494 | |
| 3495 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3496 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3497 | |
| 3498 | LocationSummary* locations = instruction->GetLocations(); |
| 3499 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 3500 | |
| 3501 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 3502 | Register out = locations->Out().AsRegister<Register>(); |
| 3503 | Register num; |
| 3504 | Register edx; |
| 3505 | |
| 3506 | if (instruction->IsDiv()) { |
| 3507 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 3508 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 3509 | } else { |
| 3510 | edx = locations->Out().AsRegister<Register>(); |
| 3511 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 3512 | } |
| 3513 | |
| 3514 | DCHECK_EQ(EAX, eax); |
| 3515 | DCHECK_EQ(EDX, edx); |
| 3516 | if (instruction->IsDiv()) { |
| 3517 | DCHECK_EQ(EAX, out); |
| 3518 | } else { |
| 3519 | DCHECK_EQ(EDX, out); |
| 3520 | } |
| 3521 | |
| 3522 | int64_t magic; |
| 3523 | int shift; |
| 3524 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3525 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3526 | // Save the numerator. |
| 3527 | __ movl(num, eax); |
| 3528 | |
| 3529 | // EAX = magic |
| 3530 | __ movl(eax, Immediate(magic)); |
| 3531 | |
| 3532 | // EDX:EAX = magic * numerator |
| 3533 | __ imull(num); |
| 3534 | |
| 3535 | if (imm > 0 && magic < 0) { |
| 3536 | // EDX += num |
| 3537 | __ addl(edx, num); |
| 3538 | } else if (imm < 0 && magic > 0) { |
| 3539 | __ subl(edx, num); |
| 3540 | } |
| 3541 | |
| 3542 | // Shift if needed. |
| 3543 | if (shift != 0) { |
| 3544 | __ sarl(edx, Immediate(shift)); |
| 3545 | } |
| 3546 | |
| 3547 | // EDX += 1 if EDX < 0 |
| 3548 | __ movl(eax, edx); |
| 3549 | __ shrl(edx, Immediate(31)); |
| 3550 | __ addl(edx, eax); |
| 3551 | |
| 3552 | if (instruction->IsRem()) { |
| 3553 | __ movl(eax, num); |
| 3554 | __ imull(edx, Immediate(imm)); |
| 3555 | __ subl(eax, edx); |
| 3556 | __ movl(edx, eax); |
| 3557 | } else { |
| 3558 | __ movl(eax, edx); |
| 3559 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3560 | } |
| 3561 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3562 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3563 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3564 | |
| 3565 | LocationSummary* locations = instruction->GetLocations(); |
| 3566 | Location out = locations->Out(); |
| 3567 | Location first = locations->InAt(0); |
| 3568 | Location second = locations->InAt(1); |
| 3569 | bool is_div = instruction->IsDiv(); |
| 3570 | |
| 3571 | switch (instruction->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3572 | case DataType::Type::kInt32: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3573 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 3574 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3575 | |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3576 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3577 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3578 | |
| 3579 | if (imm == 0) { |
| 3580 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 3581 | } else if (imm == 1 || imm == -1) { |
| 3582 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3583 | } else if (is_div && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3584 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3585 | } else { |
| 3586 | DCHECK(imm <= -2 || imm >= 2); |
| 3587 | GenerateDivRemWithAnyConstant(instruction); |
| 3588 | } |
| 3589 | } else { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3590 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) DivRemMinusOneSlowPathX86( |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3591 | instruction, out.AsRegister<Register>(), is_div); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3592 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3593 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3594 | Register second_reg = second.AsRegister<Register>(); |
| 3595 | // 0x80000000/-1 triggers an arithmetic exception! |
| 3596 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 3597 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3598 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3599 | __ cmpl(second_reg, Immediate(-1)); |
| 3600 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3601 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3602 | // edx:eax <- sign-extended of eax |
| 3603 | __ cdq(); |
| 3604 | // eax = quotient, edx = remainder |
| 3605 | __ idivl(second_reg); |
| 3606 | __ Bind(slow_path->GetExitLabel()); |
| 3607 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3608 | break; |
| 3609 | } |
| 3610 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3611 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3612 | InvokeRuntimeCallingConvention calling_convention; |
| 3613 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3614 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3615 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3616 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3617 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 3618 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 3619 | |
| 3620 | if (is_div) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3621 | codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3622 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3623 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3624 | codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3625 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3626 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3627 | break; |
| 3628 | } |
| 3629 | |
| 3630 | default: |
| 3631 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 3632 | } |
| 3633 | } |
| 3634 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3635 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3636 | LocationSummary::CallKind call_kind = (div->GetResultType() == DataType::Type::kInt64) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3637 | ? LocationSummary::kCallOnMainOnly |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3638 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3639 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(div, call_kind); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3640 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3641 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3642 | case DataType::Type::kInt32: { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3643 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3644 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3645 | locations->SetOut(Location::SameAsFirstInput()); |
| 3646 | // Intel uses edx:eax as the dividend. |
| 3647 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3648 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3649 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 3650 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3651 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3652 | locations->AddTemp(Location::RequiresRegister()); |
| 3653 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3654 | break; |
| 3655 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3656 | case DataType::Type::kInt64: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3657 | InvokeRuntimeCallingConvention calling_convention; |
| 3658 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3659 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3660 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3661 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3662 | // Runtime helper puts the result in EAX, EDX. |
| 3663 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3664 | break; |
| 3665 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3666 | case DataType::Type::kFloat32: |
| 3667 | case DataType::Type::kFloat64: { |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3668 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3669 | if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3670 | DCHECK(div->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3671 | } else if (div->InputAt(1)->IsConstant()) { |
| 3672 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3673 | } else { |
| 3674 | locations->SetInAt(1, Location::Any()); |
| 3675 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3676 | locations->SetOut(Location::SameAsFirstInput()); |
| 3677 | break; |
| 3678 | } |
| 3679 | |
| 3680 | default: |
| 3681 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3682 | } |
| 3683 | } |
| 3684 | |
| 3685 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 3686 | LocationSummary* locations = div->GetLocations(); |
| 3687 | Location first = locations->InAt(0); |
| 3688 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3689 | |
| 3690 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3691 | case DataType::Type::kInt32: |
| 3692 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3693 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3694 | break; |
| 3695 | } |
| 3696 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3697 | case DataType::Type::kFloat32: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3698 | if (second.IsFpuRegister()) { |
| 3699 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3700 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3701 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3702 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3703 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3704 | codegen_->LiteralFloatAddress( |
| 3705 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3706 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3707 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3708 | } else { |
| 3709 | DCHECK(second.IsStackSlot()); |
| 3710 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3711 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3712 | break; |
| 3713 | } |
| 3714 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3715 | case DataType::Type::kFloat64: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3716 | if (second.IsFpuRegister()) { |
| 3717 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3718 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3719 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3720 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3721 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3722 | codegen_->LiteralDoubleAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3723 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3724 | const_area->GetBaseMethodAddress(), |
| 3725 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3726 | } else { |
| 3727 | DCHECK(second.IsDoubleStackSlot()); |
| 3728 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3729 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3730 | break; |
| 3731 | } |
| 3732 | |
| 3733 | default: |
| 3734 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3735 | } |
| 3736 | } |
| 3737 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3738 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3739 | DataType::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3740 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3741 | LocationSummary::CallKind call_kind = (rem->GetResultType() == DataType::Type::kInt64) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3742 | ? LocationSummary::kCallOnMainOnly |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3743 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3744 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3745 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3746 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3747 | case DataType::Type::kInt32: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3748 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3749 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3750 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3751 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3752 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 3753 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3754 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3755 | locations->AddTemp(Location::RequiresRegister()); |
| 3756 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3757 | break; |
| 3758 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3759 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3760 | InvokeRuntimeCallingConvention calling_convention; |
| 3761 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3762 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3763 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3764 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3765 | // Runtime helper puts the result in EAX, EDX. |
| 3766 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3767 | break; |
| 3768 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3769 | case DataType::Type::kFloat64: |
| 3770 | case DataType::Type::kFloat32: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3771 | locations->SetInAt(0, Location::Any()); |
| 3772 | locations->SetInAt(1, Location::Any()); |
| 3773 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3774 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3775 | break; |
| 3776 | } |
| 3777 | |
| 3778 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3779 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3780 | } |
| 3781 | } |
| 3782 | |
| 3783 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3784 | DataType::Type type = rem->GetResultType(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3785 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3786 | case DataType::Type::kInt32: |
| 3787 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3788 | GenerateDivRemIntegral(rem); |
| 3789 | break; |
| 3790 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3791 | case DataType::Type::kFloat32: |
| 3792 | case DataType::Type::kFloat64: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3793 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3794 | break; |
| 3795 | } |
| 3796 | default: |
| 3797 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3798 | } |
| 3799 | } |
| 3800 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3801 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3802 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3803 | switch (instruction->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3804 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3805 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3806 | case DataType::Type::kInt8: |
| 3807 | case DataType::Type::kUint16: |
| 3808 | case DataType::Type::kInt16: |
| 3809 | case DataType::Type::kInt32: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3810 | locations->SetInAt(0, Location::Any()); |
| 3811 | break; |
| 3812 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3813 | case DataType::Type::kInt64: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3814 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 3815 | if (!instruction->IsConstant()) { |
| 3816 | locations->AddTemp(Location::RequiresRegister()); |
| 3817 | } |
| 3818 | break; |
| 3819 | } |
| 3820 | default: |
| 3821 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3822 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3823 | } |
| 3824 | |
| 3825 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3826 | SlowPathCode* slow_path = |
| 3827 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathX86(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3828 | codegen_->AddSlowPath(slow_path); |
| 3829 | |
| 3830 | LocationSummary* locations = instruction->GetLocations(); |
| 3831 | Location value = locations->InAt(0); |
| 3832 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3833 | switch (instruction->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3834 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3835 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3836 | case DataType::Type::kInt8: |
| 3837 | case DataType::Type::kUint16: |
| 3838 | case DataType::Type::kInt16: |
| 3839 | case DataType::Type::kInt32: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3840 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3841 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3842 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3843 | } else if (value.IsStackSlot()) { |
| 3844 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 3845 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3846 | } else { |
| 3847 | DCHECK(value.IsConstant()) << value; |
| 3848 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 3849 | __ jmp(slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3850 | } |
| 3851 | } |
| 3852 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3853 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3854 | case DataType::Type::kInt64: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3855 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3856 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3857 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 3858 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 3859 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3860 | } else { |
| 3861 | DCHECK(value.IsConstant()) << value; |
| 3862 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3863 | __ jmp(slow_path->GetEntryLabel()); |
| 3864 | } |
| 3865 | } |
| 3866 | break; |
| 3867 | } |
| 3868 | default: |
| 3869 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3870 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3871 | } |
| 3872 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3873 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 3874 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3875 | |
| 3876 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3877 | new (GetGraph()->GetAllocator()) LocationSummary(op, LocationSummary::kNoCall); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3878 | |
| 3879 | switch (op->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3880 | case DataType::Type::kInt32: |
| 3881 | case DataType::Type::kInt64: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3882 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3883 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3884 | // The shift count needs to be in CL or a constant. |
| 3885 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3886 | locations->SetOut(Location::SameAsFirstInput()); |
| 3887 | break; |
| 3888 | } |
| 3889 | default: |
| 3890 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3891 | } |
| 3892 | } |
| 3893 | |
| 3894 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 3895 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3896 | |
| 3897 | LocationSummary* locations = op->GetLocations(); |
| 3898 | Location first = locations->InAt(0); |
| 3899 | Location second = locations->InAt(1); |
| 3900 | DCHECK(first.Equals(locations->Out())); |
| 3901 | |
| 3902 | switch (op->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3903 | case DataType::Type::kInt32: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3904 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3905 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3906 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3907 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3908 | DCHECK_EQ(ECX, second_reg); |
| 3909 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3910 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3911 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3912 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3913 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3914 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3915 | } |
| 3916 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3917 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3918 | if (shift == 0) { |
| 3919 | return; |
| 3920 | } |
| 3921 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3922 | if (op->IsShl()) { |
| 3923 | __ shll(first_reg, imm); |
| 3924 | } else if (op->IsShr()) { |
| 3925 | __ sarl(first_reg, imm); |
| 3926 | } else { |
| 3927 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3928 | } |
| 3929 | } |
| 3930 | break; |
| 3931 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3932 | case DataType::Type::kInt64: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3933 | if (second.IsRegister()) { |
| 3934 | Register second_reg = second.AsRegister<Register>(); |
| 3935 | DCHECK_EQ(ECX, second_reg); |
| 3936 | if (op->IsShl()) { |
| 3937 | GenerateShlLong(first, second_reg); |
| 3938 | } else if (op->IsShr()) { |
| 3939 | GenerateShrLong(first, second_reg); |
| 3940 | } else { |
| 3941 | GenerateUShrLong(first, second_reg); |
| 3942 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3943 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3944 | // Shift by a constant. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3945 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3946 | // Nothing to do if the shift is 0, as the input is already the output. |
| 3947 | if (shift != 0) { |
| 3948 | if (op->IsShl()) { |
| 3949 | GenerateShlLong(first, shift); |
| 3950 | } else if (op->IsShr()) { |
| 3951 | GenerateShrLong(first, shift); |
| 3952 | } else { |
| 3953 | GenerateUShrLong(first, shift); |
| 3954 | } |
| 3955 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3956 | } |
| 3957 | break; |
| 3958 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3959 | default: |
| 3960 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3961 | } |
| 3962 | } |
| 3963 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3964 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 3965 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3966 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 3967 | if (shift == 1) { |
| 3968 | // This is just an addition. |
| 3969 | __ addl(low, low); |
| 3970 | __ adcl(high, high); |
| 3971 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3972 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 3973 | codegen_->EmitParallelMoves( |
| 3974 | loc.ToLow(), |
| 3975 | loc.ToHigh(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3976 | DataType::Type::kInt32, |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3977 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3978 | loc.ToLow(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3979 | DataType::Type::kInt32); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3980 | } else if (shift > 32) { |
| 3981 | // Low part becomes 0. High part is low part << (shift-32). |
| 3982 | __ movl(high, low); |
| 3983 | __ shll(high, Immediate(shift - 32)); |
| 3984 | __ xorl(low, low); |
| 3985 | } else { |
| 3986 | // Between 1 and 31. |
| 3987 | __ shld(high, low, Immediate(shift)); |
| 3988 | __ shll(low, Immediate(shift)); |
| 3989 | } |
| 3990 | } |
| 3991 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3992 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3993 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3994 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 3995 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 3996 | __ testl(shifter, Immediate(32)); |
| 3997 | __ j(kEqual, &done); |
| 3998 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 3999 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 4000 | __ Bind(&done); |
| 4001 | } |
| 4002 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4003 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 4004 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4005 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 4006 | if (shift == 32) { |
| 4007 | // Need to copy the sign. |
| 4008 | DCHECK_NE(low, high); |
| 4009 | __ movl(low, high); |
| 4010 | __ sarl(high, Immediate(31)); |
| 4011 | } else if (shift > 32) { |
| 4012 | DCHECK_NE(low, high); |
| 4013 | // High part becomes sign. Low part is shifted by shift - 32. |
| 4014 | __ movl(low, high); |
| 4015 | __ sarl(high, Immediate(31)); |
| 4016 | __ sarl(low, Immediate(shift - 32)); |
| 4017 | } else { |
| 4018 | // Between 1 and 31. |
| 4019 | __ shrd(low, high, Immediate(shift)); |
| 4020 | __ sarl(high, Immediate(shift)); |
| 4021 | } |
| 4022 | } |
| 4023 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4024 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4025 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4026 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4027 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4028 | __ testl(shifter, Immediate(32)); |
| 4029 | __ j(kEqual, &done); |
| 4030 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4031 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 4032 | __ Bind(&done); |
| 4033 | } |
| 4034 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4035 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 4036 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4037 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 4038 | if (shift == 32) { |
| 4039 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 4040 | codegen_->EmitParallelMoves( |
| 4041 | loc.ToHigh(), |
| 4042 | loc.ToLow(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4043 | DataType::Type::kInt32, |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4044 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 4045 | loc.ToHigh(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4046 | DataType::Type::kInt32); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4047 | } else if (shift > 32) { |
| 4048 | // Low part is high >> (shift - 32). High part becomes 0. |
| 4049 | __ movl(low, high); |
| 4050 | __ shrl(low, Immediate(shift - 32)); |
| 4051 | __ xorl(high, high); |
| 4052 | } else { |
| 4053 | // Between 1 and 31. |
| 4054 | __ shrd(low, high, Immediate(shift)); |
| 4055 | __ shrl(high, Immediate(shift)); |
| 4056 | } |
| 4057 | } |
| 4058 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4059 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4060 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4061 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4062 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4063 | __ testl(shifter, Immediate(32)); |
| 4064 | __ j(kEqual, &done); |
| 4065 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4066 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 4067 | __ Bind(&done); |
| 4068 | } |
| 4069 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4070 | void LocationsBuilderX86::VisitRor(HRor* ror) { |
| 4071 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4072 | new (GetGraph()->GetAllocator()) LocationSummary(ror, LocationSummary::kNoCall); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4073 | |
| 4074 | switch (ror->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4075 | case DataType::Type::kInt64: |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4076 | // Add the temporary needed. |
| 4077 | locations->AddTemp(Location::RequiresRegister()); |
| 4078 | FALLTHROUGH_INTENDED; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4079 | case DataType::Type::kInt32: |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4080 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4081 | // The shift count needs to be in CL (unless it is a constant). |
| 4082 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); |
| 4083 | locations->SetOut(Location::SameAsFirstInput()); |
| 4084 | break; |
| 4085 | default: |
| 4086 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4087 | UNREACHABLE(); |
| 4088 | } |
| 4089 | } |
| 4090 | |
| 4091 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { |
| 4092 | LocationSummary* locations = ror->GetLocations(); |
| 4093 | Location first = locations->InAt(0); |
| 4094 | Location second = locations->InAt(1); |
| 4095 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4096 | if (ror->GetResultType() == DataType::Type::kInt32) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4097 | Register first_reg = first.AsRegister<Register>(); |
| 4098 | if (second.IsRegister()) { |
| 4099 | Register second_reg = second.AsRegister<Register>(); |
| 4100 | __ rorl(first_reg, second_reg); |
| 4101 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4102 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4103 | __ rorl(first_reg, imm); |
| 4104 | } |
| 4105 | return; |
| 4106 | } |
| 4107 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4108 | DCHECK_EQ(ror->GetResultType(), DataType::Type::kInt64); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4109 | Register first_reg_lo = first.AsRegisterPairLow<Register>(); |
| 4110 | Register first_reg_hi = first.AsRegisterPairHigh<Register>(); |
| 4111 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 4112 | if (second.IsRegister()) { |
| 4113 | Register second_reg = second.AsRegister<Register>(); |
| 4114 | DCHECK_EQ(second_reg, ECX); |
| 4115 | __ movl(temp_reg, first_reg_hi); |
| 4116 | __ shrd(first_reg_hi, first_reg_lo, second_reg); |
| 4117 | __ shrd(first_reg_lo, temp_reg, second_reg); |
| 4118 | __ movl(temp_reg, first_reg_hi); |
| 4119 | __ testl(second_reg, Immediate(32)); |
| 4120 | __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); |
| 4121 | __ cmovl(kNotEqual, first_reg_lo, temp_reg); |
| 4122 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4123 | int32_t shift_amt = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4124 | if (shift_amt == 0) { |
| 4125 | // Already fine. |
| 4126 | return; |
| 4127 | } |
| 4128 | if (shift_amt == 32) { |
| 4129 | // Just swap. |
| 4130 | __ movl(temp_reg, first_reg_lo); |
| 4131 | __ movl(first_reg_lo, first_reg_hi); |
| 4132 | __ movl(first_reg_hi, temp_reg); |
| 4133 | return; |
| 4134 | } |
| 4135 | |
| 4136 | Immediate imm(shift_amt); |
| 4137 | // Save the constents of the low value. |
| 4138 | __ movl(temp_reg, first_reg_lo); |
| 4139 | |
| 4140 | // Shift right into low, feeding bits from high. |
| 4141 | __ shrd(first_reg_lo, first_reg_hi, imm); |
| 4142 | |
| 4143 | // Shift right into high, feeding bits from the original low. |
| 4144 | __ shrd(first_reg_hi, temp_reg, imm); |
| 4145 | |
| 4146 | // Swap if needed. |
| 4147 | if (shift_amt > 32) { |
| 4148 | __ movl(temp_reg, first_reg_lo); |
| 4149 | __ movl(first_reg_lo, first_reg_hi); |
| 4150 | __ movl(first_reg_hi, temp_reg); |
| 4151 | } |
| 4152 | } |
| 4153 | } |
| 4154 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4155 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 4156 | HandleShift(shl); |
| 4157 | } |
| 4158 | |
| 4159 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 4160 | HandleShift(shl); |
| 4161 | } |
| 4162 | |
| 4163 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 4164 | HandleShift(shr); |
| 4165 | } |
| 4166 | |
| 4167 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 4168 | HandleShift(shr); |
| 4169 | } |
| 4170 | |
| 4171 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 4172 | HandleShift(ushr); |
| 4173 | } |
| 4174 | |
| 4175 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 4176 | HandleShift(ushr); |
| 4177 | } |
| 4178 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4179 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4180 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4181 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4182 | locations->SetOut(Location::RegisterLocation(EAX)); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4183 | if (instruction->IsStringAlloc()) { |
| 4184 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4185 | } else { |
| 4186 | InvokeRuntimeCallingConvention calling_convention; |
| 4187 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4188 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4189 | } |
| 4190 | |
| 4191 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4192 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4193 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4194 | if (instruction->IsStringAlloc()) { |
| 4195 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4196 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4197 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4198 | __ fs()->movl(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString))); |
| 4199 | __ call(Address(temp, code_offset.Int32Value())); |
| 4200 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4201 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 4202 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 4203 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4204 | DCHECK(!codegen_->IsLeafMethod()); |
| 4205 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4206 | } |
| 4207 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4208 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4209 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4210 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4211 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 4212 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4213 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4214 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4215 | } |
| 4216 | |
| 4217 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4218 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4219 | // of poisoning the reference. |
Nicolas Geoffray | d095844 | 2017-01-30 14:57:16 +0000 | [diff] [blame] | 4220 | QuickEntrypointEnum entrypoint = |
| 4221 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 4222 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4223 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4224 | DCHECK(!codegen_->IsLeafMethod()); |
| 4225 | } |
| 4226 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4227 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4228 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4229 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4230 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4231 | if (location.IsStackSlot()) { |
| 4232 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4233 | } else if (location.IsDoubleStackSlot()) { |
| 4234 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4235 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4236 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4237 | } |
| 4238 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4239 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 4240 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 4241 | } |
| 4242 | |
| 4243 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4244 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4245 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4246 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4247 | } |
| 4248 | |
| 4249 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4250 | } |
| 4251 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4252 | void LocationsBuilderX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4253 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4254 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4255 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4256 | locations->SetOut(Location::RequiresRegister()); |
| 4257 | } |
| 4258 | |
| 4259 | void InstructionCodeGeneratorX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4260 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4261 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4262 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4263 | instruction->GetIndex(), kX86PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4264 | __ movl(locations->Out().AsRegister<Register>(), |
| 4265 | Address(locations->InAt(0).AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4266 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4267 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4268 | instruction->GetIndex(), kX86PointerSize)); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4269 | __ movl(locations->Out().AsRegister<Register>(), |
| 4270 | Address(locations->InAt(0).AsRegister<Register>(), |
| 4271 | mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
| 4272 | // temp = temp->GetImtEntryAt(method_offset); |
| 4273 | __ movl(locations->Out().AsRegister<Register>(), |
| 4274 | Address(locations->Out().AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4275 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4276 | } |
| 4277 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4278 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4279 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4280 | new (GetGraph()->GetAllocator()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4281 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4282 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4283 | } |
| 4284 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4285 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 4286 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4287 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4288 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4289 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4290 | switch (not_->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4291 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4292 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4293 | break; |
| 4294 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4295 | case DataType::Type::kInt64: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4296 | __ notl(out.AsRegisterPairLow<Register>()); |
| 4297 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4298 | break; |
| 4299 | |
| 4300 | default: |
| 4301 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4302 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4303 | } |
| 4304 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4305 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4306 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4307 | new (GetGraph()->GetAllocator()) LocationSummary(bool_not, LocationSummary::kNoCall); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4308 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4309 | locations->SetOut(Location::SameAsFirstInput()); |
| 4310 | } |
| 4311 | |
| 4312 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4313 | LocationSummary* locations = bool_not->GetLocations(); |
| 4314 | Location in = locations->InAt(0); |
| 4315 | Location out = locations->Out(); |
| 4316 | DCHECK(in.Equals(out)); |
| 4317 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 4318 | } |
| 4319 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4320 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4321 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4322 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4323 | switch (compare->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4324 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4325 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4326 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4327 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4328 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4329 | case DataType::Type::kInt32: |
| 4330 | case DataType::Type::kInt64: { |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4331 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4332 | locations->SetInAt(1, Location::Any()); |
| 4333 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4334 | break; |
| 4335 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4336 | case DataType::Type::kFloat32: |
| 4337 | case DataType::Type::kFloat64: { |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4338 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4339 | if (compare->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4340 | DCHECK(compare->InputAt(1)->IsEmittedAtUseSite()); |
| 4341 | } else if (compare->InputAt(1)->IsConstant()) { |
| 4342 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4343 | } else { |
| 4344 | locations->SetInAt(1, Location::Any()); |
| 4345 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4346 | locations->SetOut(Location::RequiresRegister()); |
| 4347 | break; |
| 4348 | } |
| 4349 | default: |
| 4350 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4351 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4352 | } |
| 4353 | |
| 4354 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4355 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4356 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4357 | Location left = locations->InAt(0); |
| 4358 | Location right = locations->InAt(1); |
| 4359 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4360 | NearLabel less, greater, done; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4361 | Condition less_cond = kLess; |
| 4362 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4363 | switch (compare->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4364 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4365 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4366 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4367 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4368 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4369 | case DataType::Type::kInt32: { |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 4370 | codegen_->GenerateIntCompare(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4371 | break; |
| 4372 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4373 | case DataType::Type::kInt64: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4374 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 4375 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 4376 | int32_t val_low = 0; |
| 4377 | int32_t val_high = 0; |
| 4378 | bool right_is_const = false; |
| 4379 | |
| 4380 | if (right.IsConstant()) { |
| 4381 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 4382 | right_is_const = true; |
| 4383 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 4384 | val_low = Low32Bits(val); |
| 4385 | val_high = High32Bits(val); |
| 4386 | } |
| 4387 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4388 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4389 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4390 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4391 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4392 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4393 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4394 | codegen_->Compare32BitValue(left_high, val_high); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4395 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4396 | __ j(kLess, &less); // Signed compare. |
| 4397 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4398 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4399 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4400 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4401 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4402 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4403 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4404 | codegen_->Compare32BitValue(left_low, val_low); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4405 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4406 | less_cond = kBelow; // for CF (unsigned). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4407 | break; |
| 4408 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4409 | case DataType::Type::kFloat32: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4410 | GenerateFPCompare(left, right, compare, false); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4411 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4412 | less_cond = kBelow; // for CF (floats). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4413 | break; |
| 4414 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4415 | case DataType::Type::kFloat64: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4416 | GenerateFPCompare(left, right, compare, true); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4417 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4418 | less_cond = kBelow; // for CF (floats). |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4419 | break; |
| 4420 | } |
| 4421 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4422 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4423 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4424 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4425 | __ movl(out, Immediate(0)); |
| 4426 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4427 | __ j(less_cond, &less); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4428 | |
| 4429 | __ Bind(&greater); |
| 4430 | __ movl(out, Immediate(1)); |
| 4431 | __ jmp(&done); |
| 4432 | |
| 4433 | __ Bind(&less); |
| 4434 | __ movl(out, Immediate(-1)); |
| 4435 | |
| 4436 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4437 | } |
| 4438 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4439 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4440 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4441 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4442 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4443 | locations->SetInAt(i, Location::Any()); |
| 4444 | } |
| 4445 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4446 | } |
| 4447 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4448 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4449 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4450 | } |
| 4451 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4452 | void CodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4453 | /* |
| 4454 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 4455 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 4456 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4457 | */ |
| 4458 | switch (kind) { |
| 4459 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4460 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4461 | break; |
| 4462 | } |
| 4463 | case MemBarrierKind::kAnyStore: |
| 4464 | case MemBarrierKind::kLoadAny: |
| 4465 | case MemBarrierKind::kStoreStore: { |
| 4466 | // nop |
| 4467 | break; |
| 4468 | } |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4469 | case MemBarrierKind::kNTStoreStore: |
| 4470 | // Non-Temporal Store/Store needs an explicit fence. |
| 4471 | MemoryFence(/* non-temporal */ true); |
| 4472 | break; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4473 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4474 | } |
| 4475 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4476 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( |
| 4477 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4478 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4479 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4480 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4481 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4482 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 4483 | Register temp) { |
| 4484 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4485 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4486 | if (!invoke->GetLocations()->Intrinsified()) { |
| 4487 | return location.AsRegister<Register>(); |
| 4488 | } |
| 4489 | // For intrinsics we allow any location, so it may be on the stack. |
| 4490 | if (!location.IsRegister()) { |
| 4491 | __ movl(temp, Address(ESP, location.GetStackIndex())); |
| 4492 | return temp; |
| 4493 | } |
| 4494 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 4495 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 4496 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 4497 | // simple and more robust approach rather that trying to determine if that's the case. |
| 4498 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
Vladimir Marko | 4ee8e29 | 2017-06-02 15:39:30 +0000 | [diff] [blame] | 4499 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 4500 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 4501 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 4502 | __ movl(temp, Address(ESP, stack_offset)); |
| 4503 | return temp; |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4504 | } |
| 4505 | return location.AsRegister<Register>(); |
| 4506 | } |
| 4507 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4508 | void CodeGeneratorX86::GenerateStaticOrDirectCall( |
| 4509 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4510 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4511 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4512 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4513 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4514 | uint32_t offset = |
| 4515 | GetThreadOffset<kX86PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 4516 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4517 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4518 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4519 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4520 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4521 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4522 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 4523 | DCHECK(GetCompilerOptions().IsBootImage()); |
| 4524 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4525 | temp.AsRegister<Register>()); |
| 4526 | __ leal(temp.AsRegister<Register>(), Address(base_reg, CodeGeneratorX86::kDummy32BitOffset)); |
| 4527 | RecordBootMethodPatch(invoke); |
| 4528 | break; |
| 4529 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4530 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4531 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 4532 | break; |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4533 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4534 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4535 | temp.AsRegister<Register>()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4536 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4537 | // Bind a new fixup label at the end of the "movl" insn. |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4538 | __ Bind(NewMethodBssEntryPatch( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4539 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(), |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4540 | MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()))); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4541 | break; |
| 4542 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4543 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 4544 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 4545 | return; // No code pointer retrieval; the runtime performs the call directly. |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4546 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4547 | } |
| 4548 | |
| 4549 | switch (invoke->GetCodePtrLocation()) { |
| 4550 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 4551 | __ call(GetFrameEntryLabel()); |
| 4552 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4553 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4554 | // (callee_method + offset_of_quick_compiled_code)() |
| 4555 | __ call(Address(callee_method.AsRegister<Register>(), |
| 4556 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4557 | kX86PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4558 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4559 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4560 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4561 | |
| 4562 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4563 | } |
| 4564 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4565 | void CodeGeneratorX86::GenerateVirtualCall( |
| 4566 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4567 | Register temp = temp_in.AsRegister<Register>(); |
| 4568 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4569 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4570 | |
| 4571 | // Use the calling convention instead of the location of the receiver, as |
| 4572 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4573 | // slow path, the arguments have been moved to the right place, so here we are |
| 4574 | // guaranteed that the receiver is the first register of the calling convention. |
| 4575 | InvokeDexCallingConvention calling_convention; |
| 4576 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4577 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4578 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4579 | __ movl(temp, Address(receiver, class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4580 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4581 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4582 | // emit a read barrier for the previous class reference load. |
| 4583 | // However this is not required in practice, as this is an |
| 4584 | // intermediate/temporary reference and because the current |
| 4585 | // concurrent copying collector keeps the from-space memory |
| 4586 | // intact/accessible until the end of the marking phase (the |
| 4587 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4588 | __ MaybeUnpoisonHeapReference(temp); |
| 4589 | // temp = temp->GetMethodAt(method_offset); |
| 4590 | __ movl(temp, Address(temp, method_offset)); |
| 4591 | // call temp->GetEntryPoint(); |
| 4592 | __ call(Address( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4593 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4594 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4595 | } |
| 4596 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4597 | void CodeGeneratorX86::RecordBootMethodPatch(HInvokeStaticOrDirect* invoke) { |
| 4598 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 4599 | HX86ComputeBaseMethodAddress* address = |
| 4600 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
| 4601 | boot_image_method_patches_.emplace_back(address, |
| 4602 | *invoke->GetTargetMethod().dex_file, |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 4603 | invoke->GetTargetMethod().index); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4604 | __ Bind(&boot_image_method_patches_.back().label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4605 | } |
| 4606 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4607 | Label* CodeGeneratorX86::NewMethodBssEntryPatch( |
| 4608 | HX86ComputeBaseMethodAddress* method_address, |
| 4609 | MethodReference target_method) { |
| 4610 | // Add the patch entry and bind its label at the end of the instruction. |
| 4611 | method_bss_entry_patches_.emplace_back(method_address, |
| 4612 | *target_method.dex_file, |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 4613 | target_method.index); |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4614 | return &method_bss_entry_patches_.back().label; |
| 4615 | } |
| 4616 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4617 | void CodeGeneratorX86::RecordBootTypePatch(HLoadClass* load_class) { |
Vladimir Marko | 00916b9 | 2017-05-17 17:45:45 +0100 | [diff] [blame] | 4618 | HX86ComputeBaseMethodAddress* address = load_class->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4619 | boot_image_type_patches_.emplace_back(address, |
| 4620 | load_class->GetDexFile(), |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4621 | load_class->GetTypeIndex().index_); |
| 4622 | __ Bind(&boot_image_type_patches_.back().label); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4623 | } |
| 4624 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4625 | Label* CodeGeneratorX86::NewTypeBssEntryPatch(HLoadClass* load_class) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4626 | HX86ComputeBaseMethodAddress* address = |
| 4627 | load_class->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 4628 | type_bss_entry_patches_.emplace_back( |
| 4629 | address, load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4630 | return &type_bss_entry_patches_.back().label; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4631 | } |
| 4632 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4633 | void CodeGeneratorX86::RecordBootStringPatch(HLoadString* load_string) { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4634 | HX86ComputeBaseMethodAddress* address = load_string->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 4635 | string_patches_.emplace_back(address, |
| 4636 | load_string->GetDexFile(), |
| 4637 | load_string->GetStringIndex().index_); |
| 4638 | __ Bind(&string_patches_.back().label); |
| 4639 | } |
| 4640 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4641 | Label* CodeGeneratorX86::NewStringBssEntryPatch(HLoadString* load_string) { |
| 4642 | DCHECK(!GetCompilerOptions().IsBootImage()); |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4643 | HX86ComputeBaseMethodAddress* address = |
| 4644 | load_string->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4645 | string_bss_entry_patches_.emplace_back( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4646 | address, load_string->GetDexFile(), load_string->GetStringIndex().index_); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4647 | return &string_bss_entry_patches_.back().label; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4648 | } |
| 4649 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4650 | // The label points to the end of the "movl" or another instruction but the literal offset |
| 4651 | // for method patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 4652 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
| 4653 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4654 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4655 | inline void CodeGeneratorX86::EmitPcRelativeLinkerPatches( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4656 | const ArenaDeque<X86PcRelativePatchInfo>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4657 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4658 | for (const X86PcRelativePatchInfo& info : infos) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4659 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4660 | linker_patches->push_back(Factory( |
| 4661 | literal_offset, &info.dex_file, GetMethodAddressOffset(info.method_address), info.index)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4662 | } |
| 4663 | } |
| 4664 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4665 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4666 | DCHECK(linker_patches->empty()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4667 | size_t size = |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4668 | boot_image_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4669 | method_bss_entry_patches_.size() + |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4670 | boot_image_type_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4671 | type_bss_entry_patches_.size() + |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4672 | string_patches_.size() + |
| 4673 | string_bss_entry_patches_.size(); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4674 | linker_patches->reserve(size); |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 4675 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4676 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
| 4677 | boot_image_method_patches_, linker_patches); |
| 4678 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
| 4679 | boot_image_type_patches_, linker_patches); |
| 4680 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
| 4681 | string_patches_, linker_patches); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4682 | } else { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4683 | DCHECK(boot_image_method_patches_.empty()); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4684 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeClassTablePatch>( |
| 4685 | boot_image_type_patches_, linker_patches); |
| 4686 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringInternTablePatch>( |
| 4687 | string_patches_, linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4688 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4689 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 4690 | method_bss_entry_patches_, linker_patches); |
| 4691 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 4692 | type_bss_entry_patches_, linker_patches); |
| 4693 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 4694 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4695 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4696 | } |
| 4697 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4698 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 4699 | Register card, |
| 4700 | Register object, |
| 4701 | Register value, |
| 4702 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4703 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4704 | if (value_can_be_null) { |
| 4705 | __ testl(value, value); |
| 4706 | __ j(kEqual, &is_null); |
| 4707 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4708 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86PointerSize>().Int32Value())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4709 | __ movl(temp, object); |
| 4710 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4711 | __ movb(Address(temp, card, TIMES_1, 0), |
| 4712 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4713 | if (value_can_be_null) { |
| 4714 | __ Bind(&is_null); |
| 4715 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4716 | } |
| 4717 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4718 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4719 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4720 | |
| 4721 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4722 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4723 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4724 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 4725 | kEmitCompilerReadBarrier |
| 4726 | ? LocationSummary::kCallOnSlowPath |
| 4727 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4728 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4729 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4730 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4731 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4732 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4733 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4734 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4735 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4736 | // The output overlaps in case of long: we don't want the low move |
| 4737 | // to overwrite the object's location. Likewise, in the case of |
| 4738 | // an object field get with read barriers enabled, we do not want |
| 4739 | // the move to overwrite the object's location, as we need it to emit |
| 4740 | // the read barrier. |
| 4741 | locations->SetOut( |
| 4742 | Location::RequiresRegister(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4743 | (object_field_get_with_read_barrier || instruction->GetType() == DataType::Type::kInt64) ? |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4744 | Location::kOutputOverlap : |
| 4745 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4746 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4747 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4748 | if (field_info.IsVolatile() && (field_info.GetFieldType() == DataType::Type::kInt64)) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4749 | // Long values can be loaded atomically into an XMM using movsd. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4750 | // So we use an XMM register as a temp to achieve atomicity (first |
| 4751 | // load the temp into the XMM and then copy the XMM into the |
| 4752 | // output, 32 bits at a time). |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4753 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4754 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4755 | } |
| 4756 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4757 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 4758 | const FieldInfo& field_info) { |
| 4759 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4760 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4761 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4762 | Location base_loc = locations->InAt(0); |
| 4763 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4764 | Location out = locations->Out(); |
| 4765 | bool is_volatile = field_info.IsVolatile(); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4766 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 4767 | DataType::Type load_type = instruction->GetType(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4768 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4769 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4770 | switch (load_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4771 | case DataType::Type::kBool: |
| 4772 | case DataType::Type::kUint8: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4773 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4774 | break; |
| 4775 | } |
| 4776 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4777 | case DataType::Type::kInt8: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4778 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4779 | break; |
| 4780 | } |
| 4781 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4782 | case DataType::Type::kUint16: { |
| 4783 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4784 | break; |
| 4785 | } |
| 4786 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4787 | case DataType::Type::kInt16: { |
| 4788 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4789 | break; |
| 4790 | } |
| 4791 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4792 | case DataType::Type::kInt32: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4793 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4794 | break; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4795 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4796 | case DataType::Type::kReference: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4797 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4798 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4799 | // Note that a potential implicit null check is handled in this |
| 4800 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 4801 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 4802 | instruction, out, base, offset, /* needs_null_check */ true); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4803 | if (is_volatile) { |
| 4804 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4805 | } |
| 4806 | } else { |
| 4807 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| 4808 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4809 | if (is_volatile) { |
| 4810 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4811 | } |
| 4812 | // If read barriers are enabled, emit read barriers other than |
| 4813 | // Baker's using a slow path (and also unpoison the loaded |
| 4814 | // reference, if heap poisoning is enabled). |
| 4815 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4816 | } |
| 4817 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4818 | } |
| 4819 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4820 | case DataType::Type::kInt64: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4821 | if (is_volatile) { |
| 4822 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4823 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4824 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4825 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 4826 | __ psrlq(temp, Immediate(32)); |
| 4827 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 4828 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4829 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4830 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4831 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4832 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 4833 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4834 | break; |
| 4835 | } |
| 4836 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4837 | case DataType::Type::kFloat32: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4838 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4839 | break; |
| 4840 | } |
| 4841 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4842 | case DataType::Type::kFloat64: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4843 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4844 | break; |
| 4845 | } |
| 4846 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4847 | case DataType::Type::kVoid: |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4848 | LOG(FATAL) << "Unreachable type " << load_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4849 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4850 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4851 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4852 | if (load_type == DataType::Type::kReference || load_type == DataType::Type::kInt64) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4853 | // Potential implicit null checks, in the case of reference or |
| 4854 | // long fields, are handled in the previous switch statement. |
| 4855 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4856 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4857 | } |
| 4858 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4859 | if (is_volatile) { |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4860 | if (load_type == DataType::Type::kReference) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4861 | // Memory barriers, in the case of references, are also handled |
| 4862 | // in the previous switch statement. |
| 4863 | } else { |
| 4864 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4865 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4866 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4867 | } |
| 4868 | |
| 4869 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4870 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4871 | |
| 4872 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4873 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4874 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4875 | bool is_volatile = field_info.IsVolatile(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4876 | DataType::Type field_type = field_info.GetFieldType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4877 | bool is_byte_type = DataType::Size(field_type) == 1u; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4878 | |
| 4879 | // The register allocator does not support multiple |
| 4880 | // inputs that die at entry with one in a specific register. |
| 4881 | if (is_byte_type) { |
| 4882 | // Ensure the value is in a byte register. |
| 4883 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4884 | } else if (DataType::IsFloatingPointType(field_type)) { |
| 4885 | if (is_volatile && field_type == DataType::Type::kFloat64) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4886 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4887 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4888 | } else { |
| 4889 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4890 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4891 | } else if (is_volatile && field_type == DataType::Type::kInt64) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4892 | // 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] | 4893 | locations->SetInAt(1, Location::RequiresRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4894 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4895 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 4896 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 4897 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 4898 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 4899 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 4900 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4901 | locations->AddTemp(Location::RequiresFpuRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4902 | } else { |
| 4903 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4904 | |
| 4905 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4906 | // Temporary registers for the write barrier. |
| 4907 | locations->AddTemp(Location::RequiresRegister()); // May be used for reference poisoning too. |
| 4908 | // Ensure the card is in a byte register. |
| 4909 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 4910 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4911 | } |
| 4912 | } |
| 4913 | |
| 4914 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4915 | const FieldInfo& field_info, |
| 4916 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4917 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4918 | |
| 4919 | LocationSummary* locations = instruction->GetLocations(); |
| 4920 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 4921 | Location value = locations->InAt(1); |
| 4922 | bool is_volatile = field_info.IsVolatile(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4923 | DataType::Type field_type = field_info.GetFieldType(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4924 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4925 | bool needs_write_barrier = |
| 4926 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4927 | |
| 4928 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4929 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4930 | } |
| 4931 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4932 | bool maybe_record_implicit_null_check_done = false; |
| 4933 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4934 | switch (field_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4935 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4936 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4937 | case DataType::Type::kInt8: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4938 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 4939 | break; |
| 4940 | } |
| 4941 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4942 | case DataType::Type::kUint16: |
| 4943 | case DataType::Type::kInt16: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4944 | if (value.IsConstant()) { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 4945 | __ movw(Address(base, offset), |
| 4946 | Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4947 | } else { |
| 4948 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 4949 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4950 | break; |
| 4951 | } |
| 4952 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4953 | case DataType::Type::kInt32: |
| 4954 | case DataType::Type::kReference: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4955 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4956 | // Note that in the case where `value` is a null reference, |
| 4957 | // we do not enter this block, as the reference does not |
| 4958 | // need poisoning. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4959 | DCHECK_EQ(field_type, DataType::Type::kReference); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4960 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4961 | __ movl(temp, value.AsRegister<Register>()); |
| 4962 | __ PoisonHeapReference(temp); |
| 4963 | __ movl(Address(base, offset), temp); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4964 | } else if (value.IsConstant()) { |
| 4965 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4966 | __ movl(Address(base, offset), Immediate(v)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4967 | } else { |
Nicolas Geoffray | 0397163 | 2016-03-17 10:44:24 +0000 | [diff] [blame] | 4968 | DCHECK(value.IsRegister()) << value; |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4969 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 4970 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4971 | break; |
| 4972 | } |
| 4973 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4974 | case DataType::Type::kInt64: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4975 | if (is_volatile) { |
| 4976 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4977 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 4978 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 4979 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 4980 | __ punpckldq(temp1, temp2); |
| 4981 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4982 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4983 | } else if (value.IsConstant()) { |
| 4984 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4985 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4986 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4987 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4988 | } else { |
| 4989 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4990 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4991 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 4992 | } |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4993 | maybe_record_implicit_null_check_done = true; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4994 | break; |
| 4995 | } |
| 4996 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4997 | case DataType::Type::kFloat32: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4998 | if (value.IsConstant()) { |
| 4999 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5000 | __ movl(Address(base, offset), Immediate(v)); |
| 5001 | } else { |
| 5002 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 5003 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5004 | break; |
| 5005 | } |
| 5006 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5007 | case DataType::Type::kFloat64: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5008 | if (value.IsConstant()) { |
| 5009 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 5010 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 5011 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5012 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
| 5013 | maybe_record_implicit_null_check_done = true; |
| 5014 | } else { |
| 5015 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 5016 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5017 | break; |
| 5018 | } |
| 5019 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5020 | case DataType::Type::kVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5021 | LOG(FATAL) << "Unreachable type " << field_type; |
| 5022 | UNREACHABLE(); |
| 5023 | } |
| 5024 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5025 | if (!maybe_record_implicit_null_check_done) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5026 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5027 | } |
| 5028 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5029 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5030 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5031 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5032 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5033 | } |
| 5034 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5035 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5036 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5037 | } |
| 5038 | } |
| 5039 | |
| 5040 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5041 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5042 | } |
| 5043 | |
| 5044 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5045 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5046 | } |
| 5047 | |
| 5048 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 5049 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5050 | } |
| 5051 | |
| 5052 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5053 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5054 | } |
| 5055 | |
| 5056 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5057 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5058 | } |
| 5059 | |
| 5060 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5061 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5062 | } |
| 5063 | |
| 5064 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5065 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5066 | } |
| 5067 | |
| 5068 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5069 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5070 | } |
| 5071 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5072 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 5073 | HUnresolvedInstanceFieldGet* instruction) { |
| 5074 | FieldAccessCallingConventionX86 calling_convention; |
| 5075 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5076 | instruction, instruction->GetFieldType(), calling_convention); |
| 5077 | } |
| 5078 | |
| 5079 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 5080 | HUnresolvedInstanceFieldGet* instruction) { |
| 5081 | FieldAccessCallingConventionX86 calling_convention; |
| 5082 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5083 | instruction->GetFieldType(), |
| 5084 | instruction->GetFieldIndex(), |
| 5085 | instruction->GetDexPc(), |
| 5086 | calling_convention); |
| 5087 | } |
| 5088 | |
| 5089 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 5090 | HUnresolvedInstanceFieldSet* instruction) { |
| 5091 | FieldAccessCallingConventionX86 calling_convention; |
| 5092 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5093 | instruction, instruction->GetFieldType(), calling_convention); |
| 5094 | } |
| 5095 | |
| 5096 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 5097 | HUnresolvedInstanceFieldSet* instruction) { |
| 5098 | FieldAccessCallingConventionX86 calling_convention; |
| 5099 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5100 | instruction->GetFieldType(), |
| 5101 | instruction->GetFieldIndex(), |
| 5102 | instruction->GetDexPc(), |
| 5103 | calling_convention); |
| 5104 | } |
| 5105 | |
| 5106 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 5107 | HUnresolvedStaticFieldGet* instruction) { |
| 5108 | FieldAccessCallingConventionX86 calling_convention; |
| 5109 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5110 | instruction, instruction->GetFieldType(), calling_convention); |
| 5111 | } |
| 5112 | |
| 5113 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 5114 | HUnresolvedStaticFieldGet* instruction) { |
| 5115 | FieldAccessCallingConventionX86 calling_convention; |
| 5116 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5117 | instruction->GetFieldType(), |
| 5118 | instruction->GetFieldIndex(), |
| 5119 | instruction->GetDexPc(), |
| 5120 | calling_convention); |
| 5121 | } |
| 5122 | |
| 5123 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 5124 | HUnresolvedStaticFieldSet* instruction) { |
| 5125 | FieldAccessCallingConventionX86 calling_convention; |
| 5126 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5127 | instruction, instruction->GetFieldType(), calling_convention); |
| 5128 | } |
| 5129 | |
| 5130 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 5131 | HUnresolvedStaticFieldSet* instruction) { |
| 5132 | FieldAccessCallingConventionX86 calling_convention; |
| 5133 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5134 | instruction->GetFieldType(), |
| 5135 | instruction->GetFieldIndex(), |
| 5136 | instruction->GetDexPc(), |
| 5137 | calling_convention); |
| 5138 | } |
| 5139 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5140 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5141 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5142 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 5143 | ? Location::RequiresRegister() |
| 5144 | : Location::Any(); |
| 5145 | locations->SetInAt(0, loc); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5146 | } |
| 5147 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5148 | void CodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5149 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5150 | return; |
| 5151 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5152 | LocationSummary* locations = instruction->GetLocations(); |
| 5153 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5154 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5155 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5156 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5157 | } |
| 5158 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5159 | void CodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5160 | SlowPathCode* slow_path = new (GetScopedAllocator()) NullCheckSlowPathX86(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5161 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5162 | |
| 5163 | LocationSummary* locations = instruction->GetLocations(); |
| 5164 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5165 | |
| 5166 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 5167 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5168 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5169 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5170 | } else { |
| 5171 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5172 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5173 | __ jmp(slow_path->GetEntryLabel()); |
| 5174 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5175 | } |
| 5176 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5177 | } |
| 5178 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5179 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5180 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5181 | } |
| 5182 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5183 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5184 | bool object_array_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5185 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5186 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5187 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 5188 | object_array_get_with_read_barrier |
| 5189 | ? LocationSummary::kCallOnSlowPath |
| 5190 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5191 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5192 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5193 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5194 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5195 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5196 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5197 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5198 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5199 | // The output overlaps in case of long: we don't want the low move |
| 5200 | // to overwrite the array's location. Likewise, in the case of an |
| 5201 | // object array get with read barriers enabled, we do not want the |
| 5202 | // move to overwrite the array's location, as we need it to emit |
| 5203 | // the read barrier. |
| 5204 | locations->SetOut( |
| 5205 | Location::RequiresRegister(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5206 | (instruction->GetType() == DataType::Type::kInt64 || object_array_get_with_read_barrier) |
| 5207 | ? Location::kOutputOverlap |
| 5208 | : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5209 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5210 | } |
| 5211 | |
| 5212 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 5213 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5214 | Location obj_loc = locations->InAt(0); |
| 5215 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5216 | Location index = locations->InAt(1); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5217 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5218 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5219 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5220 | DataType::Type type = instruction->GetType(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5221 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5222 | case DataType::Type::kBool: |
| 5223 | case DataType::Type::kUint8: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5224 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5225 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5226 | break; |
| 5227 | } |
| 5228 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5229 | case DataType::Type::kInt8: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5230 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5231 | __ movsxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5232 | break; |
| 5233 | } |
| 5234 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5235 | case DataType::Type::kUint16: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5236 | Register out = out_loc.AsRegister<Register>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5237 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5238 | // Branch cases into compressed and uncompressed for each index's type. |
| 5239 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 5240 | NearLabel done, not_compressed; |
Vladimir Marko | 3c89d42 | 2017-02-17 11:30:23 +0000 | [diff] [blame] | 5241 | __ testb(Address(obj, count_offset), Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5242 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5243 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 5244 | "Expecting 0=compressed, 1=uncompressed"); |
| 5245 | __ j(kNotZero, ¬_compressed); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5246 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| 5247 | __ jmp(&done); |
| 5248 | __ Bind(¬_compressed); |
| 5249 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5250 | __ Bind(&done); |
| 5251 | } else { |
| 5252 | // Common case for charAt of array of char or when string compression's |
| 5253 | // feature is turned off. |
| 5254 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5255 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5256 | break; |
| 5257 | } |
| 5258 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5259 | case DataType::Type::kInt16: { |
| 5260 | Register out = out_loc.AsRegister<Register>(); |
| 5261 | __ movsxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5262 | break; |
| 5263 | } |
| 5264 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5265 | case DataType::Type::kInt32: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5266 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5267 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5268 | break; |
| 5269 | } |
| 5270 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5271 | case DataType::Type::kReference: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5272 | static_assert( |
| 5273 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5274 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5275 | // /* HeapReference<Object> */ out = |
| 5276 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5277 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5278 | // Note that a potential implicit null check is handled in this |
| 5279 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 5280 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5281 | instruction, out_loc, obj, data_offset, index, /* needs_null_check */ true); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5282 | } else { |
| 5283 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5284 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| 5285 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5286 | // If read barriers are enabled, emit read barriers other than |
| 5287 | // Baker's using a slow path (and also unpoison the loaded |
| 5288 | // reference, if heap poisoning is enabled). |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5289 | if (index.IsConstant()) { |
| 5290 | uint32_t offset = |
| 5291 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5292 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5293 | } else { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5294 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5295 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5296 | } |
| 5297 | } |
| 5298 | break; |
| 5299 | } |
| 5300 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5301 | case DataType::Type::kInt64: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5302 | DCHECK_NE(obj, out_loc.AsRegisterPairLow<Register>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5303 | __ movl(out_loc.AsRegisterPairLow<Register>(), |
| 5304 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
| 5305 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5306 | __ movl(out_loc.AsRegisterPairHigh<Register>(), |
| 5307 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5308 | break; |
| 5309 | } |
| 5310 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5311 | case DataType::Type::kFloat32: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5312 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5313 | __ movss(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5314 | break; |
| 5315 | } |
| 5316 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5317 | case DataType::Type::kFloat64: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5318 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5319 | __ movsd(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5320 | break; |
| 5321 | } |
| 5322 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5323 | case DataType::Type::kVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5324 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5325 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5326 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5327 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5328 | if (type == DataType::Type::kReference || type == DataType::Type::kInt64) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5329 | // Potential implicit null checks, in the case of reference or |
| 5330 | // long arrays, are handled in the previous switch statement. |
| 5331 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5332 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5333 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5334 | } |
| 5335 | |
| 5336 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5337 | DataType::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5338 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5339 | bool needs_write_barrier = |
| 5340 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5341 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5342 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5343 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5344 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 5345 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5346 | LocationSummary::kCallOnSlowPath : |
| 5347 | LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5348 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5349 | bool is_byte_type = DataType::Size(value_type) == 1u; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5350 | // We need the inputs to be different than the output in case of long operation. |
| 5351 | // In case of a byte operation, the register allocator does not support multiple |
| 5352 | // inputs that die at entry with one in a specific register. |
| 5353 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5354 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5355 | if (is_byte_type) { |
| 5356 | // Ensure the value is in a byte register. |
| 5357 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5358 | } else if (DataType::IsFloatingPointType(value_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5359 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5360 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5361 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 5362 | } |
| 5363 | if (needs_write_barrier) { |
| 5364 | // Temporary registers for the write barrier. |
| 5365 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 5366 | // Ensure the card is in a byte register. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5367 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5368 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5369 | } |
| 5370 | |
| 5371 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 5372 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5373 | Location array_loc = locations->InAt(0); |
| 5374 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5375 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5376 | Location value = locations->InAt(2); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5377 | DataType::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5378 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5379 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5380 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5381 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5382 | bool needs_write_barrier = |
| 5383 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5384 | |
| 5385 | switch (value_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5386 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5387 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5388 | case DataType::Type::kInt8: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5389 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5390 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_1, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5391 | if (value.IsRegister()) { |
| 5392 | __ movb(address, value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5393 | } else { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5394 | __ movb(address, Immediate(CodeGenerator::GetInt8ValueOf(value.GetConstant()))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5395 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5396 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5397 | break; |
| 5398 | } |
| 5399 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5400 | case DataType::Type::kUint16: |
| 5401 | case DataType::Type::kInt16: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5402 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5403 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_2, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5404 | if (value.IsRegister()) { |
| 5405 | __ movw(address, value.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5406 | } else { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5407 | __ movw(address, Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5408 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5409 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5410 | break; |
| 5411 | } |
| 5412 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5413 | case DataType::Type::kReference: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5414 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5415 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5416 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5417 | if (!value.IsRegister()) { |
| 5418 | // Just setting null. |
| 5419 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5420 | DCHECK(value.IsConstant()) << value; |
| 5421 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5422 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5423 | DCHECK(!needs_write_barrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5424 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5425 | break; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5426 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5427 | |
| 5428 | DCHECK(needs_write_barrier); |
| 5429 | Register register_value = value.AsRegister<Register>(); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5430 | // We cannot use a NearLabel for `done`, as its range may be too |
| 5431 | // short when Baker read barriers are enabled. |
| 5432 | Label done; |
| 5433 | NearLabel not_null, do_put; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5434 | SlowPathCode* slow_path = nullptr; |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5435 | Location temp_loc = locations->GetTemp(0); |
| 5436 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5437 | if (may_need_runtime_call_for_type_check) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5438 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathX86(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5439 | codegen_->AddSlowPath(slow_path); |
| 5440 | if (instruction->GetValueCanBeNull()) { |
| 5441 | __ testl(register_value, register_value); |
| 5442 | __ j(kNotEqual, ¬_null); |
| 5443 | __ movl(address, Immediate(0)); |
| 5444 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5445 | __ jmp(&done); |
| 5446 | __ Bind(¬_null); |
| 5447 | } |
| 5448 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5449 | // Note that when Baker read barriers are enabled, the type |
| 5450 | // checks are performed without read barriers. This is fine, |
| 5451 | // even in the case where a class object is in the from-space |
| 5452 | // after the flip, as a comparison involving such a type would |
| 5453 | // not produce a false positive; it may of course produce a |
| 5454 | // false negative, in which case we would take the ArraySet |
| 5455 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5456 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5457 | // /* HeapReference<Class> */ temp = array->klass_ |
| 5458 | __ movl(temp, Address(array, class_offset)); |
| 5459 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5460 | __ MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5461 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5462 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5463 | __ movl(temp, Address(temp, component_offset)); |
| 5464 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 5465 | // nor the object reference in `register_value->klass`, as |
| 5466 | // we are comparing two poisoned references. |
| 5467 | __ cmpl(temp, Address(register_value, class_offset)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5468 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5469 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5470 | __ j(kEqual, &do_put); |
| 5471 | // If heap poisoning is enabled, the `temp` reference has |
| 5472 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5473 | __ MaybeUnpoisonHeapReference(temp); |
| 5474 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5475 | // If heap poisoning is enabled, no need to unpoison the |
| 5476 | // heap reference loaded below, as it is only used for a |
| 5477 | // comparison with null. |
| 5478 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 5479 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5480 | __ Bind(&do_put); |
| 5481 | } else { |
| 5482 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5483 | } |
| 5484 | } |
| 5485 | |
| 5486 | if (kPoisonHeapReferences) { |
| 5487 | __ movl(temp, register_value); |
| 5488 | __ PoisonHeapReference(temp); |
| 5489 | __ movl(address, temp); |
| 5490 | } else { |
| 5491 | __ movl(address, register_value); |
| 5492 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5493 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5494 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5495 | } |
| 5496 | |
| 5497 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 5498 | codegen_->MarkGCCard( |
| 5499 | temp, card, array, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); |
| 5500 | __ Bind(&done); |
| 5501 | |
| 5502 | if (slow_path != nullptr) { |
| 5503 | __ Bind(slow_path->GetExitLabel()); |
| 5504 | } |
| 5505 | |
| 5506 | break; |
| 5507 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5508 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5509 | case DataType::Type::kInt32: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5510 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5511 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5512 | if (value.IsRegister()) { |
| 5513 | __ movl(address, value.AsRegister<Register>()); |
| 5514 | } else { |
| 5515 | DCHECK(value.IsConstant()) << value; |
| 5516 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5517 | __ movl(address, Immediate(v)); |
| 5518 | } |
| 5519 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5520 | break; |
| 5521 | } |
| 5522 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5523 | case DataType::Type::kInt64: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5524 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5525 | if (value.IsRegisterPair()) { |
| 5526 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 5527 | value.AsRegisterPairLow<Register>()); |
| 5528 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5529 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 5530 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5531 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5532 | DCHECK(value.IsConstant()); |
| 5533 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
| 5534 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 5535 | Immediate(Low32Bits(val))); |
| 5536 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5537 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 5538 | Immediate(High32Bits(val))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5539 | } |
| 5540 | break; |
| 5541 | } |
| 5542 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5543 | case DataType::Type::kFloat32: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5544 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5545 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5546 | if (value.IsFpuRegister()) { |
| 5547 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5548 | } else { |
| 5549 | DCHECK(value.IsConstant()); |
| 5550 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 5551 | __ movl(address, Immediate(v)); |
| 5552 | } |
| 5553 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5554 | break; |
| 5555 | } |
| 5556 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5557 | case DataType::Type::kFloat64: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5558 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5559 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5560 | if (value.IsFpuRegister()) { |
| 5561 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5562 | } else { |
| 5563 | DCHECK(value.IsConstant()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5564 | Address address_hi = |
| 5565 | CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset + kX86WordSize); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5566 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 5567 | __ movl(address, Immediate(Low32Bits(v))); |
| 5568 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5569 | __ movl(address_hi, Immediate(High32Bits(v))); |
| 5570 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5571 | break; |
| 5572 | } |
| 5573 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5574 | case DataType::Type::kVoid: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5575 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5576 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5577 | } |
| 5578 | } |
| 5579 | |
| 5580 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5581 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5582 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5583 | if (!instruction->IsEmittedAtUseSite()) { |
| 5584 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5585 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5586 | } |
| 5587 | |
| 5588 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5589 | if (instruction->IsEmittedAtUseSite()) { |
| 5590 | return; |
| 5591 | } |
| 5592 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5593 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5594 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5595 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5596 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5597 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5598 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5599 | // Mask out most significant bit in case the array is String's array of char. |
| 5600 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5601 | __ shrl(out, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5602 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5603 | } |
| 5604 | |
| 5605 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5606 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5607 | InvokeRuntimeCallingConvention calling_convention; |
| 5608 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5609 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5610 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5611 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5612 | HInstruction* length = instruction->InputAt(1); |
| 5613 | if (!length->IsEmittedAtUseSite()) { |
| 5614 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5615 | } |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5616 | // Need register to see array's length. |
| 5617 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5618 | locations->AddTemp(Location::RequiresRegister()); |
| 5619 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5620 | } |
| 5621 | |
| 5622 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5623 | const bool is_string_compressed_char_at = |
| 5624 | mirror::kUseStringCompression && instruction->IsStringCharAt(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5625 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5626 | Location index_loc = locations->InAt(0); |
| 5627 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5628 | SlowPathCode* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5629 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathX86(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5630 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5631 | if (length_loc.IsConstant()) { |
| 5632 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5633 | if (index_loc.IsConstant()) { |
| 5634 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5635 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5636 | if (index < 0 || index >= length) { |
| 5637 | codegen_->AddSlowPath(slow_path); |
| 5638 | __ jmp(slow_path->GetEntryLabel()); |
| 5639 | } else { |
| 5640 | // Some optimization after BCE may have generated this, and we should not |
| 5641 | // generate a bounds check if it is a valid range. |
| 5642 | } |
| 5643 | return; |
| 5644 | } |
| 5645 | |
| 5646 | // We have to reverse the jump condition because the length is the constant. |
| 5647 | Register index_reg = index_loc.AsRegister<Register>(); |
| 5648 | __ cmpl(index_reg, Immediate(length)); |
| 5649 | codegen_->AddSlowPath(slow_path); |
| 5650 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5651 | } else { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5652 | HInstruction* array_length = instruction->InputAt(1); |
| 5653 | if (array_length->IsEmittedAtUseSite()) { |
| 5654 | // Address the length field in the array. |
| 5655 | DCHECK(array_length->IsArrayLength()); |
| 5656 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 5657 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 5658 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5659 | if (is_string_compressed_char_at) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5660 | // TODO: if index_loc.IsConstant(), compare twice the index (to compensate for |
| 5661 | // the string compression flag) with the in-memory length and avoid the temporary. |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5662 | Register length_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 5663 | __ movl(length_reg, array_len); |
| 5664 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5665 | __ shrl(length_reg, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5666 | codegen_->GenerateIntCompare(length_reg, index_loc); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5667 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5668 | // Checking bounds for general case: |
| 5669 | // Array of char or string's array with feature compression off. |
| 5670 | if (index_loc.IsConstant()) { |
| 5671 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5672 | __ cmpl(array_len, Immediate(value)); |
| 5673 | } else { |
| 5674 | __ cmpl(array_len, index_loc.AsRegister<Register>()); |
| 5675 | } |
| 5676 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5677 | } |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5678 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5679 | codegen_->GenerateIntCompare(length_loc, index_loc); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5680 | } |
| 5681 | codegen_->AddSlowPath(slow_path); |
| 5682 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5683 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5684 | } |
| 5685 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5686 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5687 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5688 | } |
| 5689 | |
| 5690 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 5691 | if (instruction->GetNext()->IsSuspendCheck() && |
| 5692 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 5693 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 5694 | // The back edge will generate the suspend check. |
| 5695 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 5696 | } |
| 5697 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5698 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5699 | } |
| 5700 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5701 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5702 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5703 | instruction, LocationSummary::kCallOnSlowPath); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 5704 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 5705 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 5706 | // registers in full width (since the runtime only saves/restores lower part). |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5707 | locations->SetCustomSlowPathCallerSaves( |
| 5708 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5709 | } |
| 5710 | |
| 5711 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5712 | HBasicBlock* block = instruction->GetBlock(); |
| 5713 | if (block->GetLoopInformation() != nullptr) { |
| 5714 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5715 | // The back edge will generate the suspend check. |
| 5716 | return; |
| 5717 | } |
| 5718 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5719 | // The goto will generate the suspend check. |
| 5720 | return; |
| 5721 | } |
| 5722 | GenerateSuspendCheck(instruction, nullptr); |
| 5723 | } |
| 5724 | |
| 5725 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5726 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5727 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5728 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 5729 | if (slow_path == nullptr) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5730 | slow_path = |
| 5731 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathX86(instruction, successor); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5732 | instruction->SetSlowPath(slow_path); |
| 5733 | codegen_->AddSlowPath(slow_path); |
| 5734 | if (successor != nullptr) { |
| 5735 | DCHECK(successor->IsLoopHeader()); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5736 | } |
| 5737 | } else { |
| 5738 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5739 | } |
| 5740 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5741 | __ fs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86PointerSize>().Int32Value()), |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5742 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5743 | if (successor == nullptr) { |
| 5744 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5745 | __ Bind(slow_path->GetReturnLabel()); |
| 5746 | } else { |
| 5747 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5748 | __ jmp(slow_path->GetEntryLabel()); |
| 5749 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5750 | } |
| 5751 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5752 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 5753 | return codegen_->GetAssembler(); |
| 5754 | } |
| 5755 | |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5756 | void ParallelMoveResolverX86::MoveMemoryToMemory(int dst, int src, int number_of_words) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5757 | ScratchRegisterScope ensure_scratch( |
| 5758 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5759 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5760 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5761 | |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5762 | // Now that temp register is available (possibly spilled), move blocks of memory. |
| 5763 | for (int i = 0; i < number_of_words; i++) { |
| 5764 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5765 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 5766 | stack_offset += kX86WordSize; |
| 5767 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5768 | } |
| 5769 | |
| 5770 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5771 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5772 | Location source = move->GetSource(); |
| 5773 | Location destination = move->GetDestination(); |
| 5774 | |
| 5775 | if (source.IsRegister()) { |
| 5776 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5777 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5778 | } else if (destination.IsFpuRegister()) { |
| 5779 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5780 | } else { |
| 5781 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5782 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5783 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5784 | } else if (source.IsRegisterPair()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5785 | size_t elem_size = DataType::Size(DataType::Type::kInt32); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5786 | // Create stack space for 2 elements. |
| 5787 | __ subl(ESP, Immediate(2 * elem_size)); |
| 5788 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 5789 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 5790 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 5791 | // And remove the temporary stack space we allocated. |
| 5792 | __ addl(ESP, Immediate(2 * elem_size)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5793 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5794 | if (destination.IsRegister()) { |
| 5795 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
| 5796 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5797 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5798 | } else if (destination.IsRegisterPair()) { |
| 5799 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 5800 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 5801 | __ psrlq(src_reg, Immediate(32)); |
| 5802 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5803 | } else if (destination.IsStackSlot()) { |
| 5804 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5805 | } else if (destination.IsDoubleStackSlot()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5806 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5807 | } else { |
| 5808 | DCHECK(destination.IsSIMDStackSlot()); |
| 5809 | __ movups(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5810 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5811 | } else if (source.IsStackSlot()) { |
| 5812 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5813 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5814 | } else if (destination.IsFpuRegister()) { |
| 5815 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5816 | } else { |
| 5817 | DCHECK(destination.IsStackSlot()); |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5818 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 1); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5819 | } |
| 5820 | } else if (source.IsDoubleStackSlot()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5821 | if (destination.IsRegisterPair()) { |
| 5822 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 5823 | __ movl(destination.AsRegisterPairHigh<Register>(), |
| 5824 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 5825 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5826 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 5827 | } else { |
| 5828 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5829 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 2); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5830 | } |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5831 | } else if (source.IsSIMDStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5832 | if (destination.IsFpuRegister()) { |
| 5833 | __ movups(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 5834 | } else { |
| 5835 | DCHECK(destination.IsSIMDStackSlot()); |
| 5836 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 4); |
| 5837 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5838 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5839 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5840 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5841 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5842 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5843 | if (value == 0) { |
| 5844 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5845 | } else { |
| 5846 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 5847 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5848 | } else { |
| 5849 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5850 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5851 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5852 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5853 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5854 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5855 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5856 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5857 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5858 | if (value == 0) { |
| 5859 | // Easy handling of 0.0. |
| 5860 | __ xorps(dest, dest); |
| 5861 | } else { |
| 5862 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5863 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5864 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5865 | __ movl(temp, Immediate(value)); |
| 5866 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5867 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5868 | } else { |
| 5869 | DCHECK(destination.IsStackSlot()) << destination; |
| 5870 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 5871 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5872 | } else if (constant->IsLongConstant()) { |
| 5873 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5874 | int32_t low_value = Low32Bits(value); |
| 5875 | int32_t high_value = High32Bits(value); |
| 5876 | Immediate low(low_value); |
| 5877 | Immediate high(high_value); |
| 5878 | if (destination.IsDoubleStackSlot()) { |
| 5879 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5880 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5881 | } else { |
| 5882 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 5883 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 5884 | } |
| 5885 | } else { |
| 5886 | DCHECK(constant->IsDoubleConstant()); |
| 5887 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5888 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5889 | int32_t low_value = Low32Bits(value); |
| 5890 | int32_t high_value = High32Bits(value); |
| 5891 | Immediate low(low_value); |
| 5892 | Immediate high(high_value); |
| 5893 | if (destination.IsFpuRegister()) { |
| 5894 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5895 | if (value == 0) { |
| 5896 | // Easy handling of 0.0. |
| 5897 | __ xorpd(dest, dest); |
| 5898 | } else { |
| 5899 | __ pushl(high); |
| 5900 | __ pushl(low); |
| 5901 | __ movsd(dest, Address(ESP, 0)); |
| 5902 | __ addl(ESP, Immediate(8)); |
| 5903 | } |
| 5904 | } else { |
| 5905 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5906 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5907 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5908 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5909 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5910 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5911 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5912 | } |
| 5913 | } |
| 5914 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 5915 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5916 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 5917 | ScratchRegisterScope ensure_scratch( |
| 5918 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 5919 | |
| 5920 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5921 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 5922 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 5923 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5924 | } |
| 5925 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5926 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5927 | ScratchRegisterScope ensure_scratch( |
| 5928 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5929 | |
| 5930 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5931 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5932 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 5933 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 5934 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5935 | } |
| 5936 | |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5937 | void ParallelMoveResolverX86::Exchange128(XmmRegister reg, int mem) { |
| 5938 | size_t extra_slot = 4 * kX86WordSize; |
| 5939 | __ subl(ESP, Immediate(extra_slot)); |
| 5940 | __ movups(Address(ESP, 0), XmmRegister(reg)); |
| 5941 | ExchangeMemory(0, mem + extra_slot, 4); |
| 5942 | __ movups(XmmRegister(reg), Address(ESP, 0)); |
| 5943 | __ addl(ESP, Immediate(extra_slot)); |
| 5944 | } |
| 5945 | |
| 5946 | void ParallelMoveResolverX86::ExchangeMemory(int mem1, int mem2, int number_of_words) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5947 | ScratchRegisterScope ensure_scratch1( |
| 5948 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5949 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5950 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 5951 | ScratchRegisterScope ensure_scratch2( |
| 5952 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5953 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5954 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 5955 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5956 | |
| 5957 | // Now that temp registers are available (possibly spilled), exchange blocks of memory. |
| 5958 | for (int i = 0; i < number_of_words; i++) { |
| 5959 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 5960 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 5961 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 5962 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
| 5963 | stack_offset += kX86WordSize; |
| 5964 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5965 | } |
| 5966 | |
| 5967 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5968 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5969 | Location source = move->GetSource(); |
| 5970 | Location destination = move->GetDestination(); |
| 5971 | |
| 5972 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 5973 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 5974 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5975 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5976 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5977 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5978 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5979 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5980 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5981 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5982 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5983 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 1); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5984 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 5985 | // Use XOR Swap algorithm to avoid a temporary. |
| 5986 | DCHECK_NE(source.reg(), destination.reg()); |
| 5987 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5988 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5989 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5990 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 5991 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 5992 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 5993 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5994 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 5995 | // Take advantage of the 16 bytes in the XMM register. |
| 5996 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 5997 | Address stack(ESP, destination.GetStackIndex()); |
| 5998 | // Load the double into the high doubleword. |
| 5999 | __ movhpd(reg, stack); |
| 6000 | |
| 6001 | // Store the low double into the destination. |
| 6002 | __ movsd(stack, reg); |
| 6003 | |
| 6004 | // Move the high double to the low double. |
| 6005 | __ psrldq(reg, Immediate(8)); |
| 6006 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 6007 | // Take advantage of the 16 bytes in the XMM register. |
| 6008 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 6009 | Address stack(ESP, source.GetStackIndex()); |
| 6010 | // Load the double into the high doubleword. |
| 6011 | __ movhpd(reg, stack); |
| 6012 | |
| 6013 | // Store the low double into the destination. |
| 6014 | __ movsd(stack, reg); |
| 6015 | |
| 6016 | // Move the high double to the low double. |
| 6017 | __ psrldq(reg, Immediate(8)); |
| 6018 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6019 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 2); |
| 6020 | } else if (source.IsSIMDStackSlot() && destination.IsSIMDStackSlot()) { |
| 6021 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 4); |
| 6022 | } else if (source.IsFpuRegister() && destination.IsSIMDStackSlot()) { |
| 6023 | Exchange128(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 6024 | } else if (destination.IsFpuRegister() && source.IsSIMDStackSlot()) { |
| 6025 | Exchange128(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6026 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6027 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6028 | } |
| 6029 | } |
| 6030 | |
| 6031 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 6032 | __ pushl(static_cast<Register>(reg)); |
| 6033 | } |
| 6034 | |
| 6035 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 6036 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6037 | } |
| 6038 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6039 | HLoadClass::LoadKind CodeGeneratorX86::GetSupportedLoadClassKind( |
| 6040 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6041 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6042 | case HLoadClass::LoadKind::kInvalid: |
| 6043 | LOG(FATAL) << "UNREACHABLE"; |
| 6044 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6045 | case HLoadClass::LoadKind::kReferrersClass: |
| 6046 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6047 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6048 | case HLoadClass::LoadKind::kBootImageClassTable: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6049 | case HLoadClass::LoadKind::kBssEntry: |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6050 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6051 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6052 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6053 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6054 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6055 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6056 | case HLoadClass::LoadKind::kRuntimeCall: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6057 | break; |
| 6058 | } |
| 6059 | return desired_class_load_kind; |
| 6060 | } |
| 6061 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6062 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6063 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6064 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6065 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6066 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6067 | cls, |
| 6068 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6069 | Location::RegisterLocation(EAX)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6070 | DCHECK_EQ(calling_convention.GetRegisterAt(0), EAX); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6071 | return; |
| 6072 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6073 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6074 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6075 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 6076 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6077 | ? LocationSummary::kCallOnSlowPath |
| 6078 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6079 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6080 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6081 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6082 | } |
| 6083 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6084 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6085 | load_kind == HLoadClass::LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6086 | load_kind == HLoadClass::LoadKind::kBootImageClassTable || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6087 | load_kind == HLoadClass::LoadKind::kBssEntry) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6088 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6089 | } |
| 6090 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6091 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 6092 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 6093 | // Rely on the type resolution and/or initialization to save everything. |
| 6094 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6095 | InvokeRuntimeCallingConvention calling_convention; |
| 6096 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6097 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6098 | } else { |
| 6099 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6100 | } |
| 6101 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6102 | } |
| 6103 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6104 | Label* CodeGeneratorX86::NewJitRootClassPatch(const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6105 | dex::TypeIndex type_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6106 | Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6107 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6108 | // Add a patch entry and return the label. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6109 | jit_class_patches_.emplace_back(dex_file, type_index.index_); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6110 | PatchInfo<Label>* info = &jit_class_patches_.back(); |
| 6111 | return &info->label; |
| 6112 | } |
| 6113 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6114 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6115 | // move. |
| 6116 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6117 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6118 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6119 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6120 | return; |
| 6121 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6122 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6123 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6124 | LocationSummary* locations = cls->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6125 | Location out_loc = locations->Out(); |
| 6126 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6127 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6128 | bool generate_null_check = false; |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6129 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 6130 | ? kWithoutReadBarrier |
| 6131 | : kCompilerReadBarrierOption; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6132 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6133 | case HLoadClass::LoadKind::kReferrersClass: { |
| 6134 | DCHECK(!cls->CanCallRuntime()); |
| 6135 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 6136 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6137 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 6138 | GenerateGcRootFieldLoad( |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6139 | cls, |
| 6140 | out_loc, |
| 6141 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 6142 | /* fixup_label */ nullptr, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6143 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6144 | break; |
| 6145 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6146 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6147 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6148 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6149 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6150 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 6151 | codegen_->RecordBootTypePatch(cls); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6152 | break; |
| 6153 | } |
| 6154 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6155 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6156 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6157 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 6158 | DCHECK_NE(address, 0u); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6159 | __ movl(out, Immediate(address)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6160 | break; |
| 6161 | } |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6162 | case HLoadClass::LoadKind::kBootImageClassTable: { |
| 6163 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 6164 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6165 | __ movl(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
| 6166 | codegen_->RecordBootTypePatch(cls); |
| 6167 | // Extract the reference from the slot data, i.e. clear the hash bits. |
| 6168 | int32_t masked_hash = ClassTable::TableSlot::MaskHash( |
| 6169 | ComputeModifiedUtf8Hash(cls->GetDexFile().StringByTypeIdx(cls->GetTypeIndex()))); |
| 6170 | if (masked_hash != 0) { |
| 6171 | __ subl(out, Immediate(masked_hash)); |
| 6172 | } |
| 6173 | break; |
| 6174 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6175 | case HLoadClass::LoadKind::kBssEntry: { |
| 6176 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6177 | Address address(method_address, CodeGeneratorX86::kDummy32BitOffset); |
| 6178 | Label* fixup_label = codegen_->NewTypeBssEntryPatch(cls); |
| 6179 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
| 6180 | generate_null_check = true; |
| 6181 | break; |
| 6182 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6183 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 6184 | Address address = Address::Absolute(CodeGeneratorX86::kDummy32BitOffset); |
| 6185 | Label* fixup_label = codegen_->NewJitRootClassPatch( |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6186 | cls->GetDexFile(), cls->GetTypeIndex(), cls->GetClass()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6187 | // /* GcRoot<mirror::Class> */ out = *address |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6188 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6189 | break; |
| 6190 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6191 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6192 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6193 | LOG(FATAL) << "UNREACHABLE"; |
| 6194 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6195 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6196 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6197 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6198 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6199 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6200 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 6201 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6202 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6203 | if (generate_null_check) { |
| 6204 | __ testl(out, out); |
| 6205 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6206 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6207 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6208 | if (cls->MustGenerateClinitCheck()) { |
| 6209 | GenerateClassInitializationCheck(slow_path, out); |
| 6210 | } else { |
| 6211 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6212 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6213 | } |
| 6214 | } |
| 6215 | |
| 6216 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 6217 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6218 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6219 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6220 | if (check->HasUses()) { |
| 6221 | locations->SetOut(Location::SameAsFirstInput()); |
| 6222 | } |
| 6223 | } |
| 6224 | |
| 6225 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6226 | // We assume the class to not be null. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6227 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6228 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6229 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6230 | GenerateClassInitializationCheck(slow_path, |
| 6231 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6232 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6233 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6234 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6235 | SlowPathCode* slow_path, Register class_reg) { |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 6236 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
| 6237 | const size_t status_byte_offset = |
| 6238 | mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte); |
| 6239 | constexpr uint32_t shifted_initialized_value = |
| 6240 | enum_cast<uint32_t>(ClassStatus::kInitialized) << (status_lsb_position % kBitsPerByte); |
| 6241 | |
| 6242 | __ cmpb(Address(class_reg, status_byte_offset), Immediate(shifted_initialized_value)); |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 6243 | __ j(kBelow, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6244 | __ Bind(slow_path->GetExitLabel()); |
| 6245 | // No need for memory fence, thanks to the X86 memory model. |
| 6246 | } |
| 6247 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6248 | HLoadString::LoadKind CodeGeneratorX86::GetSupportedLoadStringKind( |
| 6249 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6250 | switch (desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6251 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6252 | case HLoadString::LoadKind::kBootImageInternTable: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6253 | case HLoadString::LoadKind::kBssEntry: |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6254 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6255 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6256 | case HLoadString::LoadKind::kJitTableAddress: |
| 6257 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6258 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6259 | case HLoadString::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6260 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6261 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6262 | } |
| 6263 | return desired_string_load_kind; |
| 6264 | } |
| 6265 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6266 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6267 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6268 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6269 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6270 | if (load_kind == HLoadString::LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6271 | load_kind == HLoadString::LoadKind::kBootImageInternTable || |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6272 | load_kind == HLoadString::LoadKind::kBssEntry) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6273 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6274 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6275 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6276 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 6277 | } else { |
| 6278 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6279 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 6280 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6281 | // Rely on the pResolveString to save everything. |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6282 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6283 | InvokeRuntimeCallingConvention calling_convention; |
| 6284 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6285 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6286 | } else { |
| 6287 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6288 | } |
| 6289 | } |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6290 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6291 | } |
| 6292 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6293 | Label* CodeGeneratorX86::NewJitRootStringPatch(const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6294 | dex::StringIndex string_index, |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6295 | Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6296 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6297 | // Add a patch entry and return the label. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6298 | jit_string_patches_.emplace_back(dex_file, string_index.index_); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6299 | PatchInfo<Label>* info = &jit_string_patches_.back(); |
| 6300 | return &info->label; |
| 6301 | } |
| 6302 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6303 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6304 | // move. |
| 6305 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6306 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6307 | Location out_loc = locations->Out(); |
| 6308 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6309 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6310 | switch (load->GetLoadKind()) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6311 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6312 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6313 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6314 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6315 | codegen_->RecordBootStringPatch(load); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6316 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6317 | } |
| 6318 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6319 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6320 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 6321 | DCHECK_NE(address, 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6322 | __ movl(out, Immediate(address)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6323 | return; |
| 6324 | } |
| 6325 | case HLoadString::LoadKind::kBootImageInternTable: { |
| 6326 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 6327 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6328 | __ movl(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
| 6329 | codegen_->RecordBootStringPatch(load); |
| 6330 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6331 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6332 | case HLoadString::LoadKind::kBssEntry: { |
| 6333 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6334 | Address address = Address(method_address, CodeGeneratorX86::kDummy32BitOffset); |
| 6335 | Label* fixup_label = codegen_->NewStringBssEntryPatch(load); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6336 | // /* GcRoot<mirror::String> */ out = *address /* PC-relative */ |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6337 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6338 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadStringSlowPathX86(load); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6339 | codegen_->AddSlowPath(slow_path); |
| 6340 | __ testl(out, out); |
| 6341 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6342 | __ Bind(slow_path->GetExitLabel()); |
| 6343 | return; |
| 6344 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6345 | case HLoadString::LoadKind::kJitTableAddress: { |
| 6346 | Address address = Address::Absolute(CodeGeneratorX86::kDummy32BitOffset); |
| 6347 | Label* fixup_label = codegen_->NewJitRootStringPatch( |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6348 | load->GetDexFile(), load->GetStringIndex(), load->GetString()); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6349 | // /* GcRoot<mirror::String> */ out = *address |
| 6350 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
| 6351 | return; |
| 6352 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6353 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6354 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6355 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6356 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6357 | // 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] | 6358 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6359 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6360 | __ movl(calling_convention.GetRegisterAt(0), Immediate(load->GetStringIndex().index_)); |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6361 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 6362 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6363 | } |
| 6364 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6365 | static Address GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6366 | return Address::Absolute(Thread::ExceptionOffset<kX86PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6367 | } |
| 6368 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6369 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 6370 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6371 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6372 | locations->SetOut(Location::RequiresRegister()); |
| 6373 | } |
| 6374 | |
| 6375 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6376 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 6377 | } |
| 6378 | |
| 6379 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6380 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6381 | } |
| 6382 | |
| 6383 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6384 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6385 | } |
| 6386 | |
| 6387 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6388 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6389 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6390 | InvokeRuntimeCallingConvention calling_convention; |
| 6391 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6392 | } |
| 6393 | |
| 6394 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6395 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6396 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6397 | } |
| 6398 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6399 | // Temp is used for read barrier. |
| 6400 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 6401 | if (kEmitCompilerReadBarrier && |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6402 | !kUseBakerReadBarrier && |
| 6403 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6404 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6405 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 6406 | return 1; |
| 6407 | } |
| 6408 | return 0; |
| 6409 | } |
| 6410 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6411 | // 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] | 6412 | // interface pointer, one for loading the current interface. |
| 6413 | // The other checks have one temp for loading the object's class. |
| 6414 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 6415 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6416 | return 2; |
| 6417 | } |
| 6418 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6419 | } |
| 6420 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6421 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6422 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6423 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6424 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6425 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6426 | case TypeCheckKind::kExactCheck: |
| 6427 | case TypeCheckKind::kAbstractClassCheck: |
| 6428 | case TypeCheckKind::kClassHierarchyCheck: |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6429 | case TypeCheckKind::kArrayObjectCheck: { |
| 6430 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 6431 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 6432 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6433 | break; |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6434 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6435 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6436 | case TypeCheckKind::kUnresolvedCheck: |
| 6437 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6438 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6439 | break; |
| 6440 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6441 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6442 | LocationSummary* locations = |
| 6443 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6444 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6445 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6446 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6447 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 6448 | locations->SetInAt(1, Location::Any()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6449 | // Note that TypeCheckSlowPathX86 uses this "out" register too. |
| 6450 | locations->SetOut(Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6451 | // When read barriers are enabled, we need a temporary register for some cases. |
| 6452 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6453 | } |
| 6454 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6455 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6456 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6457 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6458 | Location obj_loc = locations->InAt(0); |
| 6459 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6460 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6461 | Location out_loc = locations->Out(); |
| 6462 | Register out = out_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6463 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 6464 | DCHECK_LE(num_temps, 1u); |
| 6465 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6466 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6467 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6468 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6469 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6470 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6471 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6472 | |
| 6473 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6474 | // Avoid null check if we know obj is not null. |
| 6475 | if (instruction->MustDoNullCheck()) { |
| 6476 | __ testl(obj, obj); |
| 6477 | __ j(kEqual, &zero); |
| 6478 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6479 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6480 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6481 | case TypeCheckKind::kExactCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6482 | ReadBarrierOption read_barrier_option = |
| 6483 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6484 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6485 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6486 | out_loc, |
| 6487 | obj_loc, |
| 6488 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6489 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6490 | if (cls.IsRegister()) { |
| 6491 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6492 | } else { |
| 6493 | DCHECK(cls.IsStackSlot()) << cls; |
| 6494 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6495 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6496 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6497 | // Classes must be equal for the instanceof to succeed. |
| 6498 | __ j(kNotEqual, &zero); |
| 6499 | __ movl(out, Immediate(1)); |
| 6500 | __ jmp(&done); |
| 6501 | break; |
| 6502 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6503 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6504 | case TypeCheckKind::kAbstractClassCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6505 | ReadBarrierOption read_barrier_option = |
| 6506 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6507 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6508 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6509 | out_loc, |
| 6510 | obj_loc, |
| 6511 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6512 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6513 | // If the class is abstract, we eagerly fetch the super class of the |
| 6514 | // object to avoid doing a comparison we know will fail. |
| 6515 | NearLabel loop; |
| 6516 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6517 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6518 | GenerateReferenceLoadOneRegister(instruction, |
| 6519 | out_loc, |
| 6520 | super_offset, |
| 6521 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6522 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6523 | __ testl(out, out); |
| 6524 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6525 | __ j(kEqual, &done); |
| 6526 | if (cls.IsRegister()) { |
| 6527 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6528 | } else { |
| 6529 | DCHECK(cls.IsStackSlot()) << cls; |
| 6530 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6531 | } |
| 6532 | __ j(kNotEqual, &loop); |
| 6533 | __ movl(out, Immediate(1)); |
| 6534 | if (zero.IsLinked()) { |
| 6535 | __ jmp(&done); |
| 6536 | } |
| 6537 | break; |
| 6538 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6539 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6540 | case TypeCheckKind::kClassHierarchyCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6541 | ReadBarrierOption read_barrier_option = |
| 6542 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6543 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6544 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6545 | out_loc, |
| 6546 | obj_loc, |
| 6547 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6548 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6549 | // Walk over the class hierarchy to find a match. |
| 6550 | NearLabel loop, success; |
| 6551 | __ Bind(&loop); |
| 6552 | if (cls.IsRegister()) { |
| 6553 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6554 | } else { |
| 6555 | DCHECK(cls.IsStackSlot()) << cls; |
| 6556 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6557 | } |
| 6558 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6559 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6560 | GenerateReferenceLoadOneRegister(instruction, |
| 6561 | out_loc, |
| 6562 | super_offset, |
| 6563 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6564 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6565 | __ testl(out, out); |
| 6566 | __ j(kNotEqual, &loop); |
| 6567 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6568 | __ jmp(&done); |
| 6569 | __ Bind(&success); |
| 6570 | __ movl(out, Immediate(1)); |
| 6571 | if (zero.IsLinked()) { |
| 6572 | __ jmp(&done); |
| 6573 | } |
| 6574 | break; |
| 6575 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6576 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6577 | case TypeCheckKind::kArrayObjectCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6578 | ReadBarrierOption read_barrier_option = |
| 6579 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6580 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6581 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6582 | out_loc, |
| 6583 | obj_loc, |
| 6584 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6585 | read_barrier_option); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6586 | // Do an exact check. |
| 6587 | NearLabel exact_check; |
| 6588 | if (cls.IsRegister()) { |
| 6589 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6590 | } else { |
| 6591 | DCHECK(cls.IsStackSlot()) << cls; |
| 6592 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6593 | } |
| 6594 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6595 | // 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] | 6596 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6597 | GenerateReferenceLoadOneRegister(instruction, |
| 6598 | out_loc, |
| 6599 | component_offset, |
| 6600 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6601 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6602 | __ testl(out, out); |
| 6603 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6604 | __ j(kEqual, &done); |
| 6605 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 6606 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6607 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6608 | __ movl(out, Immediate(1)); |
| 6609 | __ jmp(&done); |
| 6610 | break; |
| 6611 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6612 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6613 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6614 | // No read barrier since the slow path will retry upon failure. |
| 6615 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6616 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6617 | out_loc, |
| 6618 | obj_loc, |
| 6619 | class_offset, |
| 6620 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6621 | if (cls.IsRegister()) { |
| 6622 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6623 | } else { |
| 6624 | DCHECK(cls.IsStackSlot()) << cls; |
| 6625 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6626 | } |
| 6627 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6628 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
| 6629 | instruction, /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6630 | codegen_->AddSlowPath(slow_path); |
| 6631 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6632 | __ movl(out, Immediate(1)); |
| 6633 | if (zero.IsLinked()) { |
| 6634 | __ jmp(&done); |
| 6635 | } |
| 6636 | break; |
| 6637 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6638 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6639 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6640 | case TypeCheckKind::kInterfaceCheck: { |
| 6641 | // 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] | 6642 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6643 | // cases. |
| 6644 | // |
| 6645 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6646 | // entry point without resorting to a type checking slow path |
| 6647 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6648 | // require to assign fixed registers for the inputs of this |
| 6649 | // HInstanceOf instruction (following the runtime calling |
| 6650 | // convention), which might be cluttered by the potential first |
| 6651 | // read barrier emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6652 | // |
| 6653 | // TODO: Introduce a new runtime entry point taking the object |
| 6654 | // to test (instead of its class) as argument, and let it deal |
| 6655 | // with the read barrier issues. This will let us refactor this |
| 6656 | // case of the `switch` code as it was previously (with a direct |
| 6657 | // call to the runtime not using a type checking slow path). |
| 6658 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6659 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6660 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
| 6661 | instruction, /* is_fatal */ false); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6662 | codegen_->AddSlowPath(slow_path); |
| 6663 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6664 | if (zero.IsLinked()) { |
| 6665 | __ jmp(&done); |
| 6666 | } |
| 6667 | break; |
| 6668 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6669 | } |
| 6670 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6671 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6672 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6673 | __ xorl(out, out); |
| 6674 | } |
| 6675 | |
| 6676 | if (done.IsLinked()) { |
| 6677 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6678 | } |
| 6679 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6680 | if (slow_path != nullptr) { |
| 6681 | __ Bind(slow_path->GetExitLabel()); |
| 6682 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6683 | } |
| 6684 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6685 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6686 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6687 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6688 | LocationSummary* locations = |
| 6689 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6690 | locations->SetInAt(0, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6691 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6692 | // Require a register for the interface check since there is a loop that compares the class to |
| 6693 | // a memory address. |
| 6694 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6695 | } else { |
| 6696 | locations->SetInAt(1, Location::Any()); |
| 6697 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6698 | // Note that TypeCheckSlowPathX86 uses this "temp" register too. |
| 6699 | locations->AddTemp(Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6700 | // When read barriers are enabled, we need an additional temporary register for some cases. |
| 6701 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
| 6702 | } |
| 6703 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6704 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6705 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6706 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6707 | Location obj_loc = locations->InAt(0); |
| 6708 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6709 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6710 | Location temp_loc = locations->GetTemp(0); |
| 6711 | Register temp = temp_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6712 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 6713 | DCHECK_GE(num_temps, 1u); |
| 6714 | DCHECK_LE(num_temps, 2u); |
| 6715 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 6716 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6717 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6718 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6719 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 6720 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 6721 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 6722 | const uint32_t object_array_data_offset = |
| 6723 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6724 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6725 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6726 | SlowPathCode* type_check_slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6727 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( |
| 6728 | instruction, is_type_check_slow_path_fatal); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6729 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6730 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6731 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6732 | // Avoid null check if we know obj is not null. |
| 6733 | if (instruction->MustDoNullCheck()) { |
| 6734 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6735 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6736 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6737 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6738 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6739 | case TypeCheckKind::kExactCheck: |
| 6740 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6741 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6742 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6743 | temp_loc, |
| 6744 | obj_loc, |
| 6745 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6746 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6747 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6748 | if (cls.IsRegister()) { |
| 6749 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6750 | } else { |
| 6751 | DCHECK(cls.IsStackSlot()) << cls; |
| 6752 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6753 | } |
| 6754 | // Jump to slow path for throwing the exception or doing a |
| 6755 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6756 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6757 | break; |
| 6758 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6759 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6760 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6761 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6762 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6763 | temp_loc, |
| 6764 | obj_loc, |
| 6765 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6766 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6767 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6768 | // If the class is abstract, we eagerly fetch the super class of the |
| 6769 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6770 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6771 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6772 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6773 | GenerateReferenceLoadOneRegister(instruction, |
| 6774 | temp_loc, |
| 6775 | super_offset, |
| 6776 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6777 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6778 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6779 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 6780 | // exception. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6781 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6782 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6783 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6784 | // Otherwise, compare the classes |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6785 | if (cls.IsRegister()) { |
| 6786 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6787 | } else { |
| 6788 | DCHECK(cls.IsStackSlot()) << cls; |
| 6789 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6790 | } |
| 6791 | __ j(kNotEqual, &loop); |
| 6792 | break; |
| 6793 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6794 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6795 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6796 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6797 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6798 | temp_loc, |
| 6799 | obj_loc, |
| 6800 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6801 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6802 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6803 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6804 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6805 | __ Bind(&loop); |
| 6806 | if (cls.IsRegister()) { |
| 6807 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6808 | } else { |
| 6809 | DCHECK(cls.IsStackSlot()) << cls; |
| 6810 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6811 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6812 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6813 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6814 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6815 | GenerateReferenceLoadOneRegister(instruction, |
| 6816 | temp_loc, |
| 6817 | super_offset, |
| 6818 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6819 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6820 | |
| 6821 | // If the class reference currently in `temp` is not null, jump |
| 6822 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6823 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6824 | __ j(kNotZero, &loop); |
| 6825 | // Otherwise, jump to the slow path to throw the exception.; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6826 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6827 | break; |
| 6828 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6829 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6830 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6831 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6832 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6833 | temp_loc, |
| 6834 | obj_loc, |
| 6835 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6836 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6837 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6838 | // Do an exact check. |
| 6839 | if (cls.IsRegister()) { |
| 6840 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6841 | } else { |
| 6842 | DCHECK(cls.IsStackSlot()) << cls; |
| 6843 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6844 | } |
| 6845 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6846 | |
| 6847 | // 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] | 6848 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6849 | GenerateReferenceLoadOneRegister(instruction, |
| 6850 | temp_loc, |
| 6851 | component_offset, |
| 6852 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6853 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6854 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6855 | // If the component type is null (i.e. the object not an array), jump to the slow path to |
| 6856 | // throw the exception. Otherwise proceed with the check. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6857 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6858 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6859 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6860 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6861 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6862 | break; |
| 6863 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6864 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6865 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6866 | // 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] | 6867 | // We cannot directly call the CheckCast runtime entry point |
| 6868 | // without resorting to a type checking slow path here (i.e. by |
| 6869 | // calling InvokeRuntime directly), as it would require to |
| 6870 | // assign fixed registers for the inputs of this HInstanceOf |
| 6871 | // instruction (following the runtime calling convention), which |
| 6872 | // might be cluttered by the potential first read barrier |
| 6873 | // emission at the beginning of this method. |
| 6874 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6875 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6876 | |
| 6877 | case TypeCheckKind::kInterfaceCheck: { |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 6878 | // Fast path for the interface check. Try to avoid read barriers to improve the fast path. |
| 6879 | // We can not get false positives by doing this. |
| 6880 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6881 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6882 | temp_loc, |
| 6883 | obj_loc, |
| 6884 | class_offset, |
| 6885 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6886 | |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 6887 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 6888 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6889 | temp_loc, |
| 6890 | temp_loc, |
| 6891 | iftable_offset, |
| 6892 | kWithoutReadBarrier); |
| 6893 | // Iftable is never null. |
| 6894 | __ movl(maybe_temp2_loc.AsRegister<Register>(), Address(temp, array_length_offset)); |
| 6895 | // Maybe poison the `cls` for direct comparison with memory. |
| 6896 | __ MaybePoisonHeapReference(cls.AsRegister<Register>()); |
| 6897 | // Loop through the iftable and check if any class matches. |
| 6898 | NearLabel start_loop; |
| 6899 | __ Bind(&start_loop); |
| 6900 | // Need to subtract first to handle the empty array case. |
| 6901 | __ subl(maybe_temp2_loc.AsRegister<Register>(), Immediate(2)); |
| 6902 | __ j(kNegative, type_check_slow_path->GetEntryLabel()); |
| 6903 | // Go to next interface if the classes do not match. |
| 6904 | __ cmpl(cls.AsRegister<Register>(), |
| 6905 | CodeGeneratorX86::ArrayAddress(temp, |
| 6906 | maybe_temp2_loc, |
| 6907 | TIMES_4, |
| 6908 | object_array_data_offset)); |
| 6909 | __ j(kNotEqual, &start_loop); |
| 6910 | // If `cls` was poisoned above, unpoison it. |
| 6911 | __ MaybeUnpoisonHeapReference(cls.AsRegister<Register>()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6912 | break; |
| 6913 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6914 | } |
| 6915 | __ Bind(&done); |
| 6916 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6917 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6918 | } |
| 6919 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6920 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6921 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6922 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6923 | InvokeRuntimeCallingConvention calling_convention; |
| 6924 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6925 | } |
| 6926 | |
| 6927 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6928 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject |
| 6929 | : kQuickUnlockObject, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6930 | instruction, |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6931 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6932 | if (instruction->IsEnter()) { |
| 6933 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6934 | } else { |
| 6935 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6936 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6937 | } |
| 6938 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6939 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6940 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6941 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6942 | |
| 6943 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6944 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6945 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6946 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 |
| 6947 | || instruction->GetResultType() == DataType::Type::kInt64); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6948 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6949 | locations->SetInAt(1, Location::Any()); |
| 6950 | locations->SetOut(Location::SameAsFirstInput()); |
| 6951 | } |
| 6952 | |
| 6953 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 6954 | HandleBitwiseOperation(instruction); |
| 6955 | } |
| 6956 | |
| 6957 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 6958 | HandleBitwiseOperation(instruction); |
| 6959 | } |
| 6960 | |
| 6961 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 6962 | HandleBitwiseOperation(instruction); |
| 6963 | } |
| 6964 | |
| 6965 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6966 | LocationSummary* locations = instruction->GetLocations(); |
| 6967 | Location first = locations->InAt(0); |
| 6968 | Location second = locations->InAt(1); |
| 6969 | DCHECK(first.Equals(locations->Out())); |
| 6970 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6971 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6972 | if (second.IsRegister()) { |
| 6973 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6974 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6975 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6976 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6977 | } else { |
| 6978 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6979 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6980 | } |
| 6981 | } else if (second.IsConstant()) { |
| 6982 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6983 | __ andl(first.AsRegister<Register>(), |
| 6984 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6985 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6986 | __ orl(first.AsRegister<Register>(), |
| 6987 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6988 | } else { |
| 6989 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6990 | __ xorl(first.AsRegister<Register>(), |
| 6991 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6992 | } |
| 6993 | } else { |
| 6994 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6995 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6996 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6997 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6998 | } else { |
| 6999 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7000 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7001 | } |
| 7002 | } |
| 7003 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7004 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7005 | if (second.IsRegisterPair()) { |
| 7006 | if (instruction->IsAnd()) { |
| 7007 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 7008 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 7009 | } else if (instruction->IsOr()) { |
| 7010 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 7011 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 7012 | } else { |
| 7013 | DCHECK(instruction->IsXor()); |
| 7014 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 7015 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 7016 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7017 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7018 | if (instruction->IsAnd()) { |
| 7019 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7020 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 7021 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7022 | } else if (instruction->IsOr()) { |
| 7023 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7024 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 7025 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7026 | } else { |
| 7027 | DCHECK(instruction->IsXor()); |
| 7028 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7029 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 7030 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7031 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7032 | } else { |
| 7033 | DCHECK(second.IsConstant()) << second; |
| 7034 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7035 | int32_t low_value = Low32Bits(value); |
| 7036 | int32_t high_value = High32Bits(value); |
| 7037 | Immediate low(low_value); |
| 7038 | Immediate high(high_value); |
| 7039 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 7040 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7041 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7042 | if (low_value == 0) { |
| 7043 | __ xorl(first_low, first_low); |
| 7044 | } else if (low_value != -1) { |
| 7045 | __ andl(first_low, low); |
| 7046 | } |
| 7047 | if (high_value == 0) { |
| 7048 | __ xorl(first_high, first_high); |
| 7049 | } else if (high_value != -1) { |
| 7050 | __ andl(first_high, high); |
| 7051 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7052 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7053 | if (low_value != 0) { |
| 7054 | __ orl(first_low, low); |
| 7055 | } |
| 7056 | if (high_value != 0) { |
| 7057 | __ orl(first_high, high); |
| 7058 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7059 | } else { |
| 7060 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7061 | if (low_value != 0) { |
| 7062 | __ xorl(first_low, low); |
| 7063 | } |
| 7064 | if (high_value != 0) { |
| 7065 | __ xorl(first_high, high); |
| 7066 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7067 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7068 | } |
| 7069 | } |
| 7070 | } |
| 7071 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7072 | void InstructionCodeGeneratorX86::GenerateReferenceLoadOneRegister( |
| 7073 | HInstruction* instruction, |
| 7074 | Location out, |
| 7075 | uint32_t offset, |
| 7076 | Location maybe_temp, |
| 7077 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7078 | Register out_reg = out.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7079 | if (read_barrier_option == kWithReadBarrier) { |
| 7080 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7081 | if (kUseBakerReadBarrier) { |
| 7082 | // Load with fast path based Baker's read barrier. |
| 7083 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7084 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7085 | instruction, out, out_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7086 | } else { |
| 7087 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7088 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7089 | // in the following move operation, as we will need it for the |
| 7090 | // read barrier below. |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7091 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7092 | __ movl(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7093 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7094 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7095 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7096 | } |
| 7097 | } else { |
| 7098 | // Plain load with no read barrier. |
| 7099 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7100 | __ movl(out_reg, Address(out_reg, offset)); |
| 7101 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7102 | } |
| 7103 | } |
| 7104 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7105 | void InstructionCodeGeneratorX86::GenerateReferenceLoadTwoRegisters( |
| 7106 | HInstruction* instruction, |
| 7107 | Location out, |
| 7108 | Location obj, |
| 7109 | uint32_t offset, |
| 7110 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7111 | Register out_reg = out.AsRegister<Register>(); |
| 7112 | Register obj_reg = obj.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7113 | if (read_barrier_option == kWithReadBarrier) { |
| 7114 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7115 | if (kUseBakerReadBarrier) { |
| 7116 | // Load with fast path based Baker's read barrier. |
| 7117 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7118 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7119 | instruction, out, obj_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7120 | } else { |
| 7121 | // Load with slow path based read barrier. |
| 7122 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7123 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7124 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 7125 | } |
| 7126 | } else { |
| 7127 | // Plain load with no read barrier. |
| 7128 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7129 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7130 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7131 | } |
| 7132 | } |
| 7133 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7134 | void InstructionCodeGeneratorX86::GenerateGcRootFieldLoad( |
| 7135 | HInstruction* instruction, |
| 7136 | Location root, |
| 7137 | const Address& address, |
| 7138 | Label* fixup_label, |
| 7139 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7140 | Register root_reg = root.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7141 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7142 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7143 | if (kUseBakerReadBarrier) { |
| 7144 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 7145 | // Baker's read barrier are used: |
| 7146 | // |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7147 | // root = obj.field; |
| 7148 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 7149 | // if (temp != null) { |
| 7150 | // root = temp(root) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7151 | // } |
| 7152 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7153 | // /* GcRoot<mirror::Object> */ root = *address |
| 7154 | __ movl(root_reg, address); |
| 7155 | if (fixup_label != nullptr) { |
| 7156 | __ Bind(fixup_label); |
| 7157 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7158 | static_assert( |
| 7159 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 7160 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 7161 | "have different sizes."); |
| 7162 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 7163 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 7164 | "have different sizes."); |
| 7165 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7166 | // Slow path marking the GC root `root`. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7167 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathX86( |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7168 | instruction, root, /* unpoison_ref_before_marking */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7169 | codegen_->AddSlowPath(slow_path); |
| 7170 | |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7171 | // Test the entrypoint (`Thread::Current()->pReadBarrierMarkReg ## root.reg()`). |
| 7172 | const int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 7173 | Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(root.reg()); |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7174 | __ fs()->cmpl(Address::Absolute(entry_point_offset), Immediate(0)); |
| 7175 | // The entrypoint is null when the GC is not marking. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7176 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 7177 | __ Bind(slow_path->GetExitLabel()); |
| 7178 | } else { |
| 7179 | // GC root loaded through a slow path for read barriers other |
| 7180 | // than Baker's. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7181 | // /* GcRoot<mirror::Object>* */ root = address |
| 7182 | __ leal(root_reg, address); |
| 7183 | if (fixup_label != nullptr) { |
| 7184 | __ Bind(fixup_label); |
| 7185 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7186 | // /* mirror::Object* */ root = root->Read() |
| 7187 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 7188 | } |
| 7189 | } else { |
| 7190 | // Plain GC root load with no read barrier. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7191 | // /* GcRoot<mirror::Object> */ root = *address |
| 7192 | __ movl(root_reg, address); |
| 7193 | if (fixup_label != nullptr) { |
| 7194 | __ Bind(fixup_label); |
| 7195 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7196 | // Note that GC roots are not affected by heap poisoning, thus we |
| 7197 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7198 | } |
| 7199 | } |
| 7200 | |
| 7201 | void CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7202 | Location ref, |
| 7203 | Register obj, |
| 7204 | uint32_t offset, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7205 | bool needs_null_check) { |
| 7206 | DCHECK(kEmitCompilerReadBarrier); |
| 7207 | DCHECK(kUseBakerReadBarrier); |
| 7208 | |
| 7209 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7210 | Address src(obj, offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7211 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7212 | } |
| 7213 | |
| 7214 | void CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7215 | Location ref, |
| 7216 | Register obj, |
| 7217 | uint32_t data_offset, |
| 7218 | Location index, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7219 | bool needs_null_check) { |
| 7220 | DCHECK(kEmitCompilerReadBarrier); |
| 7221 | DCHECK(kUseBakerReadBarrier); |
| 7222 | |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 7223 | static_assert( |
| 7224 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 7225 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7226 | // /* HeapReference<Object> */ ref = |
| 7227 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7228 | Address src = CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7229 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7230 | } |
| 7231 | |
| 7232 | void CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7233 | Location ref, |
| 7234 | Register obj, |
| 7235 | const Address& src, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7236 | bool needs_null_check, |
| 7237 | bool always_update_field, |
| 7238 | Register* temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7239 | DCHECK(kEmitCompilerReadBarrier); |
| 7240 | DCHECK(kUseBakerReadBarrier); |
| 7241 | |
| 7242 | // In slow path based read barriers, the read barrier call is |
| 7243 | // inserted after the original load. However, in fast path based |
| 7244 | // Baker's read barriers, we need to perform the load of |
| 7245 | // mirror::Object::monitor_ *before* the original reference load. |
| 7246 | // This load-load ordering is required by the read barrier. |
| 7247 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 7248 | // |
| 7249 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7250 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7251 | // HeapReference<Object> ref = *src; // Original reference load. |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7252 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7253 | // if (is_gray) { |
| 7254 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 7255 | // } |
| 7256 | // |
| 7257 | // Note: the original implementation in ReadBarrier::Barrier is |
| 7258 | // slightly more complex as: |
| 7259 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7260 | // the high-bits of rb_state, which are expected to be all zeroes |
| 7261 | // (we use CodeGeneratorX86::GenerateMemoryBarrier instead here, |
| 7262 | // which is a no-op thanks to the x86 memory model); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7263 | // - it performs additional checks that we do not do here for |
| 7264 | // performance reasons. |
| 7265 | |
| 7266 | Register ref_reg = ref.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7267 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 7268 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7269 | // 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] | 7270 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 7271 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7272 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 7273 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 7274 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 7275 | |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7276 | // if (rb_state == ReadBarrier::GrayState()) |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7277 | // ref = ReadBarrier::Mark(ref); |
| 7278 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 7279 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7280 | if (needs_null_check) { |
| 7281 | MaybeRecordImplicitNullCheck(instruction); |
| 7282 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7283 | |
| 7284 | // Load fence to prevent load-load reordering. |
| 7285 | // Note that this is a no-op, thanks to the x86 memory model. |
| 7286 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 7287 | |
| 7288 | // The actual reference load. |
| 7289 | // /* HeapReference<Object> */ ref = *src |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7290 | __ movl(ref_reg, src); // Flags are unaffected. |
| 7291 | |
| 7292 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 7293 | // Slow path marking the object `ref` when it is gray. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7294 | SlowPathCode* slow_path; |
| 7295 | if (always_update_field) { |
| 7296 | DCHECK(temp != nullptr); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7297 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkAndUpdateFieldSlowPathX86( |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7298 | instruction, ref, obj, src, /* unpoison_ref_before_marking */ true, *temp); |
| 7299 | } else { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7300 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkSlowPathX86( |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7301 | instruction, ref, /* unpoison_ref_before_marking */ true); |
| 7302 | } |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7303 | AddSlowPath(slow_path); |
| 7304 | |
| 7305 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 7306 | __ j(kNotZero, slow_path->GetEntryLabel()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7307 | |
| 7308 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7309 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7310 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7311 | __ Bind(slow_path->GetExitLabel()); |
| 7312 | } |
| 7313 | |
| 7314 | void CodeGeneratorX86::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7315 | Location out, |
| 7316 | Location ref, |
| 7317 | Location obj, |
| 7318 | uint32_t offset, |
| 7319 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7320 | DCHECK(kEmitCompilerReadBarrier); |
| 7321 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7322 | // Insert a slow path based read barrier *after* the reference load. |
| 7323 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7324 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7325 | // reference will be carried out by the runtime within the slow |
| 7326 | // path. |
| 7327 | // |
| 7328 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7329 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7330 | // not used by the artReadBarrierSlow entry point. |
| 7331 | // |
| 7332 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7333 | SlowPathCode* slow_path = new (GetScopedAllocator()) |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7334 | ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); |
| 7335 | AddSlowPath(slow_path); |
| 7336 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7337 | __ jmp(slow_path->GetEntryLabel()); |
| 7338 | __ Bind(slow_path->GetExitLabel()); |
| 7339 | } |
| 7340 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7341 | void CodeGeneratorX86::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 7342 | Location out, |
| 7343 | Location ref, |
| 7344 | Location obj, |
| 7345 | uint32_t offset, |
| 7346 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7347 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7348 | // Baker's read barriers shall be handled by the fast path |
| 7349 | // (CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier). |
| 7350 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7351 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7352 | // by the runtime within the slow path. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7353 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7354 | } else if (kPoisonHeapReferences) { |
| 7355 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 7356 | } |
| 7357 | } |
| 7358 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7359 | void CodeGeneratorX86::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7360 | Location out, |
| 7361 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7362 | DCHECK(kEmitCompilerReadBarrier); |
| 7363 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7364 | // Insert a slow path based read barrier *after* the GC root load. |
| 7365 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7366 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7367 | // not need to do anything special for this here. |
| 7368 | SlowPathCode* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7369 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathX86(instruction, out, root); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7370 | AddSlowPath(slow_path); |
| 7371 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7372 | __ jmp(slow_path->GetEntryLabel()); |
| 7373 | __ Bind(slow_path->GetExitLabel()); |
| 7374 | } |
| 7375 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7376 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7377 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7378 | LOG(FATAL) << "Unreachable"; |
| 7379 | } |
| 7380 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7381 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7382 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7383 | LOG(FATAL) << "Unreachable"; |
| 7384 | } |
| 7385 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7386 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7387 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7388 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7389 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7390 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7391 | } |
| 7392 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7393 | void InstructionCodeGeneratorX86::GenPackedSwitchWithCompares(Register value_reg, |
| 7394 | int32_t lower_bound, |
| 7395 | uint32_t num_entries, |
| 7396 | HBasicBlock* switch_block, |
| 7397 | HBasicBlock* default_block) { |
| 7398 | // Figure out the correct compare values and jump conditions. |
| 7399 | // Handle the first compare/branch as a special case because it might |
| 7400 | // jump to the default case. |
| 7401 | DCHECK_GT(num_entries, 2u); |
| 7402 | Condition first_condition; |
| 7403 | uint32_t index; |
| 7404 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 7405 | if (lower_bound != 0) { |
| 7406 | first_condition = kLess; |
| 7407 | __ cmpl(value_reg, Immediate(lower_bound)); |
| 7408 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 7409 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7410 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7411 | index = 1; |
| 7412 | } else { |
| 7413 | // Handle all the compare/jumps below. |
| 7414 | first_condition = kBelow; |
| 7415 | index = 0; |
| 7416 | } |
| 7417 | |
| 7418 | // Handle the rest of the compare/jumps. |
| 7419 | for (; index + 1 < num_entries; index += 2) { |
| 7420 | int32_t compare_to_value = lower_bound + index + 1; |
| 7421 | __ cmpl(value_reg, Immediate(compare_to_value)); |
| 7422 | // Jump to successors[index] if value < case_value[index]. |
| 7423 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 7424 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 7425 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 7426 | } |
| 7427 | |
| 7428 | if (index != num_entries) { |
| 7429 | // There are an odd number of entries. Handle the last one. |
| 7430 | DCHECK_EQ(index + 1, num_entries); |
| 7431 | __ cmpl(value_reg, Immediate(lower_bound + index)); |
| 7432 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7433 | } |
| 7434 | |
| 7435 | // And the default for any other value. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7436 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
| 7437 | __ jmp(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7438 | } |
| 7439 | } |
| 7440 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7441 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7442 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 7443 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 7444 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7445 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7446 | |
| 7447 | GenPackedSwitchWithCompares(value_reg, |
| 7448 | lower_bound, |
| 7449 | num_entries, |
| 7450 | switch_instr->GetBlock(), |
| 7451 | switch_instr->GetDefaultBlock()); |
| 7452 | } |
| 7453 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7454 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7455 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7456 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7457 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7458 | |
| 7459 | // Constant area pointer. |
| 7460 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7461 | |
| 7462 | // And the temporary we need. |
| 7463 | locations->AddTemp(Location::RequiresRegister()); |
| 7464 | } |
| 7465 | |
| 7466 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7467 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7468 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7469 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7470 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7471 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7472 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7473 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 7474 | GenPackedSwitchWithCompares(value_reg, |
| 7475 | lower_bound, |
| 7476 | num_entries, |
| 7477 | switch_instr->GetBlock(), |
| 7478 | default_block); |
| 7479 | return; |
| 7480 | } |
| 7481 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7482 | // Optimizing has a jump area. |
| 7483 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 7484 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 7485 | |
| 7486 | // Remove the bias, if needed. |
| 7487 | if (lower_bound != 0) { |
| 7488 | __ leal(temp_reg, Address(value_reg, -lower_bound)); |
| 7489 | value_reg = temp_reg; |
| 7490 | } |
| 7491 | |
| 7492 | // Is the value in range? |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7493 | DCHECK_GE(num_entries, 1u); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7494 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 7495 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| 7496 | |
| 7497 | // We are in the range of the table. |
| 7498 | // Load (target-constant_area) from the jump table, indexing by the value. |
| 7499 | __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); |
| 7500 | |
| 7501 | // Compute the actual target address by adding in constant_area. |
| 7502 | __ addl(temp_reg, constant_area); |
| 7503 | |
| 7504 | // And jump. |
| 7505 | __ jmp(temp_reg); |
| 7506 | } |
| 7507 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7508 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 7509 | HX86ComputeBaseMethodAddress* insn) { |
| 7510 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7511 | new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7512 | locations->SetOut(Location::RequiresRegister()); |
| 7513 | } |
| 7514 | |
| 7515 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 7516 | HX86ComputeBaseMethodAddress* insn) { |
| 7517 | LocationSummary* locations = insn->GetLocations(); |
| 7518 | Register reg = locations->Out().AsRegister<Register>(); |
| 7519 | |
| 7520 | // Generate call to next instruction. |
| 7521 | Label next_instruction; |
| 7522 | __ call(&next_instruction); |
| 7523 | __ Bind(&next_instruction); |
| 7524 | |
| 7525 | // Remember this offset for later use with constant area. |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7526 | codegen_->AddMethodAddressOffset(insn, GetAssembler()->CodeSize()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7527 | |
| 7528 | // Grab the return address off the stack. |
| 7529 | __ popl(reg); |
| 7530 | } |
| 7531 | |
| 7532 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 7533 | HX86LoadFromConstantTable* insn) { |
| 7534 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7535 | new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7536 | |
| 7537 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7538 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 7539 | |
| 7540 | // 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] | 7541 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7542 | return; |
| 7543 | } |
| 7544 | |
| 7545 | switch (insn->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7546 | case DataType::Type::kFloat32: |
| 7547 | case DataType::Type::kFloat64: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7548 | locations->SetOut(Location::RequiresFpuRegister()); |
| 7549 | break; |
| 7550 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7551 | case DataType::Type::kInt32: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7552 | locations->SetOut(Location::RequiresRegister()); |
| 7553 | break; |
| 7554 | |
| 7555 | default: |
| 7556 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7557 | } |
| 7558 | } |
| 7559 | |
| 7560 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 7561 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7562 | return; |
| 7563 | } |
| 7564 | |
| 7565 | LocationSummary* locations = insn->GetLocations(); |
| 7566 | Location out = locations->Out(); |
| 7567 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 7568 | HConstant *value = insn->GetConstant(); |
| 7569 | |
| 7570 | switch (insn->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7571 | case DataType::Type::kFloat32: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7572 | __ movss(out.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7573 | codegen_->LiteralFloatAddress( |
| 7574 | value->AsFloatConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7575 | break; |
| 7576 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7577 | case DataType::Type::kFloat64: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7578 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7579 | codegen_->LiteralDoubleAddress( |
| 7580 | value->AsDoubleConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7581 | break; |
| 7582 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7583 | case DataType::Type::kInt32: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7584 | __ movl(out.AsRegister<Register>(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7585 | codegen_->LiteralInt32Address( |
| 7586 | value->AsIntConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7587 | break; |
| 7588 | |
| 7589 | default: |
| 7590 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7591 | } |
| 7592 | } |
| 7593 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7594 | /** |
| 7595 | * Class to handle late fixup of offsets into constant area. |
| 7596 | */ |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 7597 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7598 | public: |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7599 | RIPFixup(CodeGeneratorX86& codegen, |
| 7600 | HX86ComputeBaseMethodAddress* base_method_address, |
| 7601 | size_t offset) |
| 7602 | : codegen_(&codegen), |
| 7603 | base_method_address_(base_method_address), |
| 7604 | offset_into_constant_area_(offset) {} |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7605 | |
| 7606 | protected: |
| 7607 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 7608 | |
| 7609 | CodeGeneratorX86* codegen_; |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7610 | HX86ComputeBaseMethodAddress* base_method_address_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7611 | |
| 7612 | private: |
| 7613 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 7614 | // Patch the correct offset for the instruction. The place to patch is the |
| 7615 | // last 4 bytes of the instruction. |
| 7616 | // The value to patch is the distance from the offset in the constant area |
| 7617 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7618 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7619 | int32_t relative_position = |
| 7620 | constant_offset - codegen_->GetMethodAddressOffset(base_method_address_); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7621 | |
| 7622 | // Patch in the right value. |
| 7623 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 7624 | } |
| 7625 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7626 | // Location in constant area that the fixup refers to. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7627 | int32_t offset_into_constant_area_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7628 | }; |
| 7629 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7630 | /** |
| 7631 | * Class to handle late fixup of offsets to a jump table that will be created in the |
| 7632 | * constant area. |
| 7633 | */ |
| 7634 | class JumpTableRIPFixup : public RIPFixup { |
| 7635 | public: |
| 7636 | JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7637 | : RIPFixup(codegen, switch_instr->GetBaseMethodAddress(), static_cast<size_t>(-1)), |
| 7638 | switch_instr_(switch_instr) {} |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7639 | |
| 7640 | void CreateJumpTable() { |
| 7641 | X86Assembler* assembler = codegen_->GetAssembler(); |
| 7642 | |
| 7643 | // Ensure that the reference to the jump table has the correct offset. |
| 7644 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 7645 | SetOffset(offset_in_constant_table); |
| 7646 | |
| 7647 | // The label values in the jump table are computed relative to the |
| 7648 | // instruction addressing the constant area. |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7649 | const int32_t relative_offset = codegen_->GetMethodAddressOffset(base_method_address_); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7650 | |
| 7651 | // Populate the jump table with the correct values for the jump table. |
| 7652 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 7653 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 7654 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 7655 | // The value that we want is the target offset - the position of the table. |
| 7656 | for (int32_t i = 0; i < num_entries; i++) { |
| 7657 | HBasicBlock* b = successors[i]; |
| 7658 | Label* l = codegen_->GetLabelOf(b); |
| 7659 | DCHECK(l->IsBound()); |
| 7660 | int32_t offset_to_block = l->Position() - relative_offset; |
| 7661 | assembler->AppendInt32(offset_to_block); |
| 7662 | } |
| 7663 | } |
| 7664 | |
| 7665 | private: |
| 7666 | const HX86PackedSwitch* switch_instr_; |
| 7667 | }; |
| 7668 | |
| 7669 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 7670 | // Generate the constant area if needed. |
| 7671 | X86Assembler* assembler = GetAssembler(); |
| 7672 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7673 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 7674 | // byte values. |
| 7675 | assembler->Align(4, 0); |
| 7676 | constant_area_start_ = assembler->CodeSize(); |
| 7677 | |
| 7678 | // Populate any jump tables. |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7679 | for (JumpTableRIPFixup* jump_table : fixups_to_jump_tables_) { |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7680 | jump_table->CreateJumpTable(); |
| 7681 | } |
| 7682 | |
| 7683 | // And now add the constant area to the generated code. |
| 7684 | assembler->AddConstantArea(); |
| 7685 | } |
| 7686 | |
| 7687 | // And finish up. |
| 7688 | CodeGenerator::Finalize(allocator); |
| 7689 | } |
| 7690 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7691 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, |
| 7692 | HX86ComputeBaseMethodAddress* method_base, |
| 7693 | Register reg) { |
| 7694 | AssemblerFixup* fixup = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7695 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddDouble(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7696 | return Address(reg, kDummy32BitOffset, fixup); |
| 7697 | } |
| 7698 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7699 | Address CodeGeneratorX86::LiteralFloatAddress(float v, |
| 7700 | HX86ComputeBaseMethodAddress* method_base, |
| 7701 | Register reg) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7702 | AssemblerFixup* fixup = |
| 7703 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddFloat(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7704 | return Address(reg, kDummy32BitOffset, fixup); |
| 7705 | } |
| 7706 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7707 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, |
| 7708 | HX86ComputeBaseMethodAddress* method_base, |
| 7709 | Register reg) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7710 | AssemblerFixup* fixup = |
| 7711 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddInt32(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7712 | return Address(reg, kDummy32BitOffset, fixup); |
| 7713 | } |
| 7714 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7715 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, |
| 7716 | HX86ComputeBaseMethodAddress* method_base, |
| 7717 | Register reg) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7718 | AssemblerFixup* fixup = |
| 7719 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddInt64(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7720 | return Address(reg, kDummy32BitOffset, fixup); |
| 7721 | } |
| 7722 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 7723 | void CodeGeneratorX86::Load32BitValue(Register dest, int32_t value) { |
| 7724 | if (value == 0) { |
| 7725 | __ xorl(dest, dest); |
| 7726 | } else { |
| 7727 | __ movl(dest, Immediate(value)); |
| 7728 | } |
| 7729 | } |
| 7730 | |
| 7731 | void CodeGeneratorX86::Compare32BitValue(Register dest, int32_t value) { |
| 7732 | if (value == 0) { |
| 7733 | __ testl(dest, dest); |
| 7734 | } else { |
| 7735 | __ cmpl(dest, Immediate(value)); |
| 7736 | } |
| 7737 | } |
| 7738 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7739 | void CodeGeneratorX86::GenerateIntCompare(Location lhs, Location rhs) { |
| 7740 | Register lhs_reg = lhs.AsRegister<Register>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7741 | GenerateIntCompare(lhs_reg, rhs); |
| 7742 | } |
| 7743 | |
| 7744 | void CodeGeneratorX86::GenerateIntCompare(Register lhs, Location rhs) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7745 | if (rhs.IsConstant()) { |
| 7746 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7747 | Compare32BitValue(lhs, value); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7748 | } else if (rhs.IsStackSlot()) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7749 | __ cmpl(lhs, Address(ESP, rhs.GetStackIndex())); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7750 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7751 | __ cmpl(lhs, rhs.AsRegister<Register>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7752 | } |
| 7753 | } |
| 7754 | |
| 7755 | Address CodeGeneratorX86::ArrayAddress(Register obj, |
| 7756 | Location index, |
| 7757 | ScaleFactor scale, |
| 7758 | uint32_t data_offset) { |
| 7759 | return index.IsConstant() ? |
| 7760 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) : |
| 7761 | Address(obj, index.AsRegister<Register>(), scale, data_offset); |
| 7762 | } |
| 7763 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7764 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, |
| 7765 | Register reg, |
| 7766 | Register value) { |
| 7767 | // Create a fixup to be used to create and address the jump table. |
| 7768 | JumpTableRIPFixup* table_fixup = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7769 | new (GetGraph()->GetAllocator()) JumpTableRIPFixup(*this, switch_instr); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7770 | |
| 7771 | // We have to populate the jump tables. |
| 7772 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7773 | |
| 7774 | // We want a scaled address, as we are extracting the correct offset from the table. |
| 7775 | return Address(reg, value, TIMES_4, kDummy32BitOffset, table_fixup); |
| 7776 | } |
| 7777 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7778 | // TODO: target as memory. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7779 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, DataType::Type type) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7780 | if (!target.IsValid()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7781 | DCHECK_EQ(type, DataType::Type::kVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7782 | return; |
| 7783 | } |
| 7784 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7785 | DCHECK_NE(type, DataType::Type::kVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7786 | |
| 7787 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 7788 | if (target.Equals(return_loc)) { |
| 7789 | return; |
| 7790 | } |
| 7791 | |
| 7792 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 7793 | // with the else branch. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7794 | if (type == DataType::Type::kInt64) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7795 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7796 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), DataType::Type::kInt32, nullptr); |
| 7797 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), DataType::Type::kInt32, nullptr); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7798 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7799 | } else { |
| 7800 | // Let the parallel move resolver take care of all of this. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7801 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7802 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 7803 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7804 | } |
| 7805 | } |
| 7806 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7807 | void CodeGeneratorX86::PatchJitRootUse(uint8_t* code, |
| 7808 | const uint8_t* roots_data, |
| 7809 | const PatchInfo<Label>& info, |
| 7810 | uint64_t index_in_table) const { |
| 7811 | uint32_t code_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 7812 | uintptr_t address = |
| 7813 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 7814 | typedef __attribute__((__aligned__(1))) uint32_t unaligned_uint32_t; |
| 7815 | reinterpret_cast<unaligned_uint32_t*>(code + code_offset)[0] = |
| 7816 | dchecked_integral_cast<uint32_t>(address); |
| 7817 | } |
| 7818 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7819 | void CodeGeneratorX86::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 7820 | for (const PatchInfo<Label>& info : jit_string_patches_) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7821 | StringReference string_reference(&info.dex_file, dex::StringIndex(info.index)); |
| 7822 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7823 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7824 | } |
| 7825 | |
| 7826 | for (const PatchInfo<Label>& info : jit_class_patches_) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7827 | TypeReference type_reference(&info.dex_file, dex::TypeIndex(info.index)); |
| 7828 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7829 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7830 | } |
| 7831 | } |
| 7832 | |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7833 | void LocationsBuilderX86::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 7834 | ATTRIBUTE_UNUSED) { |
| 7835 | LOG(FATAL) << "Unreachable"; |
| 7836 | } |
| 7837 | |
| 7838 | void InstructionCodeGeneratorX86::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 7839 | ATTRIBUTE_UNUSED) { |
| 7840 | LOG(FATAL) << "Unreachable"; |
| 7841 | } |
| 7842 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7843 | #undef __ |
| 7844 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7845 | } // namespace x86 |
| 7846 | } // namespace art |