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. |
| 147 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 148 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 149 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
| 150 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(1)); |
| 151 | // Check for conflicts with index. |
| 152 | if (length_loc.Equals(locations->InAt(0))) { |
| 153 | // We know we aren't using parameter 2. |
| 154 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(2)); |
| 155 | } |
| 156 | __ movl(length_loc.AsRegister<Register>(), array_len); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 157 | if (mirror::kUseStringCompression) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 158 | __ shrl(length_loc.AsRegister<Register>(), Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 159 | } |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 160 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 161 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 162 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 163 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 164 | DataType::Type::kInt32, |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 165 | length_loc, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 166 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 167 | DataType::Type::kInt32); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 168 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 169 | ? kQuickThrowStringBounds |
| 170 | : kQuickThrowArrayBounds; |
| 171 | x86_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 172 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 173 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 174 | } |
| 175 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 176 | bool IsFatal() const OVERRIDE { return true; } |
| 177 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 178 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86"; } |
| 179 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 180 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 181 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86); |
| 182 | }; |
| 183 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 184 | class SuspendCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 185 | public: |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 186 | SuspendCheckSlowPathX86(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 187 | : SlowPathCode(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 188 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 189 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 190 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 191 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 192 | __ Bind(GetEntryLabel()); |
Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 193 | SaveLiveRegisters(codegen, locations); // Only saves full width XMM for SIMD. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 194 | x86_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 195 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 196 | RestoreLiveRegisters(codegen, locations); // Only restores full width XMM for SIMD. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 197 | if (successor_ == nullptr) { |
| 198 | __ jmp(GetReturnLabel()); |
| 199 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 200 | __ jmp(x86_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 201 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 202 | } |
| 203 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 204 | Label* GetReturnLabel() { |
| 205 | DCHECK(successor_ == nullptr); |
| 206 | return &return_label_; |
| 207 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 208 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 209 | HBasicBlock* GetSuccessor() const { |
| 210 | return successor_; |
| 211 | } |
| 212 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 213 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86"; } |
| 214 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 215 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 216 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 217 | Label return_label_; |
| 218 | |
| 219 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86); |
| 220 | }; |
| 221 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 222 | class LoadStringSlowPathX86 : public SlowPathCode { |
| 223 | public: |
| 224 | explicit LoadStringSlowPathX86(HLoadString* instruction): SlowPathCode(instruction) {} |
| 225 | |
| 226 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 227 | LocationSummary* locations = instruction_->GetLocations(); |
| 228 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 229 | |
| 230 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 231 | __ Bind(GetEntryLabel()); |
| 232 | SaveLiveRegisters(codegen, locations); |
| 233 | |
| 234 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 235 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 236 | __ movl(calling_convention.GetRegisterAt(0), Immediate(string_index.index_)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 237 | x86_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 238 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 239 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 240 | RestoreLiveRegisters(codegen, locations); |
| 241 | |
| 242 | // Store the resolved String to the BSS entry. |
| 243 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 244 | __ movl(Address(method_address, CodeGeneratorX86::kDummy32BitOffset), |
| 245 | locations->Out().AsRegister<Register>()); |
| 246 | Label* fixup_label = x86_codegen->NewStringBssEntryPatch(instruction_->AsLoadString()); |
| 247 | __ Bind(fixup_label); |
| 248 | |
| 249 | __ jmp(GetExitLabel()); |
| 250 | } |
| 251 | |
| 252 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86"; } |
| 253 | |
| 254 | private: |
| 255 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86); |
| 256 | }; |
| 257 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 258 | class LoadClassSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 259 | public: |
| 260 | LoadClassSlowPathX86(HLoadClass* cls, |
| 261 | HInstruction* at, |
| 262 | uint32_t dex_pc, |
| 263 | bool do_clinit) |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 264 | : SlowPathCode(at), cls_(cls), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 265 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 266 | } |
| 267 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 268 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 269 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 270 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 271 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 272 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 273 | |
| 274 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 275 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 276 | __ movl(calling_convention.GetRegisterAt(0), Immediate(type_index.index_)); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 277 | x86_codegen->InvokeRuntime(do_clinit_ ? kQuickInitializeStaticStorage |
| 278 | : kQuickInitializeType, |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 279 | instruction_, |
| 280 | dex_pc_, |
| 281 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 282 | if (do_clinit_) { |
| 283 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 284 | } else { |
| 285 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 286 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 287 | |
| 288 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 289 | Location out = locations->Out(); |
| 290 | if (out.IsValid()) { |
| 291 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 292 | x86_codegen->Move32(out, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 293 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 294 | RestoreLiveRegisters(codegen, locations); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 295 | // For HLoadClass/kBssEntry, store the resolved Class to the BSS entry. |
| 296 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| 297 | if (cls_ == instruction_ && cls_->GetLoadKind() == HLoadClass::LoadKind::kBssEntry) { |
| 298 | DCHECK(out.IsValid()); |
| 299 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 300 | __ movl(Address(method_address, CodeGeneratorX86::kDummy32BitOffset), |
| 301 | locations->Out().AsRegister<Register>()); |
| 302 | Label* fixup_label = x86_codegen->NewTypeBssEntryPatch(cls_); |
| 303 | __ Bind(fixup_label); |
| 304 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 305 | __ jmp(GetExitLabel()); |
| 306 | } |
| 307 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 308 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86"; } |
| 309 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 310 | private: |
| 311 | // The class this slow path will load. |
| 312 | HLoadClass* const cls_; |
| 313 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 314 | // The dex PC of `at_`. |
| 315 | const uint32_t dex_pc_; |
| 316 | |
| 317 | // Whether to initialize the class. |
| 318 | const bool do_clinit_; |
| 319 | |
| 320 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86); |
| 321 | }; |
| 322 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 323 | class TypeCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 324 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 325 | TypeCheckSlowPathX86(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 326 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 327 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 328 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 329 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 330 | DCHECK(instruction_->IsCheckCast() |
| 331 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 332 | |
| 333 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 334 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 335 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 336 | if (!is_fatal_) { |
| 337 | SaveLiveRegisters(codegen, locations); |
| 338 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 339 | |
| 340 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 341 | // move resolver. |
| 342 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 343 | x86_codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 344 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 345 | DataType::Type::kReference, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 346 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 347 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 348 | DataType::Type::kReference); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 349 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 350 | x86_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 351 | instruction_, |
| 352 | instruction_->GetDexPc(), |
| 353 | this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 354 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 355 | } else { |
| 356 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 357 | x86_codegen->InvokeRuntime(kQuickCheckInstanceOf, |
| 358 | instruction_, |
| 359 | instruction_->GetDexPc(), |
| 360 | this); |
| 361 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 362 | } |
| 363 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 364 | if (!is_fatal_) { |
| 365 | if (instruction_->IsInstanceOf()) { |
| 366 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 367 | } |
| 368 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 369 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 370 | __ jmp(GetExitLabel()); |
| 371 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 372 | } |
| 373 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 374 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86"; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 375 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 376 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 377 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 378 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 379 | |
| 380 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86); |
| 381 | }; |
| 382 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 383 | class DeoptimizationSlowPathX86 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 384 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 385 | explicit DeoptimizationSlowPathX86(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 386 | : SlowPathCode(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 387 | |
| 388 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 389 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 390 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 391 | LocationSummary* locations = instruction_->GetLocations(); |
| 392 | SaveLiveRegisters(codegen, locations); |
| 393 | InvokeRuntimeCallingConvention calling_convention; |
| 394 | x86_codegen->Load32BitValue( |
| 395 | calling_convention.GetRegisterAt(0), |
| 396 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 397 | x86_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 398 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 399 | } |
| 400 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 401 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86"; } |
| 402 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 403 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 404 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86); |
| 405 | }; |
| 406 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 407 | class ArraySetSlowPathX86 : public SlowPathCode { |
| 408 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 409 | explicit ArraySetSlowPathX86(HInstruction* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 410 | |
| 411 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 412 | LocationSummary* locations = instruction_->GetLocations(); |
| 413 | __ Bind(GetEntryLabel()); |
| 414 | SaveLiveRegisters(codegen, locations); |
| 415 | |
| 416 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 417 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 418 | parallel_move.AddMove( |
| 419 | locations->InAt(0), |
| 420 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 421 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 422 | nullptr); |
| 423 | parallel_move.AddMove( |
| 424 | locations->InAt(1), |
| 425 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 426 | DataType::Type::kInt32, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 427 | nullptr); |
| 428 | parallel_move.AddMove( |
| 429 | locations->InAt(2), |
| 430 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 431 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 432 | nullptr); |
| 433 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 434 | |
| 435 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 436 | x86_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 437 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 438 | RestoreLiveRegisters(codegen, locations); |
| 439 | __ jmp(GetExitLabel()); |
| 440 | } |
| 441 | |
| 442 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86"; } |
| 443 | |
| 444 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 445 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86); |
| 446 | }; |
| 447 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 448 | // Slow path marking an object reference `ref` during a read |
| 449 | // barrier. The field `obj.field` in the object `obj` holding this |
| 450 | // reference does not get updated by this slow path after marking (see |
| 451 | // ReadBarrierMarkAndUpdateFieldSlowPathX86 below for that). |
| 452 | // |
| 453 | // This means that after the execution of this slow path, `ref` will |
| 454 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 455 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 456 | // probably still be a from-space reference (unless it gets updated by |
| 457 | // another thread, or if another thread installed another object |
| 458 | // reference (different from `ref`) in `obj.field`). |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 459 | class ReadBarrierMarkSlowPathX86 : public SlowPathCode { |
| 460 | public: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 461 | ReadBarrierMarkSlowPathX86(HInstruction* instruction, |
| 462 | Location ref, |
| 463 | bool unpoison_ref_before_marking) |
| 464 | : SlowPathCode(instruction), |
| 465 | ref_(ref), |
| 466 | unpoison_ref_before_marking_(unpoison_ref_before_marking) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 467 | DCHECK(kEmitCompilerReadBarrier); |
| 468 | } |
| 469 | |
| 470 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathX86"; } |
| 471 | |
| 472 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 473 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 474 | Register ref_reg = ref_.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 475 | DCHECK(locations->CanCall()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 476 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 477 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 478 | instruction_->IsStaticFieldGet() || |
| 479 | instruction_->IsArrayGet() || |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 480 | instruction_->IsArraySet() || |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 481 | instruction_->IsLoadClass() || |
| 482 | instruction_->IsLoadString() || |
| 483 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 484 | instruction_->IsCheckCast() || |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 485 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 486 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 487 | << "Unexpected instruction in read barrier marking slow path: " |
| 488 | << instruction_->DebugName(); |
| 489 | |
| 490 | __ Bind(GetEntryLabel()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 491 | if (unpoison_ref_before_marking_) { |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 492 | // Object* ref = ref_addr->AsMirrorPtr() |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 493 | __ MaybeUnpoisonHeapReference(ref_reg); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 494 | } |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 495 | // No need to save live registers; it's taken care of by the |
| 496 | // entrypoint. Also, there is no need to update the stack mask, |
| 497 | // as this runtime call will not trigger a garbage collection. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 498 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 499 | DCHECK_NE(ref_reg, ESP); |
| 500 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 501 | // "Compact" slow path, saving two moves. |
| 502 | // |
| 503 | // Instead of using the standard runtime calling convention (input |
| 504 | // and output in EAX): |
| 505 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 506 | // EAX <- ref |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 507 | // EAX <- ReadBarrierMark(EAX) |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 508 | // ref <- EAX |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 509 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 510 | // we just use rX (the register containing `ref`) as input and output |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 511 | // of a dedicated entrypoint: |
| 512 | // |
| 513 | // rX <- ReadBarrierMarkRegX(rX) |
| 514 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 515 | int32_t entry_point_offset = Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(ref_reg); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 516 | // This runtime call does not require a stack map. |
| 517 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 518 | __ jmp(GetExitLabel()); |
| 519 | } |
| 520 | |
| 521 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 522 | // The location (register) of the marked object reference. |
| 523 | const Location ref_; |
| 524 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 525 | const bool unpoison_ref_before_marking_; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 526 | |
| 527 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86); |
| 528 | }; |
| 529 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 530 | // Slow path marking an object reference `ref` during a read barrier, |
| 531 | // and if needed, atomically updating the field `obj.field` in the |
| 532 | // object `obj` holding this reference after marking (contrary to |
| 533 | // ReadBarrierMarkSlowPathX86 above, which never tries to update |
| 534 | // `obj.field`). |
| 535 | // |
| 536 | // This means that after the execution of this slow path, both `ref` |
| 537 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 538 | // hold the same to-space reference (unless another thread installed |
| 539 | // another object reference (different from `ref`) in `obj.field`). |
| 540 | class ReadBarrierMarkAndUpdateFieldSlowPathX86 : public SlowPathCode { |
| 541 | public: |
| 542 | ReadBarrierMarkAndUpdateFieldSlowPathX86(HInstruction* instruction, |
| 543 | Location ref, |
| 544 | Register obj, |
| 545 | const Address& field_addr, |
| 546 | bool unpoison_ref_before_marking, |
| 547 | Register temp) |
| 548 | : SlowPathCode(instruction), |
| 549 | ref_(ref), |
| 550 | obj_(obj), |
| 551 | field_addr_(field_addr), |
| 552 | unpoison_ref_before_marking_(unpoison_ref_before_marking), |
| 553 | temp_(temp) { |
| 554 | DCHECK(kEmitCompilerReadBarrier); |
| 555 | } |
| 556 | |
| 557 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkAndUpdateFieldSlowPathX86"; } |
| 558 | |
| 559 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 560 | LocationSummary* locations = instruction_->GetLocations(); |
| 561 | Register ref_reg = ref_.AsRegister<Register>(); |
| 562 | DCHECK(locations->CanCall()); |
| 563 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 564 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 565 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 566 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 567 | << instruction_->DebugName(); |
| 568 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 569 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 570 | |
| 571 | __ Bind(GetEntryLabel()); |
| 572 | if (unpoison_ref_before_marking_) { |
| 573 | // Object* ref = ref_addr->AsMirrorPtr() |
| 574 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 575 | } |
| 576 | |
| 577 | // Save the old (unpoisoned) reference. |
| 578 | __ movl(temp_, ref_reg); |
| 579 | |
| 580 | // No need to save live registers; it's taken care of by the |
| 581 | // entrypoint. Also, there is no need to update the stack mask, |
| 582 | // as this runtime call will not trigger a garbage collection. |
| 583 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 584 | DCHECK_NE(ref_reg, ESP); |
| 585 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
| 586 | // "Compact" slow path, saving two moves. |
| 587 | // |
| 588 | // Instead of using the standard runtime calling convention (input |
| 589 | // and output in EAX): |
| 590 | // |
| 591 | // EAX <- ref |
| 592 | // EAX <- ReadBarrierMark(EAX) |
| 593 | // ref <- EAX |
| 594 | // |
| 595 | // we just use rX (the register containing `ref`) as input and output |
| 596 | // of a dedicated entrypoint: |
| 597 | // |
| 598 | // rX <- ReadBarrierMarkRegX(rX) |
| 599 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 600 | int32_t entry_point_offset = Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(ref_reg); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 601 | // This runtime call does not require a stack map. |
| 602 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 603 | |
| 604 | // If the new reference is different from the old reference, |
| 605 | // update the field in the holder (`*field_addr`). |
| 606 | // |
| 607 | // Note that this field could also hold a different object, if |
| 608 | // another thread had concurrently changed it. In that case, the |
| 609 | // LOCK CMPXCHGL instruction in the compare-and-set (CAS) |
| 610 | // operation below would abort the CAS, leaving the field as-is. |
| 611 | NearLabel done; |
| 612 | __ cmpl(temp_, ref_reg); |
| 613 | __ j(kEqual, &done); |
| 614 | |
| 615 | // Update the the holder's field atomically. This may fail if |
| 616 | // mutator updates before us, but it's OK. This is achieved |
| 617 | // using a strong compare-and-set (CAS) operation with relaxed |
| 618 | // memory synchronization ordering, where the expected value is |
| 619 | // the old reference and the desired value is the new reference. |
| 620 | // This operation is implemented with a 32-bit LOCK CMPXLCHG |
| 621 | // instruction, which requires the expected value (the old |
| 622 | // reference) to be in EAX. Save EAX beforehand, and move the |
| 623 | // expected value (stored in `temp_`) into EAX. |
| 624 | __ pushl(EAX); |
| 625 | __ movl(EAX, temp_); |
| 626 | |
| 627 | // Convenience aliases. |
| 628 | Register base = obj_; |
| 629 | Register expected = EAX; |
| 630 | Register value = ref_reg; |
| 631 | |
| 632 | bool base_equals_value = (base == value); |
| 633 | if (kPoisonHeapReferences) { |
| 634 | if (base_equals_value) { |
| 635 | // If `base` and `value` are the same register location, move |
| 636 | // `value` to a temporary register. This way, poisoning |
| 637 | // `value` won't invalidate `base`. |
| 638 | value = temp_; |
| 639 | __ movl(value, base); |
| 640 | } |
| 641 | |
| 642 | // Check that the register allocator did not assign the location |
| 643 | // of `expected` (EAX) to `value` nor to `base`, so that heap |
| 644 | // poisoning (when enabled) works as intended below. |
| 645 | // - If `value` were equal to `expected`, both references would |
| 646 | // be poisoned twice, meaning they would not be poisoned at |
| 647 | // all, as heap poisoning uses address negation. |
| 648 | // - If `base` were equal to `expected`, poisoning `expected` |
| 649 | // would invalidate `base`. |
| 650 | DCHECK_NE(value, expected); |
| 651 | DCHECK_NE(base, expected); |
| 652 | |
| 653 | __ PoisonHeapReference(expected); |
| 654 | __ PoisonHeapReference(value); |
| 655 | } |
| 656 | |
| 657 | __ LockCmpxchgl(field_addr_, value); |
| 658 | |
| 659 | // If heap poisoning is enabled, we need to unpoison the values |
| 660 | // that were poisoned earlier. |
| 661 | if (kPoisonHeapReferences) { |
| 662 | if (base_equals_value) { |
| 663 | // `value` has been moved to a temporary register, no need |
| 664 | // to unpoison it. |
| 665 | } else { |
| 666 | __ UnpoisonHeapReference(value); |
| 667 | } |
| 668 | // No need to unpoison `expected` (EAX), as it is be overwritten below. |
| 669 | } |
| 670 | |
| 671 | // Restore EAX. |
| 672 | __ popl(EAX); |
| 673 | |
| 674 | __ Bind(&done); |
| 675 | __ jmp(GetExitLabel()); |
| 676 | } |
| 677 | |
| 678 | private: |
| 679 | // The location (register) of the marked object reference. |
| 680 | const Location ref_; |
| 681 | // The register containing the object holding the marked object reference field. |
| 682 | const Register obj_; |
| 683 | // The address of the marked reference field. The base of this address must be `obj_`. |
| 684 | const Address field_addr_; |
| 685 | |
| 686 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 687 | const bool unpoison_ref_before_marking_; |
| 688 | |
| 689 | const Register temp_; |
| 690 | |
| 691 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathX86); |
| 692 | }; |
| 693 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 694 | // Slow path generating a read barrier for a heap reference. |
| 695 | class ReadBarrierForHeapReferenceSlowPathX86 : public SlowPathCode { |
| 696 | public: |
| 697 | ReadBarrierForHeapReferenceSlowPathX86(HInstruction* instruction, |
| 698 | Location out, |
| 699 | Location ref, |
| 700 | Location obj, |
| 701 | uint32_t offset, |
| 702 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 703 | : SlowPathCode(instruction), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 704 | out_(out), |
| 705 | ref_(ref), |
| 706 | obj_(obj), |
| 707 | offset_(offset), |
| 708 | index_(index) { |
| 709 | DCHECK(kEmitCompilerReadBarrier); |
| 710 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 711 | // has been overwritten by (or after) the heap object reference load |
| 712 | // to be instrumented, e.g.: |
| 713 | // |
| 714 | // __ movl(out, Address(out, offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 715 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 716 | // |
| 717 | // In that case, we have lost the information about the original |
| 718 | // object, and the emitted read barrier cannot work properly. |
| 719 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 720 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 721 | } |
| 722 | |
| 723 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 724 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 725 | LocationSummary* locations = instruction_->GetLocations(); |
| 726 | Register reg_out = out_.AsRegister<Register>(); |
| 727 | DCHECK(locations->CanCall()); |
| 728 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 729 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 730 | instruction_->IsStaticFieldGet() || |
| 731 | instruction_->IsArrayGet() || |
| 732 | instruction_->IsInstanceOf() || |
| 733 | instruction_->IsCheckCast() || |
Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 734 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 735 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 736 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 737 | |
| 738 | __ Bind(GetEntryLabel()); |
| 739 | SaveLiveRegisters(codegen, locations); |
| 740 | |
| 741 | // We may have to change the index's value, but as `index_` is a |
| 742 | // constant member (like other "inputs" of this slow path), |
| 743 | // introduce a copy of it, `index`. |
| 744 | Location index = index_; |
| 745 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 746 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 747 | if (instruction_->IsArrayGet()) { |
| 748 | // Compute the actual memory offset and store it in `index`. |
| 749 | Register index_reg = index_.AsRegister<Register>(); |
| 750 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 751 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 752 | // We are about to change the value of `index_reg` (see the |
| 753 | // calls to art::x86::X86Assembler::shll and |
| 754 | // art::x86::X86Assembler::AddImmediate below), but it has |
| 755 | // not been saved by the previous call to |
| 756 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 757 | // callee-save register -- |
| 758 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 759 | // callee-save registers, as it has been designed with the |
| 760 | // assumption that callee-save registers are supposed to be |
| 761 | // handled by the called function. So, as a callee-save |
| 762 | // register, `index_reg` _would_ eventually be saved onto |
| 763 | // the stack, but it would be too late: we would have |
| 764 | // changed its value earlier. Therefore, we manually save |
| 765 | // it here into another freely available register, |
| 766 | // `free_reg`, chosen of course among the caller-save |
| 767 | // registers (as a callee-save `free_reg` register would |
| 768 | // exhibit the same problem). |
| 769 | // |
| 770 | // Note we could have requested a temporary register from |
| 771 | // the register allocator instead; but we prefer not to, as |
| 772 | // this is a slow path, and we know we can find a |
| 773 | // caller-save register that is available. |
| 774 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 775 | __ movl(free_reg, index_reg); |
| 776 | index_reg = free_reg; |
| 777 | index = Location::RegisterLocation(index_reg); |
| 778 | } else { |
| 779 | // The initial register stored in `index_` has already been |
| 780 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 781 | // (as it is not a callee-save register), so we can freely |
| 782 | // use it. |
| 783 | } |
| 784 | // Shifting the index value contained in `index_reg` by the scale |
| 785 | // factor (2) cannot overflow in practice, as the runtime is |
| 786 | // unable to allocate object arrays with a size larger than |
| 787 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 788 | __ shll(index_reg, Immediate(TIMES_4)); |
| 789 | static_assert( |
| 790 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 791 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 792 | __ AddImmediate(index_reg, Immediate(offset_)); |
| 793 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 794 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 795 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 796 | // (as in the case of ArrayGet), as it is actually an offset |
| 797 | // to an object field within an object. |
| 798 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 799 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 800 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 801 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 802 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 803 | DCHECK_EQ(offset_, 0U); |
| 804 | DCHECK(index_.IsRegisterPair()); |
| 805 | // UnsafeGet's offset location is a register pair, the low |
| 806 | // part contains the correct offset. |
| 807 | index = index_.ToLow(); |
| 808 | } |
| 809 | } |
| 810 | |
| 811 | // We're moving two or three locations to locations that could |
| 812 | // overlap, so we need a parallel move resolver. |
| 813 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 814 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 815 | parallel_move.AddMove(ref_, |
| 816 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 817 | DataType::Type::kReference, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 818 | nullptr); |
| 819 | parallel_move.AddMove(obj_, |
| 820 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 821 | DataType::Type::kReference, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 822 | nullptr); |
| 823 | if (index.IsValid()) { |
| 824 | parallel_move.AddMove(index, |
| 825 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 826 | DataType::Type::kInt32, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 827 | nullptr); |
| 828 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 829 | } else { |
| 830 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 831 | __ movl(calling_convention.GetRegisterAt(2), Immediate(offset_)); |
| 832 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 833 | x86_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 834 | CheckEntrypointTypes< |
| 835 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 836 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 837 | |
| 838 | RestoreLiveRegisters(codegen, locations); |
| 839 | __ jmp(GetExitLabel()); |
| 840 | } |
| 841 | |
| 842 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathX86"; } |
| 843 | |
| 844 | private: |
| 845 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 846 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 847 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 848 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 849 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 850 | return static_cast<Register>(i); |
| 851 | } |
| 852 | } |
| 853 | // We shall never fail to find a free caller-save register, as |
| 854 | // there are more than two core caller-save registers on x86 |
| 855 | // (meaning it is possible to find one which is different from |
| 856 | // `ref` and `obj`). |
| 857 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 858 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 859 | UNREACHABLE(); |
| 860 | } |
| 861 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 862 | const Location out_; |
| 863 | const Location ref_; |
| 864 | const Location obj_; |
| 865 | const uint32_t offset_; |
| 866 | // An additional location containing an index to an array. |
| 867 | // Only used for HArrayGet and the UnsafeGetObject & |
| 868 | // UnsafeGetObjectVolatile intrinsics. |
| 869 | const Location index_; |
| 870 | |
| 871 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86); |
| 872 | }; |
| 873 | |
| 874 | // Slow path generating a read barrier for a GC root. |
| 875 | class ReadBarrierForRootSlowPathX86 : public SlowPathCode { |
| 876 | public: |
| 877 | ReadBarrierForRootSlowPathX86(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 878 | : SlowPathCode(instruction), out_(out), root_(root) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 879 | DCHECK(kEmitCompilerReadBarrier); |
| 880 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 881 | |
| 882 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 883 | LocationSummary* locations = instruction_->GetLocations(); |
| 884 | Register reg_out = out_.AsRegister<Register>(); |
| 885 | DCHECK(locations->CanCall()); |
| 886 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 887 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 888 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 889 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 890 | |
| 891 | __ Bind(GetEntryLabel()); |
| 892 | SaveLiveRegisters(codegen, locations); |
| 893 | |
| 894 | InvokeRuntimeCallingConvention calling_convention; |
| 895 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 896 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 897 | x86_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 898 | instruction_, |
| 899 | instruction_->GetDexPc(), |
| 900 | this); |
| 901 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 902 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 903 | |
| 904 | RestoreLiveRegisters(codegen, locations); |
| 905 | __ jmp(GetExitLabel()); |
| 906 | } |
| 907 | |
| 908 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathX86"; } |
| 909 | |
| 910 | private: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 911 | const Location out_; |
| 912 | const Location root_; |
| 913 | |
| 914 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86); |
| 915 | }; |
| 916 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 917 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 918 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 919 | #define __ down_cast<X86Assembler*>(GetAssembler())-> // NOLINT |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 920 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 921 | inline Condition X86Condition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 922 | switch (cond) { |
| 923 | case kCondEQ: return kEqual; |
| 924 | case kCondNE: return kNotEqual; |
| 925 | case kCondLT: return kLess; |
| 926 | case kCondLE: return kLessEqual; |
| 927 | case kCondGT: return kGreater; |
| 928 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 929 | case kCondB: return kBelow; |
| 930 | case kCondBE: return kBelowEqual; |
| 931 | case kCondA: return kAbove; |
| 932 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 933 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 934 | LOG(FATAL) << "Unreachable"; |
| 935 | UNREACHABLE(); |
| 936 | } |
| 937 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 938 | // Maps signed condition to unsigned condition and FP condition to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 939 | inline Condition X86UnsignedOrFPCondition(IfCondition cond) { |
| 940 | switch (cond) { |
| 941 | case kCondEQ: return kEqual; |
| 942 | case kCondNE: return kNotEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 943 | // Signed to unsigned, and FP to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 944 | case kCondLT: return kBelow; |
| 945 | case kCondLE: return kBelowEqual; |
| 946 | case kCondGT: return kAbove; |
| 947 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 948 | // Unsigned remain unchanged. |
| 949 | case kCondB: return kBelow; |
| 950 | case kCondBE: return kBelowEqual; |
| 951 | case kCondA: return kAbove; |
| 952 | case kCondAE: return kAboveEqual; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 953 | } |
| 954 | LOG(FATAL) << "Unreachable"; |
| 955 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 956 | } |
| 957 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 958 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 959 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 963 | stream << XmmRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 964 | } |
| 965 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 966 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 967 | __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); |
| 968 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 969 | } |
| 970 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 971 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 972 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); |
| 973 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 974 | } |
| 975 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 976 | size_t CodeGeneratorX86::SaveFloatingPointRegister(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(Address(ESP, stack_index), XmmRegister(reg_id)); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 979 | } else { |
| 980 | __ movsd(Address(ESP, stack_index), XmmRegister(reg_id)); |
| 981 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 982 | return GetFloatingPointSpillSlotSize(); |
| 983 | } |
| 984 | |
| 985 | size_t CodeGeneratorX86::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 986 | if (GetGraph()->HasSIMD()) { |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 987 | __ movups(XmmRegister(reg_id), Address(ESP, stack_index)); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 988 | } else { |
| 989 | __ movsd(XmmRegister(reg_id), Address(ESP, stack_index)); |
| 990 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 991 | return GetFloatingPointSpillSlotSize(); |
| 992 | } |
| 993 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 994 | void CodeGeneratorX86::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 995 | HInstruction* instruction, |
| 996 | uint32_t dex_pc, |
| 997 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 998 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 999 | GenerateInvokeRuntime(GetThreadOffset<kX86PointerSize>(entrypoint).Int32Value()); |
| 1000 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1001 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1002 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 1003 | } |
| 1004 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1005 | void CodeGeneratorX86::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1006 | HInstruction* instruction, |
| 1007 | SlowPathCode* slow_path) { |
| 1008 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1009 | GenerateInvokeRuntime(entry_point_offset); |
| 1010 | } |
| 1011 | |
| 1012 | void CodeGeneratorX86::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1013 | __ fs()->call(Address::Absolute(entry_point_offset)); |
| 1014 | } |
| 1015 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1016 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1017 | const X86InstructionSetFeatures& isa_features, |
| 1018 | const CompilerOptions& compiler_options, |
| 1019 | OptimizingCompilerStats* stats) |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1020 | : CodeGenerator(graph, |
| 1021 | kNumberOfCpuRegisters, |
| 1022 | kNumberOfXmmRegisters, |
| 1023 | kNumberOfRegisterPairs, |
| 1024 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1025 | arraysize(kCoreCalleeSaves)) |
| 1026 | | (1 << kFakeReturnRegister), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1027 | 0, |
| 1028 | compiler_options, |
| 1029 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1030 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1031 | location_builder_(graph, this), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1032 | instruction_visitor_(graph, this), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1033 | move_resolver_(graph->GetAllocator(), this), |
| 1034 | assembler_(graph->GetAllocator()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1035 | isa_features_(isa_features), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1036 | boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1037 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1038 | boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1039 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1040 | string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1041 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1042 | jit_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1043 | jit_class_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1044 | constant_area_start_(-1), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1045 | fixups_to_jump_tables_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1046 | method_address_offset_(std::less<uint32_t>(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1047 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1048 | // Use a fake return address register to mimic Quick. |
| 1049 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1050 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1051 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1052 | void CodeGeneratorX86::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1053 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1054 | blocked_core_registers_[ESP] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1055 | } |
| 1056 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1057 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1058 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1059 | assembler_(codegen->GetAssembler()), |
| 1060 | codegen_(codegen) {} |
| 1061 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1062 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1063 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1064 | } |
| 1065 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1066 | void CodeGeneratorX86::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1067 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1068 | __ Bind(&frame_entry_label_); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1069 | bool skip_overflow_check = |
| 1070 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1071 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 1072 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1073 | if (!skip_overflow_check) { |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 1074 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1075 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 1076 | } |
| 1077 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1078 | if (HasEmptyFrame()) { |
| 1079 | return; |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1080 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1081 | |
| 1082 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 1083 | Register reg = kCoreCalleeSaves[i]; |
| 1084 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1085 | __ pushl(reg); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1086 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 1087 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1088 | } |
| 1089 | } |
| 1090 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1091 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1092 | __ subl(ESP, Immediate(adjust)); |
| 1093 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1094 | // Save the current method if we need it. Note that we do not |
| 1095 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1096 | // in the SSA graph. |
| 1097 | if (RequiresCurrentMethod()) { |
| 1098 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
| 1099 | } |
Nicolas Geoffray | f789353 | 2017-06-15 12:34:36 +0100 | [diff] [blame] | 1100 | |
| 1101 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1102 | // Initialize should_deoptimize flag to 0. |
| 1103 | __ movl(Address(ESP, GetStackOffsetOfShouldDeoptimizeFlag()), Immediate(0)); |
| 1104 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1105 | } |
| 1106 | |
| 1107 | void CodeGeneratorX86::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1108 | __ cfi().RememberState(); |
| 1109 | if (!HasEmptyFrame()) { |
| 1110 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1111 | __ addl(ESP, Immediate(adjust)); |
| 1112 | __ cfi().AdjustCFAOffset(-adjust); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1113 | |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1114 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1115 | Register reg = kCoreCalleeSaves[i]; |
| 1116 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1117 | __ popl(reg); |
| 1118 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 1119 | __ cfi().Restore(DWARFReg(reg)); |
| 1120 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1121 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1122 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1123 | __ ret(); |
| 1124 | __ cfi().RestoreState(); |
| 1125 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1126 | } |
| 1127 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1128 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 1129 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1130 | } |
| 1131 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1132 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(DataType::Type type) const { |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1133 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1134 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1135 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1136 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1137 | case DataType::Type::kInt8: |
| 1138 | case DataType::Type::kUint16: |
| 1139 | case DataType::Type::kInt16: |
| 1140 | case DataType::Type::kInt32: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1141 | return Location::RegisterLocation(EAX); |
| 1142 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1143 | case DataType::Type::kInt64: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1144 | return Location::RegisterPairLocation(EAX, EDX); |
| 1145 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1146 | case DataType::Type::kVoid: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1147 | return Location::NoLocation(); |
| 1148 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1149 | case DataType::Type::kFloat64: |
| 1150 | case DataType::Type::kFloat32: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1151 | return Location::FpuRegisterLocation(XMM0); |
| 1152 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1153 | |
| 1154 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 1158 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1159 | } |
| 1160 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1161 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(DataType::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1162 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1163 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1164 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1165 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1166 | case DataType::Type::kInt8: |
| 1167 | case DataType::Type::kUint16: |
| 1168 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1169 | case DataType::Type::kInt32: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1170 | uint32_t index = gp_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1171 | stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1172 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1173 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1174 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1175 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1176 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1177 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1178 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1179 | case DataType::Type::kInt64: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1180 | uint32_t index = gp_index_; |
| 1181 | gp_index_ += 2; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1182 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1183 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1184 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 1185 | calling_convention.GetRegisterPairAt(index)); |
| 1186 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1187 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1188 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1189 | } |
| 1190 | } |
| 1191 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1192 | case DataType::Type::kFloat32: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1193 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1194 | stack_index_++; |
| 1195 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1196 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1197 | } else { |
| 1198 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1199 | } |
| 1200 | } |
| 1201 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1202 | case DataType::Type::kFloat64: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1203 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1204 | stack_index_ += 2; |
| 1205 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1206 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1207 | } else { |
| 1208 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1209 | } |
| 1210 | } |
| 1211 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1212 | case DataType::Type::kVoid: |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1213 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1214 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1215 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1216 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1217 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1218 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1219 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 1220 | if (source.Equals(destination)) { |
| 1221 | return; |
| 1222 | } |
| 1223 | if (destination.IsRegister()) { |
| 1224 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1225 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1226 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1227 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1228 | } else { |
| 1229 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1230 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1231 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1232 | } else if (destination.IsFpuRegister()) { |
| 1233 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1234 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1235 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1236 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1237 | } else { |
| 1238 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1239 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1240 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1241 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1242 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1243 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1244 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1245 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1246 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1247 | } else if (source.IsConstant()) { |
| 1248 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1249 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1250 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1251 | } else { |
| 1252 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1253 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 1254 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1255 | } |
| 1256 | } |
| 1257 | } |
| 1258 | |
| 1259 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 1260 | if (source.Equals(destination)) { |
| 1261 | return; |
| 1262 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1263 | if (destination.IsRegisterPair()) { |
| 1264 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1265 | EmitParallelMoves( |
| 1266 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1267 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1268 | DataType::Type::kInt32, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1269 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1270 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1271 | DataType::Type::kInt32); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1272 | } else if (source.IsFpuRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1273 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 1274 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 1275 | __ psrlq(src_reg, Immediate(32)); |
| 1276 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1277 | } else { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1278 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1279 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1280 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 1281 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1282 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 1283 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1284 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1285 | if (source.IsFpuRegister()) { |
| 1286 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 1287 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1288 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1289 | } else if (source.IsRegisterPair()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1290 | size_t elem_size = DataType::Size(DataType::Type::kInt32); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1291 | // Create stack space for 2 elements. |
| 1292 | __ subl(ESP, Immediate(2 * elem_size)); |
| 1293 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 1294 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 1295 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 1296 | // And remove the temporary stack space we allocated. |
| 1297 | __ addl(ESP, Immediate(2 * elem_size)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1298 | } else { |
| 1299 | LOG(FATAL) << "Unimplemented"; |
| 1300 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1301 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1302 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1303 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1304 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1305 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1306 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1307 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1308 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1309 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1310 | } else if (source.IsConstant()) { |
| 1311 | HConstant* constant = source.GetConstant(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1312 | DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant()); |
| 1313 | int64_t value = GetInt64ValueOf(constant); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1314 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1315 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
| 1316 | Immediate(High32Bits(value))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1317 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1318 | DCHECK(source.IsDoubleStackSlot()) << source; |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1319 | EmitParallelMoves( |
| 1320 | Location::StackSlot(source.GetStackIndex()), |
| 1321 | Location::StackSlot(destination.GetStackIndex()), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1322 | DataType::Type::kInt32, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1323 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1324 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1325 | DataType::Type::kInt32); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1326 | } |
| 1327 | } |
| 1328 | } |
| 1329 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1330 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { |
| 1331 | DCHECK(location.IsRegister()); |
| 1332 | __ movl(location.AsRegister<Register>(), Immediate(value)); |
| 1333 | } |
| 1334 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1335 | void CodeGeneratorX86::MoveLocation(Location dst, Location src, DataType::Type dst_type) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1336 | HParallelMove move(GetGraph()->GetAllocator()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1337 | if (dst_type == DataType::Type::kInt64 && !src.IsConstant() && !src.IsFpuRegister()) { |
| 1338 | move.AddMove(src.ToLow(), dst.ToLow(), DataType::Type::kInt32, nullptr); |
| 1339 | move.AddMove(src.ToHigh(), dst.ToHigh(), DataType::Type::kInt32, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1340 | } else { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1341 | move.AddMove(src, dst, dst_type, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1342 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1343 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1344 | } |
| 1345 | |
| 1346 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1347 | if (location.IsRegister()) { |
| 1348 | locations->AddTemp(location); |
| 1349 | } else if (location.IsRegisterPair()) { |
| 1350 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1351 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1352 | } else { |
| 1353 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1354 | } |
| 1355 | } |
| 1356 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1357 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1358 | DCHECK(!successor->IsExitBlock()); |
| 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 | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1365 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1366 | return; |
| 1367 | } |
| 1368 | |
| 1369 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1370 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1371 | } |
| 1372 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1373 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1374 | } |
| 1375 | } |
| 1376 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1377 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 1378 | got->SetLocations(nullptr); |
| 1379 | } |
| 1380 | |
| 1381 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 1382 | HandleGoto(got, got->GetSuccessor()); |
| 1383 | } |
| 1384 | |
| 1385 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1386 | try_boundary->SetLocations(nullptr); |
| 1387 | } |
| 1388 | |
| 1389 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1390 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1391 | if (!successor->IsExitBlock()) { |
| 1392 | HandleGoto(try_boundary, successor); |
| 1393 | } |
| 1394 | } |
| 1395 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1396 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1397 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1398 | } |
| 1399 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1400 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1401 | } |
| 1402 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1403 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1404 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1405 | LabelType* true_label, |
| 1406 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1407 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1408 | __ j(kUnordered, true_label); |
| 1409 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1410 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1411 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1412 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1413 | } |
| 1414 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1415 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1416 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1417 | LabelType* true_label, |
| 1418 | LabelType* false_label) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1419 | LocationSummary* locations = cond->GetLocations(); |
| 1420 | Location left = locations->InAt(0); |
| 1421 | Location right = locations->InAt(1); |
| 1422 | IfCondition if_cond = cond->GetCondition(); |
| 1423 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1424 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1425 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1426 | IfCondition true_high_cond = if_cond; |
| 1427 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1428 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); // unsigned on lower part |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1429 | |
| 1430 | // Set the conditions for the test, remembering that == needs to be |
| 1431 | // decided using the low words. |
| 1432 | switch (if_cond) { |
| 1433 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1434 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1435 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1436 | break; |
| 1437 | case kCondLT: |
| 1438 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1439 | break; |
| 1440 | case kCondLE: |
| 1441 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1442 | break; |
| 1443 | case kCondGT: |
| 1444 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1445 | break; |
| 1446 | case kCondGE: |
| 1447 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1448 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1449 | case kCondB: |
| 1450 | false_high_cond = kCondA; |
| 1451 | break; |
| 1452 | case kCondBE: |
| 1453 | true_high_cond = kCondB; |
| 1454 | break; |
| 1455 | case kCondA: |
| 1456 | false_high_cond = kCondB; |
| 1457 | break; |
| 1458 | case kCondAE: |
| 1459 | true_high_cond = kCondA; |
| 1460 | break; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1461 | } |
| 1462 | |
| 1463 | if (right.IsConstant()) { |
| 1464 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1465 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1466 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1467 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1468 | codegen_->Compare32BitValue(left_high, val_high); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1469 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1470 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1471 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1472 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1473 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1474 | __ j(X86Condition(true_high_cond), true_label); |
| 1475 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1476 | } |
| 1477 | // Must be equal high, so compare the lows. |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1478 | codegen_->Compare32BitValue(left_low, val_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1479 | } else if (right.IsRegisterPair()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1480 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1481 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1482 | |
| 1483 | __ cmpl(left_high, right_high); |
| 1484 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1485 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1486 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1487 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1488 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1489 | __ j(X86Condition(true_high_cond), true_label); |
| 1490 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1491 | } |
| 1492 | // Must be equal high, so compare the lows. |
| 1493 | __ cmpl(left_low, right_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1494 | } else { |
| 1495 | DCHECK(right.IsDoubleStackSlot()); |
| 1496 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
| 1497 | if (if_cond == kCondNE) { |
| 1498 | __ j(X86Condition(true_high_cond), true_label); |
| 1499 | } else if (if_cond == kCondEQ) { |
| 1500 | __ j(X86Condition(false_high_cond), false_label); |
| 1501 | } else { |
| 1502 | __ j(X86Condition(true_high_cond), true_label); |
| 1503 | __ j(X86Condition(false_high_cond), false_label); |
| 1504 | } |
| 1505 | // Must be equal high, so compare the lows. |
| 1506 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1507 | } |
| 1508 | // The last comparison might be unsigned. |
| 1509 | __ j(final_condition, true_label); |
| 1510 | } |
| 1511 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1512 | void InstructionCodeGeneratorX86::GenerateFPCompare(Location lhs, |
| 1513 | Location rhs, |
| 1514 | HInstruction* insn, |
| 1515 | bool is_double) { |
| 1516 | HX86LoadFromConstantTable* const_area = insn->InputAt(1)->AsX86LoadFromConstantTable(); |
| 1517 | if (is_double) { |
| 1518 | if (rhs.IsFpuRegister()) { |
| 1519 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1520 | } else if (const_area != nullptr) { |
| 1521 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1522 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), |
| 1523 | codegen_->LiteralDoubleAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1524 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 1525 | const_area->GetBaseMethodAddress(), |
| 1526 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1527 | } else { |
| 1528 | DCHECK(rhs.IsDoubleStackSlot()); |
| 1529 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1530 | } |
| 1531 | } else { |
| 1532 | if (rhs.IsFpuRegister()) { |
| 1533 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1534 | } else if (const_area != nullptr) { |
| 1535 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1536 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), |
| 1537 | codegen_->LiteralFloatAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1538 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 1539 | const_area->GetBaseMethodAddress(), |
| 1540 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1541 | } else { |
| 1542 | DCHECK(rhs.IsStackSlot()); |
| 1543 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1544 | } |
| 1545 | } |
| 1546 | } |
| 1547 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1548 | template<class LabelType> |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1549 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1550 | LabelType* true_target_in, |
| 1551 | LabelType* false_target_in) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1552 | // Generated branching requires both targets to be explicit. If either of the |
| 1553 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1554 | LabelType fallthrough_target; |
| 1555 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1556 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1557 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1558 | LocationSummary* locations = condition->GetLocations(); |
| 1559 | Location left = locations->InAt(0); |
| 1560 | Location right = locations->InAt(1); |
| 1561 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1562 | DataType::Type type = condition->InputAt(0)->GetType(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1563 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1564 | case DataType::Type::kInt64: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1565 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1566 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1567 | case DataType::Type::kFloat32: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1568 | GenerateFPCompare(left, right, condition, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1569 | GenerateFPJumps(condition, true_target, false_target); |
| 1570 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1571 | case DataType::Type::kFloat64: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1572 | GenerateFPCompare(left, right, condition, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1573 | GenerateFPJumps(condition, true_target, false_target); |
| 1574 | break; |
| 1575 | default: |
| 1576 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1577 | } |
| 1578 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1579 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1580 | __ jmp(false_target); |
| 1581 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1582 | |
| 1583 | if (fallthrough_target.IsLinked()) { |
| 1584 | __ Bind(&fallthrough_target); |
| 1585 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1586 | } |
| 1587 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1588 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1589 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1590 | // are set only strictly before `branch`. We can't use the eflags on long/FP |
| 1591 | // conditions if they are materialized due to the complex branching. |
| 1592 | return cond->IsCondition() && |
| 1593 | cond->GetNext() == branch && |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1594 | cond->InputAt(0)->GetType() != DataType::Type::kInt64 && |
| 1595 | !DataType::IsFloatingPointType(cond->InputAt(0)->GetType()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1596 | } |
| 1597 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1598 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1599 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1600 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1601 | LabelType* true_target, |
| 1602 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1603 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1604 | |
| 1605 | if (true_target == nullptr && false_target == nullptr) { |
| 1606 | // Nothing to do. The code always falls through. |
| 1607 | return; |
| 1608 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1609 | // Constant condition, statically compared against "true" (integer value 1). |
| 1610 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1611 | if (true_target != nullptr) { |
| 1612 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1613 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1614 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1615 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1616 | if (false_target != nullptr) { |
| 1617 | __ jmp(false_target); |
| 1618 | } |
| 1619 | } |
| 1620 | return; |
| 1621 | } |
| 1622 | |
| 1623 | // The following code generates these patterns: |
| 1624 | // (1) true_target == nullptr && false_target != nullptr |
| 1625 | // - opposite condition true => branch to false_target |
| 1626 | // (2) true_target != nullptr && false_target == nullptr |
| 1627 | // - condition true => branch to true_target |
| 1628 | // (3) true_target != nullptr && false_target != nullptr |
| 1629 | // - condition true => branch to true_target |
| 1630 | // - branch to false_target |
| 1631 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1632 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1633 | if (true_target == nullptr) { |
| 1634 | __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1635 | } else { |
| 1636 | __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); |
| 1637 | } |
| 1638 | } else { |
| 1639 | // Materialized condition, compare against 0. |
| 1640 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1641 | if (lhs.IsRegister()) { |
| 1642 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1643 | } else { |
| 1644 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1645 | } |
| 1646 | if (true_target == nullptr) { |
| 1647 | __ j(kEqual, false_target); |
| 1648 | } else { |
| 1649 | __ j(kNotEqual, true_target); |
| 1650 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1651 | } |
| 1652 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1653 | // Condition has not been materialized, use its inputs as the comparison and |
| 1654 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1655 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1656 | |
| 1657 | // If this is a long or FP comparison that has been folded into |
| 1658 | // the HCondition, generate the comparison directly. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1659 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 1660 | if (type == DataType::Type::kInt64 || DataType::IsFloatingPointType(type)) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1661 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1662 | return; |
| 1663 | } |
| 1664 | |
| 1665 | Location lhs = condition->GetLocations()->InAt(0); |
| 1666 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1667 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition). |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1668 | codegen_->GenerateIntCompare(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1669 | if (true_target == nullptr) { |
| 1670 | __ j(X86Condition(condition->GetOppositeCondition()), false_target); |
| 1671 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1672 | __ j(X86Condition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1673 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1674 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1675 | |
| 1676 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1677 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1678 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1679 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1680 | } |
| 1681 | } |
| 1682 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1683 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1684 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1685 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1686 | locations->SetInAt(0, Location::Any()); |
| 1687 | } |
| 1688 | } |
| 1689 | |
| 1690 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1691 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1692 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1693 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1694 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1695 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1696 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1697 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1698 | } |
| 1699 | |
| 1700 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1701 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1702 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 1703 | InvokeRuntimeCallingConvention calling_convention; |
| 1704 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 1705 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1706 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1707 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1708 | locations->SetInAt(0, Location::Any()); |
| 1709 | } |
| 1710 | } |
| 1711 | |
| 1712 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1713 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1714 | GenerateTestAndBranch<Label>(deoptimize, |
| 1715 | /* condition_input_index */ 0, |
| 1716 | slow_path->GetEntryLabel(), |
| 1717 | /* false_target */ nullptr); |
| 1718 | } |
| 1719 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1720 | void LocationsBuilderX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1721 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1722 | LocationSummary(flag, LocationSummary::kNoCall); |
| 1723 | locations->SetOut(Location::RequiresRegister()); |
| 1724 | } |
| 1725 | |
| 1726 | void InstructionCodeGeneratorX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1727 | __ movl(flag->GetLocations()->Out().AsRegister<Register>(), |
| 1728 | Address(ESP, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1729 | } |
| 1730 | |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1731 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1732 | // There are no conditional move instructions for XMMs. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1733 | if (DataType::IsFloatingPointType(select->GetType())) { |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1734 | return false; |
| 1735 | } |
| 1736 | |
| 1737 | // A FP condition doesn't generate the single CC that we need. |
| 1738 | // In 32 bit mode, a long condition doesn't generate a single CC either. |
| 1739 | HInstruction* condition = select->GetCondition(); |
| 1740 | if (condition->IsCondition()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1741 | DataType::Type compare_type = condition->InputAt(0)->GetType(); |
| 1742 | if (compare_type == DataType::Type::kInt64 || |
| 1743 | DataType::IsFloatingPointType(compare_type)) { |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1744 | return false; |
| 1745 | } |
| 1746 | } |
| 1747 | |
| 1748 | // We can generate a CMOV for this Select. |
| 1749 | return true; |
| 1750 | } |
| 1751 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1752 | void LocationsBuilderX86::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1753 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1754 | if (DataType::IsFloatingPointType(select->GetType())) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1755 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1756 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1757 | } else { |
| 1758 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1759 | if (SelectCanUseCMOV(select)) { |
| 1760 | if (select->InputAt(1)->IsConstant()) { |
| 1761 | // Cmov can't handle a constant value. |
| 1762 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1763 | } else { |
| 1764 | locations->SetInAt(1, Location::Any()); |
| 1765 | } |
| 1766 | } else { |
| 1767 | locations->SetInAt(1, Location::Any()); |
| 1768 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1769 | } |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1770 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1771 | locations->SetInAt(2, Location::RequiresRegister()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1772 | } |
| 1773 | locations->SetOut(Location::SameAsFirstInput()); |
| 1774 | } |
| 1775 | |
| 1776 | void InstructionCodeGeneratorX86::VisitSelect(HSelect* select) { |
| 1777 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1778 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1779 | if (SelectCanUseCMOV(select)) { |
| 1780 | // If both the condition and the source types are integer, we can generate |
| 1781 | // a CMOV to implement Select. |
| 1782 | |
| 1783 | HInstruction* select_condition = select->GetCondition(); |
| 1784 | Condition cond = kNotEqual; |
| 1785 | |
| 1786 | // Figure out how to test the 'condition'. |
| 1787 | if (select_condition->IsCondition()) { |
| 1788 | HCondition* condition = select_condition->AsCondition(); |
| 1789 | if (!condition->IsEmittedAtUseSite()) { |
| 1790 | // This was a previously materialized condition. |
| 1791 | // Can we use the existing condition code? |
| 1792 | if (AreEflagsSetFrom(condition, select)) { |
| 1793 | // Materialization was the previous instruction. Condition codes are right. |
| 1794 | cond = X86Condition(condition->GetCondition()); |
| 1795 | } else { |
| 1796 | // No, we have to recreate the condition code. |
| 1797 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1798 | __ testl(cond_reg, cond_reg); |
| 1799 | } |
| 1800 | } else { |
| 1801 | // We can't handle FP or long here. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1802 | DCHECK_NE(condition->InputAt(0)->GetType(), DataType::Type::kInt64); |
| 1803 | DCHECK(!DataType::IsFloatingPointType(condition->InputAt(0)->GetType())); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1804 | LocationSummary* cond_locations = condition->GetLocations(); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1805 | codegen_->GenerateIntCompare(cond_locations->InAt(0), cond_locations->InAt(1)); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1806 | cond = X86Condition(condition->GetCondition()); |
| 1807 | } |
| 1808 | } else { |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 1809 | // Must be a Boolean condition, which needs to be compared to 0. |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1810 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1811 | __ testl(cond_reg, cond_reg); |
| 1812 | } |
| 1813 | |
| 1814 | // If the condition is true, overwrite the output, which already contains false. |
| 1815 | Location false_loc = locations->InAt(0); |
| 1816 | Location true_loc = locations->InAt(1); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1817 | if (select->GetType() == DataType::Type::kInt64) { |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1818 | // 64 bit conditional move. |
| 1819 | Register false_high = false_loc.AsRegisterPairHigh<Register>(); |
| 1820 | Register false_low = false_loc.AsRegisterPairLow<Register>(); |
| 1821 | if (true_loc.IsRegisterPair()) { |
| 1822 | __ cmovl(cond, false_high, true_loc.AsRegisterPairHigh<Register>()); |
| 1823 | __ cmovl(cond, false_low, true_loc.AsRegisterPairLow<Register>()); |
| 1824 | } else { |
| 1825 | __ cmovl(cond, false_high, Address(ESP, true_loc.GetHighStackIndex(kX86WordSize))); |
| 1826 | __ cmovl(cond, false_low, Address(ESP, true_loc.GetStackIndex())); |
| 1827 | } |
| 1828 | } else { |
| 1829 | // 32 bit conditional move. |
| 1830 | Register false_reg = false_loc.AsRegister<Register>(); |
| 1831 | if (true_loc.IsRegister()) { |
| 1832 | __ cmovl(cond, false_reg, true_loc.AsRegister<Register>()); |
| 1833 | } else { |
| 1834 | __ cmovl(cond, false_reg, Address(ESP, true_loc.GetStackIndex())); |
| 1835 | } |
| 1836 | } |
| 1837 | } else { |
| 1838 | NearLabel false_target; |
| 1839 | GenerateTestAndBranch<NearLabel>( |
| 1840 | select, /* condition_input_index */ 2, /* true_target */ nullptr, &false_target); |
| 1841 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1842 | __ Bind(&false_target); |
| 1843 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1844 | } |
| 1845 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1846 | void LocationsBuilderX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1847 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1848 | } |
| 1849 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1850 | void InstructionCodeGeneratorX86::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1851 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1852 | } |
| 1853 | |
| 1854 | void CodeGeneratorX86::GenerateNop() { |
| 1855 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1856 | } |
| 1857 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1858 | void LocationsBuilderX86::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1859 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1860 | new (GetGraph()->GetAllocator()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1861 | // Handle the long/FP comparisons made in instruction simplification. |
| 1862 | switch (cond->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1863 | case DataType::Type::kInt64: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1864 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1865 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1866 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1867 | locations->SetOut(Location::RequiresRegister()); |
| 1868 | } |
| 1869 | break; |
| 1870 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1871 | case DataType::Type::kFloat32: |
| 1872 | case DataType::Type::kFloat64: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1873 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1874 | if (cond->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 1875 | DCHECK(cond->InputAt(1)->IsEmittedAtUseSite()); |
| 1876 | } else if (cond->InputAt(1)->IsConstant()) { |
| 1877 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1878 | } else { |
| 1879 | locations->SetInAt(1, Location::Any()); |
| 1880 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1881 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1882 | locations->SetOut(Location::RequiresRegister()); |
| 1883 | } |
| 1884 | break; |
| 1885 | } |
| 1886 | default: |
| 1887 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1888 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1889 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1890 | // We need a byte register. |
| 1891 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1892 | } |
| 1893 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1894 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1895 | } |
| 1896 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1897 | void InstructionCodeGeneratorX86::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1898 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1899 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1900 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1901 | |
| 1902 | LocationSummary* locations = cond->GetLocations(); |
| 1903 | Location lhs = locations->InAt(0); |
| 1904 | Location rhs = locations->InAt(1); |
| 1905 | Register reg = locations->Out().AsRegister<Register>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1906 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1907 | |
| 1908 | switch (cond->InputAt(0)->GetType()) { |
| 1909 | default: { |
| 1910 | // Integer case. |
| 1911 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 1912 | // Clear output register: setb only sets the low byte. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1913 | __ xorl(reg, reg); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1914 | codegen_->GenerateIntCompare(lhs, rhs); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1915 | __ setb(X86Condition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1916 | return; |
| 1917 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1918 | case DataType::Type::kInt64: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1919 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1920 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1921 | case DataType::Type::kFloat32: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1922 | GenerateFPCompare(lhs, rhs, cond, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1923 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1924 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1925 | case DataType::Type::kFloat64: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1926 | GenerateFPCompare(lhs, rhs, cond, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1927 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1928 | break; |
| 1929 | } |
| 1930 | |
| 1931 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1932 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1933 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1934 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1935 | __ Bind(&false_label); |
| 1936 | __ xorl(reg, reg); |
| 1937 | __ jmp(&done_label); |
| 1938 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1939 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1940 | __ Bind(&true_label); |
| 1941 | __ movl(reg, Immediate(1)); |
| 1942 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1943 | } |
| 1944 | |
| 1945 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1946 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1947 | } |
| 1948 | |
| 1949 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1950 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1951 | } |
| 1952 | |
| 1953 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1954 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1955 | } |
| 1956 | |
| 1957 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1958 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1959 | } |
| 1960 | |
| 1961 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1962 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1963 | } |
| 1964 | |
| 1965 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1966 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1967 | } |
| 1968 | |
| 1969 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1970 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1971 | } |
| 1972 | |
| 1973 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1974 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1975 | } |
| 1976 | |
| 1977 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1978 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1979 | } |
| 1980 | |
| 1981 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1982 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1983 | } |
| 1984 | |
| 1985 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1986 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1987 | } |
| 1988 | |
| 1989 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1990 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1991 | } |
| 1992 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1993 | void LocationsBuilderX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1994 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1995 | } |
| 1996 | |
| 1997 | void InstructionCodeGeneratorX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1998 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1999 | } |
| 2000 | |
| 2001 | void LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2002 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2003 | } |
| 2004 | |
| 2005 | void InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2006 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2007 | } |
| 2008 | |
| 2009 | void LocationsBuilderX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2010 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2011 | } |
| 2012 | |
| 2013 | void InstructionCodeGeneratorX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2014 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2015 | } |
| 2016 | |
| 2017 | void LocationsBuilderX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2018 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2019 | } |
| 2020 | |
| 2021 | void InstructionCodeGeneratorX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2022 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2023 | } |
| 2024 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2025 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2026 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2027 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2028 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2029 | } |
| 2030 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2031 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2032 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2033 | } |
| 2034 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2035 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 2036 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2037 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2038 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2039 | } |
| 2040 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2041 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2042 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2043 | } |
| 2044 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2045 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2046 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2047 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2048 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2049 | } |
| 2050 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2051 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2052 | // Will be generated at use site. |
| 2053 | } |
| 2054 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2055 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 2056 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2057 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2058 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2059 | } |
| 2060 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2061 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2062 | // Will be generated at use site. |
| 2063 | } |
| 2064 | |
| 2065 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2066 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2067 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2068 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2069 | } |
| 2070 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2071 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2072 | // Will be generated at use site. |
| 2073 | } |
| 2074 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2075 | void LocationsBuilderX86::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 2076 | constructor_fence->SetLocations(nullptr); |
| 2077 | } |
| 2078 | |
| 2079 | void InstructionCodeGeneratorX86::VisitConstructorFence( |
| 2080 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 2081 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 2082 | } |
| 2083 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2084 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2085 | memory_barrier->SetLocations(nullptr); |
| 2086 | } |
| 2087 | |
| 2088 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 2089 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2090 | } |
| 2091 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2092 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2093 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2094 | } |
| 2095 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2096 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2097 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2098 | } |
| 2099 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2100 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2101 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2102 | new (GetGraph()->GetAllocator()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2103 | switch (ret->InputAt(0)->GetType()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2104 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2105 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2106 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2107 | case DataType::Type::kInt8: |
| 2108 | case DataType::Type::kUint16: |
| 2109 | case DataType::Type::kInt16: |
| 2110 | case DataType::Type::kInt32: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2111 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2112 | break; |
| 2113 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2114 | case DataType::Type::kInt64: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2115 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2116 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2117 | break; |
| 2118 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2119 | case DataType::Type::kFloat32: |
| 2120 | case DataType::Type::kFloat64: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2121 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2122 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2123 | break; |
| 2124 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2125 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2126 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2127 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2128 | } |
| 2129 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2130 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2131 | if (kIsDebugBuild) { |
| 2132 | switch (ret->InputAt(0)->GetType()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2133 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2134 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2135 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2136 | case DataType::Type::kInt8: |
| 2137 | case DataType::Type::kUint16: |
| 2138 | case DataType::Type::kInt16: |
| 2139 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2140 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2141 | break; |
| 2142 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2143 | case DataType::Type::kInt64: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2144 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 2145 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2146 | break; |
| 2147 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2148 | case DataType::Type::kFloat32: |
| 2149 | case DataType::Type::kFloat64: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2150 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2151 | break; |
| 2152 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2153 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2154 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2155 | } |
| 2156 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2157 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2158 | } |
| 2159 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2160 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2161 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2162 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2163 | // the method_idx. |
| 2164 | HandleInvoke(invoke); |
| 2165 | } |
| 2166 | |
| 2167 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2168 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2169 | } |
| 2170 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2171 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2172 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2173 | // art::PrepareForRegisterAllocation. |
| 2174 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2175 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2176 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2177 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 2178 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeMethodLoadKind()) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 2179 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2180 | } |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2181 | return; |
| 2182 | } |
| 2183 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2184 | HandleInvoke(invoke); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2185 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2186 | // 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] | 2187 | if (invoke->HasPcRelativeMethodLoadKind()) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2188 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2189 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2190 | } |
| 2191 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2192 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 2193 | if (invoke->GetLocations()->Intrinsified()) { |
| 2194 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 2195 | intrinsic.Dispatch(invoke); |
| 2196 | return true; |
| 2197 | } |
| 2198 | return false; |
| 2199 | } |
| 2200 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2201 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2202 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2203 | // art::PrepareForRegisterAllocation. |
| 2204 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2205 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2206 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2207 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2208 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2209 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2210 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2211 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2212 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2213 | } |
| 2214 | |
| 2215 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 2216 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 2217 | if (intrinsic.TryDispatch(invoke)) { |
| 2218 | return; |
| 2219 | } |
| 2220 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2221 | HandleInvoke(invoke); |
| 2222 | } |
| 2223 | |
| 2224 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2225 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2226 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2227 | } |
| 2228 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2229 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2230 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2231 | return; |
| 2232 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2233 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2234 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2235 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2236 | } |
| 2237 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2238 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2239 | // This call to HandleInvoke allocates a temporary (core) register |
| 2240 | // which is also used to transfer the hidden argument from FP to |
| 2241 | // core register. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2242 | HandleInvoke(invoke); |
| 2243 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2244 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2245 | } |
| 2246 | |
| 2247 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2248 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2249 | LocationSummary* locations = invoke->GetLocations(); |
| 2250 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2251 | XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2252 | Location receiver = locations->InAt(0); |
| 2253 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2254 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2255 | // Set the hidden argument. This is safe to do this here, as XMM7 |
| 2256 | // won't be modified thereafter, before the `call` instruction. |
| 2257 | DCHECK_EQ(XMM7, hidden_reg); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2258 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2259 | __ movd(hidden_reg, temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2260 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2261 | if (receiver.IsStackSlot()) { |
| 2262 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2263 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2264 | __ movl(temp, Address(temp, class_offset)); |
| 2265 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2266 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2267 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2268 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2269 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2270 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2271 | // emit a read barrier for the previous class reference load. |
| 2272 | // However this is not required in practice, as this is an |
| 2273 | // intermediate/temporary reference and because the current |
| 2274 | // concurrent copying collector keeps the from-space memory |
| 2275 | // intact/accessible until the end of the marking phase (the |
| 2276 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2277 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2278 | // temp = temp->GetAddressOfIMT() |
| 2279 | __ movl(temp, |
| 2280 | Address(temp, mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2281 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2282 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2283 | invoke->GetImtIndex(), kX86PointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2284 | __ movl(temp, Address(temp, method_offset)); |
| 2285 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2286 | __ call(Address(temp, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2287 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2288 | |
| 2289 | DCHECK(!codegen_->IsLeafMethod()); |
| 2290 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2291 | } |
| 2292 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2293 | void LocationsBuilderX86::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2294 | HandleInvoke(invoke); |
| 2295 | } |
| 2296 | |
| 2297 | void InstructionCodeGeneratorX86::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2298 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 2299 | } |
| 2300 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2301 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 2302 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2303 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2304 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2305 | case DataType::Type::kInt32: |
| 2306 | case DataType::Type::kInt64: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2307 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2308 | locations->SetOut(Location::SameAsFirstInput()); |
| 2309 | break; |
| 2310 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2311 | case DataType::Type::kFloat32: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2312 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2313 | locations->SetOut(Location::SameAsFirstInput()); |
| 2314 | locations->AddTemp(Location::RequiresRegister()); |
| 2315 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2316 | break; |
| 2317 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2318 | case DataType::Type::kFloat64: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2319 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2320 | locations->SetOut(Location::SameAsFirstInput()); |
| 2321 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2322 | break; |
| 2323 | |
| 2324 | default: |
| 2325 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2326 | } |
| 2327 | } |
| 2328 | |
| 2329 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 2330 | LocationSummary* locations = neg->GetLocations(); |
| 2331 | Location out = locations->Out(); |
| 2332 | Location in = locations->InAt(0); |
| 2333 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2334 | case DataType::Type::kInt32: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2335 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2336 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2337 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2338 | break; |
| 2339 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2340 | case DataType::Type::kInt64: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2341 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2342 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2343 | __ negl(out.AsRegisterPairLow<Register>()); |
| 2344 | // Negation is similar to subtraction from zero. The least |
| 2345 | // significant byte triggers a borrow when it is different from |
| 2346 | // zero; to take it into account, add 1 to the most significant |
| 2347 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 2348 | // operation. |
| 2349 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2350 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 2351 | break; |
| 2352 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2353 | case DataType::Type::kFloat32: { |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2354 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2355 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 2356 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2357 | // Implement float negation with an exclusive or with value |
| 2358 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2359 | // single-precision floating-point number). |
| 2360 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 2361 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2362 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2363 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2364 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2365 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2366 | case DataType::Type::kFloat64: { |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2367 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2368 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2369 | // Implement double negation with an exclusive or with value |
| 2370 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 2371 | // a double-precision floating-point number). |
| 2372 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2373 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2374 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2375 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2376 | |
| 2377 | default: |
| 2378 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2379 | } |
| 2380 | } |
| 2381 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2382 | void LocationsBuilderX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2383 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2384 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2385 | DCHECK(DataType::IsFloatingPointType(neg->GetType())); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2386 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2387 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2388 | locations->SetOut(Location::SameAsFirstInput()); |
| 2389 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2390 | } |
| 2391 | |
| 2392 | void InstructionCodeGeneratorX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2393 | LocationSummary* locations = neg->GetLocations(); |
| 2394 | Location out = locations->Out(); |
| 2395 | DCHECK(locations->InAt(0).Equals(out)); |
| 2396 | |
| 2397 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 2398 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2399 | if (neg->GetType() == DataType::Type::kFloat32) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 2400 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x80000000), |
| 2401 | neg->GetBaseMethodAddress(), |
| 2402 | constant_area)); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2403 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| 2404 | } else { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 2405 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000), |
| 2406 | neg->GetBaseMethodAddress(), |
| 2407 | constant_area)); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2408 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| 2409 | } |
| 2410 | } |
| 2411 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2412 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2413 | DataType::Type result_type = conversion->GetResultType(); |
| 2414 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2415 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 2416 | << input_type << " -> " << result_type; |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2417 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2418 | // The float-to-long and double-to-long type conversions rely on a |
| 2419 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2420 | LocationSummary::CallKind call_kind = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2421 | ((input_type == DataType::Type::kFloat32 || input_type == DataType::Type::kFloat64) |
| 2422 | && result_type == DataType::Type::kInt64) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2423 | ? LocationSummary::kCallOnMainOnly |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2424 | : LocationSummary::kNoCall; |
| 2425 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2426 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, call_kind); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2427 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2428 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2429 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2430 | case DataType::Type::kInt8: |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2431 | switch (input_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2432 | case DataType::Type::kUint8: |
| 2433 | case DataType::Type::kInt8: |
| 2434 | case DataType::Type::kUint16: |
| 2435 | case DataType::Type::kInt16: |
| 2436 | case DataType::Type::kInt32: |
| 2437 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 2438 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2439 | // the validation of the linear scan implementation |
| 2440 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2441 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2442 | case DataType::Type::kInt64: { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2443 | HInstruction* input = conversion->InputAt(0); |
| 2444 | Location input_location = input->IsConstant() |
| 2445 | ? Location::ConstantLocation(input->AsConstant()) |
| 2446 | : Location::RegisterPairLocation(EAX, EDX); |
| 2447 | locations->SetInAt(0, input_location); |
| 2448 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2449 | // the validation of the linear scan implementation |
| 2450 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2451 | break; |
| 2452 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2453 | |
| 2454 | default: |
| 2455 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2456 | << " to " << result_type; |
| 2457 | } |
| 2458 | break; |
| 2459 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2460 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2461 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2462 | DCHECK(DataType::IsIntegralType(input_type)) << input_type; |
| 2463 | locations->SetInAt(0, Location::Any()); |
| 2464 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2465 | break; |
| 2466 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2467 | case DataType::Type::kInt32: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2468 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2469 | case DataType::Type::kInt64: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2470 | locations->SetInAt(0, Location::Any()); |
| 2471 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2472 | break; |
| 2473 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2474 | case DataType::Type::kFloat32: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2475 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2476 | locations->SetOut(Location::RequiresRegister()); |
| 2477 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2478 | break; |
| 2479 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2480 | case DataType::Type::kFloat64: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2481 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2482 | locations->SetOut(Location::RequiresRegister()); |
| 2483 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2484 | break; |
| 2485 | |
| 2486 | default: |
| 2487 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2488 | << " to " << result_type; |
| 2489 | } |
| 2490 | break; |
| 2491 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2492 | case DataType::Type::kInt64: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2493 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2494 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2495 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2496 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2497 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2498 | case DataType::Type::kInt16: |
| 2499 | case DataType::Type::kInt32: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2500 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 2501 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2502 | break; |
| 2503 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2504 | case DataType::Type::kFloat32: |
| 2505 | case DataType::Type::kFloat64: { |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2506 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2507 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 2508 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 2509 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2510 | // The runtime helper puts the result in EAX, EDX. |
| 2511 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2512 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2513 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2514 | |
| 2515 | default: |
| 2516 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2517 | << " to " << result_type; |
| 2518 | } |
| 2519 | break; |
| 2520 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2521 | case DataType::Type::kFloat32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2522 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2523 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2524 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2525 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2526 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2527 | case DataType::Type::kInt16: |
| 2528 | case DataType::Type::kInt32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2529 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2530 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2531 | break; |
| 2532 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2533 | case DataType::Type::kInt64: |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2534 | locations->SetInAt(0, Location::Any()); |
| 2535 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2536 | break; |
| 2537 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2538 | case DataType::Type::kFloat64: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2539 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2540 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2541 | break; |
| 2542 | |
| 2543 | default: |
| 2544 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2545 | << " to " << result_type; |
| 2546 | }; |
| 2547 | break; |
| 2548 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2549 | case DataType::Type::kFloat64: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2550 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2551 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2552 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2553 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2554 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2555 | case DataType::Type::kInt16: |
| 2556 | case DataType::Type::kInt32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2557 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2558 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2559 | break; |
| 2560 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2561 | case DataType::Type::kInt64: |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2562 | locations->SetInAt(0, Location::Any()); |
| 2563 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2564 | break; |
| 2565 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2566 | case DataType::Type::kFloat32: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2567 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2568 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2569 | break; |
| 2570 | |
| 2571 | default: |
| 2572 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2573 | << " to " << result_type; |
| 2574 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2575 | break; |
| 2576 | |
| 2577 | default: |
| 2578 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2579 | << " to " << result_type; |
| 2580 | } |
| 2581 | } |
| 2582 | |
| 2583 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 2584 | LocationSummary* locations = conversion->GetLocations(); |
| 2585 | Location out = locations->Out(); |
| 2586 | Location in = locations->InAt(0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2587 | DataType::Type result_type = conversion->GetResultType(); |
| 2588 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2589 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 2590 | << input_type << " -> " << result_type; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2591 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2592 | case DataType::Type::kUint8: |
| 2593 | switch (input_type) { |
| 2594 | case DataType::Type::kInt8: |
| 2595 | case DataType::Type::kUint16: |
| 2596 | case DataType::Type::kInt16: |
| 2597 | case DataType::Type::kInt32: |
| 2598 | if (in.IsRegister()) { |
| 2599 | __ movzxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
| 2600 | } else { |
| 2601 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2602 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2603 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint8_t>(value))); |
| 2604 | } |
| 2605 | break; |
| 2606 | case DataType::Type::kInt64: |
| 2607 | if (in.IsRegisterPair()) { |
| 2608 | __ movzxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 2609 | } else { |
| 2610 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2611 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2612 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint8_t>(value))); |
| 2613 | } |
| 2614 | break; |
| 2615 | |
| 2616 | default: |
| 2617 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2618 | << " to " << result_type; |
| 2619 | } |
| 2620 | break; |
| 2621 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2622 | case DataType::Type::kInt8: |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2623 | switch (input_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2624 | case DataType::Type::kUint8: |
| 2625 | case DataType::Type::kUint16: |
| 2626 | case DataType::Type::kInt16: |
| 2627 | case DataType::Type::kInt32: |
| 2628 | if (in.IsRegister()) { |
| 2629 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
| 2630 | } else { |
| 2631 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2632 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2633 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2634 | } |
| 2635 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2636 | case DataType::Type::kInt64: |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2637 | if (in.IsRegisterPair()) { |
| 2638 | __ movsxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 2639 | } else { |
| 2640 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2641 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2642 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2643 | } |
| 2644 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2645 | |
| 2646 | default: |
| 2647 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2648 | << " to " << result_type; |
| 2649 | } |
| 2650 | break; |
| 2651 | |
| 2652 | case DataType::Type::kUint16: |
| 2653 | switch (input_type) { |
| 2654 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2655 | case DataType::Type::kInt16: |
| 2656 | case DataType::Type::kInt32: |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2657 | if (in.IsRegister()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2658 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
| 2659 | } else if (in.IsStackSlot()) { |
| 2660 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2661 | } else { |
| 2662 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2663 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2664 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
| 2665 | } |
| 2666 | break; |
| 2667 | case DataType::Type::kInt64: |
| 2668 | if (in.IsRegisterPair()) { |
| 2669 | __ movzxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2670 | } else if (in.IsDoubleStackSlot()) { |
| 2671 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2672 | } else { |
| 2673 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2674 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2675 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2676 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2677 | break; |
| 2678 | |
| 2679 | default: |
| 2680 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2681 | << " to " << result_type; |
| 2682 | } |
| 2683 | break; |
| 2684 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2685 | case DataType::Type::kInt16: |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2686 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2687 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2688 | case DataType::Type::kInt32: |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2689 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2690 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2691 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2692 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2693 | } else { |
| 2694 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2695 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2696 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2697 | } |
| 2698 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2699 | case DataType::Type::kInt64: |
| 2700 | if (in.IsRegisterPair()) { |
| 2701 | __ movsxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2702 | } else if (in.IsDoubleStackSlot()) { |
| 2703 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2704 | } else { |
| 2705 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2706 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2707 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
| 2708 | } |
| 2709 | break; |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2710 | |
| 2711 | default: |
| 2712 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2713 | << " to " << result_type; |
| 2714 | } |
| 2715 | break; |
| 2716 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2717 | case DataType::Type::kInt32: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2718 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2719 | case DataType::Type::kInt64: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2720 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2721 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2722 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2723 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2724 | } else { |
| 2725 | DCHECK(in.IsConstant()); |
| 2726 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2727 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2728 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2729 | } |
| 2730 | break; |
| 2731 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2732 | case DataType::Type::kFloat32: { |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2733 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2734 | Register output = out.AsRegister<Register>(); |
| 2735 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2736 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2737 | |
| 2738 | __ movl(output, Immediate(kPrimIntMax)); |
| 2739 | // temp = int-to-float(output) |
| 2740 | __ cvtsi2ss(temp, output); |
| 2741 | // if input >= temp goto done |
| 2742 | __ comiss(input, temp); |
| 2743 | __ j(kAboveEqual, &done); |
| 2744 | // if input == NaN goto nan |
| 2745 | __ j(kUnordered, &nan); |
| 2746 | // output = float-to-int-truncate(input) |
| 2747 | __ cvttss2si(output, input); |
| 2748 | __ jmp(&done); |
| 2749 | __ Bind(&nan); |
| 2750 | // output = 0 |
| 2751 | __ xorl(output, output); |
| 2752 | __ Bind(&done); |
| 2753 | break; |
| 2754 | } |
| 2755 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2756 | case DataType::Type::kFloat64: { |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2757 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2758 | Register output = out.AsRegister<Register>(); |
| 2759 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2760 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2761 | |
| 2762 | __ movl(output, Immediate(kPrimIntMax)); |
| 2763 | // temp = int-to-double(output) |
| 2764 | __ cvtsi2sd(temp, output); |
| 2765 | // if input >= temp goto done |
| 2766 | __ comisd(input, temp); |
| 2767 | __ j(kAboveEqual, &done); |
| 2768 | // if input == NaN goto nan |
| 2769 | __ j(kUnordered, &nan); |
| 2770 | // output = double-to-int-truncate(input) |
| 2771 | __ cvttsd2si(output, input); |
| 2772 | __ jmp(&done); |
| 2773 | __ Bind(&nan); |
| 2774 | // output = 0 |
| 2775 | __ xorl(output, output); |
| 2776 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2777 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2778 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2779 | |
| 2780 | default: |
| 2781 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2782 | << " to " << result_type; |
| 2783 | } |
| 2784 | break; |
| 2785 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2786 | case DataType::Type::kInt64: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2787 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2788 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2789 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2790 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2791 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2792 | case DataType::Type::kInt16: |
| 2793 | case DataType::Type::kInt32: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2794 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2795 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2796 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2797 | __ cdq(); |
| 2798 | break; |
| 2799 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2800 | case DataType::Type::kFloat32: |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2801 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2802 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2803 | break; |
| 2804 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2805 | case DataType::Type::kFloat64: |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2806 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2807 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2808 | break; |
| 2809 | |
| 2810 | default: |
| 2811 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2812 | << " to " << result_type; |
| 2813 | } |
| 2814 | break; |
| 2815 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2816 | case DataType::Type::kFloat32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2817 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2818 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2819 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2820 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2821 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2822 | case DataType::Type::kInt16: |
| 2823 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2824 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2825 | break; |
| 2826 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2827 | case DataType::Type::kInt64: { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2828 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2829 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2830 | // Create stack space for the call to |
| 2831 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2832 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2833 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2834 | adjustment = DataType::Size(DataType::Type::kInt64); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2835 | __ subl(ESP, Immediate(adjustment)); |
| 2836 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2837 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2838 | // Load the value to the FP stack, using temporaries if needed. |
| 2839 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2840 | |
| 2841 | if (out.IsStackSlot()) { |
| 2842 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2843 | } else { |
| 2844 | __ fstps(Address(ESP, 0)); |
| 2845 | Location stack_temp = Location::StackSlot(0); |
| 2846 | codegen_->Move32(out, stack_temp); |
| 2847 | } |
| 2848 | |
| 2849 | // Remove the temporary stack space we allocated. |
| 2850 | if (adjustment != 0) { |
| 2851 | __ addl(ESP, Immediate(adjustment)); |
| 2852 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2853 | break; |
| 2854 | } |
| 2855 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2856 | case DataType::Type::kFloat64: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2857 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2858 | break; |
| 2859 | |
| 2860 | default: |
| 2861 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2862 | << " to " << result_type; |
| 2863 | }; |
| 2864 | break; |
| 2865 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2866 | case DataType::Type::kFloat64: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2867 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2868 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2869 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2870 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2871 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2872 | case DataType::Type::kInt16: |
| 2873 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2874 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2875 | break; |
| 2876 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2877 | case DataType::Type::kInt64: { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2878 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2879 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2880 | // Create stack space for the call to |
| 2881 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2882 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2883 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2884 | adjustment = DataType::Size(DataType::Type::kInt64); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2885 | __ subl(ESP, Immediate(adjustment)); |
| 2886 | } |
| 2887 | |
| 2888 | // Load the value to the FP stack, using temporaries if needed. |
| 2889 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2890 | |
| 2891 | if (out.IsDoubleStackSlot()) { |
| 2892 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2893 | } else { |
| 2894 | __ fstpl(Address(ESP, 0)); |
| 2895 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2896 | codegen_->Move64(out, stack_temp); |
| 2897 | } |
| 2898 | |
| 2899 | // Remove the temporary stack space we allocated. |
| 2900 | if (adjustment != 0) { |
| 2901 | __ addl(ESP, Immediate(adjustment)); |
| 2902 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2903 | break; |
| 2904 | } |
| 2905 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2906 | case DataType::Type::kFloat32: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2907 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2908 | break; |
| 2909 | |
| 2910 | default: |
| 2911 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2912 | << " to " << result_type; |
| 2913 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2914 | break; |
| 2915 | |
| 2916 | default: |
| 2917 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2918 | << " to " << result_type; |
| 2919 | } |
| 2920 | } |
| 2921 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2922 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2923 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2924 | new (GetGraph()->GetAllocator()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2925 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2926 | case DataType::Type::kInt32: { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2927 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2928 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2929 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2930 | break; |
| 2931 | } |
| 2932 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2933 | case DataType::Type::kInt64: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2934 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2935 | locations->SetInAt(1, Location::Any()); |
| 2936 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2937 | break; |
| 2938 | } |
| 2939 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2940 | case DataType::Type::kFloat32: |
| 2941 | case DataType::Type::kFloat64: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2942 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2943 | if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2944 | DCHECK(add->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2945 | } else if (add->InputAt(1)->IsConstant()) { |
| 2946 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2947 | } else { |
| 2948 | locations->SetInAt(1, Location::Any()); |
| 2949 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2950 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2951 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2952 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2953 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2954 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2955 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2956 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2957 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2958 | } |
| 2959 | |
| 2960 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 2961 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2962 | Location first = locations->InAt(0); |
| 2963 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2964 | Location out = locations->Out(); |
| 2965 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2966 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2967 | case DataType::Type::kInt32: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2968 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2969 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2970 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2971 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2972 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2973 | } else { |
| 2974 | __ leal(out.AsRegister<Register>(), Address( |
| 2975 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 2976 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2977 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2978 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2979 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2980 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 2981 | } else { |
| 2982 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 2983 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2984 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2985 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2986 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2987 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2988 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2989 | } |
| 2990 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2991 | case DataType::Type::kInt64: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2992 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2993 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2994 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2995 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2996 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 2997 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2998 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2999 | } else { |
| 3000 | DCHECK(second.IsConstant()) << second; |
| 3001 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3002 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 3003 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3004 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3005 | break; |
| 3006 | } |
| 3007 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3008 | case DataType::Type::kFloat32: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3009 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3010 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3011 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3012 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3013 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3014 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 3015 | codegen_->LiteralFloatAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3016 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3017 | const_area->GetBaseMethodAddress(), |
| 3018 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3019 | } else { |
| 3020 | DCHECK(second.IsStackSlot()); |
| 3021 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3022 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3023 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3024 | } |
| 3025 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3026 | case DataType::Type::kFloat64: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3027 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3028 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3029 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3030 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3031 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3032 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 3033 | codegen_->LiteralDoubleAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3034 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3035 | const_area->GetBaseMethodAddress(), |
| 3036 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3037 | } else { |
| 3038 | DCHECK(second.IsDoubleStackSlot()); |
| 3039 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3040 | } |
| 3041 | break; |
| 3042 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3043 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3044 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3045 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3046 | } |
| 3047 | } |
| 3048 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3049 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3050 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3051 | new (GetGraph()->GetAllocator()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3052 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3053 | case DataType::Type::kInt32: |
| 3054 | case DataType::Type::kInt64: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3055 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3056 | locations->SetInAt(1, Location::Any()); |
| 3057 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3058 | break; |
| 3059 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3060 | case DataType::Type::kFloat32: |
| 3061 | case DataType::Type::kFloat64: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3062 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3063 | if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3064 | DCHECK(sub->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3065 | } else if (sub->InputAt(1)->IsConstant()) { |
| 3066 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3067 | } else { |
| 3068 | locations->SetInAt(1, Location::Any()); |
| 3069 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3070 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3071 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3072 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3073 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3074 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3075 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3076 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3077 | } |
| 3078 | |
| 3079 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 3080 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3081 | Location first = locations->InAt(0); |
| 3082 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3083 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3084 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3085 | case DataType::Type::kInt32: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3086 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3087 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3088 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3089 | __ subl(first.AsRegister<Register>(), |
| 3090 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3091 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3092 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3093 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3094 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3095 | } |
| 3096 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3097 | case DataType::Type::kInt64: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3098 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3099 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3100 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3101 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3102 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3103 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 3104 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3105 | } else { |
| 3106 | DCHECK(second.IsConstant()) << second; |
| 3107 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3108 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 3109 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3110 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3111 | break; |
| 3112 | } |
| 3113 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3114 | case DataType::Type::kFloat32: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3115 | if (second.IsFpuRegister()) { |
| 3116 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3117 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3118 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3119 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3120 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3121 | codegen_->LiteralFloatAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3122 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3123 | const_area->GetBaseMethodAddress(), |
| 3124 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3125 | } else { |
| 3126 | DCHECK(second.IsStackSlot()); |
| 3127 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3128 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3129 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3130 | } |
| 3131 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3132 | case DataType::Type::kFloat64: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3133 | if (second.IsFpuRegister()) { |
| 3134 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3135 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3136 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3137 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3138 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3139 | codegen_->LiteralDoubleAddress( |
| 3140 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3141 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3142 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3143 | } else { |
| 3144 | DCHECK(second.IsDoubleStackSlot()); |
| 3145 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3146 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3147 | break; |
| 3148 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3149 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3150 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3151 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3152 | } |
| 3153 | } |
| 3154 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3155 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 3156 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3157 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3158 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3159 | case DataType::Type::kInt32: |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3160 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3161 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3162 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3163 | // Can use 3 operand multiply. |
| 3164 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3165 | } else { |
| 3166 | locations->SetOut(Location::SameAsFirstInput()); |
| 3167 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3168 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3169 | case DataType::Type::kInt64: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3170 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3171 | locations->SetInAt(1, Location::Any()); |
| 3172 | locations->SetOut(Location::SameAsFirstInput()); |
| 3173 | // Needed for imul on 32bits with 64bits output. |
| 3174 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 3175 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 3176 | break; |
| 3177 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3178 | case DataType::Type::kFloat32: |
| 3179 | case DataType::Type::kFloat64: { |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3180 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3181 | if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3182 | DCHECK(mul->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3183 | } else if (mul->InputAt(1)->IsConstant()) { |
| 3184 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3185 | } else { |
| 3186 | locations->SetInAt(1, Location::Any()); |
| 3187 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3188 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3189 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3190 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3191 | |
| 3192 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3193 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3194 | } |
| 3195 | } |
| 3196 | |
| 3197 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 3198 | LocationSummary* locations = mul->GetLocations(); |
| 3199 | Location first = locations->InAt(0); |
| 3200 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3201 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3202 | |
| 3203 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3204 | case DataType::Type::kInt32: |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3205 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3206 | // problems where the output may not be the same as the first operand. |
| 3207 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3208 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3209 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 3210 | } else if (second.IsRegister()) { |
| 3211 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3212 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3213 | } else { |
| 3214 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3215 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3216 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3217 | } |
| 3218 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3219 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3220 | case DataType::Type::kInt64: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3221 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 3222 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3223 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 3224 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3225 | |
| 3226 | DCHECK_EQ(EAX, eax); |
| 3227 | DCHECK_EQ(EDX, edx); |
| 3228 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3229 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3230 | // output: in1 |
| 3231 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3232 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3233 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3234 | if (second.IsConstant()) { |
| 3235 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3236 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3237 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3238 | int32_t low_value = Low32Bits(value); |
| 3239 | int32_t high_value = High32Bits(value); |
| 3240 | Immediate low(low_value); |
| 3241 | Immediate high(high_value); |
| 3242 | |
| 3243 | __ movl(eax, high); |
| 3244 | // eax <- in1.lo * in2.hi |
| 3245 | __ imull(eax, in1_lo); |
| 3246 | // in1.hi <- in1.hi * in2.lo |
| 3247 | __ imull(in1_hi, low); |
| 3248 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3249 | __ addl(in1_hi, eax); |
| 3250 | // move in2_lo to eax to prepare for double precision |
| 3251 | __ movl(eax, low); |
| 3252 | // edx:eax <- in1.lo * in2.lo |
| 3253 | __ mull(in1_lo); |
| 3254 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3255 | __ addl(in1_hi, edx); |
| 3256 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3257 | __ movl(in1_lo, eax); |
| 3258 | } else if (second.IsRegisterPair()) { |
| 3259 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3260 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3261 | |
| 3262 | __ movl(eax, in2_hi); |
| 3263 | // eax <- in1.lo * in2.hi |
| 3264 | __ imull(eax, in1_lo); |
| 3265 | // in1.hi <- in1.hi * in2.lo |
| 3266 | __ imull(in1_hi, in2_lo); |
| 3267 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3268 | __ addl(in1_hi, eax); |
| 3269 | // move in1_lo to eax to prepare for double precision |
| 3270 | __ movl(eax, in1_lo); |
| 3271 | // edx:eax <- in1.lo * in2.lo |
| 3272 | __ mull(in2_lo); |
| 3273 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3274 | __ addl(in1_hi, edx); |
| 3275 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3276 | __ movl(in1_lo, eax); |
| 3277 | } else { |
| 3278 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 3279 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 3280 | Address in2_lo(ESP, second.GetStackIndex()); |
| 3281 | |
| 3282 | __ movl(eax, in2_hi); |
| 3283 | // eax <- in1.lo * in2.hi |
| 3284 | __ imull(eax, in1_lo); |
| 3285 | // in1.hi <- in1.hi * in2.lo |
| 3286 | __ imull(in1_hi, in2_lo); |
| 3287 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3288 | __ addl(in1_hi, eax); |
| 3289 | // move in1_lo to eax to prepare for double precision |
| 3290 | __ movl(eax, in1_lo); |
| 3291 | // edx:eax <- in1.lo * in2.lo |
| 3292 | __ mull(in2_lo); |
| 3293 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3294 | __ addl(in1_hi, edx); |
| 3295 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3296 | __ movl(in1_lo, eax); |
| 3297 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3298 | |
| 3299 | break; |
| 3300 | } |
| 3301 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3302 | case DataType::Type::kFloat32: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3303 | DCHECK(first.Equals(locations->Out())); |
| 3304 | if (second.IsFpuRegister()) { |
| 3305 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3306 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3307 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3308 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3309 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3310 | codegen_->LiteralFloatAddress( |
| 3311 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3312 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3313 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3314 | } else { |
| 3315 | DCHECK(second.IsStackSlot()); |
| 3316 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3317 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3318 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3319 | } |
| 3320 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3321 | case DataType::Type::kFloat64: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3322 | DCHECK(first.Equals(locations->Out())); |
| 3323 | if (second.IsFpuRegister()) { |
| 3324 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3325 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3326 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3327 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3328 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3329 | codegen_->LiteralDoubleAddress( |
| 3330 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3331 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3332 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3333 | } else { |
| 3334 | DCHECK(second.IsDoubleStackSlot()); |
| 3335 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3336 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3337 | break; |
| 3338 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3339 | |
| 3340 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3341 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3342 | } |
| 3343 | } |
| 3344 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3345 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 3346 | uint32_t temp_offset, |
| 3347 | uint32_t stack_adjustment, |
| 3348 | bool is_fp, |
| 3349 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3350 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3351 | DCHECK(!is_wide); |
| 3352 | if (is_fp) { |
| 3353 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3354 | } else { |
| 3355 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3356 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3357 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3358 | DCHECK(is_wide); |
| 3359 | if (is_fp) { |
| 3360 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3361 | } else { |
| 3362 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3363 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3364 | } else { |
| 3365 | // 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] | 3366 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3367 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3368 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3369 | if (is_fp) { |
| 3370 | __ flds(Address(ESP, temp_offset)); |
| 3371 | } else { |
| 3372 | __ filds(Address(ESP, temp_offset)); |
| 3373 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3374 | } else { |
| 3375 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3376 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3377 | if (is_fp) { |
| 3378 | __ fldl(Address(ESP, temp_offset)); |
| 3379 | } else { |
| 3380 | __ fildl(Address(ESP, temp_offset)); |
| 3381 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3382 | } |
| 3383 | } |
| 3384 | } |
| 3385 | |
| 3386 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3387 | DataType::Type type = rem->GetResultType(); |
| 3388 | bool is_float = type == DataType::Type::kFloat32; |
| 3389 | size_t elem_size = DataType::Size(type); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3390 | LocationSummary* locations = rem->GetLocations(); |
| 3391 | Location first = locations->InAt(0); |
| 3392 | Location second = locations->InAt(1); |
| 3393 | Location out = locations->Out(); |
| 3394 | |
| 3395 | // Create stack space for 2 elements. |
| 3396 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3397 | __ subl(ESP, Immediate(2 * elem_size)); |
| 3398 | |
| 3399 | // 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] | 3400 | const bool is_wide = !is_float; |
| 3401 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); |
| 3402 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3403 | |
| 3404 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3405 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3406 | __ Bind(&retry); |
| 3407 | __ fprem(); |
| 3408 | |
| 3409 | // Move FP status to AX. |
| 3410 | __ fstsw(); |
| 3411 | |
| 3412 | // And see if the argument reduction is complete. This is signaled by the |
| 3413 | // C2 FPU flag bit set to 0. |
| 3414 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 3415 | __ j(kNotEqual, &retry); |
| 3416 | |
| 3417 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3418 | // Store FP top of stack to real stack. |
| 3419 | if (is_float) { |
| 3420 | __ fsts(Address(ESP, 0)); |
| 3421 | } else { |
| 3422 | __ fstl(Address(ESP, 0)); |
| 3423 | } |
| 3424 | |
| 3425 | // Pop the 2 items from the FP stack. |
| 3426 | __ fucompp(); |
| 3427 | |
| 3428 | // Load the value from the stack into an XMM register. |
| 3429 | DCHECK(out.IsFpuRegister()) << out; |
| 3430 | if (is_float) { |
| 3431 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3432 | } else { |
| 3433 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3434 | } |
| 3435 | |
| 3436 | // And remove the temporary stack space we allocated. |
| 3437 | __ addl(ESP, Immediate(2 * elem_size)); |
| 3438 | } |
| 3439 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3440 | |
| 3441 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3442 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3443 | |
| 3444 | LocationSummary* locations = instruction->GetLocations(); |
| 3445 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3446 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3447 | |
| 3448 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3449 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3450 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3451 | |
| 3452 | DCHECK(imm == 1 || imm == -1); |
| 3453 | |
| 3454 | if (instruction->IsRem()) { |
| 3455 | __ xorl(out_register, out_register); |
| 3456 | } else { |
| 3457 | __ movl(out_register, input_register); |
| 3458 | if (imm == -1) { |
| 3459 | __ negl(out_register); |
| 3460 | } |
| 3461 | } |
| 3462 | } |
| 3463 | |
| 3464 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3465 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3466 | LocationSummary* locations = instruction->GetLocations(); |
| 3467 | |
| 3468 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3469 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3470 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3471 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3472 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3473 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3474 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 3475 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3476 | __ leal(num, Address(input_register, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3477 | __ testl(input_register, input_register); |
| 3478 | __ cmovl(kGreaterEqual, num, input_register); |
| 3479 | int shift = CTZ(imm); |
| 3480 | __ sarl(num, Immediate(shift)); |
| 3481 | |
| 3482 | if (imm < 0) { |
| 3483 | __ negl(num); |
| 3484 | } |
| 3485 | |
| 3486 | __ movl(out_register, num); |
| 3487 | } |
| 3488 | |
| 3489 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3490 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3491 | |
| 3492 | LocationSummary* locations = instruction->GetLocations(); |
| 3493 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 3494 | |
| 3495 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 3496 | Register out = locations->Out().AsRegister<Register>(); |
| 3497 | Register num; |
| 3498 | Register edx; |
| 3499 | |
| 3500 | if (instruction->IsDiv()) { |
| 3501 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 3502 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 3503 | } else { |
| 3504 | edx = locations->Out().AsRegister<Register>(); |
| 3505 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 3506 | } |
| 3507 | |
| 3508 | DCHECK_EQ(EAX, eax); |
| 3509 | DCHECK_EQ(EDX, edx); |
| 3510 | if (instruction->IsDiv()) { |
| 3511 | DCHECK_EQ(EAX, out); |
| 3512 | } else { |
| 3513 | DCHECK_EQ(EDX, out); |
| 3514 | } |
| 3515 | |
| 3516 | int64_t magic; |
| 3517 | int shift; |
| 3518 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3519 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3520 | // Save the numerator. |
| 3521 | __ movl(num, eax); |
| 3522 | |
| 3523 | // EAX = magic |
| 3524 | __ movl(eax, Immediate(magic)); |
| 3525 | |
| 3526 | // EDX:EAX = magic * numerator |
| 3527 | __ imull(num); |
| 3528 | |
| 3529 | if (imm > 0 && magic < 0) { |
| 3530 | // EDX += num |
| 3531 | __ addl(edx, num); |
| 3532 | } else if (imm < 0 && magic > 0) { |
| 3533 | __ subl(edx, num); |
| 3534 | } |
| 3535 | |
| 3536 | // Shift if needed. |
| 3537 | if (shift != 0) { |
| 3538 | __ sarl(edx, Immediate(shift)); |
| 3539 | } |
| 3540 | |
| 3541 | // EDX += 1 if EDX < 0 |
| 3542 | __ movl(eax, edx); |
| 3543 | __ shrl(edx, Immediate(31)); |
| 3544 | __ addl(edx, eax); |
| 3545 | |
| 3546 | if (instruction->IsRem()) { |
| 3547 | __ movl(eax, num); |
| 3548 | __ imull(edx, Immediate(imm)); |
| 3549 | __ subl(eax, edx); |
| 3550 | __ movl(edx, eax); |
| 3551 | } else { |
| 3552 | __ movl(eax, edx); |
| 3553 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3554 | } |
| 3555 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3556 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3557 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3558 | |
| 3559 | LocationSummary* locations = instruction->GetLocations(); |
| 3560 | Location out = locations->Out(); |
| 3561 | Location first = locations->InAt(0); |
| 3562 | Location second = locations->InAt(1); |
| 3563 | bool is_div = instruction->IsDiv(); |
| 3564 | |
| 3565 | switch (instruction->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3566 | case DataType::Type::kInt32: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3567 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 3568 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3569 | |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3570 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3571 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3572 | |
| 3573 | if (imm == 0) { |
| 3574 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 3575 | } else if (imm == 1 || imm == -1) { |
| 3576 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3577 | } else if (is_div && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3578 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3579 | } else { |
| 3580 | DCHECK(imm <= -2 || imm >= 2); |
| 3581 | GenerateDivRemWithAnyConstant(instruction); |
| 3582 | } |
| 3583 | } else { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3584 | SlowPathCode* slow_path = new (GetGraph()->GetAllocator()) DivRemMinusOneSlowPathX86( |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3585 | instruction, out.AsRegister<Register>(), is_div); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3586 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3587 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3588 | Register second_reg = second.AsRegister<Register>(); |
| 3589 | // 0x80000000/-1 triggers an arithmetic exception! |
| 3590 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 3591 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3592 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3593 | __ cmpl(second_reg, Immediate(-1)); |
| 3594 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3595 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3596 | // edx:eax <- sign-extended of eax |
| 3597 | __ cdq(); |
| 3598 | // eax = quotient, edx = remainder |
| 3599 | __ idivl(second_reg); |
| 3600 | __ Bind(slow_path->GetExitLabel()); |
| 3601 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3602 | break; |
| 3603 | } |
| 3604 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3605 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3606 | InvokeRuntimeCallingConvention calling_convention; |
| 3607 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3608 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3609 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3610 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3611 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 3612 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 3613 | |
| 3614 | if (is_div) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3615 | codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3616 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3617 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3618 | codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3619 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3620 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3621 | break; |
| 3622 | } |
| 3623 | |
| 3624 | default: |
| 3625 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 3626 | } |
| 3627 | } |
| 3628 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3629 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3630 | LocationSummary::CallKind call_kind = (div->GetResultType() == DataType::Type::kInt64) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3631 | ? LocationSummary::kCallOnMainOnly |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3632 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3633 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(div, call_kind); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3634 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3635 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3636 | case DataType::Type::kInt32: { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3637 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3638 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3639 | locations->SetOut(Location::SameAsFirstInput()); |
| 3640 | // Intel uses edx:eax as the dividend. |
| 3641 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3642 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3643 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 3644 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3645 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3646 | locations->AddTemp(Location::RequiresRegister()); |
| 3647 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3648 | break; |
| 3649 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3650 | case DataType::Type::kInt64: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3651 | InvokeRuntimeCallingConvention calling_convention; |
| 3652 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3653 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3654 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3655 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3656 | // Runtime helper puts the result in EAX, EDX. |
| 3657 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3658 | break; |
| 3659 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3660 | case DataType::Type::kFloat32: |
| 3661 | case DataType::Type::kFloat64: { |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3662 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3663 | if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3664 | DCHECK(div->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3665 | } else if (div->InputAt(1)->IsConstant()) { |
| 3666 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3667 | } else { |
| 3668 | locations->SetInAt(1, Location::Any()); |
| 3669 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3670 | locations->SetOut(Location::SameAsFirstInput()); |
| 3671 | break; |
| 3672 | } |
| 3673 | |
| 3674 | default: |
| 3675 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3676 | } |
| 3677 | } |
| 3678 | |
| 3679 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 3680 | LocationSummary* locations = div->GetLocations(); |
| 3681 | Location first = locations->InAt(0); |
| 3682 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3683 | |
| 3684 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3685 | case DataType::Type::kInt32: |
| 3686 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3687 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3688 | break; |
| 3689 | } |
| 3690 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3691 | case DataType::Type::kFloat32: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3692 | if (second.IsFpuRegister()) { |
| 3693 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3694 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3695 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3696 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3697 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3698 | codegen_->LiteralFloatAddress( |
| 3699 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3700 | const_area->GetBaseMethodAddress(), |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3701 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3702 | } else { |
| 3703 | DCHECK(second.IsStackSlot()); |
| 3704 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3705 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3706 | break; |
| 3707 | } |
| 3708 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3709 | case DataType::Type::kFloat64: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3710 | if (second.IsFpuRegister()) { |
| 3711 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3712 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3713 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3714 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3715 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3716 | codegen_->LiteralDoubleAddress( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3717 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3718 | const_area->GetBaseMethodAddress(), |
| 3719 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3720 | } else { |
| 3721 | DCHECK(second.IsDoubleStackSlot()); |
| 3722 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3723 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3724 | break; |
| 3725 | } |
| 3726 | |
| 3727 | default: |
| 3728 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3729 | } |
| 3730 | } |
| 3731 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3732 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3733 | DataType::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3734 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3735 | LocationSummary::CallKind call_kind = (rem->GetResultType() == DataType::Type::kInt64) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3736 | ? LocationSummary::kCallOnMainOnly |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3737 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3738 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3739 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3740 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3741 | case DataType::Type::kInt32: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3742 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3743 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3744 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3745 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3746 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 3747 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3748 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3749 | locations->AddTemp(Location::RequiresRegister()); |
| 3750 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3751 | break; |
| 3752 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3753 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3754 | InvokeRuntimeCallingConvention calling_convention; |
| 3755 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3756 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3757 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3758 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3759 | // Runtime helper puts the result in EAX, EDX. |
| 3760 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3761 | break; |
| 3762 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3763 | case DataType::Type::kFloat64: |
| 3764 | case DataType::Type::kFloat32: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3765 | locations->SetInAt(0, Location::Any()); |
| 3766 | locations->SetInAt(1, Location::Any()); |
| 3767 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3768 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3769 | break; |
| 3770 | } |
| 3771 | |
| 3772 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3773 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3774 | } |
| 3775 | } |
| 3776 | |
| 3777 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3778 | DataType::Type type = rem->GetResultType(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3779 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3780 | case DataType::Type::kInt32: |
| 3781 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3782 | GenerateDivRemIntegral(rem); |
| 3783 | break; |
| 3784 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3785 | case DataType::Type::kFloat32: |
| 3786 | case DataType::Type::kFloat64: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3787 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3788 | break; |
| 3789 | } |
| 3790 | default: |
| 3791 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3792 | } |
| 3793 | } |
| 3794 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3795 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3796 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3797 | switch (instruction->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3798 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3799 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3800 | case DataType::Type::kInt8: |
| 3801 | case DataType::Type::kUint16: |
| 3802 | case DataType::Type::kInt16: |
| 3803 | case DataType::Type::kInt32: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3804 | locations->SetInAt(0, Location::Any()); |
| 3805 | break; |
| 3806 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3807 | case DataType::Type::kInt64: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3808 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 3809 | if (!instruction->IsConstant()) { |
| 3810 | locations->AddTemp(Location::RequiresRegister()); |
| 3811 | } |
| 3812 | break; |
| 3813 | } |
| 3814 | default: |
| 3815 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3816 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3817 | } |
| 3818 | |
| 3819 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3820 | SlowPathCode* slow_path = new (GetGraph()->GetAllocator()) DivZeroCheckSlowPathX86(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3821 | codegen_->AddSlowPath(slow_path); |
| 3822 | |
| 3823 | LocationSummary* locations = instruction->GetLocations(); |
| 3824 | Location value = locations->InAt(0); |
| 3825 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3826 | switch (instruction->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3827 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3828 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3829 | case DataType::Type::kInt8: |
| 3830 | case DataType::Type::kUint16: |
| 3831 | case DataType::Type::kInt16: |
| 3832 | case DataType::Type::kInt32: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3833 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3834 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3835 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3836 | } else if (value.IsStackSlot()) { |
| 3837 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 3838 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3839 | } else { |
| 3840 | DCHECK(value.IsConstant()) << value; |
| 3841 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 3842 | __ jmp(slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3843 | } |
| 3844 | } |
| 3845 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3846 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3847 | case DataType::Type::kInt64: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3848 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3849 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3850 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 3851 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 3852 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3853 | } else { |
| 3854 | DCHECK(value.IsConstant()) << value; |
| 3855 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3856 | __ jmp(slow_path->GetEntryLabel()); |
| 3857 | } |
| 3858 | } |
| 3859 | break; |
| 3860 | } |
| 3861 | default: |
| 3862 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3863 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3864 | } |
| 3865 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3866 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 3867 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3868 | |
| 3869 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3870 | new (GetGraph()->GetAllocator()) LocationSummary(op, LocationSummary::kNoCall); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3871 | |
| 3872 | switch (op->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3873 | case DataType::Type::kInt32: |
| 3874 | case DataType::Type::kInt64: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3875 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3876 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3877 | // The shift count needs to be in CL or a constant. |
| 3878 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3879 | locations->SetOut(Location::SameAsFirstInput()); |
| 3880 | break; |
| 3881 | } |
| 3882 | default: |
| 3883 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3884 | } |
| 3885 | } |
| 3886 | |
| 3887 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 3888 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3889 | |
| 3890 | LocationSummary* locations = op->GetLocations(); |
| 3891 | Location first = locations->InAt(0); |
| 3892 | Location second = locations->InAt(1); |
| 3893 | DCHECK(first.Equals(locations->Out())); |
| 3894 | |
| 3895 | switch (op->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3896 | case DataType::Type::kInt32: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3897 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3898 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3899 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3900 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3901 | DCHECK_EQ(ECX, second_reg); |
| 3902 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3903 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3904 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3905 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3906 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3907 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3908 | } |
| 3909 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3910 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3911 | if (shift == 0) { |
| 3912 | return; |
| 3913 | } |
| 3914 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3915 | if (op->IsShl()) { |
| 3916 | __ shll(first_reg, imm); |
| 3917 | } else if (op->IsShr()) { |
| 3918 | __ sarl(first_reg, imm); |
| 3919 | } else { |
| 3920 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3921 | } |
| 3922 | } |
| 3923 | break; |
| 3924 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3925 | case DataType::Type::kInt64: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3926 | if (second.IsRegister()) { |
| 3927 | Register second_reg = second.AsRegister<Register>(); |
| 3928 | DCHECK_EQ(ECX, second_reg); |
| 3929 | if (op->IsShl()) { |
| 3930 | GenerateShlLong(first, second_reg); |
| 3931 | } else if (op->IsShr()) { |
| 3932 | GenerateShrLong(first, second_reg); |
| 3933 | } else { |
| 3934 | GenerateUShrLong(first, second_reg); |
| 3935 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3936 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3937 | // Shift by a constant. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3938 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3939 | // Nothing to do if the shift is 0, as the input is already the output. |
| 3940 | if (shift != 0) { |
| 3941 | if (op->IsShl()) { |
| 3942 | GenerateShlLong(first, shift); |
| 3943 | } else if (op->IsShr()) { |
| 3944 | GenerateShrLong(first, shift); |
| 3945 | } else { |
| 3946 | GenerateUShrLong(first, shift); |
| 3947 | } |
| 3948 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3949 | } |
| 3950 | break; |
| 3951 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3952 | default: |
| 3953 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3954 | } |
| 3955 | } |
| 3956 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3957 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 3958 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3959 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 3960 | if (shift == 1) { |
| 3961 | // This is just an addition. |
| 3962 | __ addl(low, low); |
| 3963 | __ adcl(high, high); |
| 3964 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3965 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 3966 | codegen_->EmitParallelMoves( |
| 3967 | loc.ToLow(), |
| 3968 | loc.ToHigh(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3969 | DataType::Type::kInt32, |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3970 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3971 | loc.ToLow(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3972 | DataType::Type::kInt32); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3973 | } else if (shift > 32) { |
| 3974 | // Low part becomes 0. High part is low part << (shift-32). |
| 3975 | __ movl(high, low); |
| 3976 | __ shll(high, Immediate(shift - 32)); |
| 3977 | __ xorl(low, low); |
| 3978 | } else { |
| 3979 | // Between 1 and 31. |
| 3980 | __ shld(high, low, Immediate(shift)); |
| 3981 | __ shll(low, Immediate(shift)); |
| 3982 | } |
| 3983 | } |
| 3984 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3985 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3986 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3987 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 3988 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 3989 | __ testl(shifter, Immediate(32)); |
| 3990 | __ j(kEqual, &done); |
| 3991 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 3992 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 3993 | __ Bind(&done); |
| 3994 | } |
| 3995 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3996 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 3997 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3998 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3999 | if (shift == 32) { |
| 4000 | // Need to copy the sign. |
| 4001 | DCHECK_NE(low, high); |
| 4002 | __ movl(low, high); |
| 4003 | __ sarl(high, Immediate(31)); |
| 4004 | } else if (shift > 32) { |
| 4005 | DCHECK_NE(low, high); |
| 4006 | // High part becomes sign. Low part is shifted by shift - 32. |
| 4007 | __ movl(low, high); |
| 4008 | __ sarl(high, Immediate(31)); |
| 4009 | __ sarl(low, Immediate(shift - 32)); |
| 4010 | } else { |
| 4011 | // Between 1 and 31. |
| 4012 | __ shrd(low, high, Immediate(shift)); |
| 4013 | __ sarl(high, Immediate(shift)); |
| 4014 | } |
| 4015 | } |
| 4016 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4017 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4018 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4019 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4020 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4021 | __ testl(shifter, Immediate(32)); |
| 4022 | __ j(kEqual, &done); |
| 4023 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4024 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 4025 | __ Bind(&done); |
| 4026 | } |
| 4027 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4028 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 4029 | Register low = loc.AsRegisterPairLow<Register>(); |
| 4030 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 4031 | if (shift == 32) { |
| 4032 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 4033 | codegen_->EmitParallelMoves( |
| 4034 | loc.ToHigh(), |
| 4035 | loc.ToLow(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4036 | DataType::Type::kInt32, |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4037 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 4038 | loc.ToHigh(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4039 | DataType::Type::kInt32); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4040 | } else if (shift > 32) { |
| 4041 | // Low part is high >> (shift - 32). High part becomes 0. |
| 4042 | __ movl(low, high); |
| 4043 | __ shrl(low, Immediate(shift - 32)); |
| 4044 | __ xorl(high, high); |
| 4045 | } else { |
| 4046 | // Between 1 and 31. |
| 4047 | __ shrd(low, high, Immediate(shift)); |
| 4048 | __ shrl(high, Immediate(shift)); |
| 4049 | } |
| 4050 | } |
| 4051 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4052 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4053 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4054 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 4055 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 4056 | __ testl(shifter, Immediate(32)); |
| 4057 | __ j(kEqual, &done); |
| 4058 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 4059 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 4060 | __ Bind(&done); |
| 4061 | } |
| 4062 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4063 | void LocationsBuilderX86::VisitRor(HRor* ror) { |
| 4064 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4065 | new (GetGraph()->GetAllocator()) LocationSummary(ror, LocationSummary::kNoCall); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4066 | |
| 4067 | switch (ror->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4068 | case DataType::Type::kInt64: |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4069 | // Add the temporary needed. |
| 4070 | locations->AddTemp(Location::RequiresRegister()); |
| 4071 | FALLTHROUGH_INTENDED; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4072 | case DataType::Type::kInt32: |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4073 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4074 | // The shift count needs to be in CL (unless it is a constant). |
| 4075 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); |
| 4076 | locations->SetOut(Location::SameAsFirstInput()); |
| 4077 | break; |
| 4078 | default: |
| 4079 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4080 | UNREACHABLE(); |
| 4081 | } |
| 4082 | } |
| 4083 | |
| 4084 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { |
| 4085 | LocationSummary* locations = ror->GetLocations(); |
| 4086 | Location first = locations->InAt(0); |
| 4087 | Location second = locations->InAt(1); |
| 4088 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4089 | if (ror->GetResultType() == DataType::Type::kInt32) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4090 | Register first_reg = first.AsRegister<Register>(); |
| 4091 | if (second.IsRegister()) { |
| 4092 | Register second_reg = second.AsRegister<Register>(); |
| 4093 | __ rorl(first_reg, second_reg); |
| 4094 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4095 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4096 | __ rorl(first_reg, imm); |
| 4097 | } |
| 4098 | return; |
| 4099 | } |
| 4100 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4101 | DCHECK_EQ(ror->GetResultType(), DataType::Type::kInt64); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4102 | Register first_reg_lo = first.AsRegisterPairLow<Register>(); |
| 4103 | Register first_reg_hi = first.AsRegisterPairHigh<Register>(); |
| 4104 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 4105 | if (second.IsRegister()) { |
| 4106 | Register second_reg = second.AsRegister<Register>(); |
| 4107 | DCHECK_EQ(second_reg, ECX); |
| 4108 | __ movl(temp_reg, first_reg_hi); |
| 4109 | __ shrd(first_reg_hi, first_reg_lo, second_reg); |
| 4110 | __ shrd(first_reg_lo, temp_reg, second_reg); |
| 4111 | __ movl(temp_reg, first_reg_hi); |
| 4112 | __ testl(second_reg, Immediate(32)); |
| 4113 | __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); |
| 4114 | __ cmovl(kNotEqual, first_reg_lo, temp_reg); |
| 4115 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4116 | int32_t shift_amt = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4117 | if (shift_amt == 0) { |
| 4118 | // Already fine. |
| 4119 | return; |
| 4120 | } |
| 4121 | if (shift_amt == 32) { |
| 4122 | // Just swap. |
| 4123 | __ movl(temp_reg, first_reg_lo); |
| 4124 | __ movl(first_reg_lo, first_reg_hi); |
| 4125 | __ movl(first_reg_hi, temp_reg); |
| 4126 | return; |
| 4127 | } |
| 4128 | |
| 4129 | Immediate imm(shift_amt); |
| 4130 | // Save the constents of the low value. |
| 4131 | __ movl(temp_reg, first_reg_lo); |
| 4132 | |
| 4133 | // Shift right into low, feeding bits from high. |
| 4134 | __ shrd(first_reg_lo, first_reg_hi, imm); |
| 4135 | |
| 4136 | // Shift right into high, feeding bits from the original low. |
| 4137 | __ shrd(first_reg_hi, temp_reg, imm); |
| 4138 | |
| 4139 | // Swap if needed. |
| 4140 | if (shift_amt > 32) { |
| 4141 | __ movl(temp_reg, first_reg_lo); |
| 4142 | __ movl(first_reg_lo, first_reg_hi); |
| 4143 | __ movl(first_reg_hi, temp_reg); |
| 4144 | } |
| 4145 | } |
| 4146 | } |
| 4147 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4148 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 4149 | HandleShift(shl); |
| 4150 | } |
| 4151 | |
| 4152 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 4153 | HandleShift(shl); |
| 4154 | } |
| 4155 | |
| 4156 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 4157 | HandleShift(shr); |
| 4158 | } |
| 4159 | |
| 4160 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 4161 | HandleShift(shr); |
| 4162 | } |
| 4163 | |
| 4164 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 4165 | HandleShift(ushr); |
| 4166 | } |
| 4167 | |
| 4168 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 4169 | HandleShift(ushr); |
| 4170 | } |
| 4171 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4172 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4173 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4174 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4175 | locations->SetOut(Location::RegisterLocation(EAX)); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4176 | if (instruction->IsStringAlloc()) { |
| 4177 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4178 | } else { |
| 4179 | InvokeRuntimeCallingConvention calling_convention; |
| 4180 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4181 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4182 | } |
| 4183 | |
| 4184 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4185 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4186 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4187 | if (instruction->IsStringAlloc()) { |
| 4188 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4189 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4190 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4191 | __ fs()->movl(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString))); |
| 4192 | __ call(Address(temp, code_offset.Int32Value())); |
| 4193 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4194 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 4195 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 4196 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4197 | DCHECK(!codegen_->IsLeafMethod()); |
| 4198 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4199 | } |
| 4200 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4201 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4202 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4203 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4204 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 4205 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4206 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4207 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4208 | } |
| 4209 | |
| 4210 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4211 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4212 | // of poisoning the reference. |
Nicolas Geoffray | d095844 | 2017-01-30 14:57:16 +0000 | [diff] [blame] | 4213 | QuickEntrypointEnum entrypoint = |
| 4214 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 4215 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4216 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4217 | DCHECK(!codegen_->IsLeafMethod()); |
| 4218 | } |
| 4219 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4220 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4221 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4222 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4223 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4224 | if (location.IsStackSlot()) { |
| 4225 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4226 | } else if (location.IsDoubleStackSlot()) { |
| 4227 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4228 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4229 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4230 | } |
| 4231 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4232 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 4233 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 4234 | } |
| 4235 | |
| 4236 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4237 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4238 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4239 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4240 | } |
| 4241 | |
| 4242 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4243 | } |
| 4244 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4245 | void LocationsBuilderX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4246 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4247 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4248 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4249 | locations->SetOut(Location::RequiresRegister()); |
| 4250 | } |
| 4251 | |
| 4252 | void InstructionCodeGeneratorX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4253 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4254 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4255 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4256 | instruction->GetIndex(), kX86PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4257 | __ movl(locations->Out().AsRegister<Register>(), |
| 4258 | Address(locations->InAt(0).AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4259 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4260 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4261 | instruction->GetIndex(), kX86PointerSize)); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4262 | __ movl(locations->Out().AsRegister<Register>(), |
| 4263 | Address(locations->InAt(0).AsRegister<Register>(), |
| 4264 | mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
| 4265 | // temp = temp->GetImtEntryAt(method_offset); |
| 4266 | __ movl(locations->Out().AsRegister<Register>(), |
| 4267 | Address(locations->Out().AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4268 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4269 | } |
| 4270 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4271 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4272 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4273 | new (GetGraph()->GetAllocator()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4274 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4275 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4276 | } |
| 4277 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4278 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 4279 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4280 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4281 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4282 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4283 | switch (not_->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4284 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4285 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4286 | break; |
| 4287 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4288 | case DataType::Type::kInt64: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4289 | __ notl(out.AsRegisterPairLow<Register>()); |
| 4290 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4291 | break; |
| 4292 | |
| 4293 | default: |
| 4294 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4295 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4296 | } |
| 4297 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4298 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4299 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4300 | new (GetGraph()->GetAllocator()) LocationSummary(bool_not, LocationSummary::kNoCall); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4301 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4302 | locations->SetOut(Location::SameAsFirstInput()); |
| 4303 | } |
| 4304 | |
| 4305 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4306 | LocationSummary* locations = bool_not->GetLocations(); |
| 4307 | Location in = locations->InAt(0); |
| 4308 | Location out = locations->Out(); |
| 4309 | DCHECK(in.Equals(out)); |
| 4310 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 4311 | } |
| 4312 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4313 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4314 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4315 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4316 | switch (compare->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4317 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4318 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4319 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4320 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4321 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4322 | case DataType::Type::kInt32: |
| 4323 | case DataType::Type::kInt64: { |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4324 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4325 | locations->SetInAt(1, Location::Any()); |
| 4326 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4327 | break; |
| 4328 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4329 | case DataType::Type::kFloat32: |
| 4330 | case DataType::Type::kFloat64: { |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4331 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4332 | if (compare->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4333 | DCHECK(compare->InputAt(1)->IsEmittedAtUseSite()); |
| 4334 | } else if (compare->InputAt(1)->IsConstant()) { |
| 4335 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4336 | } else { |
| 4337 | locations->SetInAt(1, Location::Any()); |
| 4338 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4339 | locations->SetOut(Location::RequiresRegister()); |
| 4340 | break; |
| 4341 | } |
| 4342 | default: |
| 4343 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4344 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4345 | } |
| 4346 | |
| 4347 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4348 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4349 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4350 | Location left = locations->InAt(0); |
| 4351 | Location right = locations->InAt(1); |
| 4352 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4353 | NearLabel less, greater, done; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4354 | Condition less_cond = kLess; |
| 4355 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4356 | switch (compare->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4357 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4358 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4359 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4360 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4361 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4362 | case DataType::Type::kInt32: { |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 4363 | codegen_->GenerateIntCompare(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4364 | break; |
| 4365 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4366 | case DataType::Type::kInt64: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4367 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 4368 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 4369 | int32_t val_low = 0; |
| 4370 | int32_t val_high = 0; |
| 4371 | bool right_is_const = false; |
| 4372 | |
| 4373 | if (right.IsConstant()) { |
| 4374 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 4375 | right_is_const = true; |
| 4376 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 4377 | val_low = Low32Bits(val); |
| 4378 | val_high = High32Bits(val); |
| 4379 | } |
| 4380 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4381 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4382 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4383 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4384 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4385 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4386 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4387 | codegen_->Compare32BitValue(left_high, val_high); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4388 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4389 | __ j(kLess, &less); // Signed compare. |
| 4390 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4391 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4392 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4393 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4394 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4395 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4396 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4397 | codegen_->Compare32BitValue(left_low, val_low); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4398 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4399 | less_cond = kBelow; // for CF (unsigned). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4400 | break; |
| 4401 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4402 | case DataType::Type::kFloat32: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4403 | GenerateFPCompare(left, right, compare, false); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4404 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4405 | less_cond = kBelow; // for CF (floats). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4406 | break; |
| 4407 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4408 | case DataType::Type::kFloat64: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4409 | GenerateFPCompare(left, right, compare, true); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4410 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4411 | less_cond = kBelow; // for CF (floats). |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4412 | break; |
| 4413 | } |
| 4414 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4415 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4416 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4417 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4418 | __ movl(out, Immediate(0)); |
| 4419 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4420 | __ j(less_cond, &less); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4421 | |
| 4422 | __ Bind(&greater); |
| 4423 | __ movl(out, Immediate(1)); |
| 4424 | __ jmp(&done); |
| 4425 | |
| 4426 | __ Bind(&less); |
| 4427 | __ movl(out, Immediate(-1)); |
| 4428 | |
| 4429 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4430 | } |
| 4431 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4432 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4433 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4434 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4435 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4436 | locations->SetInAt(i, Location::Any()); |
| 4437 | } |
| 4438 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4439 | } |
| 4440 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4441 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4442 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4443 | } |
| 4444 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4445 | void CodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4446 | /* |
| 4447 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 4448 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 4449 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4450 | */ |
| 4451 | switch (kind) { |
| 4452 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4453 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4454 | break; |
| 4455 | } |
| 4456 | case MemBarrierKind::kAnyStore: |
| 4457 | case MemBarrierKind::kLoadAny: |
| 4458 | case MemBarrierKind::kStoreStore: { |
| 4459 | // nop |
| 4460 | break; |
| 4461 | } |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4462 | case MemBarrierKind::kNTStoreStore: |
| 4463 | // Non-Temporal Store/Store needs an explicit fence. |
| 4464 | MemoryFence(/* non-temporal */ true); |
| 4465 | break; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4466 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4467 | } |
| 4468 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4469 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( |
| 4470 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4471 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4472 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4473 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4474 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4475 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 4476 | Register temp) { |
| 4477 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4478 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4479 | if (!invoke->GetLocations()->Intrinsified()) { |
| 4480 | return location.AsRegister<Register>(); |
| 4481 | } |
| 4482 | // For intrinsics we allow any location, so it may be on the stack. |
| 4483 | if (!location.IsRegister()) { |
| 4484 | __ movl(temp, Address(ESP, location.GetStackIndex())); |
| 4485 | return temp; |
| 4486 | } |
| 4487 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 4488 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 4489 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 4490 | // simple and more robust approach rather that trying to determine if that's the case. |
| 4491 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
Vladimir Marko | 4ee8e29 | 2017-06-02 15:39:30 +0000 | [diff] [blame] | 4492 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 4493 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 4494 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 4495 | __ movl(temp, Address(ESP, stack_offset)); |
| 4496 | return temp; |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4497 | } |
| 4498 | return location.AsRegister<Register>(); |
| 4499 | } |
| 4500 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4501 | void CodeGeneratorX86::GenerateStaticOrDirectCall( |
| 4502 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4503 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4504 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4505 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4506 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4507 | uint32_t offset = |
| 4508 | GetThreadOffset<kX86PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 4509 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4510 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4511 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4512 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4513 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4514 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4515 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 4516 | DCHECK(GetCompilerOptions().IsBootImage()); |
| 4517 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4518 | temp.AsRegister<Register>()); |
| 4519 | __ leal(temp.AsRegister<Register>(), Address(base_reg, CodeGeneratorX86::kDummy32BitOffset)); |
| 4520 | RecordBootMethodPatch(invoke); |
| 4521 | break; |
| 4522 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4523 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4524 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 4525 | break; |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4526 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4527 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4528 | temp.AsRegister<Register>()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4529 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4530 | // Bind a new fixup label at the end of the "movl" insn. |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4531 | __ Bind(NewMethodBssEntryPatch( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4532 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(), |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4533 | MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()))); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4534 | break; |
| 4535 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4536 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 4537 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 4538 | return; // No code pointer retrieval; the runtime performs the call directly. |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4539 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4540 | } |
| 4541 | |
| 4542 | switch (invoke->GetCodePtrLocation()) { |
| 4543 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 4544 | __ call(GetFrameEntryLabel()); |
| 4545 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4546 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4547 | // (callee_method + offset_of_quick_compiled_code)() |
| 4548 | __ call(Address(callee_method.AsRegister<Register>(), |
| 4549 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4550 | kX86PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4551 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4552 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4553 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4554 | |
| 4555 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4556 | } |
| 4557 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4558 | void CodeGeneratorX86::GenerateVirtualCall( |
| 4559 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4560 | Register temp = temp_in.AsRegister<Register>(); |
| 4561 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4562 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4563 | |
| 4564 | // Use the calling convention instead of the location of the receiver, as |
| 4565 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4566 | // slow path, the arguments have been moved to the right place, so here we are |
| 4567 | // guaranteed that the receiver is the first register of the calling convention. |
| 4568 | InvokeDexCallingConvention calling_convention; |
| 4569 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4570 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4571 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4572 | __ movl(temp, Address(receiver, class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4573 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4574 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4575 | // emit a read barrier for the previous class reference load. |
| 4576 | // However this is not required in practice, as this is an |
| 4577 | // intermediate/temporary reference and because the current |
| 4578 | // concurrent copying collector keeps the from-space memory |
| 4579 | // intact/accessible until the end of the marking phase (the |
| 4580 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4581 | __ MaybeUnpoisonHeapReference(temp); |
| 4582 | // temp = temp->GetMethodAt(method_offset); |
| 4583 | __ movl(temp, Address(temp, method_offset)); |
| 4584 | // call temp->GetEntryPoint(); |
| 4585 | __ call(Address( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4586 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4587 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4588 | } |
| 4589 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4590 | void CodeGeneratorX86::RecordBootMethodPatch(HInvokeStaticOrDirect* invoke) { |
| 4591 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 4592 | HX86ComputeBaseMethodAddress* address = |
| 4593 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); |
| 4594 | boot_image_method_patches_.emplace_back(address, |
| 4595 | *invoke->GetTargetMethod().dex_file, |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 4596 | invoke->GetTargetMethod().index); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4597 | __ Bind(&boot_image_method_patches_.back().label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4598 | } |
| 4599 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4600 | Label* CodeGeneratorX86::NewMethodBssEntryPatch( |
| 4601 | HX86ComputeBaseMethodAddress* method_address, |
| 4602 | MethodReference target_method) { |
| 4603 | // Add the patch entry and bind its label at the end of the instruction. |
| 4604 | method_bss_entry_patches_.emplace_back(method_address, |
| 4605 | *target_method.dex_file, |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 4606 | target_method.index); |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4607 | return &method_bss_entry_patches_.back().label; |
| 4608 | } |
| 4609 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4610 | void CodeGeneratorX86::RecordBootTypePatch(HLoadClass* load_class) { |
Vladimir Marko | 00916b9 | 2017-05-17 17:45:45 +0100 | [diff] [blame] | 4611 | HX86ComputeBaseMethodAddress* address = load_class->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4612 | boot_image_type_patches_.emplace_back(address, |
| 4613 | load_class->GetDexFile(), |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4614 | load_class->GetTypeIndex().index_); |
| 4615 | __ Bind(&boot_image_type_patches_.back().label); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4616 | } |
| 4617 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4618 | Label* CodeGeneratorX86::NewTypeBssEntryPatch(HLoadClass* load_class) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4619 | HX86ComputeBaseMethodAddress* address = |
| 4620 | load_class->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 4621 | type_bss_entry_patches_.emplace_back( |
| 4622 | address, load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4623 | return &type_bss_entry_patches_.back().label; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4624 | } |
| 4625 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4626 | void CodeGeneratorX86::RecordBootStringPatch(HLoadString* load_string) { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4627 | HX86ComputeBaseMethodAddress* address = load_string->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
| 4628 | string_patches_.emplace_back(address, |
| 4629 | load_string->GetDexFile(), |
| 4630 | load_string->GetStringIndex().index_); |
| 4631 | __ Bind(&string_patches_.back().label); |
| 4632 | } |
| 4633 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4634 | Label* CodeGeneratorX86::NewStringBssEntryPatch(HLoadString* load_string) { |
| 4635 | DCHECK(!GetCompilerOptions().IsBootImage()); |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4636 | HX86ComputeBaseMethodAddress* address = |
| 4637 | load_string->InputAt(0)->AsX86ComputeBaseMethodAddress(); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4638 | string_bss_entry_patches_.emplace_back( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4639 | address, load_string->GetDexFile(), load_string->GetStringIndex().index_); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4640 | return &string_bss_entry_patches_.back().label; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4641 | } |
| 4642 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4643 | // The label points to the end of the "movl" or another instruction but the literal offset |
| 4644 | // for method patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 4645 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
| 4646 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4647 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4648 | inline void CodeGeneratorX86::EmitPcRelativeLinkerPatches( |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4649 | const ArenaDeque<X86PcRelativePatchInfo>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4650 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4651 | for (const X86PcRelativePatchInfo& info : infos) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4652 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4653 | linker_patches->push_back(Factory( |
| 4654 | literal_offset, &info.dex_file, GetMethodAddressOffset(info.method_address), info.index)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4655 | } |
| 4656 | } |
| 4657 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4658 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4659 | DCHECK(linker_patches->empty()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4660 | size_t size = |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4661 | boot_image_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4662 | method_bss_entry_patches_.size() + |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4663 | boot_image_type_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4664 | type_bss_entry_patches_.size() + |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4665 | string_patches_.size() + |
| 4666 | string_bss_entry_patches_.size(); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4667 | linker_patches->reserve(size); |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 4668 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4669 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
| 4670 | boot_image_method_patches_, linker_patches); |
| 4671 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
| 4672 | boot_image_type_patches_, linker_patches); |
| 4673 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
| 4674 | string_patches_, linker_patches); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4675 | } else { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4676 | DCHECK(boot_image_method_patches_.empty()); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4677 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeClassTablePatch>( |
| 4678 | boot_image_type_patches_, linker_patches); |
| 4679 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringInternTablePatch>( |
| 4680 | string_patches_, linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4681 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4682 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 4683 | method_bss_entry_patches_, linker_patches); |
| 4684 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 4685 | type_bss_entry_patches_, linker_patches); |
| 4686 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 4687 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4688 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4689 | } |
| 4690 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4691 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 4692 | Register card, |
| 4693 | Register object, |
| 4694 | Register value, |
| 4695 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4696 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4697 | if (value_can_be_null) { |
| 4698 | __ testl(value, value); |
| 4699 | __ j(kEqual, &is_null); |
| 4700 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4701 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86PointerSize>().Int32Value())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4702 | __ movl(temp, object); |
| 4703 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4704 | __ movb(Address(temp, card, TIMES_1, 0), |
| 4705 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4706 | if (value_can_be_null) { |
| 4707 | __ Bind(&is_null); |
| 4708 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4709 | } |
| 4710 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4711 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4712 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4713 | |
| 4714 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4715 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4716 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4717 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 4718 | kEmitCompilerReadBarrier |
| 4719 | ? LocationSummary::kCallOnSlowPath |
| 4720 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4721 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4722 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4723 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4724 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4725 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4726 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4727 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4728 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4729 | // The output overlaps in case of long: we don't want the low move |
| 4730 | // to overwrite the object's location. Likewise, in the case of |
| 4731 | // an object field get with read barriers enabled, we do not want |
| 4732 | // the move to overwrite the object's location, as we need it to emit |
| 4733 | // the read barrier. |
| 4734 | locations->SetOut( |
| 4735 | Location::RequiresRegister(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4736 | (object_field_get_with_read_barrier || instruction->GetType() == DataType::Type::kInt64) ? |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4737 | Location::kOutputOverlap : |
| 4738 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4739 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4740 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4741 | if (field_info.IsVolatile() && (field_info.GetFieldType() == DataType::Type::kInt64)) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4742 | // Long values can be loaded atomically into an XMM using movsd. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4743 | // So we use an XMM register as a temp to achieve atomicity (first |
| 4744 | // load the temp into the XMM and then copy the XMM into the |
| 4745 | // output, 32 bits at a time). |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4746 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4747 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4748 | } |
| 4749 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4750 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 4751 | const FieldInfo& field_info) { |
| 4752 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4753 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4754 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4755 | Location base_loc = locations->InAt(0); |
| 4756 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4757 | Location out = locations->Out(); |
| 4758 | bool is_volatile = field_info.IsVolatile(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4759 | DataType::Type field_type = field_info.GetFieldType(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4760 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4761 | |
| 4762 | switch (field_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4763 | case DataType::Type::kBool: |
| 4764 | case DataType::Type::kUint8: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4765 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4766 | break; |
| 4767 | } |
| 4768 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4769 | case DataType::Type::kInt8: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4770 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4771 | break; |
| 4772 | } |
| 4773 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4774 | case DataType::Type::kUint16: { |
| 4775 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4776 | break; |
| 4777 | } |
| 4778 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4779 | case DataType::Type::kInt16: { |
| 4780 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4781 | break; |
| 4782 | } |
| 4783 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4784 | case DataType::Type::kInt32: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4785 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4786 | break; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4787 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4788 | case DataType::Type::kReference: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4789 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4790 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4791 | // Note that a potential implicit null check is handled in this |
| 4792 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 4793 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 4794 | instruction, out, base, offset, /* needs_null_check */ true); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4795 | if (is_volatile) { |
| 4796 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4797 | } |
| 4798 | } else { |
| 4799 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| 4800 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4801 | if (is_volatile) { |
| 4802 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4803 | } |
| 4804 | // If read barriers are enabled, emit read barriers other than |
| 4805 | // Baker's using a slow path (and also unpoison the loaded |
| 4806 | // reference, if heap poisoning is enabled). |
| 4807 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4808 | } |
| 4809 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4810 | } |
| 4811 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4812 | case DataType::Type::kInt64: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4813 | if (is_volatile) { |
| 4814 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4815 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4816 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4817 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 4818 | __ psrlq(temp, Immediate(32)); |
| 4819 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 4820 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4821 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4822 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4823 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4824 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 4825 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4826 | break; |
| 4827 | } |
| 4828 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4829 | case DataType::Type::kFloat32: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4830 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4831 | break; |
| 4832 | } |
| 4833 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4834 | case DataType::Type::kFloat64: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4835 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4836 | break; |
| 4837 | } |
| 4838 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4839 | case DataType::Type::kVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4840 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4841 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4842 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4843 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4844 | if (field_type == DataType::Type::kReference || field_type == DataType::Type::kInt64) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4845 | // Potential implicit null checks, in the case of reference or |
| 4846 | // long fields, are handled in the previous switch statement. |
| 4847 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4848 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4849 | } |
| 4850 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4851 | if (is_volatile) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4852 | if (field_type == DataType::Type::kReference) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4853 | // Memory barriers, in the case of references, are also handled |
| 4854 | // in the previous switch statement. |
| 4855 | } else { |
| 4856 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4857 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4858 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4859 | } |
| 4860 | |
| 4861 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4862 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4863 | |
| 4864 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4865 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4866 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4867 | bool is_volatile = field_info.IsVolatile(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4868 | DataType::Type field_type = field_info.GetFieldType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4869 | bool is_byte_type = DataType::Size(field_type) == 1u; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4870 | |
| 4871 | // The register allocator does not support multiple |
| 4872 | // inputs that die at entry with one in a specific register. |
| 4873 | if (is_byte_type) { |
| 4874 | // Ensure the value is in a byte register. |
| 4875 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4876 | } else if (DataType::IsFloatingPointType(field_type)) { |
| 4877 | if (is_volatile && field_type == DataType::Type::kFloat64) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4878 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4879 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4880 | } else { |
| 4881 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4882 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4883 | } else if (is_volatile && field_type == DataType::Type::kInt64) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4884 | // 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] | 4885 | locations->SetInAt(1, Location::RequiresRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4886 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4887 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 4888 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 4889 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 4890 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 4891 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 4892 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4893 | locations->AddTemp(Location::RequiresFpuRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4894 | } else { |
| 4895 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4896 | |
| 4897 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4898 | // Temporary registers for the write barrier. |
| 4899 | locations->AddTemp(Location::RequiresRegister()); // May be used for reference poisoning too. |
| 4900 | // Ensure the card is in a byte register. |
| 4901 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 4902 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4903 | } |
| 4904 | } |
| 4905 | |
| 4906 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4907 | const FieldInfo& field_info, |
| 4908 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4909 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4910 | |
| 4911 | LocationSummary* locations = instruction->GetLocations(); |
| 4912 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 4913 | Location value = locations->InAt(1); |
| 4914 | bool is_volatile = field_info.IsVolatile(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4915 | DataType::Type field_type = field_info.GetFieldType(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4916 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4917 | bool needs_write_barrier = |
| 4918 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4919 | |
| 4920 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4921 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4922 | } |
| 4923 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4924 | bool maybe_record_implicit_null_check_done = false; |
| 4925 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4926 | switch (field_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4927 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4928 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4929 | case DataType::Type::kInt8: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4930 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 4931 | break; |
| 4932 | } |
| 4933 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4934 | case DataType::Type::kUint16: |
| 4935 | case DataType::Type::kInt16: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4936 | if (value.IsConstant()) { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 4937 | __ movw(Address(base, offset), |
| 4938 | Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4939 | } else { |
| 4940 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 4941 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4942 | break; |
| 4943 | } |
| 4944 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4945 | case DataType::Type::kInt32: |
| 4946 | case DataType::Type::kReference: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4947 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4948 | // Note that in the case where `value` is a null reference, |
| 4949 | // we do not enter this block, as the reference does not |
| 4950 | // need poisoning. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4951 | DCHECK_EQ(field_type, DataType::Type::kReference); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4952 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4953 | __ movl(temp, value.AsRegister<Register>()); |
| 4954 | __ PoisonHeapReference(temp); |
| 4955 | __ movl(Address(base, offset), temp); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4956 | } else if (value.IsConstant()) { |
| 4957 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4958 | __ movl(Address(base, offset), Immediate(v)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4959 | } else { |
Nicolas Geoffray | 0397163 | 2016-03-17 10:44:24 +0000 | [diff] [blame] | 4960 | DCHECK(value.IsRegister()) << value; |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4961 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 4962 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4963 | break; |
| 4964 | } |
| 4965 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4966 | case DataType::Type::kInt64: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4967 | if (is_volatile) { |
| 4968 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4969 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 4970 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 4971 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 4972 | __ punpckldq(temp1, temp2); |
| 4973 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4974 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4975 | } else if (value.IsConstant()) { |
| 4976 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4977 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4978 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4979 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4980 | } else { |
| 4981 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4982 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4983 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 4984 | } |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4985 | maybe_record_implicit_null_check_done = true; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4986 | break; |
| 4987 | } |
| 4988 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4989 | case DataType::Type::kFloat32: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4990 | if (value.IsConstant()) { |
| 4991 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4992 | __ movl(Address(base, offset), Immediate(v)); |
| 4993 | } else { |
| 4994 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4995 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4996 | break; |
| 4997 | } |
| 4998 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4999 | case DataType::Type::kFloat64: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5000 | if (value.IsConstant()) { |
| 5001 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 5002 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 5003 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5004 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
| 5005 | maybe_record_implicit_null_check_done = true; |
| 5006 | } else { |
| 5007 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 5008 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5009 | break; |
| 5010 | } |
| 5011 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5012 | case DataType::Type::kVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5013 | LOG(FATAL) << "Unreachable type " << field_type; |
| 5014 | UNREACHABLE(); |
| 5015 | } |
| 5016 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5017 | if (!maybe_record_implicit_null_check_done) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5018 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5019 | } |
| 5020 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5021 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5022 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5023 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5024 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5025 | } |
| 5026 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5027 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5028 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5029 | } |
| 5030 | } |
| 5031 | |
| 5032 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5033 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5034 | } |
| 5035 | |
| 5036 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5037 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5038 | } |
| 5039 | |
| 5040 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 5041 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5042 | } |
| 5043 | |
| 5044 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5045 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5046 | } |
| 5047 | |
| 5048 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5049 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5050 | } |
| 5051 | |
| 5052 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* 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::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5057 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5058 | } |
| 5059 | |
| 5060 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5061 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5062 | } |
| 5063 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5064 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 5065 | HUnresolvedInstanceFieldGet* instruction) { |
| 5066 | FieldAccessCallingConventionX86 calling_convention; |
| 5067 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5068 | instruction, instruction->GetFieldType(), calling_convention); |
| 5069 | } |
| 5070 | |
| 5071 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 5072 | HUnresolvedInstanceFieldGet* instruction) { |
| 5073 | FieldAccessCallingConventionX86 calling_convention; |
| 5074 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5075 | instruction->GetFieldType(), |
| 5076 | instruction->GetFieldIndex(), |
| 5077 | instruction->GetDexPc(), |
| 5078 | calling_convention); |
| 5079 | } |
| 5080 | |
| 5081 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 5082 | HUnresolvedInstanceFieldSet* instruction) { |
| 5083 | FieldAccessCallingConventionX86 calling_convention; |
| 5084 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5085 | instruction, instruction->GetFieldType(), calling_convention); |
| 5086 | } |
| 5087 | |
| 5088 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 5089 | HUnresolvedInstanceFieldSet* instruction) { |
| 5090 | FieldAccessCallingConventionX86 calling_convention; |
| 5091 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5092 | instruction->GetFieldType(), |
| 5093 | instruction->GetFieldIndex(), |
| 5094 | instruction->GetDexPc(), |
| 5095 | calling_convention); |
| 5096 | } |
| 5097 | |
| 5098 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 5099 | HUnresolvedStaticFieldGet* instruction) { |
| 5100 | FieldAccessCallingConventionX86 calling_convention; |
| 5101 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5102 | instruction, instruction->GetFieldType(), calling_convention); |
| 5103 | } |
| 5104 | |
| 5105 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 5106 | HUnresolvedStaticFieldGet* instruction) { |
| 5107 | FieldAccessCallingConventionX86 calling_convention; |
| 5108 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5109 | instruction->GetFieldType(), |
| 5110 | instruction->GetFieldIndex(), |
| 5111 | instruction->GetDexPc(), |
| 5112 | calling_convention); |
| 5113 | } |
| 5114 | |
| 5115 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 5116 | HUnresolvedStaticFieldSet* instruction) { |
| 5117 | FieldAccessCallingConventionX86 calling_convention; |
| 5118 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5119 | instruction, instruction->GetFieldType(), calling_convention); |
| 5120 | } |
| 5121 | |
| 5122 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 5123 | HUnresolvedStaticFieldSet* instruction) { |
| 5124 | FieldAccessCallingConventionX86 calling_convention; |
| 5125 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5126 | instruction->GetFieldType(), |
| 5127 | instruction->GetFieldIndex(), |
| 5128 | instruction->GetDexPc(), |
| 5129 | calling_convention); |
| 5130 | } |
| 5131 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5132 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5133 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5134 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 5135 | ? Location::RequiresRegister() |
| 5136 | : Location::Any(); |
| 5137 | locations->SetInAt(0, loc); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5138 | } |
| 5139 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5140 | void CodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5141 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5142 | return; |
| 5143 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5144 | LocationSummary* locations = instruction->GetLocations(); |
| 5145 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5146 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5147 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5148 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5149 | } |
| 5150 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5151 | void CodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5152 | SlowPathCode* slow_path = new (GetGraph()->GetAllocator()) NullCheckSlowPathX86(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5153 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5154 | |
| 5155 | LocationSummary* locations = instruction->GetLocations(); |
| 5156 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5157 | |
| 5158 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 5159 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5160 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5161 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5162 | } else { |
| 5163 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5164 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5165 | __ jmp(slow_path->GetEntryLabel()); |
| 5166 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5167 | } |
| 5168 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5169 | } |
| 5170 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5171 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5172 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5173 | } |
| 5174 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5175 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5176 | bool object_array_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5177 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5178 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5179 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 5180 | object_array_get_with_read_barrier |
| 5181 | ? LocationSummary::kCallOnSlowPath |
| 5182 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5183 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5184 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5185 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5186 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5187 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5188 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5189 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5190 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5191 | // The output overlaps in case of long: we don't want the low move |
| 5192 | // to overwrite the array's location. Likewise, in the case of an |
| 5193 | // object array get with read barriers enabled, we do not want the |
| 5194 | // move to overwrite the array's location, as we need it to emit |
| 5195 | // the read barrier. |
| 5196 | locations->SetOut( |
| 5197 | Location::RequiresRegister(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5198 | (instruction->GetType() == DataType::Type::kInt64 || object_array_get_with_read_barrier) |
| 5199 | ? Location::kOutputOverlap |
| 5200 | : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5201 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5202 | } |
| 5203 | |
| 5204 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 5205 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5206 | Location obj_loc = locations->InAt(0); |
| 5207 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5208 | Location index = locations->InAt(1); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5209 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5210 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5211 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5212 | DataType::Type type = instruction->GetType(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5213 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5214 | case DataType::Type::kBool: |
| 5215 | case DataType::Type::kUint8: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5216 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5217 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5218 | break; |
| 5219 | } |
| 5220 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5221 | case DataType::Type::kInt8: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5222 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5223 | __ movsxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5224 | break; |
| 5225 | } |
| 5226 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5227 | case DataType::Type::kUint16: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5228 | Register out = out_loc.AsRegister<Register>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5229 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5230 | // Branch cases into compressed and uncompressed for each index's type. |
| 5231 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 5232 | NearLabel done, not_compressed; |
Vladimir Marko | 3c89d42 | 2017-02-17 11:30:23 +0000 | [diff] [blame] | 5233 | __ testb(Address(obj, count_offset), Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5234 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5235 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 5236 | "Expecting 0=compressed, 1=uncompressed"); |
| 5237 | __ j(kNotZero, ¬_compressed); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5238 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| 5239 | __ jmp(&done); |
| 5240 | __ Bind(¬_compressed); |
| 5241 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5242 | __ Bind(&done); |
| 5243 | } else { |
| 5244 | // Common case for charAt of array of char or when string compression's |
| 5245 | // feature is turned off. |
| 5246 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5247 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5248 | break; |
| 5249 | } |
| 5250 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5251 | case DataType::Type::kInt16: { |
| 5252 | Register out = out_loc.AsRegister<Register>(); |
| 5253 | __ movsxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5254 | break; |
| 5255 | } |
| 5256 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5257 | case DataType::Type::kInt32: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5258 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5259 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5260 | break; |
| 5261 | } |
| 5262 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5263 | case DataType::Type::kReference: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5264 | static_assert( |
| 5265 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5266 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5267 | // /* HeapReference<Object> */ out = |
| 5268 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5269 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5270 | // Note that a potential implicit null check is handled in this |
| 5271 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 5272 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5273 | instruction, out_loc, obj, data_offset, index, /* needs_null_check */ true); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5274 | } else { |
| 5275 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5276 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| 5277 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5278 | // If read barriers are enabled, emit read barriers other than |
| 5279 | // Baker's using a slow path (and also unpoison the loaded |
| 5280 | // reference, if heap poisoning is enabled). |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5281 | if (index.IsConstant()) { |
| 5282 | uint32_t offset = |
| 5283 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5284 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5285 | } else { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5286 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5287 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5288 | } |
| 5289 | } |
| 5290 | break; |
| 5291 | } |
| 5292 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5293 | case DataType::Type::kInt64: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5294 | DCHECK_NE(obj, out_loc.AsRegisterPairLow<Register>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5295 | __ movl(out_loc.AsRegisterPairLow<Register>(), |
| 5296 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
| 5297 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5298 | __ movl(out_loc.AsRegisterPairHigh<Register>(), |
| 5299 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5300 | break; |
| 5301 | } |
| 5302 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5303 | case DataType::Type::kFloat32: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5304 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5305 | __ movss(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5306 | break; |
| 5307 | } |
| 5308 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5309 | case DataType::Type::kFloat64: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5310 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5311 | __ movsd(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5312 | break; |
| 5313 | } |
| 5314 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5315 | case DataType::Type::kVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5316 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5317 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5318 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5319 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5320 | if (type == DataType::Type::kReference || type == DataType::Type::kInt64) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5321 | // Potential implicit null checks, in the case of reference or |
| 5322 | // long arrays, are handled in the previous switch statement. |
| 5323 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5324 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5325 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5326 | } |
| 5327 | |
| 5328 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5329 | DataType::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5330 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5331 | bool needs_write_barrier = |
| 5332 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5333 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5334 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5335 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5336 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 5337 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5338 | LocationSummary::kCallOnSlowPath : |
| 5339 | LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5340 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5341 | bool is_byte_type = DataType::Size(value_type) == 1u; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5342 | // We need the inputs to be different than the output in case of long operation. |
| 5343 | // In case of a byte operation, the register allocator does not support multiple |
| 5344 | // inputs that die at entry with one in a specific register. |
| 5345 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5346 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5347 | if (is_byte_type) { |
| 5348 | // Ensure the value is in a byte register. |
| 5349 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5350 | } else if (DataType::IsFloatingPointType(value_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5351 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5352 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5353 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 5354 | } |
| 5355 | if (needs_write_barrier) { |
| 5356 | // Temporary registers for the write barrier. |
| 5357 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 5358 | // Ensure the card is in a byte register. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5359 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5360 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5361 | } |
| 5362 | |
| 5363 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 5364 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5365 | Location array_loc = locations->InAt(0); |
| 5366 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5367 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5368 | Location value = locations->InAt(2); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5369 | DataType::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5370 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5371 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5372 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5373 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5374 | bool needs_write_barrier = |
| 5375 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5376 | |
| 5377 | switch (value_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5378 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5379 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5380 | case DataType::Type::kInt8: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5381 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5382 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_1, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5383 | if (value.IsRegister()) { |
| 5384 | __ movb(address, value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5385 | } else { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5386 | __ movb(address, Immediate(CodeGenerator::GetInt8ValueOf(value.GetConstant()))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5387 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5388 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5389 | break; |
| 5390 | } |
| 5391 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5392 | case DataType::Type::kUint16: |
| 5393 | case DataType::Type::kInt16: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5394 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5395 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_2, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5396 | if (value.IsRegister()) { |
| 5397 | __ movw(address, value.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5398 | } else { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5399 | __ movw(address, Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5400 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5401 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5402 | break; |
| 5403 | } |
| 5404 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5405 | case DataType::Type::kReference: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5406 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5407 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5408 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5409 | if (!value.IsRegister()) { |
| 5410 | // Just setting null. |
| 5411 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5412 | DCHECK(value.IsConstant()) << value; |
| 5413 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5414 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5415 | DCHECK(!needs_write_barrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5416 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5417 | break; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5418 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5419 | |
| 5420 | DCHECK(needs_write_barrier); |
| 5421 | Register register_value = value.AsRegister<Register>(); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5422 | // We cannot use a NearLabel for `done`, as its range may be too |
| 5423 | // short when Baker read barriers are enabled. |
| 5424 | Label done; |
| 5425 | NearLabel not_null, do_put; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5426 | SlowPathCode* slow_path = nullptr; |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5427 | Location temp_loc = locations->GetTemp(0); |
| 5428 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5429 | if (may_need_runtime_call_for_type_check) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5430 | slow_path = new (GetGraph()->GetAllocator()) ArraySetSlowPathX86(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5431 | codegen_->AddSlowPath(slow_path); |
| 5432 | if (instruction->GetValueCanBeNull()) { |
| 5433 | __ testl(register_value, register_value); |
| 5434 | __ j(kNotEqual, ¬_null); |
| 5435 | __ movl(address, Immediate(0)); |
| 5436 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5437 | __ jmp(&done); |
| 5438 | __ Bind(¬_null); |
| 5439 | } |
| 5440 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5441 | // Note that when Baker read barriers are enabled, the type |
| 5442 | // checks are performed without read barriers. This is fine, |
| 5443 | // even in the case where a class object is in the from-space |
| 5444 | // after the flip, as a comparison involving such a type would |
| 5445 | // not produce a false positive; it may of course produce a |
| 5446 | // false negative, in which case we would take the ArraySet |
| 5447 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5448 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5449 | // /* HeapReference<Class> */ temp = array->klass_ |
| 5450 | __ movl(temp, Address(array, class_offset)); |
| 5451 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5452 | __ MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5453 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5454 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5455 | __ movl(temp, Address(temp, component_offset)); |
| 5456 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 5457 | // nor the object reference in `register_value->klass`, as |
| 5458 | // we are comparing two poisoned references. |
| 5459 | __ cmpl(temp, Address(register_value, class_offset)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5460 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5461 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5462 | __ j(kEqual, &do_put); |
| 5463 | // If heap poisoning is enabled, the `temp` reference has |
| 5464 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5465 | __ MaybeUnpoisonHeapReference(temp); |
| 5466 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5467 | // If heap poisoning is enabled, no need to unpoison the |
| 5468 | // heap reference loaded below, as it is only used for a |
| 5469 | // comparison with null. |
| 5470 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 5471 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5472 | __ Bind(&do_put); |
| 5473 | } else { |
| 5474 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5475 | } |
| 5476 | } |
| 5477 | |
| 5478 | if (kPoisonHeapReferences) { |
| 5479 | __ movl(temp, register_value); |
| 5480 | __ PoisonHeapReference(temp); |
| 5481 | __ movl(address, temp); |
| 5482 | } else { |
| 5483 | __ movl(address, register_value); |
| 5484 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5485 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5486 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5487 | } |
| 5488 | |
| 5489 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 5490 | codegen_->MarkGCCard( |
| 5491 | temp, card, array, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); |
| 5492 | __ Bind(&done); |
| 5493 | |
| 5494 | if (slow_path != nullptr) { |
| 5495 | __ Bind(slow_path->GetExitLabel()); |
| 5496 | } |
| 5497 | |
| 5498 | break; |
| 5499 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5500 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5501 | case DataType::Type::kInt32: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5502 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5503 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5504 | if (value.IsRegister()) { |
| 5505 | __ movl(address, value.AsRegister<Register>()); |
| 5506 | } else { |
| 5507 | DCHECK(value.IsConstant()) << value; |
| 5508 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5509 | __ movl(address, Immediate(v)); |
| 5510 | } |
| 5511 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5512 | break; |
| 5513 | } |
| 5514 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5515 | case DataType::Type::kInt64: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5516 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5517 | if (value.IsRegisterPair()) { |
| 5518 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 5519 | value.AsRegisterPairLow<Register>()); |
| 5520 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5521 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 5522 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5523 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5524 | DCHECK(value.IsConstant()); |
| 5525 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
| 5526 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 5527 | Immediate(Low32Bits(val))); |
| 5528 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5529 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 5530 | Immediate(High32Bits(val))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5531 | } |
| 5532 | break; |
| 5533 | } |
| 5534 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5535 | case DataType::Type::kFloat32: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5536 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5537 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5538 | if (value.IsFpuRegister()) { |
| 5539 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5540 | } else { |
| 5541 | DCHECK(value.IsConstant()); |
| 5542 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 5543 | __ movl(address, Immediate(v)); |
| 5544 | } |
| 5545 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5546 | break; |
| 5547 | } |
| 5548 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5549 | case DataType::Type::kFloat64: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5550 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5551 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5552 | if (value.IsFpuRegister()) { |
| 5553 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5554 | } else { |
| 5555 | DCHECK(value.IsConstant()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5556 | Address address_hi = |
| 5557 | CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset + kX86WordSize); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5558 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 5559 | __ movl(address, Immediate(Low32Bits(v))); |
| 5560 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5561 | __ movl(address_hi, Immediate(High32Bits(v))); |
| 5562 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5563 | break; |
| 5564 | } |
| 5565 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5566 | case DataType::Type::kVoid: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5567 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5568 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5569 | } |
| 5570 | } |
| 5571 | |
| 5572 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5573 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5574 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5575 | if (!instruction->IsEmittedAtUseSite()) { |
| 5576 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5577 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5578 | } |
| 5579 | |
| 5580 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5581 | if (instruction->IsEmittedAtUseSite()) { |
| 5582 | return; |
| 5583 | } |
| 5584 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5585 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5586 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5587 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5588 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5589 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5590 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5591 | // Mask out most significant bit in case the array is String's array of char. |
| 5592 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5593 | __ shrl(out, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5594 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5595 | } |
| 5596 | |
| 5597 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5598 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5599 | InvokeRuntimeCallingConvention calling_convention; |
| 5600 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5601 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5602 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5603 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5604 | HInstruction* length = instruction->InputAt(1); |
| 5605 | if (!length->IsEmittedAtUseSite()) { |
| 5606 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5607 | } |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5608 | // Need register to see array's length. |
| 5609 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5610 | locations->AddTemp(Location::RequiresRegister()); |
| 5611 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5612 | } |
| 5613 | |
| 5614 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5615 | const bool is_string_compressed_char_at = |
| 5616 | mirror::kUseStringCompression && instruction->IsStringCharAt(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5617 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5618 | Location index_loc = locations->InAt(0); |
| 5619 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5620 | SlowPathCode* slow_path = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5621 | new (GetGraph()->GetAllocator()) BoundsCheckSlowPathX86(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5622 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5623 | if (length_loc.IsConstant()) { |
| 5624 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5625 | if (index_loc.IsConstant()) { |
| 5626 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5627 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5628 | if (index < 0 || index >= length) { |
| 5629 | codegen_->AddSlowPath(slow_path); |
| 5630 | __ jmp(slow_path->GetEntryLabel()); |
| 5631 | } else { |
| 5632 | // Some optimization after BCE may have generated this, and we should not |
| 5633 | // generate a bounds check if it is a valid range. |
| 5634 | } |
| 5635 | return; |
| 5636 | } |
| 5637 | |
| 5638 | // We have to reverse the jump condition because the length is the constant. |
| 5639 | Register index_reg = index_loc.AsRegister<Register>(); |
| 5640 | __ cmpl(index_reg, Immediate(length)); |
| 5641 | codegen_->AddSlowPath(slow_path); |
| 5642 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5643 | } else { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5644 | HInstruction* array_length = instruction->InputAt(1); |
| 5645 | if (array_length->IsEmittedAtUseSite()) { |
| 5646 | // Address the length field in the array. |
| 5647 | DCHECK(array_length->IsArrayLength()); |
| 5648 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 5649 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 5650 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5651 | if (is_string_compressed_char_at) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5652 | // TODO: if index_loc.IsConstant(), compare twice the index (to compensate for |
| 5653 | // the string compression flag) with the in-memory length and avoid the temporary. |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5654 | Register length_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 5655 | __ movl(length_reg, array_len); |
| 5656 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5657 | __ shrl(length_reg, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5658 | codegen_->GenerateIntCompare(length_reg, index_loc); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5659 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5660 | // Checking bounds for general case: |
| 5661 | // Array of char or string's array with feature compression off. |
| 5662 | if (index_loc.IsConstant()) { |
| 5663 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5664 | __ cmpl(array_len, Immediate(value)); |
| 5665 | } else { |
| 5666 | __ cmpl(array_len, index_loc.AsRegister<Register>()); |
| 5667 | } |
| 5668 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5669 | } |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5670 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5671 | codegen_->GenerateIntCompare(length_loc, index_loc); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5672 | } |
| 5673 | codegen_->AddSlowPath(slow_path); |
| 5674 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5675 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5676 | } |
| 5677 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5678 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5679 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5680 | } |
| 5681 | |
| 5682 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5683 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5684 | } |
| 5685 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5686 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5687 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5688 | instruction, LocationSummary::kCallOnSlowPath); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 5689 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 5690 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 5691 | // registers in full width (since the runtime only saves/restores lower part). |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5692 | locations->SetCustomSlowPathCallerSaves( |
| 5693 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5694 | } |
| 5695 | |
| 5696 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5697 | HBasicBlock* block = instruction->GetBlock(); |
| 5698 | if (block->GetLoopInformation() != nullptr) { |
| 5699 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5700 | // The back edge will generate the suspend check. |
| 5701 | return; |
| 5702 | } |
| 5703 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5704 | // The goto will generate the suspend check. |
| 5705 | return; |
| 5706 | } |
| 5707 | GenerateSuspendCheck(instruction, nullptr); |
| 5708 | } |
| 5709 | |
| 5710 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5711 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5712 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5713 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 5714 | if (slow_path == nullptr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5715 | slow_path = new (GetGraph()->GetAllocator()) SuspendCheckSlowPathX86(instruction, successor); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5716 | instruction->SetSlowPath(slow_path); |
| 5717 | codegen_->AddSlowPath(slow_path); |
| 5718 | if (successor != nullptr) { |
| 5719 | DCHECK(successor->IsLoopHeader()); |
| 5720 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5721 | } |
| 5722 | } else { |
| 5723 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5724 | } |
| 5725 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5726 | __ fs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86PointerSize>().Int32Value()), |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5727 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5728 | if (successor == nullptr) { |
| 5729 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5730 | __ Bind(slow_path->GetReturnLabel()); |
| 5731 | } else { |
| 5732 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5733 | __ jmp(slow_path->GetEntryLabel()); |
| 5734 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5735 | } |
| 5736 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5737 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 5738 | return codegen_->GetAssembler(); |
| 5739 | } |
| 5740 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5741 | void ParallelMoveResolverX86::MoveMemoryToMemory32(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5742 | ScratchRegisterScope ensure_scratch( |
| 5743 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5744 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5745 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5746 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5747 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5748 | } |
| 5749 | |
| 5750 | void ParallelMoveResolverX86::MoveMemoryToMemory64(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5751 | ScratchRegisterScope ensure_scratch( |
| 5752 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5753 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5754 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5755 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5756 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 5757 | __ movl(temp_reg, Address(ESP, src + stack_offset + kX86WordSize)); |
| 5758 | __ movl(Address(ESP, dst + stack_offset + kX86WordSize), temp_reg); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5759 | } |
| 5760 | |
| 5761 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5762 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5763 | Location source = move->GetSource(); |
| 5764 | Location destination = move->GetDestination(); |
| 5765 | |
| 5766 | if (source.IsRegister()) { |
| 5767 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5768 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5769 | } else if (destination.IsFpuRegister()) { |
| 5770 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5771 | } else { |
| 5772 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5773 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5774 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5775 | } else if (source.IsRegisterPair()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5776 | size_t elem_size = DataType::Size(DataType::Type::kInt32); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5777 | // Create stack space for 2 elements. |
| 5778 | __ subl(ESP, Immediate(2 * elem_size)); |
| 5779 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 5780 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 5781 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 5782 | // And remove the temporary stack space we allocated. |
| 5783 | __ addl(ESP, Immediate(2 * elem_size)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5784 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5785 | if (destination.IsRegister()) { |
| 5786 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
| 5787 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5788 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5789 | } else if (destination.IsRegisterPair()) { |
| 5790 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 5791 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 5792 | __ psrlq(src_reg, Immediate(32)); |
| 5793 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5794 | } else if (destination.IsStackSlot()) { |
| 5795 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5796 | } else if (destination.IsDoubleStackSlot()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5797 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5798 | } else { |
| 5799 | DCHECK(destination.IsSIMDStackSlot()); |
| 5800 | __ movups(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5801 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5802 | } else if (source.IsStackSlot()) { |
| 5803 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5804 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5805 | } else if (destination.IsFpuRegister()) { |
| 5806 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5807 | } else { |
| 5808 | DCHECK(destination.IsStackSlot()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5809 | MoveMemoryToMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5810 | } |
| 5811 | } else if (source.IsDoubleStackSlot()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5812 | if (destination.IsRegisterPair()) { |
| 5813 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 5814 | __ movl(destination.AsRegisterPairHigh<Register>(), |
| 5815 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 5816 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5817 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 5818 | } else { |
| 5819 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5820 | MoveMemoryToMemory64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5821 | } |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5822 | } else if (source.IsSIMDStackSlot()) { |
| 5823 | DCHECK(destination.IsFpuRegister()); |
| 5824 | __ movups(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5825 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5826 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5827 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5828 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5829 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5830 | if (value == 0) { |
| 5831 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5832 | } else { |
| 5833 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 5834 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5835 | } else { |
| 5836 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5837 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5838 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5839 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5840 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5841 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5842 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5843 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5844 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5845 | if (value == 0) { |
| 5846 | // Easy handling of 0.0. |
| 5847 | __ xorps(dest, dest); |
| 5848 | } else { |
| 5849 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5850 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5851 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5852 | __ movl(temp, Immediate(value)); |
| 5853 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5854 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5855 | } else { |
| 5856 | DCHECK(destination.IsStackSlot()) << destination; |
| 5857 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 5858 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5859 | } else if (constant->IsLongConstant()) { |
| 5860 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5861 | int32_t low_value = Low32Bits(value); |
| 5862 | int32_t high_value = High32Bits(value); |
| 5863 | Immediate low(low_value); |
| 5864 | Immediate high(high_value); |
| 5865 | if (destination.IsDoubleStackSlot()) { |
| 5866 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5867 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5868 | } else { |
| 5869 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 5870 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 5871 | } |
| 5872 | } else { |
| 5873 | DCHECK(constant->IsDoubleConstant()); |
| 5874 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5875 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5876 | int32_t low_value = Low32Bits(value); |
| 5877 | int32_t high_value = High32Bits(value); |
| 5878 | Immediate low(low_value); |
| 5879 | Immediate high(high_value); |
| 5880 | if (destination.IsFpuRegister()) { |
| 5881 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5882 | if (value == 0) { |
| 5883 | // Easy handling of 0.0. |
| 5884 | __ xorpd(dest, dest); |
| 5885 | } else { |
| 5886 | __ pushl(high); |
| 5887 | __ pushl(low); |
| 5888 | __ movsd(dest, Address(ESP, 0)); |
| 5889 | __ addl(ESP, Immediate(8)); |
| 5890 | } |
| 5891 | } else { |
| 5892 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5893 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5894 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5895 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5896 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5897 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5898 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5899 | } |
| 5900 | } |
| 5901 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 5902 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5903 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 5904 | ScratchRegisterScope ensure_scratch( |
| 5905 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 5906 | |
| 5907 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5908 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 5909 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 5910 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5911 | } |
| 5912 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5913 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5914 | ScratchRegisterScope ensure_scratch( |
| 5915 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5916 | |
| 5917 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5918 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5919 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 5920 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 5921 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5922 | } |
| 5923 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5924 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5925 | ScratchRegisterScope ensure_scratch1( |
| 5926 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5927 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5928 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 5929 | ScratchRegisterScope ensure_scratch2( |
| 5930 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5931 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5932 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 5933 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 5934 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 5935 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 5936 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 5937 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5938 | } |
| 5939 | |
| 5940 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5941 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5942 | Location source = move->GetSource(); |
| 5943 | Location destination = move->GetDestination(); |
| 5944 | |
| 5945 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 5946 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 5947 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5948 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5949 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5950 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5951 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5952 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5953 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5954 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5955 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 5956 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5957 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 5958 | // Use XOR Swap algorithm to avoid a temporary. |
| 5959 | DCHECK_NE(source.reg(), destination.reg()); |
| 5960 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5961 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5962 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5963 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 5964 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 5965 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 5966 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5967 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 5968 | // Take advantage of the 16 bytes in the XMM register. |
| 5969 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 5970 | Address stack(ESP, destination.GetStackIndex()); |
| 5971 | // Load the double into the high doubleword. |
| 5972 | __ movhpd(reg, stack); |
| 5973 | |
| 5974 | // Store the low double into the destination. |
| 5975 | __ movsd(stack, reg); |
| 5976 | |
| 5977 | // Move the high double to the low double. |
| 5978 | __ psrldq(reg, Immediate(8)); |
| 5979 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 5980 | // Take advantage of the 16 bytes in the XMM register. |
| 5981 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 5982 | Address stack(ESP, source.GetStackIndex()); |
| 5983 | // Load the double into the high doubleword. |
| 5984 | __ movhpd(reg, stack); |
| 5985 | |
| 5986 | // Store the low double into the destination. |
| 5987 | __ movsd(stack, reg); |
| 5988 | |
| 5989 | // Move the high double to the low double. |
| 5990 | __ psrldq(reg, Immediate(8)); |
| 5991 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
| 5992 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 5993 | Exchange(destination.GetHighStackIndex(kX86WordSize), source.GetHighStackIndex(kX86WordSize)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5994 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5995 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5996 | } |
| 5997 | } |
| 5998 | |
| 5999 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 6000 | __ pushl(static_cast<Register>(reg)); |
| 6001 | } |
| 6002 | |
| 6003 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 6004 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6005 | } |
| 6006 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6007 | HLoadClass::LoadKind CodeGeneratorX86::GetSupportedLoadClassKind( |
| 6008 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6009 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6010 | case HLoadClass::LoadKind::kInvalid: |
| 6011 | LOG(FATAL) << "UNREACHABLE"; |
| 6012 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6013 | case HLoadClass::LoadKind::kReferrersClass: |
| 6014 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6015 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6016 | case HLoadClass::LoadKind::kBootImageClassTable: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6017 | case HLoadClass::LoadKind::kBssEntry: |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6018 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6019 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6020 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6021 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6022 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6023 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6024 | case HLoadClass::LoadKind::kRuntimeCall: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6025 | break; |
| 6026 | } |
| 6027 | return desired_class_load_kind; |
| 6028 | } |
| 6029 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6030 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6031 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6032 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6033 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6034 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6035 | cls, |
| 6036 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6037 | Location::RegisterLocation(EAX)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6038 | DCHECK_EQ(calling_convention.GetRegisterAt(0), EAX); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6039 | return; |
| 6040 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6041 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6042 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6043 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 6044 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6045 | ? LocationSummary::kCallOnSlowPath |
| 6046 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6047 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6048 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6049 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6050 | } |
| 6051 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6052 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6053 | load_kind == HLoadClass::LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6054 | load_kind == HLoadClass::LoadKind::kBootImageClassTable || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6055 | load_kind == HLoadClass::LoadKind::kBssEntry) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6056 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6057 | } |
| 6058 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6059 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 6060 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 6061 | // Rely on the type resolution and/or initialization to save everything. |
| 6062 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6063 | InvokeRuntimeCallingConvention calling_convention; |
| 6064 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6065 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6066 | } else { |
| 6067 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6068 | } |
| 6069 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6070 | } |
| 6071 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6072 | Label* CodeGeneratorX86::NewJitRootClassPatch(const DexFile& dex_file, |
| 6073 | dex::TypeIndex dex_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6074 | Handle<mirror::Class> handle) { |
| 6075 | jit_class_roots_.Overwrite(TypeReference(&dex_file, dex_index), |
| 6076 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6077 | // Add a patch entry and return the label. |
| 6078 | jit_class_patches_.emplace_back(dex_file, dex_index.index_); |
| 6079 | PatchInfo<Label>* info = &jit_class_patches_.back(); |
| 6080 | return &info->label; |
| 6081 | } |
| 6082 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6083 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6084 | // move. |
| 6085 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6086 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6087 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6088 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6089 | return; |
| 6090 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6091 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6092 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6093 | LocationSummary* locations = cls->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6094 | Location out_loc = locations->Out(); |
| 6095 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6096 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6097 | bool generate_null_check = false; |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6098 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 6099 | ? kWithoutReadBarrier |
| 6100 | : kCompilerReadBarrierOption; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6101 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6102 | case HLoadClass::LoadKind::kReferrersClass: { |
| 6103 | DCHECK(!cls->CanCallRuntime()); |
| 6104 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 6105 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6106 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 6107 | GenerateGcRootFieldLoad( |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6108 | cls, |
| 6109 | out_loc, |
| 6110 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 6111 | /* fixup_label */ nullptr, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6112 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6113 | break; |
| 6114 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6115 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6116 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6117 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6118 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6119 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 6120 | codegen_->RecordBootTypePatch(cls); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6121 | break; |
| 6122 | } |
| 6123 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6124 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6125 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6126 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 6127 | DCHECK_NE(address, 0u); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6128 | __ movl(out, Immediate(address)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6129 | break; |
| 6130 | } |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6131 | case HLoadClass::LoadKind::kBootImageClassTable: { |
| 6132 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 6133 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6134 | __ movl(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
| 6135 | codegen_->RecordBootTypePatch(cls); |
| 6136 | // Extract the reference from the slot data, i.e. clear the hash bits. |
| 6137 | int32_t masked_hash = ClassTable::TableSlot::MaskHash( |
| 6138 | ComputeModifiedUtf8Hash(cls->GetDexFile().StringByTypeIdx(cls->GetTypeIndex()))); |
| 6139 | if (masked_hash != 0) { |
| 6140 | __ subl(out, Immediate(masked_hash)); |
| 6141 | } |
| 6142 | break; |
| 6143 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6144 | case HLoadClass::LoadKind::kBssEntry: { |
| 6145 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6146 | Address address(method_address, CodeGeneratorX86::kDummy32BitOffset); |
| 6147 | Label* fixup_label = codegen_->NewTypeBssEntryPatch(cls); |
| 6148 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
| 6149 | generate_null_check = true; |
| 6150 | break; |
| 6151 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6152 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 6153 | Address address = Address::Absolute(CodeGeneratorX86::kDummy32BitOffset); |
| 6154 | Label* fixup_label = codegen_->NewJitRootClassPatch( |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6155 | cls->GetDexFile(), cls->GetTypeIndex(), cls->GetClass()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6156 | // /* GcRoot<mirror::Class> */ out = *address |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6157 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6158 | break; |
| 6159 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6160 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6161 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6162 | LOG(FATAL) << "UNREACHABLE"; |
| 6163 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6164 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6165 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6166 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6167 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6168 | SlowPathCode* slow_path = new (GetGraph()->GetAllocator()) LoadClassSlowPathX86( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6169 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 6170 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6171 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6172 | if (generate_null_check) { |
| 6173 | __ testl(out, out); |
| 6174 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6175 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6176 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6177 | if (cls->MustGenerateClinitCheck()) { |
| 6178 | GenerateClassInitializationCheck(slow_path, out); |
| 6179 | } else { |
| 6180 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6181 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6182 | } |
| 6183 | } |
| 6184 | |
| 6185 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 6186 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6187 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6188 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6189 | if (check->HasUses()) { |
| 6190 | locations->SetOut(Location::SameAsFirstInput()); |
| 6191 | } |
| 6192 | } |
| 6193 | |
| 6194 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6195 | // We assume the class to not be null. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6196 | SlowPathCode* slow_path = new (GetGraph()->GetAllocator()) LoadClassSlowPathX86( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6197 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6198 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6199 | GenerateClassInitializationCheck(slow_path, |
| 6200 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6201 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6202 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6203 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6204 | SlowPathCode* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6205 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 6206 | Immediate(mirror::Class::kStatusInitialized)); |
| 6207 | __ j(kLess, slow_path->GetEntryLabel()); |
| 6208 | __ Bind(slow_path->GetExitLabel()); |
| 6209 | // No need for memory fence, thanks to the X86 memory model. |
| 6210 | } |
| 6211 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6212 | HLoadString::LoadKind CodeGeneratorX86::GetSupportedLoadStringKind( |
| 6213 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6214 | switch (desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6215 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6216 | case HLoadString::LoadKind::kBootImageInternTable: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6217 | case HLoadString::LoadKind::kBssEntry: |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6218 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6219 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6220 | case HLoadString::LoadKind::kJitTableAddress: |
| 6221 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6222 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6223 | case HLoadString::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6224 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6225 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6226 | } |
| 6227 | return desired_string_load_kind; |
| 6228 | } |
| 6229 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6230 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6231 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6232 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6233 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6234 | if (load_kind == HLoadString::LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6235 | load_kind == HLoadString::LoadKind::kBootImageInternTable || |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6236 | load_kind == HLoadString::LoadKind::kBssEntry) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6237 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6238 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6239 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6240 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 6241 | } else { |
| 6242 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6243 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 6244 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6245 | // Rely on the pResolveString to save everything. |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6246 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6247 | InvokeRuntimeCallingConvention calling_convention; |
| 6248 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6249 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6250 | } else { |
| 6251 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6252 | } |
| 6253 | } |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6254 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6255 | } |
| 6256 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6257 | Label* CodeGeneratorX86::NewJitRootStringPatch(const DexFile& dex_file, |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6258 | dex::StringIndex dex_index, |
| 6259 | Handle<mirror::String> handle) { |
| 6260 | jit_string_roots_.Overwrite( |
| 6261 | StringReference(&dex_file, dex_index), reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6262 | // Add a patch entry and return the label. |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6263 | jit_string_patches_.emplace_back(dex_file, dex_index.index_); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6264 | PatchInfo<Label>* info = &jit_string_patches_.back(); |
| 6265 | return &info->label; |
| 6266 | } |
| 6267 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6268 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6269 | // move. |
| 6270 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6271 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6272 | Location out_loc = locations->Out(); |
| 6273 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6274 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6275 | switch (load->GetLoadKind()) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6276 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6277 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6278 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6279 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6280 | codegen_->RecordBootStringPatch(load); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6281 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6282 | } |
| 6283 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6284 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6285 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 6286 | DCHECK_NE(address, 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6287 | __ movl(out, Immediate(address)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6288 | return; |
| 6289 | } |
| 6290 | case HLoadString::LoadKind::kBootImageInternTable: { |
| 6291 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 6292 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6293 | __ movl(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
| 6294 | codegen_->RecordBootStringPatch(load); |
| 6295 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6296 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6297 | case HLoadString::LoadKind::kBssEntry: { |
| 6298 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6299 | Address address = Address(method_address, CodeGeneratorX86::kDummy32BitOffset); |
| 6300 | Label* fixup_label = codegen_->NewStringBssEntryPatch(load); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6301 | // /* GcRoot<mirror::String> */ out = *address /* PC-relative */ |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6302 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6303 | SlowPathCode* slow_path = new (GetGraph()->GetAllocator()) LoadStringSlowPathX86(load); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6304 | codegen_->AddSlowPath(slow_path); |
| 6305 | __ testl(out, out); |
| 6306 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6307 | __ Bind(slow_path->GetExitLabel()); |
| 6308 | return; |
| 6309 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6310 | case HLoadString::LoadKind::kJitTableAddress: { |
| 6311 | Address address = Address::Absolute(CodeGeneratorX86::kDummy32BitOffset); |
| 6312 | Label* fixup_label = codegen_->NewJitRootStringPatch( |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6313 | load->GetDexFile(), load->GetStringIndex(), load->GetString()); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6314 | // /* GcRoot<mirror::String> */ out = *address |
| 6315 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
| 6316 | return; |
| 6317 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6318 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6319 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6320 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6321 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6322 | // 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] | 6323 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6324 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6325 | __ movl(calling_convention.GetRegisterAt(0), Immediate(load->GetStringIndex().index_)); |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6326 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 6327 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6328 | } |
| 6329 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6330 | static Address GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6331 | return Address::Absolute(Thread::ExceptionOffset<kX86PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6332 | } |
| 6333 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6334 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 6335 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6336 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6337 | locations->SetOut(Location::RequiresRegister()); |
| 6338 | } |
| 6339 | |
| 6340 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6341 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 6342 | } |
| 6343 | |
| 6344 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6345 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6346 | } |
| 6347 | |
| 6348 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6349 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6350 | } |
| 6351 | |
| 6352 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6353 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6354 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6355 | InvokeRuntimeCallingConvention calling_convention; |
| 6356 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6357 | } |
| 6358 | |
| 6359 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6360 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6361 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6362 | } |
| 6363 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6364 | // Temp is used for read barrier. |
| 6365 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 6366 | if (kEmitCompilerReadBarrier && |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6367 | !kUseBakerReadBarrier && |
| 6368 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6369 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6370 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 6371 | return 1; |
| 6372 | } |
| 6373 | return 0; |
| 6374 | } |
| 6375 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6376 | // 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] | 6377 | // interface pointer, one for loading the current interface. |
| 6378 | // The other checks have one temp for loading the object's class. |
| 6379 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 6380 | if (type_check_kind == TypeCheckKind::kInterfaceCheck && !kPoisonHeapReferences) { |
| 6381 | return 2; |
| 6382 | } |
| 6383 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6384 | } |
| 6385 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6386 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6387 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6388 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6389 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6390 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6391 | case TypeCheckKind::kExactCheck: |
| 6392 | case TypeCheckKind::kAbstractClassCheck: |
| 6393 | case TypeCheckKind::kClassHierarchyCheck: |
| 6394 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6395 | call_kind = |
| 6396 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6397 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6398 | break; |
| 6399 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6400 | case TypeCheckKind::kUnresolvedCheck: |
| 6401 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6402 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6403 | break; |
| 6404 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6405 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6406 | LocationSummary* locations = |
| 6407 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6408 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6409 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6410 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6411 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6412 | locations->SetInAt(1, Location::Any()); |
| 6413 | // Note that TypeCheckSlowPathX86 uses this "out" register too. |
| 6414 | locations->SetOut(Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6415 | // When read barriers are enabled, we need a temporary register for some cases. |
| 6416 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6417 | } |
| 6418 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6419 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6420 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6421 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6422 | Location obj_loc = locations->InAt(0); |
| 6423 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6424 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6425 | Location out_loc = locations->Out(); |
| 6426 | Register out = out_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6427 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 6428 | DCHECK_LE(num_temps, 1u); |
| 6429 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6430 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6431 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6432 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6433 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6434 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6435 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6436 | |
| 6437 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6438 | // Avoid null check if we know obj is not null. |
| 6439 | if (instruction->MustDoNullCheck()) { |
| 6440 | __ testl(obj, obj); |
| 6441 | __ j(kEqual, &zero); |
| 6442 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6443 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6444 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6445 | case TypeCheckKind::kExactCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6446 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6447 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6448 | out_loc, |
| 6449 | obj_loc, |
| 6450 | class_offset, |
| 6451 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6452 | if (cls.IsRegister()) { |
| 6453 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6454 | } else { |
| 6455 | DCHECK(cls.IsStackSlot()) << cls; |
| 6456 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6457 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6458 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6459 | // Classes must be equal for the instanceof to succeed. |
| 6460 | __ j(kNotEqual, &zero); |
| 6461 | __ movl(out, Immediate(1)); |
| 6462 | __ jmp(&done); |
| 6463 | break; |
| 6464 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6465 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6466 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6467 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6468 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6469 | out_loc, |
| 6470 | obj_loc, |
| 6471 | class_offset, |
| 6472 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6473 | // If the class is abstract, we eagerly fetch the super class of the |
| 6474 | // object to avoid doing a comparison we know will fail. |
| 6475 | NearLabel loop; |
| 6476 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6477 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6478 | GenerateReferenceLoadOneRegister(instruction, |
| 6479 | out_loc, |
| 6480 | super_offset, |
| 6481 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6482 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6483 | __ testl(out, out); |
| 6484 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6485 | __ j(kEqual, &done); |
| 6486 | if (cls.IsRegister()) { |
| 6487 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6488 | } else { |
| 6489 | DCHECK(cls.IsStackSlot()) << cls; |
| 6490 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6491 | } |
| 6492 | __ j(kNotEqual, &loop); |
| 6493 | __ movl(out, Immediate(1)); |
| 6494 | if (zero.IsLinked()) { |
| 6495 | __ jmp(&done); |
| 6496 | } |
| 6497 | break; |
| 6498 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6499 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6500 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6501 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6502 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6503 | out_loc, |
| 6504 | obj_loc, |
| 6505 | class_offset, |
| 6506 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6507 | // Walk over the class hierarchy to find a match. |
| 6508 | NearLabel loop, success; |
| 6509 | __ Bind(&loop); |
| 6510 | if (cls.IsRegister()) { |
| 6511 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6512 | } else { |
| 6513 | DCHECK(cls.IsStackSlot()) << cls; |
| 6514 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6515 | } |
| 6516 | __ j(kEqual, &success); |
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, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6522 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6523 | __ testl(out, out); |
| 6524 | __ j(kNotEqual, &loop); |
| 6525 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6526 | __ jmp(&done); |
| 6527 | __ Bind(&success); |
| 6528 | __ movl(out, Immediate(1)); |
| 6529 | if (zero.IsLinked()) { |
| 6530 | __ jmp(&done); |
| 6531 | } |
| 6532 | break; |
| 6533 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6534 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6535 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6536 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6537 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6538 | out_loc, |
| 6539 | obj_loc, |
| 6540 | class_offset, |
| 6541 | kCompilerReadBarrierOption); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6542 | // Do an exact check. |
| 6543 | NearLabel exact_check; |
| 6544 | if (cls.IsRegister()) { |
| 6545 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6546 | } else { |
| 6547 | DCHECK(cls.IsStackSlot()) << cls; |
| 6548 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6549 | } |
| 6550 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6551 | // 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] | 6552 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6553 | GenerateReferenceLoadOneRegister(instruction, |
| 6554 | out_loc, |
| 6555 | component_offset, |
| 6556 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6557 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6558 | __ testl(out, out); |
| 6559 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6560 | __ j(kEqual, &done); |
| 6561 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 6562 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6563 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6564 | __ movl(out, Immediate(1)); |
| 6565 | __ jmp(&done); |
| 6566 | break; |
| 6567 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6568 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6569 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6570 | // No read barrier since the slow path will retry upon failure. |
| 6571 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6572 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6573 | out_loc, |
| 6574 | obj_loc, |
| 6575 | class_offset, |
| 6576 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6577 | if (cls.IsRegister()) { |
| 6578 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6579 | } else { |
| 6580 | DCHECK(cls.IsStackSlot()) << cls; |
| 6581 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6582 | } |
| 6583 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6584 | slow_path = new (GetGraph()->GetAllocator()) TypeCheckSlowPathX86(instruction, |
| 6585 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6586 | codegen_->AddSlowPath(slow_path); |
| 6587 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6588 | __ movl(out, Immediate(1)); |
| 6589 | if (zero.IsLinked()) { |
| 6590 | __ jmp(&done); |
| 6591 | } |
| 6592 | break; |
| 6593 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6594 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6595 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6596 | case TypeCheckKind::kInterfaceCheck: { |
| 6597 | // 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] | 6598 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6599 | // cases. |
| 6600 | // |
| 6601 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6602 | // entry point without resorting to a type checking slow path |
| 6603 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6604 | // require to assign fixed registers for the inputs of this |
| 6605 | // HInstanceOf instruction (following the runtime calling |
| 6606 | // convention), which might be cluttered by the potential first |
| 6607 | // read barrier emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6608 | // |
| 6609 | // TODO: Introduce a new runtime entry point taking the object |
| 6610 | // to test (instead of its class) as argument, and let it deal |
| 6611 | // with the read barrier issues. This will let us refactor this |
| 6612 | // case of the `switch` code as it was previously (with a direct |
| 6613 | // call to the runtime not using a type checking slow path). |
| 6614 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6615 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6616 | slow_path = new (GetGraph()->GetAllocator()) TypeCheckSlowPathX86(instruction, |
| 6617 | /* is_fatal */ false); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6618 | codegen_->AddSlowPath(slow_path); |
| 6619 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6620 | if (zero.IsLinked()) { |
| 6621 | __ jmp(&done); |
| 6622 | } |
| 6623 | break; |
| 6624 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6625 | } |
| 6626 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6627 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6628 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6629 | __ xorl(out, out); |
| 6630 | } |
| 6631 | |
| 6632 | if (done.IsLinked()) { |
| 6633 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6634 | } |
| 6635 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6636 | if (slow_path != nullptr) { |
| 6637 | __ Bind(slow_path->GetExitLabel()); |
| 6638 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6639 | } |
| 6640 | |
Mathieu Chartier | 5ac321b | 2016-11-09 16:33:54 -0800 | [diff] [blame] | 6641 | static bool IsTypeCheckSlowPathFatal(TypeCheckKind type_check_kind, bool throws_into_catch) { |
| 6642 | switch (type_check_kind) { |
| 6643 | case TypeCheckKind::kExactCheck: |
| 6644 | case TypeCheckKind::kAbstractClassCheck: |
| 6645 | case TypeCheckKind::kClassHierarchyCheck: |
| 6646 | case TypeCheckKind::kArrayObjectCheck: |
| 6647 | return !throws_into_catch && !kEmitCompilerReadBarrier; |
| 6648 | case TypeCheckKind::kInterfaceCheck: |
| 6649 | return !throws_into_catch && !kEmitCompilerReadBarrier && !kPoisonHeapReferences; |
| 6650 | case TypeCheckKind::kArrayCheck: |
| 6651 | case TypeCheckKind::kUnresolvedCheck: |
| 6652 | return false; |
| 6653 | } |
| 6654 | LOG(FATAL) << "Unreachable"; |
| 6655 | UNREACHABLE(); |
| 6656 | } |
| 6657 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6658 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6659 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6660 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Mathieu Chartier | 5ac321b | 2016-11-09 16:33:54 -0800 | [diff] [blame] | 6661 | LocationSummary::CallKind call_kind = |
| 6662 | IsTypeCheckSlowPathFatal(type_check_kind, throws_into_catch) |
| 6663 | ? LocationSummary::kNoCall |
| 6664 | : LocationSummary::kCallOnSlowPath; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6665 | LocationSummary* locations = |
| 6666 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6667 | locations->SetInAt(0, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6668 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6669 | // Require a register for the interface check since there is a loop that compares the class to |
| 6670 | // a memory address. |
| 6671 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6672 | } else { |
| 6673 | locations->SetInAt(1, Location::Any()); |
| 6674 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6675 | // Note that TypeCheckSlowPathX86 uses this "temp" register too. |
| 6676 | locations->AddTemp(Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6677 | // When read barriers are enabled, we need an additional temporary register for some cases. |
| 6678 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
| 6679 | } |
| 6680 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6681 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6682 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6683 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6684 | Location obj_loc = locations->InAt(0); |
| 6685 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6686 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6687 | Location temp_loc = locations->GetTemp(0); |
| 6688 | Register temp = temp_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6689 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 6690 | DCHECK_GE(num_temps, 1u); |
| 6691 | DCHECK_LE(num_temps, 2u); |
| 6692 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 6693 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6694 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6695 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6696 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 6697 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 6698 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 6699 | const uint32_t object_array_data_offset = |
| 6700 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6701 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6702 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 6703 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 6704 | // read barriers is done for performance and code size reasons. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6705 | bool is_type_check_slow_path_fatal = |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6706 | IsTypeCheckSlowPathFatal(type_check_kind, instruction->CanThrowIntoCatchBlock()); |
| 6707 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6708 | SlowPathCode* type_check_slow_path = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6709 | new (GetGraph()->GetAllocator()) TypeCheckSlowPathX86(instruction, |
| 6710 | is_type_check_slow_path_fatal); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6711 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6712 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6713 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6714 | // Avoid null check if we know obj is not null. |
| 6715 | if (instruction->MustDoNullCheck()) { |
| 6716 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6717 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6718 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6719 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6720 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6721 | case TypeCheckKind::kExactCheck: |
| 6722 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6723 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6724 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6725 | temp_loc, |
| 6726 | obj_loc, |
| 6727 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6728 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6729 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6730 | if (cls.IsRegister()) { |
| 6731 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6732 | } else { |
| 6733 | DCHECK(cls.IsStackSlot()) << cls; |
| 6734 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6735 | } |
| 6736 | // Jump to slow path for throwing the exception or doing a |
| 6737 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6738 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6739 | break; |
| 6740 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6741 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6742 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6743 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6744 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6745 | temp_loc, |
| 6746 | obj_loc, |
| 6747 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6748 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6749 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6750 | // If the class is abstract, we eagerly fetch the super class of the |
| 6751 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6752 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6753 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6754 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6755 | GenerateReferenceLoadOneRegister(instruction, |
| 6756 | temp_loc, |
| 6757 | super_offset, |
| 6758 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6759 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6760 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6761 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 6762 | // exception. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6763 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6764 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6765 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6766 | // Otherwise, compare the classes |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6767 | if (cls.IsRegister()) { |
| 6768 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6769 | } else { |
| 6770 | DCHECK(cls.IsStackSlot()) << cls; |
| 6771 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6772 | } |
| 6773 | __ j(kNotEqual, &loop); |
| 6774 | break; |
| 6775 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6776 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6777 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6778 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6779 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6780 | temp_loc, |
| 6781 | obj_loc, |
| 6782 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6783 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6784 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6785 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6786 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6787 | __ Bind(&loop); |
| 6788 | if (cls.IsRegister()) { |
| 6789 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6790 | } else { |
| 6791 | DCHECK(cls.IsStackSlot()) << cls; |
| 6792 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6793 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6794 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6795 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6796 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6797 | GenerateReferenceLoadOneRegister(instruction, |
| 6798 | temp_loc, |
| 6799 | super_offset, |
| 6800 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6801 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6802 | |
| 6803 | // If the class reference currently in `temp` is not null, jump |
| 6804 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6805 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6806 | __ j(kNotZero, &loop); |
| 6807 | // Otherwise, jump to the slow path to throw the exception.; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6808 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6809 | break; |
| 6810 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6811 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6812 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6813 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6814 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6815 | temp_loc, |
| 6816 | obj_loc, |
| 6817 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6818 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6819 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6820 | // Do an exact check. |
| 6821 | if (cls.IsRegister()) { |
| 6822 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6823 | } else { |
| 6824 | DCHECK(cls.IsStackSlot()) << cls; |
| 6825 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6826 | } |
| 6827 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6828 | |
| 6829 | // 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] | 6830 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6831 | GenerateReferenceLoadOneRegister(instruction, |
| 6832 | temp_loc, |
| 6833 | component_offset, |
| 6834 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6835 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6836 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6837 | // If the component type is null (i.e. the object not an array), jump to the slow path to |
| 6838 | // throw the exception. Otherwise proceed with the check. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6839 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6840 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6841 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6842 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6843 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6844 | break; |
| 6845 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6846 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6847 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6848 | // 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] | 6849 | // We cannot directly call the CheckCast runtime entry point |
| 6850 | // without resorting to a type checking slow path here (i.e. by |
| 6851 | // calling InvokeRuntime directly), as it would require to |
| 6852 | // assign fixed registers for the inputs of this HInstanceOf |
| 6853 | // instruction (following the runtime calling convention), which |
| 6854 | // might be cluttered by the potential first read barrier |
| 6855 | // emission at the beginning of this method. |
| 6856 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6857 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6858 | |
| 6859 | case TypeCheckKind::kInterfaceCheck: { |
| 6860 | // Fast path for the interface check. Since we compare with a memory location in the inner |
| 6861 | // loop we would need to have cls poisoned. However unpoisoning cls would reset the |
| 6862 | // conditional flags and cause the conditional jump to be incorrect. Therefore we just jump |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6863 | // to the slow path if we are running under poisoning. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6864 | if (!kPoisonHeapReferences) { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6865 | // Try to avoid read barriers to improve the fast path. We can not get false positives by |
| 6866 | // doing this. |
| 6867 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6868 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6869 | temp_loc, |
| 6870 | obj_loc, |
| 6871 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6872 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6873 | |
| 6874 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 6875 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6876 | temp_loc, |
| 6877 | temp_loc, |
| 6878 | iftable_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6879 | kWithoutReadBarrier); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6880 | // Iftable is never null. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6881 | __ movl(maybe_temp2_loc.AsRegister<Register>(), Address(temp, array_length_offset)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6882 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6883 | NearLabel start_loop; |
| 6884 | __ Bind(&start_loop); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6885 | // Need to subtract first to handle the empty array case. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6886 | __ subl(maybe_temp2_loc.AsRegister<Register>(), Immediate(2)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6887 | __ j(kNegative, type_check_slow_path->GetEntryLabel()); |
| 6888 | // Go to next interface if the classes do not match. |
| 6889 | __ cmpl(cls.AsRegister<Register>(), |
| 6890 | CodeGeneratorX86::ArrayAddress(temp, |
| 6891 | maybe_temp2_loc, |
| 6892 | TIMES_4, |
| 6893 | object_array_data_offset)); |
| 6894 | __ j(kNotEqual, &start_loop); |
| 6895 | } else { |
| 6896 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6897 | } |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6898 | break; |
| 6899 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6900 | } |
| 6901 | __ Bind(&done); |
| 6902 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6903 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6904 | } |
| 6905 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6906 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6907 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6908 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6909 | InvokeRuntimeCallingConvention calling_convention; |
| 6910 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6911 | } |
| 6912 | |
| 6913 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6914 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject |
| 6915 | : kQuickUnlockObject, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6916 | instruction, |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6917 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6918 | if (instruction->IsEnter()) { |
| 6919 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6920 | } else { |
| 6921 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6922 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6923 | } |
| 6924 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6925 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6926 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6927 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6928 | |
| 6929 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6930 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6931 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6932 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 |
| 6933 | || instruction->GetResultType() == DataType::Type::kInt64); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6934 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6935 | locations->SetInAt(1, Location::Any()); |
| 6936 | locations->SetOut(Location::SameAsFirstInput()); |
| 6937 | } |
| 6938 | |
| 6939 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 6940 | HandleBitwiseOperation(instruction); |
| 6941 | } |
| 6942 | |
| 6943 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 6944 | HandleBitwiseOperation(instruction); |
| 6945 | } |
| 6946 | |
| 6947 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 6948 | HandleBitwiseOperation(instruction); |
| 6949 | } |
| 6950 | |
| 6951 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6952 | LocationSummary* locations = instruction->GetLocations(); |
| 6953 | Location first = locations->InAt(0); |
| 6954 | Location second = locations->InAt(1); |
| 6955 | DCHECK(first.Equals(locations->Out())); |
| 6956 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6957 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6958 | if (second.IsRegister()) { |
| 6959 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6960 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6961 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6962 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6963 | } else { |
| 6964 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6965 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6966 | } |
| 6967 | } else if (second.IsConstant()) { |
| 6968 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6969 | __ andl(first.AsRegister<Register>(), |
| 6970 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6971 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6972 | __ orl(first.AsRegister<Register>(), |
| 6973 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6974 | } else { |
| 6975 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6976 | __ xorl(first.AsRegister<Register>(), |
| 6977 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6978 | } |
| 6979 | } else { |
| 6980 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6981 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6982 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6983 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6984 | } else { |
| 6985 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6986 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6987 | } |
| 6988 | } |
| 6989 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6990 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6991 | if (second.IsRegisterPair()) { |
| 6992 | if (instruction->IsAnd()) { |
| 6993 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6994 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6995 | } else if (instruction->IsOr()) { |
| 6996 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6997 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6998 | } else { |
| 6999 | DCHECK(instruction->IsXor()); |
| 7000 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 7001 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 7002 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7003 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7004 | if (instruction->IsAnd()) { |
| 7005 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7006 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 7007 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7008 | } else if (instruction->IsOr()) { |
| 7009 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7010 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 7011 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7012 | } else { |
| 7013 | DCHECK(instruction->IsXor()); |
| 7014 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 7015 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 7016 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 7017 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7018 | } else { |
| 7019 | DCHECK(second.IsConstant()) << second; |
| 7020 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7021 | int32_t low_value = Low32Bits(value); |
| 7022 | int32_t high_value = High32Bits(value); |
| 7023 | Immediate low(low_value); |
| 7024 | Immediate high(high_value); |
| 7025 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 7026 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7027 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7028 | if (low_value == 0) { |
| 7029 | __ xorl(first_low, first_low); |
| 7030 | } else if (low_value != -1) { |
| 7031 | __ andl(first_low, low); |
| 7032 | } |
| 7033 | if (high_value == 0) { |
| 7034 | __ xorl(first_high, first_high); |
| 7035 | } else if (high_value != -1) { |
| 7036 | __ andl(first_high, high); |
| 7037 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7038 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7039 | if (low_value != 0) { |
| 7040 | __ orl(first_low, low); |
| 7041 | } |
| 7042 | if (high_value != 0) { |
| 7043 | __ orl(first_high, high); |
| 7044 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7045 | } else { |
| 7046 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7047 | if (low_value != 0) { |
| 7048 | __ xorl(first_low, low); |
| 7049 | } |
| 7050 | if (high_value != 0) { |
| 7051 | __ xorl(first_high, high); |
| 7052 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7053 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7054 | } |
| 7055 | } |
| 7056 | } |
| 7057 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7058 | void InstructionCodeGeneratorX86::GenerateReferenceLoadOneRegister( |
| 7059 | HInstruction* instruction, |
| 7060 | Location out, |
| 7061 | uint32_t offset, |
| 7062 | Location maybe_temp, |
| 7063 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7064 | Register out_reg = out.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7065 | if (read_barrier_option == kWithReadBarrier) { |
| 7066 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7067 | if (kUseBakerReadBarrier) { |
| 7068 | // Load with fast path based Baker's read barrier. |
| 7069 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7070 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7071 | instruction, out, out_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7072 | } else { |
| 7073 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7074 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7075 | // in the following move operation, as we will need it for the |
| 7076 | // read barrier below. |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7077 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7078 | __ movl(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7079 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7080 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7081 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7082 | } |
| 7083 | } else { |
| 7084 | // Plain load with no read barrier. |
| 7085 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7086 | __ movl(out_reg, Address(out_reg, offset)); |
| 7087 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7088 | } |
| 7089 | } |
| 7090 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7091 | void InstructionCodeGeneratorX86::GenerateReferenceLoadTwoRegisters( |
| 7092 | HInstruction* instruction, |
| 7093 | Location out, |
| 7094 | Location obj, |
| 7095 | uint32_t offset, |
| 7096 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7097 | Register out_reg = out.AsRegister<Register>(); |
| 7098 | Register obj_reg = obj.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7099 | if (read_barrier_option == kWithReadBarrier) { |
| 7100 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7101 | if (kUseBakerReadBarrier) { |
| 7102 | // Load with fast path based Baker's read barrier. |
| 7103 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7104 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7105 | instruction, out, obj_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7106 | } else { |
| 7107 | // Load with slow path based read barrier. |
| 7108 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7109 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7110 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 7111 | } |
| 7112 | } else { |
| 7113 | // Plain load with no read barrier. |
| 7114 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7115 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7116 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7117 | } |
| 7118 | } |
| 7119 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7120 | void InstructionCodeGeneratorX86::GenerateGcRootFieldLoad( |
| 7121 | HInstruction* instruction, |
| 7122 | Location root, |
| 7123 | const Address& address, |
| 7124 | Label* fixup_label, |
| 7125 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7126 | Register root_reg = root.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7127 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7128 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7129 | if (kUseBakerReadBarrier) { |
| 7130 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 7131 | // Baker's read barrier are used: |
| 7132 | // |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7133 | // root = obj.field; |
| 7134 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 7135 | // if (temp != null) { |
| 7136 | // root = temp(root) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7137 | // } |
| 7138 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7139 | // /* GcRoot<mirror::Object> */ root = *address |
| 7140 | __ movl(root_reg, address); |
| 7141 | if (fixup_label != nullptr) { |
| 7142 | __ Bind(fixup_label); |
| 7143 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7144 | static_assert( |
| 7145 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 7146 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 7147 | "have different sizes."); |
| 7148 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 7149 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 7150 | "have different sizes."); |
| 7151 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7152 | // Slow path marking the GC root `root`. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7153 | SlowPathCode* slow_path = new (GetGraph()->GetAllocator()) ReadBarrierMarkSlowPathX86( |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7154 | instruction, root, /* unpoison_ref_before_marking */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7155 | codegen_->AddSlowPath(slow_path); |
| 7156 | |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7157 | // Test the entrypoint (`Thread::Current()->pReadBarrierMarkReg ## root.reg()`). |
| 7158 | const int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 7159 | Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(root.reg()); |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7160 | __ fs()->cmpl(Address::Absolute(entry_point_offset), Immediate(0)); |
| 7161 | // The entrypoint is null when the GC is not marking. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7162 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 7163 | __ Bind(slow_path->GetExitLabel()); |
| 7164 | } else { |
| 7165 | // GC root loaded through a slow path for read barriers other |
| 7166 | // than Baker's. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7167 | // /* GcRoot<mirror::Object>* */ root = address |
| 7168 | __ leal(root_reg, address); |
| 7169 | if (fixup_label != nullptr) { |
| 7170 | __ Bind(fixup_label); |
| 7171 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7172 | // /* mirror::Object* */ root = root->Read() |
| 7173 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 7174 | } |
| 7175 | } else { |
| 7176 | // Plain GC root load with no read barrier. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7177 | // /* GcRoot<mirror::Object> */ root = *address |
| 7178 | __ movl(root_reg, address); |
| 7179 | if (fixup_label != nullptr) { |
| 7180 | __ Bind(fixup_label); |
| 7181 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7182 | // Note that GC roots are not affected by heap poisoning, thus we |
| 7183 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7184 | } |
| 7185 | } |
| 7186 | |
| 7187 | void CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7188 | Location ref, |
| 7189 | Register obj, |
| 7190 | uint32_t offset, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7191 | bool needs_null_check) { |
| 7192 | DCHECK(kEmitCompilerReadBarrier); |
| 7193 | DCHECK(kUseBakerReadBarrier); |
| 7194 | |
| 7195 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7196 | Address src(obj, offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7197 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7198 | } |
| 7199 | |
| 7200 | void CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7201 | Location ref, |
| 7202 | Register obj, |
| 7203 | uint32_t data_offset, |
| 7204 | Location index, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7205 | bool needs_null_check) { |
| 7206 | DCHECK(kEmitCompilerReadBarrier); |
| 7207 | DCHECK(kUseBakerReadBarrier); |
| 7208 | |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 7209 | static_assert( |
| 7210 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 7211 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7212 | // /* HeapReference<Object> */ ref = |
| 7213 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7214 | Address src = CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7215 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7216 | } |
| 7217 | |
| 7218 | void CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7219 | Location ref, |
| 7220 | Register obj, |
| 7221 | const Address& src, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7222 | bool needs_null_check, |
| 7223 | bool always_update_field, |
| 7224 | Register* temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7225 | DCHECK(kEmitCompilerReadBarrier); |
| 7226 | DCHECK(kUseBakerReadBarrier); |
| 7227 | |
| 7228 | // In slow path based read barriers, the read barrier call is |
| 7229 | // inserted after the original load. However, in fast path based |
| 7230 | // Baker's read barriers, we need to perform the load of |
| 7231 | // mirror::Object::monitor_ *before* the original reference load. |
| 7232 | // This load-load ordering is required by the read barrier. |
| 7233 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 7234 | // |
| 7235 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7236 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7237 | // HeapReference<Object> ref = *src; // Original reference load. |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7238 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7239 | // if (is_gray) { |
| 7240 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 7241 | // } |
| 7242 | // |
| 7243 | // Note: the original implementation in ReadBarrier::Barrier is |
| 7244 | // slightly more complex as: |
| 7245 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7246 | // the high-bits of rb_state, which are expected to be all zeroes |
| 7247 | // (we use CodeGeneratorX86::GenerateMemoryBarrier instead here, |
| 7248 | // which is a no-op thanks to the x86 memory model); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7249 | // - it performs additional checks that we do not do here for |
| 7250 | // performance reasons. |
| 7251 | |
| 7252 | Register ref_reg = ref.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7253 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 7254 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7255 | // 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] | 7256 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 7257 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7258 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 7259 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 7260 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 7261 | |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7262 | // if (rb_state == ReadBarrier::GrayState()) |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7263 | // ref = ReadBarrier::Mark(ref); |
| 7264 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 7265 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7266 | if (needs_null_check) { |
| 7267 | MaybeRecordImplicitNullCheck(instruction); |
| 7268 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7269 | |
| 7270 | // Load fence to prevent load-load reordering. |
| 7271 | // Note that this is a no-op, thanks to the x86 memory model. |
| 7272 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 7273 | |
| 7274 | // The actual reference load. |
| 7275 | // /* HeapReference<Object> */ ref = *src |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7276 | __ movl(ref_reg, src); // Flags are unaffected. |
| 7277 | |
| 7278 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 7279 | // Slow path marking the object `ref` when it is gray. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7280 | SlowPathCode* slow_path; |
| 7281 | if (always_update_field) { |
| 7282 | DCHECK(temp != nullptr); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7283 | slow_path = new (GetGraph()->GetAllocator()) ReadBarrierMarkAndUpdateFieldSlowPathX86( |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7284 | instruction, ref, obj, src, /* unpoison_ref_before_marking */ true, *temp); |
| 7285 | } else { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7286 | slow_path = new (GetGraph()->GetAllocator()) ReadBarrierMarkSlowPathX86( |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7287 | instruction, ref, /* unpoison_ref_before_marking */ true); |
| 7288 | } |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7289 | AddSlowPath(slow_path); |
| 7290 | |
| 7291 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 7292 | __ j(kNotZero, slow_path->GetEntryLabel()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7293 | |
| 7294 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7295 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7296 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7297 | __ Bind(slow_path->GetExitLabel()); |
| 7298 | } |
| 7299 | |
| 7300 | void CodeGeneratorX86::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7301 | Location out, |
| 7302 | Location ref, |
| 7303 | Location obj, |
| 7304 | uint32_t offset, |
| 7305 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7306 | DCHECK(kEmitCompilerReadBarrier); |
| 7307 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7308 | // Insert a slow path based read barrier *after* the reference load. |
| 7309 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7310 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7311 | // reference will be carried out by the runtime within the slow |
| 7312 | // path. |
| 7313 | // |
| 7314 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7315 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7316 | // not used by the artReadBarrierSlow entry point. |
| 7317 | // |
| 7318 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7319 | SlowPathCode* slow_path = new (GetGraph()->GetAllocator()) |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7320 | ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); |
| 7321 | AddSlowPath(slow_path); |
| 7322 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7323 | __ jmp(slow_path->GetEntryLabel()); |
| 7324 | __ Bind(slow_path->GetExitLabel()); |
| 7325 | } |
| 7326 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7327 | void CodeGeneratorX86::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 7328 | Location out, |
| 7329 | Location ref, |
| 7330 | Location obj, |
| 7331 | uint32_t offset, |
| 7332 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7333 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7334 | // Baker's read barriers shall be handled by the fast path |
| 7335 | // (CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier). |
| 7336 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7337 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7338 | // by the runtime within the slow path. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7339 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7340 | } else if (kPoisonHeapReferences) { |
| 7341 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 7342 | } |
| 7343 | } |
| 7344 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7345 | void CodeGeneratorX86::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7346 | Location out, |
| 7347 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7348 | DCHECK(kEmitCompilerReadBarrier); |
| 7349 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7350 | // Insert a slow path based read barrier *after* the GC root load. |
| 7351 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7352 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7353 | // not need to do anything special for this here. |
| 7354 | SlowPathCode* slow_path = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7355 | new (GetGraph()->GetAllocator()) ReadBarrierForRootSlowPathX86(instruction, out, root); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7356 | AddSlowPath(slow_path); |
| 7357 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7358 | __ jmp(slow_path->GetEntryLabel()); |
| 7359 | __ Bind(slow_path->GetExitLabel()); |
| 7360 | } |
| 7361 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7362 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7363 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7364 | LOG(FATAL) << "Unreachable"; |
| 7365 | } |
| 7366 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7367 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7368 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7369 | LOG(FATAL) << "Unreachable"; |
| 7370 | } |
| 7371 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7372 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7373 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7374 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7375 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7376 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7377 | } |
| 7378 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7379 | void InstructionCodeGeneratorX86::GenPackedSwitchWithCompares(Register value_reg, |
| 7380 | int32_t lower_bound, |
| 7381 | uint32_t num_entries, |
| 7382 | HBasicBlock* switch_block, |
| 7383 | HBasicBlock* default_block) { |
| 7384 | // Figure out the correct compare values and jump conditions. |
| 7385 | // Handle the first compare/branch as a special case because it might |
| 7386 | // jump to the default case. |
| 7387 | DCHECK_GT(num_entries, 2u); |
| 7388 | Condition first_condition; |
| 7389 | uint32_t index; |
| 7390 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 7391 | if (lower_bound != 0) { |
| 7392 | first_condition = kLess; |
| 7393 | __ cmpl(value_reg, Immediate(lower_bound)); |
| 7394 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 7395 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7396 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7397 | index = 1; |
| 7398 | } else { |
| 7399 | // Handle all the compare/jumps below. |
| 7400 | first_condition = kBelow; |
| 7401 | index = 0; |
| 7402 | } |
| 7403 | |
| 7404 | // Handle the rest of the compare/jumps. |
| 7405 | for (; index + 1 < num_entries; index += 2) { |
| 7406 | int32_t compare_to_value = lower_bound + index + 1; |
| 7407 | __ cmpl(value_reg, Immediate(compare_to_value)); |
| 7408 | // Jump to successors[index] if value < case_value[index]. |
| 7409 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 7410 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 7411 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 7412 | } |
| 7413 | |
| 7414 | if (index != num_entries) { |
| 7415 | // There are an odd number of entries. Handle the last one. |
| 7416 | DCHECK_EQ(index + 1, num_entries); |
| 7417 | __ cmpl(value_reg, Immediate(lower_bound + index)); |
| 7418 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7419 | } |
| 7420 | |
| 7421 | // And the default for any other value. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7422 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
| 7423 | __ jmp(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7424 | } |
| 7425 | } |
| 7426 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7427 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7428 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 7429 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 7430 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7431 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7432 | |
| 7433 | GenPackedSwitchWithCompares(value_reg, |
| 7434 | lower_bound, |
| 7435 | num_entries, |
| 7436 | switch_instr->GetBlock(), |
| 7437 | switch_instr->GetDefaultBlock()); |
| 7438 | } |
| 7439 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7440 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7441 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7442 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7443 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7444 | |
| 7445 | // Constant area pointer. |
| 7446 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7447 | |
| 7448 | // And the temporary we need. |
| 7449 | locations->AddTemp(Location::RequiresRegister()); |
| 7450 | } |
| 7451 | |
| 7452 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7453 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7454 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7455 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7456 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7457 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7458 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7459 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 7460 | GenPackedSwitchWithCompares(value_reg, |
| 7461 | lower_bound, |
| 7462 | num_entries, |
| 7463 | switch_instr->GetBlock(), |
| 7464 | default_block); |
| 7465 | return; |
| 7466 | } |
| 7467 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7468 | // Optimizing has a jump area. |
| 7469 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 7470 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 7471 | |
| 7472 | // Remove the bias, if needed. |
| 7473 | if (lower_bound != 0) { |
| 7474 | __ leal(temp_reg, Address(value_reg, -lower_bound)); |
| 7475 | value_reg = temp_reg; |
| 7476 | } |
| 7477 | |
| 7478 | // Is the value in range? |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7479 | DCHECK_GE(num_entries, 1u); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7480 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 7481 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| 7482 | |
| 7483 | // We are in the range of the table. |
| 7484 | // Load (target-constant_area) from the jump table, indexing by the value. |
| 7485 | __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); |
| 7486 | |
| 7487 | // Compute the actual target address by adding in constant_area. |
| 7488 | __ addl(temp_reg, constant_area); |
| 7489 | |
| 7490 | // And jump. |
| 7491 | __ jmp(temp_reg); |
| 7492 | } |
| 7493 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7494 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 7495 | HX86ComputeBaseMethodAddress* insn) { |
| 7496 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7497 | new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7498 | locations->SetOut(Location::RequiresRegister()); |
| 7499 | } |
| 7500 | |
| 7501 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 7502 | HX86ComputeBaseMethodAddress* insn) { |
| 7503 | LocationSummary* locations = insn->GetLocations(); |
| 7504 | Register reg = locations->Out().AsRegister<Register>(); |
| 7505 | |
| 7506 | // Generate call to next instruction. |
| 7507 | Label next_instruction; |
| 7508 | __ call(&next_instruction); |
| 7509 | __ Bind(&next_instruction); |
| 7510 | |
| 7511 | // Remember this offset for later use with constant area. |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7512 | codegen_->AddMethodAddressOffset(insn, GetAssembler()->CodeSize()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7513 | |
| 7514 | // Grab the return address off the stack. |
| 7515 | __ popl(reg); |
| 7516 | } |
| 7517 | |
| 7518 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 7519 | HX86LoadFromConstantTable* insn) { |
| 7520 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7521 | new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7522 | |
| 7523 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7524 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 7525 | |
| 7526 | // 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] | 7527 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7528 | return; |
| 7529 | } |
| 7530 | |
| 7531 | switch (insn->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7532 | case DataType::Type::kFloat32: |
| 7533 | case DataType::Type::kFloat64: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7534 | locations->SetOut(Location::RequiresFpuRegister()); |
| 7535 | break; |
| 7536 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7537 | case DataType::Type::kInt32: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7538 | locations->SetOut(Location::RequiresRegister()); |
| 7539 | break; |
| 7540 | |
| 7541 | default: |
| 7542 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7543 | } |
| 7544 | } |
| 7545 | |
| 7546 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 7547 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7548 | return; |
| 7549 | } |
| 7550 | |
| 7551 | LocationSummary* locations = insn->GetLocations(); |
| 7552 | Location out = locations->Out(); |
| 7553 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 7554 | HConstant *value = insn->GetConstant(); |
| 7555 | |
| 7556 | switch (insn->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7557 | case DataType::Type::kFloat32: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7558 | __ movss(out.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7559 | codegen_->LiteralFloatAddress( |
| 7560 | value->AsFloatConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7561 | break; |
| 7562 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7563 | case DataType::Type::kFloat64: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7564 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7565 | codegen_->LiteralDoubleAddress( |
| 7566 | value->AsDoubleConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7567 | break; |
| 7568 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7569 | case DataType::Type::kInt32: |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7570 | __ movl(out.AsRegister<Register>(), |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7571 | codegen_->LiteralInt32Address( |
| 7572 | value->AsIntConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7573 | break; |
| 7574 | |
| 7575 | default: |
| 7576 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7577 | } |
| 7578 | } |
| 7579 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7580 | /** |
| 7581 | * Class to handle late fixup of offsets into constant area. |
| 7582 | */ |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 7583 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7584 | public: |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7585 | RIPFixup(CodeGeneratorX86& codegen, |
| 7586 | HX86ComputeBaseMethodAddress* base_method_address, |
| 7587 | size_t offset) |
| 7588 | : codegen_(&codegen), |
| 7589 | base_method_address_(base_method_address), |
| 7590 | offset_into_constant_area_(offset) {} |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7591 | |
| 7592 | protected: |
| 7593 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 7594 | |
| 7595 | CodeGeneratorX86* codegen_; |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7596 | HX86ComputeBaseMethodAddress* base_method_address_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7597 | |
| 7598 | private: |
| 7599 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 7600 | // Patch the correct offset for the instruction. The place to patch is the |
| 7601 | // last 4 bytes of the instruction. |
| 7602 | // The value to patch is the distance from the offset in the constant area |
| 7603 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7604 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7605 | int32_t relative_position = |
| 7606 | constant_offset - codegen_->GetMethodAddressOffset(base_method_address_); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7607 | |
| 7608 | // Patch in the right value. |
| 7609 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 7610 | } |
| 7611 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7612 | // Location in constant area that the fixup refers to. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7613 | int32_t offset_into_constant_area_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7614 | }; |
| 7615 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7616 | /** |
| 7617 | * Class to handle late fixup of offsets to a jump table that will be created in the |
| 7618 | * constant area. |
| 7619 | */ |
| 7620 | class JumpTableRIPFixup : public RIPFixup { |
| 7621 | public: |
| 7622 | JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7623 | : RIPFixup(codegen, switch_instr->GetBaseMethodAddress(), static_cast<size_t>(-1)), |
| 7624 | switch_instr_(switch_instr) {} |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7625 | |
| 7626 | void CreateJumpTable() { |
| 7627 | X86Assembler* assembler = codegen_->GetAssembler(); |
| 7628 | |
| 7629 | // Ensure that the reference to the jump table has the correct offset. |
| 7630 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 7631 | SetOffset(offset_in_constant_table); |
| 7632 | |
| 7633 | // The label values in the jump table are computed relative to the |
| 7634 | // instruction addressing the constant area. |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7635 | const int32_t relative_offset = codegen_->GetMethodAddressOffset(base_method_address_); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7636 | |
| 7637 | // Populate the jump table with the correct values for the jump table. |
| 7638 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 7639 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 7640 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 7641 | // The value that we want is the target offset - the position of the table. |
| 7642 | for (int32_t i = 0; i < num_entries; i++) { |
| 7643 | HBasicBlock* b = successors[i]; |
| 7644 | Label* l = codegen_->GetLabelOf(b); |
| 7645 | DCHECK(l->IsBound()); |
| 7646 | int32_t offset_to_block = l->Position() - relative_offset; |
| 7647 | assembler->AppendInt32(offset_to_block); |
| 7648 | } |
| 7649 | } |
| 7650 | |
| 7651 | private: |
| 7652 | const HX86PackedSwitch* switch_instr_; |
| 7653 | }; |
| 7654 | |
| 7655 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 7656 | // Generate the constant area if needed. |
| 7657 | X86Assembler* assembler = GetAssembler(); |
| 7658 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7659 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 7660 | // byte values. |
| 7661 | assembler->Align(4, 0); |
| 7662 | constant_area_start_ = assembler->CodeSize(); |
| 7663 | |
| 7664 | // Populate any jump tables. |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7665 | for (JumpTableRIPFixup* jump_table : fixups_to_jump_tables_) { |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7666 | jump_table->CreateJumpTable(); |
| 7667 | } |
| 7668 | |
| 7669 | // And now add the constant area to the generated code. |
| 7670 | assembler->AddConstantArea(); |
| 7671 | } |
| 7672 | |
| 7673 | // And finish up. |
| 7674 | CodeGenerator::Finalize(allocator); |
| 7675 | } |
| 7676 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7677 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, |
| 7678 | HX86ComputeBaseMethodAddress* method_base, |
| 7679 | Register reg) { |
| 7680 | AssemblerFixup* fixup = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7681 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddDouble(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7682 | return Address(reg, kDummy32BitOffset, fixup); |
| 7683 | } |
| 7684 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7685 | Address CodeGeneratorX86::LiteralFloatAddress(float v, |
| 7686 | HX86ComputeBaseMethodAddress* method_base, |
| 7687 | Register reg) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7688 | AssemblerFixup* fixup = |
| 7689 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddFloat(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7690 | return Address(reg, kDummy32BitOffset, fixup); |
| 7691 | } |
| 7692 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7693 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, |
| 7694 | HX86ComputeBaseMethodAddress* method_base, |
| 7695 | Register reg) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7696 | AssemblerFixup* fixup = |
| 7697 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddInt32(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7698 | return Address(reg, kDummy32BitOffset, fixup); |
| 7699 | } |
| 7700 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 7701 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, |
| 7702 | HX86ComputeBaseMethodAddress* method_base, |
| 7703 | Register reg) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7704 | AssemblerFixup* fixup = |
| 7705 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddInt64(v)); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7706 | return Address(reg, kDummy32BitOffset, fixup); |
| 7707 | } |
| 7708 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 7709 | void CodeGeneratorX86::Load32BitValue(Register dest, int32_t value) { |
| 7710 | if (value == 0) { |
| 7711 | __ xorl(dest, dest); |
| 7712 | } else { |
| 7713 | __ movl(dest, Immediate(value)); |
| 7714 | } |
| 7715 | } |
| 7716 | |
| 7717 | void CodeGeneratorX86::Compare32BitValue(Register dest, int32_t value) { |
| 7718 | if (value == 0) { |
| 7719 | __ testl(dest, dest); |
| 7720 | } else { |
| 7721 | __ cmpl(dest, Immediate(value)); |
| 7722 | } |
| 7723 | } |
| 7724 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7725 | void CodeGeneratorX86::GenerateIntCompare(Location lhs, Location rhs) { |
| 7726 | Register lhs_reg = lhs.AsRegister<Register>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7727 | GenerateIntCompare(lhs_reg, rhs); |
| 7728 | } |
| 7729 | |
| 7730 | void CodeGeneratorX86::GenerateIntCompare(Register lhs, Location rhs) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7731 | if (rhs.IsConstant()) { |
| 7732 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7733 | Compare32BitValue(lhs, value); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7734 | } else if (rhs.IsStackSlot()) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7735 | __ cmpl(lhs, Address(ESP, rhs.GetStackIndex())); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7736 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7737 | __ cmpl(lhs, rhs.AsRegister<Register>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7738 | } |
| 7739 | } |
| 7740 | |
| 7741 | Address CodeGeneratorX86::ArrayAddress(Register obj, |
| 7742 | Location index, |
| 7743 | ScaleFactor scale, |
| 7744 | uint32_t data_offset) { |
| 7745 | return index.IsConstant() ? |
| 7746 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) : |
| 7747 | Address(obj, index.AsRegister<Register>(), scale, data_offset); |
| 7748 | } |
| 7749 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7750 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, |
| 7751 | Register reg, |
| 7752 | Register value) { |
| 7753 | // Create a fixup to be used to create and address the jump table. |
| 7754 | JumpTableRIPFixup* table_fixup = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7755 | new (GetGraph()->GetAllocator()) JumpTableRIPFixup(*this, switch_instr); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7756 | |
| 7757 | // We have to populate the jump tables. |
| 7758 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7759 | |
| 7760 | // We want a scaled address, as we are extracting the correct offset from the table. |
| 7761 | return Address(reg, value, TIMES_4, kDummy32BitOffset, table_fixup); |
| 7762 | } |
| 7763 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7764 | // TODO: target as memory. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7765 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, DataType::Type type) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7766 | if (!target.IsValid()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7767 | DCHECK_EQ(type, DataType::Type::kVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7768 | return; |
| 7769 | } |
| 7770 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7771 | DCHECK_NE(type, DataType::Type::kVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7772 | |
| 7773 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 7774 | if (target.Equals(return_loc)) { |
| 7775 | return; |
| 7776 | } |
| 7777 | |
| 7778 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 7779 | // with the else branch. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7780 | if (type == DataType::Type::kInt64) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7781 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7782 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), DataType::Type::kInt32, nullptr); |
| 7783 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), DataType::Type::kInt32, nullptr); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7784 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7785 | } else { |
| 7786 | // Let the parallel move resolver take care of all of this. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7787 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7788 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 7789 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7790 | } |
| 7791 | } |
| 7792 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7793 | void CodeGeneratorX86::PatchJitRootUse(uint8_t* code, |
| 7794 | const uint8_t* roots_data, |
| 7795 | const PatchInfo<Label>& info, |
| 7796 | uint64_t index_in_table) const { |
| 7797 | uint32_t code_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 7798 | uintptr_t address = |
| 7799 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 7800 | typedef __attribute__((__aligned__(1))) uint32_t unaligned_uint32_t; |
| 7801 | reinterpret_cast<unaligned_uint32_t*>(code + code_offset)[0] = |
| 7802 | dchecked_integral_cast<uint32_t>(address); |
| 7803 | } |
| 7804 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7805 | void CodeGeneratorX86::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 7806 | for (const PatchInfo<Label>& info : jit_string_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7807 | const auto it = jit_string_roots_.find( |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7808 | StringReference(&info.dex_file, dex::StringIndex(info.index))); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7809 | DCHECK(it != jit_string_roots_.end()); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7810 | uint64_t index_in_table = it->second; |
| 7811 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7812 | } |
| 7813 | |
| 7814 | for (const PatchInfo<Label>& info : jit_class_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7815 | const auto it = jit_class_roots_.find( |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7816 | TypeReference(&info.dex_file, dex::TypeIndex(info.index))); |
| 7817 | DCHECK(it != jit_class_roots_.end()); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7818 | uint64_t index_in_table = it->second; |
| 7819 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7820 | } |
| 7821 | } |
| 7822 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7823 | #undef __ |
| 7824 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7825 | } // namespace x86 |
| 7826 | } // namespace art |