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" |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 20 | #include "code_generator_utils.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 21 | #include "compiled_method.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 22 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 23 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 24 | #include "gc/accounting/card_table.h" |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 25 | #include "intrinsics.h" |
| 26 | #include "intrinsics_x86.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 27 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 28 | #include "mirror/class-inl.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 29 | #include "thread.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 30 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 31 | #include "utils/stack_checks.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 32 | #include "utils/x86/assembler_x86.h" |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 33 | #include "utils/x86/managed_register_x86.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 34 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 35 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 36 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 37 | template<class MirrorType> |
| 38 | class GcRoot; |
| 39 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 40 | namespace x86 { |
| 41 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 42 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 43 | static constexpr Register kMethodRegisterArgument = EAX; |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 44 | static constexpr Register kCoreCalleeSaves[] = { EBP, ESI, EDI }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 45 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 46 | static constexpr int kC2ConditionMask = 0x400; |
| 47 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 48 | static constexpr int kFakeReturnRegister = Register(8); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 49 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 50 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 51 | #define __ down_cast<X86Assembler*>(codegen->GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 52 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86PointerSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 53 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 54 | class NullCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 55 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 56 | explicit NullCheckSlowPathX86(HNullCheck* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 57 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 58 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 59 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 60 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 61 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 62 | // Live registers will be restored in the catch block if caught. |
| 63 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 64 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 65 | x86_codegen->InvokeRuntime(kQuickThrowNullPointer, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 66 | instruction_, |
| 67 | instruction_->GetDexPc(), |
| 68 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 69 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 70 | } |
| 71 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 72 | bool IsFatal() const OVERRIDE { return true; } |
| 73 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 74 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86"; } |
| 75 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 76 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 77 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86); |
| 78 | }; |
| 79 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 80 | class DivZeroCheckSlowPathX86 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 81 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 82 | explicit DivZeroCheckSlowPathX86(HDivZeroCheck* instruction) : SlowPathCode(instruction) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 83 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 84 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 85 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 86 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 87 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 88 | // Live registers will be restored in the catch block if caught. |
| 89 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 90 | } |
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); |
| 157 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 158 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 159 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 160 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 161 | Primitive::kPrimInt, |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 162 | length_loc, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 163 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 164 | Primitive::kPrimInt); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 165 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 166 | ? kQuickThrowStringBounds |
| 167 | : kQuickThrowArrayBounds; |
| 168 | x86_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 169 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 170 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 171 | } |
| 172 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 173 | bool IsFatal() const OVERRIDE { return true; } |
| 174 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 175 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86"; } |
| 176 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 177 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 178 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86); |
| 179 | }; |
| 180 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 181 | class SuspendCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 182 | public: |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 183 | SuspendCheckSlowPathX86(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 184 | : SlowPathCode(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 185 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 186 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 187 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 188 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 189 | x86_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 190 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 191 | if (successor_ == nullptr) { |
| 192 | __ jmp(GetReturnLabel()); |
| 193 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 194 | __ jmp(x86_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 195 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 196 | } |
| 197 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 198 | Label* GetReturnLabel() { |
| 199 | DCHECK(successor_ == nullptr); |
| 200 | return &return_label_; |
| 201 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 202 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 203 | HBasicBlock* GetSuccessor() const { |
| 204 | return successor_; |
| 205 | } |
| 206 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 207 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86"; } |
| 208 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 209 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 210 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 211 | Label return_label_; |
| 212 | |
| 213 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86); |
| 214 | }; |
| 215 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 216 | class LoadStringSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 217 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 218 | explicit LoadStringSlowPathX86(HLoadString* instruction): SlowPathCode(instruction) {} |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 219 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 220 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 221 | LocationSummary* locations = instruction_->GetLocations(); |
| 222 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 223 | |
| 224 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 225 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 226 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 227 | |
| 228 | InvokeRuntimeCallingConvention calling_convention; |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 229 | const uint32_t string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 230 | __ movl(calling_convention.GetRegisterAt(0), Immediate(string_index)); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 231 | x86_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 232 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 233 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 234 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 235 | |
| 236 | __ jmp(GetExitLabel()); |
| 237 | } |
| 238 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 239 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86"; } |
| 240 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 241 | private: |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 242 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86); |
| 243 | }; |
| 244 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 245 | class LoadClassSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 246 | public: |
| 247 | LoadClassSlowPathX86(HLoadClass* cls, |
| 248 | HInstruction* at, |
| 249 | uint32_t dex_pc, |
| 250 | bool do_clinit) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 251 | : SlowPathCode(at), cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 252 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 253 | } |
| 254 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 255 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 256 | LocationSummary* locations = at_->GetLocations(); |
| 257 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 258 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 259 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 260 | |
| 261 | InvokeRuntimeCallingConvention calling_convention; |
| 262 | __ movl(calling_convention.GetRegisterAt(0), Immediate(cls_->GetTypeIndex())); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 263 | x86_codegen->InvokeRuntime(do_clinit_ ? kQuickInitializeStaticStorage |
| 264 | : kQuickInitializeType, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 265 | at_, dex_pc_, this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 266 | if (do_clinit_) { |
| 267 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 268 | } else { |
| 269 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 270 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 271 | |
| 272 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 273 | Location out = locations->Out(); |
| 274 | if (out.IsValid()) { |
| 275 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 276 | x86_codegen->Move32(out, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 277 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 278 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 279 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 280 | __ jmp(GetExitLabel()); |
| 281 | } |
| 282 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 283 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86"; } |
| 284 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 285 | private: |
| 286 | // The class this slow path will load. |
| 287 | HLoadClass* const cls_; |
| 288 | |
| 289 | // The instruction where this slow path is happening. |
| 290 | // (Might be the load class or an initialization check). |
| 291 | HInstruction* const at_; |
| 292 | |
| 293 | // The dex PC of `at_`. |
| 294 | const uint32_t dex_pc_; |
| 295 | |
| 296 | // Whether to initialize the class. |
| 297 | const bool do_clinit_; |
| 298 | |
| 299 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86); |
| 300 | }; |
| 301 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 302 | class TypeCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 303 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 304 | TypeCheckSlowPathX86(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 305 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 306 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 307 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 308 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 309 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 310 | : locations->Out(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 311 | DCHECK(instruction_->IsCheckCast() |
| 312 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 313 | |
| 314 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 315 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 316 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 317 | if (!is_fatal_) { |
| 318 | SaveLiveRegisters(codegen, locations); |
| 319 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 320 | |
| 321 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 322 | // move resolver. |
| 323 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 324 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 325 | locations->InAt(1), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 326 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 327 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 328 | object_class, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 329 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 330 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 331 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 332 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 333 | x86_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 334 | instruction_, |
| 335 | instruction_->GetDexPc(), |
| 336 | this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 337 | CheckEntrypointTypes< |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 338 | kQuickInstanceofNonTrivial, size_t, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 339 | } else { |
| 340 | DCHECK(instruction_->IsCheckCast()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 341 | x86_codegen->InvokeRuntime(kQuickCheckCast, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 342 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 343 | } |
| 344 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 345 | if (!is_fatal_) { |
| 346 | if (instruction_->IsInstanceOf()) { |
| 347 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 348 | } |
| 349 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 350 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 351 | __ jmp(GetExitLabel()); |
| 352 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 353 | } |
| 354 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 355 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86"; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 356 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 357 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 358 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 359 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 360 | |
| 361 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86); |
| 362 | }; |
| 363 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 364 | class DeoptimizationSlowPathX86 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 365 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 366 | explicit DeoptimizationSlowPathX86(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 367 | : SlowPathCode(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 368 | |
| 369 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 370 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 371 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 372 | x86_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 373 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 374 | } |
| 375 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 376 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86"; } |
| 377 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 378 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 379 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86); |
| 380 | }; |
| 381 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 382 | class ArraySetSlowPathX86 : public SlowPathCode { |
| 383 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 384 | explicit ArraySetSlowPathX86(HInstruction* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 385 | |
| 386 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 387 | LocationSummary* locations = instruction_->GetLocations(); |
| 388 | __ Bind(GetEntryLabel()); |
| 389 | SaveLiveRegisters(codegen, locations); |
| 390 | |
| 391 | InvokeRuntimeCallingConvention calling_convention; |
| 392 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 393 | parallel_move.AddMove( |
| 394 | locations->InAt(0), |
| 395 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 396 | Primitive::kPrimNot, |
| 397 | nullptr); |
| 398 | parallel_move.AddMove( |
| 399 | locations->InAt(1), |
| 400 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 401 | Primitive::kPrimInt, |
| 402 | nullptr); |
| 403 | parallel_move.AddMove( |
| 404 | locations->InAt(2), |
| 405 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 406 | Primitive::kPrimNot, |
| 407 | nullptr); |
| 408 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 409 | |
| 410 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 411 | x86_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 412 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 413 | RestoreLiveRegisters(codegen, locations); |
| 414 | __ jmp(GetExitLabel()); |
| 415 | } |
| 416 | |
| 417 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86"; } |
| 418 | |
| 419 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 420 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86); |
| 421 | }; |
| 422 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 423 | // Slow path marking an object during a read barrier. |
| 424 | class ReadBarrierMarkSlowPathX86 : public SlowPathCode { |
| 425 | public: |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 426 | ReadBarrierMarkSlowPathX86(HInstruction* instruction, Location obj, bool unpoison) |
| 427 | : SlowPathCode(instruction), obj_(obj), unpoison_(unpoison) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 428 | DCHECK(kEmitCompilerReadBarrier); |
| 429 | } |
| 430 | |
| 431 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathX86"; } |
| 432 | |
| 433 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 434 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 435 | Register reg = obj_.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 436 | DCHECK(locations->CanCall()); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 437 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 438 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 439 | instruction_->IsStaticFieldGet() || |
| 440 | instruction_->IsArrayGet() || |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 441 | instruction_->IsArraySet() || |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 442 | instruction_->IsLoadClass() || |
| 443 | instruction_->IsLoadString() || |
| 444 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 445 | instruction_->IsCheckCast() || |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 446 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 447 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 448 | << "Unexpected instruction in read barrier marking slow path: " |
| 449 | << instruction_->DebugName(); |
| 450 | |
| 451 | __ Bind(GetEntryLabel()); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 452 | if (unpoison_) { |
| 453 | // Object* ref = ref_addr->AsMirrorPtr() |
| 454 | __ MaybeUnpoisonHeapReference(reg); |
| 455 | } |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 456 | // No need to save live registers; it's taken care of by the |
| 457 | // entrypoint. Also, there is no need to update the stack mask, |
| 458 | // as this runtime call will not trigger a garbage collection. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 459 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 460 | DCHECK_NE(reg, ESP); |
| 461 | DCHECK(0 <= reg && reg < kNumberOfCpuRegisters) << reg; |
| 462 | // "Compact" slow path, saving two moves. |
| 463 | // |
| 464 | // Instead of using the standard runtime calling convention (input |
| 465 | // and output in EAX): |
| 466 | // |
| 467 | // EAX <- obj |
| 468 | // EAX <- ReadBarrierMark(EAX) |
| 469 | // obj <- EAX |
| 470 | // |
| 471 | // we just use rX (the register holding `obj`) as input and output |
| 472 | // of a dedicated entrypoint: |
| 473 | // |
| 474 | // rX <- ReadBarrierMarkRegX(rX) |
| 475 | // |
| 476 | int32_t entry_point_offset = |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 477 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kX86PointerSize>(reg); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 478 | // This runtime call does not require a stack map. |
| 479 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 480 | __ jmp(GetExitLabel()); |
| 481 | } |
| 482 | |
| 483 | private: |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 484 | const Location obj_; |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 485 | const bool unpoison_; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 486 | |
| 487 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86); |
| 488 | }; |
| 489 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 490 | // Slow path generating a read barrier for a heap reference. |
| 491 | class ReadBarrierForHeapReferenceSlowPathX86 : public SlowPathCode { |
| 492 | public: |
| 493 | ReadBarrierForHeapReferenceSlowPathX86(HInstruction* instruction, |
| 494 | Location out, |
| 495 | Location ref, |
| 496 | Location obj, |
| 497 | uint32_t offset, |
| 498 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 499 | : SlowPathCode(instruction), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 500 | out_(out), |
| 501 | ref_(ref), |
| 502 | obj_(obj), |
| 503 | offset_(offset), |
| 504 | index_(index) { |
| 505 | DCHECK(kEmitCompilerReadBarrier); |
| 506 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 507 | // has been overwritten by (or after) the heap object reference load |
| 508 | // to be instrumented, e.g.: |
| 509 | // |
| 510 | // __ movl(out, Address(out, offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 511 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 512 | // |
| 513 | // In that case, we have lost the information about the original |
| 514 | // object, and the emitted read barrier cannot work properly. |
| 515 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 516 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 517 | } |
| 518 | |
| 519 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 520 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 521 | LocationSummary* locations = instruction_->GetLocations(); |
| 522 | Register reg_out = out_.AsRegister<Register>(); |
| 523 | DCHECK(locations->CanCall()); |
| 524 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 525 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 526 | instruction_->IsStaticFieldGet() || |
| 527 | instruction_->IsArrayGet() || |
| 528 | instruction_->IsInstanceOf() || |
| 529 | instruction_->IsCheckCast() || |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 530 | (instruction_->IsInvokeVirtual()) && instruction_->GetLocations()->Intrinsified()) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 531 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 532 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 533 | |
| 534 | __ Bind(GetEntryLabel()); |
| 535 | SaveLiveRegisters(codegen, locations); |
| 536 | |
| 537 | // We may have to change the index's value, but as `index_` is a |
| 538 | // constant member (like other "inputs" of this slow path), |
| 539 | // introduce a copy of it, `index`. |
| 540 | Location index = index_; |
| 541 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 542 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 543 | if (instruction_->IsArrayGet()) { |
| 544 | // Compute the actual memory offset and store it in `index`. |
| 545 | Register index_reg = index_.AsRegister<Register>(); |
| 546 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 547 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 548 | // We are about to change the value of `index_reg` (see the |
| 549 | // calls to art::x86::X86Assembler::shll and |
| 550 | // art::x86::X86Assembler::AddImmediate below), but it has |
| 551 | // not been saved by the previous call to |
| 552 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 553 | // callee-save register -- |
| 554 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 555 | // callee-save registers, as it has been designed with the |
| 556 | // assumption that callee-save registers are supposed to be |
| 557 | // handled by the called function. So, as a callee-save |
| 558 | // register, `index_reg` _would_ eventually be saved onto |
| 559 | // the stack, but it would be too late: we would have |
| 560 | // changed its value earlier. Therefore, we manually save |
| 561 | // it here into another freely available register, |
| 562 | // `free_reg`, chosen of course among the caller-save |
| 563 | // registers (as a callee-save `free_reg` register would |
| 564 | // exhibit the same problem). |
| 565 | // |
| 566 | // Note we could have requested a temporary register from |
| 567 | // the register allocator instead; but we prefer not to, as |
| 568 | // this is a slow path, and we know we can find a |
| 569 | // caller-save register that is available. |
| 570 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 571 | __ movl(free_reg, index_reg); |
| 572 | index_reg = free_reg; |
| 573 | index = Location::RegisterLocation(index_reg); |
| 574 | } else { |
| 575 | // The initial register stored in `index_` has already been |
| 576 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 577 | // (as it is not a callee-save register), so we can freely |
| 578 | // use it. |
| 579 | } |
| 580 | // Shifting the index value contained in `index_reg` by the scale |
| 581 | // factor (2) cannot overflow in practice, as the runtime is |
| 582 | // unable to allocate object arrays with a size larger than |
| 583 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 584 | __ shll(index_reg, Immediate(TIMES_4)); |
| 585 | static_assert( |
| 586 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 587 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 588 | __ AddImmediate(index_reg, Immediate(offset_)); |
| 589 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 590 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 591 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 592 | // (as in the case of ArrayGet), as it is actually an offset |
| 593 | // to an object field within an object. |
| 594 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 595 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 596 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 597 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 598 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 599 | DCHECK_EQ(offset_, 0U); |
| 600 | DCHECK(index_.IsRegisterPair()); |
| 601 | // UnsafeGet's offset location is a register pair, the low |
| 602 | // part contains the correct offset. |
| 603 | index = index_.ToLow(); |
| 604 | } |
| 605 | } |
| 606 | |
| 607 | // We're moving two or three locations to locations that could |
| 608 | // overlap, so we need a parallel move resolver. |
| 609 | InvokeRuntimeCallingConvention calling_convention; |
| 610 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 611 | parallel_move.AddMove(ref_, |
| 612 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 613 | Primitive::kPrimNot, |
| 614 | nullptr); |
| 615 | parallel_move.AddMove(obj_, |
| 616 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 617 | Primitive::kPrimNot, |
| 618 | nullptr); |
| 619 | if (index.IsValid()) { |
| 620 | parallel_move.AddMove(index, |
| 621 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 622 | Primitive::kPrimInt, |
| 623 | nullptr); |
| 624 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 625 | } else { |
| 626 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 627 | __ movl(calling_convention.GetRegisterAt(2), Immediate(offset_)); |
| 628 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 629 | x86_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 630 | CheckEntrypointTypes< |
| 631 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 632 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 633 | |
| 634 | RestoreLiveRegisters(codegen, locations); |
| 635 | __ jmp(GetExitLabel()); |
| 636 | } |
| 637 | |
| 638 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathX86"; } |
| 639 | |
| 640 | private: |
| 641 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 642 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 643 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 644 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 645 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 646 | return static_cast<Register>(i); |
| 647 | } |
| 648 | } |
| 649 | // We shall never fail to find a free caller-save register, as |
| 650 | // there are more than two core caller-save registers on x86 |
| 651 | // (meaning it is possible to find one which is different from |
| 652 | // `ref` and `obj`). |
| 653 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 654 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 655 | UNREACHABLE(); |
| 656 | } |
| 657 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 658 | const Location out_; |
| 659 | const Location ref_; |
| 660 | const Location obj_; |
| 661 | const uint32_t offset_; |
| 662 | // An additional location containing an index to an array. |
| 663 | // Only used for HArrayGet and the UnsafeGetObject & |
| 664 | // UnsafeGetObjectVolatile intrinsics. |
| 665 | const Location index_; |
| 666 | |
| 667 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86); |
| 668 | }; |
| 669 | |
| 670 | // Slow path generating a read barrier for a GC root. |
| 671 | class ReadBarrierForRootSlowPathX86 : public SlowPathCode { |
| 672 | public: |
| 673 | ReadBarrierForRootSlowPathX86(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 674 | : SlowPathCode(instruction), out_(out), root_(root) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 675 | DCHECK(kEmitCompilerReadBarrier); |
| 676 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 677 | |
| 678 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 679 | LocationSummary* locations = instruction_->GetLocations(); |
| 680 | Register reg_out = out_.AsRegister<Register>(); |
| 681 | DCHECK(locations->CanCall()); |
| 682 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 683 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 684 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 685 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 686 | |
| 687 | __ Bind(GetEntryLabel()); |
| 688 | SaveLiveRegisters(codegen, locations); |
| 689 | |
| 690 | InvokeRuntimeCallingConvention calling_convention; |
| 691 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 692 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 693 | x86_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 694 | instruction_, |
| 695 | instruction_->GetDexPc(), |
| 696 | this); |
| 697 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 698 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 699 | |
| 700 | RestoreLiveRegisters(codegen, locations); |
| 701 | __ jmp(GetExitLabel()); |
| 702 | } |
| 703 | |
| 704 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathX86"; } |
| 705 | |
| 706 | private: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 707 | const Location out_; |
| 708 | const Location root_; |
| 709 | |
| 710 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86); |
| 711 | }; |
| 712 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 713 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 714 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 715 | #define __ down_cast<X86Assembler*>(GetAssembler())-> // NOLINT |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 716 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 717 | inline Condition X86Condition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 718 | switch (cond) { |
| 719 | case kCondEQ: return kEqual; |
| 720 | case kCondNE: return kNotEqual; |
| 721 | case kCondLT: return kLess; |
| 722 | case kCondLE: return kLessEqual; |
| 723 | case kCondGT: return kGreater; |
| 724 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 725 | case kCondB: return kBelow; |
| 726 | case kCondBE: return kBelowEqual; |
| 727 | case kCondA: return kAbove; |
| 728 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 729 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 730 | LOG(FATAL) << "Unreachable"; |
| 731 | UNREACHABLE(); |
| 732 | } |
| 733 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 734 | // Maps signed condition to unsigned condition and FP condition to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 735 | inline Condition X86UnsignedOrFPCondition(IfCondition cond) { |
| 736 | switch (cond) { |
| 737 | case kCondEQ: return kEqual; |
| 738 | case kCondNE: return kNotEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 739 | // Signed to unsigned, and FP to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 740 | case kCondLT: return kBelow; |
| 741 | case kCondLE: return kBelowEqual; |
| 742 | case kCondGT: return kAbove; |
| 743 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 744 | // Unsigned remain unchanged. |
| 745 | case kCondB: return kBelow; |
| 746 | case kCondBE: return kBelowEqual; |
| 747 | case kCondA: return kAbove; |
| 748 | case kCondAE: return kAboveEqual; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 749 | } |
| 750 | LOG(FATAL) << "Unreachable"; |
| 751 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 752 | } |
| 753 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 754 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 755 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 759 | stream << XmmRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 760 | } |
| 761 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 762 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 763 | __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); |
| 764 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 765 | } |
| 766 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 767 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 768 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); |
| 769 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 770 | } |
| 771 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 772 | size_t CodeGeneratorX86::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 773 | __ movsd(Address(ESP, stack_index), XmmRegister(reg_id)); |
| 774 | return GetFloatingPointSpillSlotSize(); |
| 775 | } |
| 776 | |
| 777 | size_t CodeGeneratorX86::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 778 | __ movsd(XmmRegister(reg_id), Address(ESP, stack_index)); |
| 779 | return GetFloatingPointSpillSlotSize(); |
| 780 | } |
| 781 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 782 | void CodeGeneratorX86::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 783 | HInstruction* instruction, |
| 784 | uint32_t dex_pc, |
| 785 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 786 | ValidateInvokeRuntime(instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 787 | GenerateInvokeRuntime(GetThreadOffset<kX86PointerSize>(entrypoint).Int32Value()); |
| 788 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 789 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 790 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 791 | } |
| 792 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 793 | void CodeGeneratorX86::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 794 | HInstruction* instruction, |
| 795 | SlowPathCode* slow_path) { |
| 796 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 797 | GenerateInvokeRuntime(entry_point_offset); |
| 798 | } |
| 799 | |
| 800 | void CodeGeneratorX86::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 801 | __ fs()->call(Address::Absolute(entry_point_offset)); |
| 802 | } |
| 803 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 804 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 805 | const X86InstructionSetFeatures& isa_features, |
| 806 | const CompilerOptions& compiler_options, |
| 807 | OptimizingCompilerStats* stats) |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 808 | : CodeGenerator(graph, |
| 809 | kNumberOfCpuRegisters, |
| 810 | kNumberOfXmmRegisters, |
| 811 | kNumberOfRegisterPairs, |
| 812 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 813 | arraysize(kCoreCalleeSaves)) |
| 814 | | (1 << kFakeReturnRegister), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 815 | 0, |
| 816 | compiler_options, |
| 817 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 818 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 819 | location_builder_(graph, this), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 820 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 821 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 822 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 823 | isa_features_(isa_features), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 824 | method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 825 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 826 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 827 | simple_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 828 | string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 829 | type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 830 | constant_area_start_(-1), |
| 831 | fixups_to_jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 832 | method_address_offset_(-1) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 833 | // Use a fake return address register to mimic Quick. |
| 834 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 835 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 836 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 837 | void CodeGeneratorX86::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 838 | // Don't allocate the dalvik style register pair passing. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 839 | blocked_register_pairs_[ECX_EDX] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 840 | |
| 841 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 842 | blocked_core_registers_[ESP] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 843 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 844 | UpdateBlockedPairRegisters(); |
| 845 | } |
| 846 | |
| 847 | void CodeGeneratorX86::UpdateBlockedPairRegisters() const { |
| 848 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 849 | X86ManagedRegister current = |
| 850 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 851 | if (blocked_core_registers_[current.AsRegisterPairLow()] |
| 852 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { |
| 853 | blocked_register_pairs_[i] = true; |
| 854 | } |
| 855 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 856 | } |
| 857 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 858 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 859 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 860 | assembler_(codegen->GetAssembler()), |
| 861 | codegen_(codegen) {} |
| 862 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 863 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 864 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 865 | } |
| 866 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 867 | void CodeGeneratorX86::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 868 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 869 | __ Bind(&frame_entry_label_); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 870 | bool skip_overflow_check = |
| 871 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 872 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 873 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 874 | if (!skip_overflow_check) { |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 875 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 876 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 877 | } |
| 878 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 879 | if (HasEmptyFrame()) { |
| 880 | return; |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 881 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 882 | |
| 883 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 884 | Register reg = kCoreCalleeSaves[i]; |
| 885 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 886 | __ pushl(reg); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 887 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 888 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 889 | } |
| 890 | } |
| 891 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 892 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 893 | __ subl(ESP, Immediate(adjust)); |
| 894 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 895 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 896 | } |
| 897 | |
| 898 | void CodeGeneratorX86::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 899 | __ cfi().RememberState(); |
| 900 | if (!HasEmptyFrame()) { |
| 901 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 902 | __ addl(ESP, Immediate(adjust)); |
| 903 | __ cfi().AdjustCFAOffset(-adjust); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 904 | |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 905 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 906 | Register reg = kCoreCalleeSaves[i]; |
| 907 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 908 | __ popl(reg); |
| 909 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 910 | __ cfi().Restore(DWARFReg(reg)); |
| 911 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 912 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 913 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 914 | __ ret(); |
| 915 | __ cfi().RestoreState(); |
| 916 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 917 | } |
| 918 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 919 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 920 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 921 | } |
| 922 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 923 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(Primitive::Type type) const { |
| 924 | switch (type) { |
| 925 | case Primitive::kPrimBoolean: |
| 926 | case Primitive::kPrimByte: |
| 927 | case Primitive::kPrimChar: |
| 928 | case Primitive::kPrimShort: |
| 929 | case Primitive::kPrimInt: |
| 930 | case Primitive::kPrimNot: |
| 931 | return Location::RegisterLocation(EAX); |
| 932 | |
| 933 | case Primitive::kPrimLong: |
| 934 | return Location::RegisterPairLocation(EAX, EDX); |
| 935 | |
| 936 | case Primitive::kPrimVoid: |
| 937 | return Location::NoLocation(); |
| 938 | |
| 939 | case Primitive::kPrimDouble: |
| 940 | case Primitive::kPrimFloat: |
| 941 | return Location::FpuRegisterLocation(XMM0); |
| 942 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 943 | |
| 944 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 948 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 949 | } |
| 950 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 951 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 952 | switch (type) { |
| 953 | case Primitive::kPrimBoolean: |
| 954 | case Primitive::kPrimByte: |
| 955 | case Primitive::kPrimChar: |
| 956 | case Primitive::kPrimShort: |
| 957 | case Primitive::kPrimInt: |
| 958 | case Primitive::kPrimNot: { |
| 959 | uint32_t index = gp_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 960 | stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 961 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 962 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 963 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 964 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 965 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 966 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 967 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 968 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 969 | uint32_t index = gp_index_; |
| 970 | gp_index_ += 2; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 971 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 972 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 973 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 974 | calling_convention.GetRegisterPairAt(index)); |
| 975 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 976 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 977 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 978 | } |
| 979 | } |
| 980 | |
| 981 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 982 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 983 | stack_index_++; |
| 984 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 985 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 986 | } else { |
| 987 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 988 | } |
| 989 | } |
| 990 | |
| 991 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 992 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 993 | stack_index_ += 2; |
| 994 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 995 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 996 | } else { |
| 997 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 998 | } |
| 999 | } |
| 1000 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1001 | case Primitive::kPrimVoid: |
| 1002 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1003 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1004 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1005 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1006 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1007 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1008 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 1009 | if (source.Equals(destination)) { |
| 1010 | return; |
| 1011 | } |
| 1012 | if (destination.IsRegister()) { |
| 1013 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1014 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1015 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1016 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1017 | } else { |
| 1018 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1019 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1020 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1021 | } else if (destination.IsFpuRegister()) { |
| 1022 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1023 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1024 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1025 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1026 | } else { |
| 1027 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1028 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1029 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1030 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1031 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1032 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1033 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1034 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1035 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1036 | } else if (source.IsConstant()) { |
| 1037 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1038 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1039 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1040 | } else { |
| 1041 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1042 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 1043 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1044 | } |
| 1045 | } |
| 1046 | } |
| 1047 | |
| 1048 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 1049 | if (source.Equals(destination)) { |
| 1050 | return; |
| 1051 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1052 | if (destination.IsRegisterPair()) { |
| 1053 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1054 | EmitParallelMoves( |
| 1055 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1056 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1057 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1058 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1059 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 1060 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1061 | } else if (source.IsFpuRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1062 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 1063 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 1064 | __ psrlq(src_reg, Immediate(32)); |
| 1065 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1066 | } else { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1067 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1068 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1069 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 1070 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1071 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 1072 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1073 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1074 | if (source.IsFpuRegister()) { |
| 1075 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 1076 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1077 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1078 | } else if (source.IsRegisterPair()) { |
| 1079 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 1080 | // Create stack space for 2 elements. |
| 1081 | __ subl(ESP, Immediate(2 * elem_size)); |
| 1082 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 1083 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 1084 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 1085 | // And remove the temporary stack space we allocated. |
| 1086 | __ addl(ESP, Immediate(2 * elem_size)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1087 | } else { |
| 1088 | LOG(FATAL) << "Unimplemented"; |
| 1089 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1090 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1091 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1092 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1093 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1094 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1095 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1096 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1097 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1098 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1099 | } else if (source.IsConstant()) { |
| 1100 | HConstant* constant = source.GetConstant(); |
| 1101 | int64_t value; |
| 1102 | if (constant->IsLongConstant()) { |
| 1103 | value = constant->AsLongConstant()->GetValue(); |
| 1104 | } else { |
| 1105 | DCHECK(constant->IsDoubleConstant()); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 1106 | value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1107 | } |
| 1108 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
| 1109 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), Immediate(High32Bits(value))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1110 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1111 | DCHECK(source.IsDoubleStackSlot()) << source; |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1112 | EmitParallelMoves( |
| 1113 | Location::StackSlot(source.GetStackIndex()), |
| 1114 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1115 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1116 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1117 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
| 1118 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1119 | } |
| 1120 | } |
| 1121 | } |
| 1122 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1123 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { |
| 1124 | DCHECK(location.IsRegister()); |
| 1125 | __ movl(location.AsRegister<Register>(), Immediate(value)); |
| 1126 | } |
| 1127 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1128 | void CodeGeneratorX86::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1129 | HParallelMove move(GetGraph()->GetArena()); |
| 1130 | if (dst_type == Primitive::kPrimLong && !src.IsConstant() && !src.IsFpuRegister()) { |
| 1131 | move.AddMove(src.ToLow(), dst.ToLow(), Primitive::kPrimInt, nullptr); |
| 1132 | move.AddMove(src.ToHigh(), dst.ToHigh(), Primitive::kPrimInt, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1133 | } else { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1134 | move.AddMove(src, dst, dst_type, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1135 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1136 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1140 | if (location.IsRegister()) { |
| 1141 | locations->AddTemp(location); |
| 1142 | } else if (location.IsRegisterPair()) { |
| 1143 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1144 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1145 | } else { |
| 1146 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1147 | } |
| 1148 | } |
| 1149 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1150 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1151 | DCHECK(!successor->IsExitBlock()); |
| 1152 | |
| 1153 | HBasicBlock* block = got->GetBlock(); |
| 1154 | HInstruction* previous = got->GetPrevious(); |
| 1155 | |
| 1156 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1157 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1158 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1159 | return; |
| 1160 | } |
| 1161 | |
| 1162 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1163 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1164 | } |
| 1165 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1166 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1167 | } |
| 1168 | } |
| 1169 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1170 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 1171 | got->SetLocations(nullptr); |
| 1172 | } |
| 1173 | |
| 1174 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 1175 | HandleGoto(got, got->GetSuccessor()); |
| 1176 | } |
| 1177 | |
| 1178 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1179 | try_boundary->SetLocations(nullptr); |
| 1180 | } |
| 1181 | |
| 1182 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1183 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1184 | if (!successor->IsExitBlock()) { |
| 1185 | HandleGoto(try_boundary, successor); |
| 1186 | } |
| 1187 | } |
| 1188 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1189 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1190 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1191 | } |
| 1192 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1193 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1194 | } |
| 1195 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1196 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1197 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1198 | LabelType* true_label, |
| 1199 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1200 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1201 | __ j(kUnordered, true_label); |
| 1202 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1203 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1204 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1205 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1206 | } |
| 1207 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1208 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1209 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1210 | LabelType* true_label, |
| 1211 | LabelType* false_label) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1212 | LocationSummary* locations = cond->GetLocations(); |
| 1213 | Location left = locations->InAt(0); |
| 1214 | Location right = locations->InAt(1); |
| 1215 | IfCondition if_cond = cond->GetCondition(); |
| 1216 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1217 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1218 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1219 | IfCondition true_high_cond = if_cond; |
| 1220 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1221 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); // unsigned on lower part |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1222 | |
| 1223 | // Set the conditions for the test, remembering that == needs to be |
| 1224 | // decided using the low words. |
| 1225 | switch (if_cond) { |
| 1226 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1227 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1228 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1229 | break; |
| 1230 | case kCondLT: |
| 1231 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1232 | break; |
| 1233 | case kCondLE: |
| 1234 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1235 | break; |
| 1236 | case kCondGT: |
| 1237 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1238 | break; |
| 1239 | case kCondGE: |
| 1240 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1241 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1242 | case kCondB: |
| 1243 | false_high_cond = kCondA; |
| 1244 | break; |
| 1245 | case kCondBE: |
| 1246 | true_high_cond = kCondB; |
| 1247 | break; |
| 1248 | case kCondA: |
| 1249 | false_high_cond = kCondB; |
| 1250 | break; |
| 1251 | case kCondAE: |
| 1252 | true_high_cond = kCondA; |
| 1253 | break; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1254 | } |
| 1255 | |
| 1256 | if (right.IsConstant()) { |
| 1257 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1258 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1259 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1260 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1261 | codegen_->Compare32BitValue(left_high, val_high); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1262 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1263 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1264 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1265 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1266 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1267 | __ j(X86Condition(true_high_cond), true_label); |
| 1268 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1269 | } |
| 1270 | // Must be equal high, so compare the lows. |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1271 | codegen_->Compare32BitValue(left_low, val_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1272 | } else if (right.IsRegisterPair()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1273 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1274 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1275 | |
| 1276 | __ cmpl(left_high, right_high); |
| 1277 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1278 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1279 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1280 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1281 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1282 | __ j(X86Condition(true_high_cond), true_label); |
| 1283 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1284 | } |
| 1285 | // Must be equal high, so compare the lows. |
| 1286 | __ cmpl(left_low, right_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1287 | } else { |
| 1288 | DCHECK(right.IsDoubleStackSlot()); |
| 1289 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
| 1290 | if (if_cond == kCondNE) { |
| 1291 | __ j(X86Condition(true_high_cond), true_label); |
| 1292 | } else if (if_cond == kCondEQ) { |
| 1293 | __ j(X86Condition(false_high_cond), false_label); |
| 1294 | } else { |
| 1295 | __ j(X86Condition(true_high_cond), true_label); |
| 1296 | __ j(X86Condition(false_high_cond), false_label); |
| 1297 | } |
| 1298 | // Must be equal high, so compare the lows. |
| 1299 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1300 | } |
| 1301 | // The last comparison might be unsigned. |
| 1302 | __ j(final_condition, true_label); |
| 1303 | } |
| 1304 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1305 | void InstructionCodeGeneratorX86::GenerateFPCompare(Location lhs, |
| 1306 | Location rhs, |
| 1307 | HInstruction* insn, |
| 1308 | bool is_double) { |
| 1309 | HX86LoadFromConstantTable* const_area = insn->InputAt(1)->AsX86LoadFromConstantTable(); |
| 1310 | if (is_double) { |
| 1311 | if (rhs.IsFpuRegister()) { |
| 1312 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1313 | } else if (const_area != nullptr) { |
| 1314 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1315 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), |
| 1316 | codegen_->LiteralDoubleAddress( |
| 1317 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 1318 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 1319 | } else { |
| 1320 | DCHECK(rhs.IsDoubleStackSlot()); |
| 1321 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1322 | } |
| 1323 | } else { |
| 1324 | if (rhs.IsFpuRegister()) { |
| 1325 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1326 | } else if (const_area != nullptr) { |
| 1327 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1328 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), |
| 1329 | codegen_->LiteralFloatAddress( |
| 1330 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 1331 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 1332 | } else { |
| 1333 | DCHECK(rhs.IsStackSlot()); |
| 1334 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1335 | } |
| 1336 | } |
| 1337 | } |
| 1338 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1339 | template<class LabelType> |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1340 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1341 | LabelType* true_target_in, |
| 1342 | LabelType* false_target_in) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1343 | // Generated branching requires both targets to be explicit. If either of the |
| 1344 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1345 | LabelType fallthrough_target; |
| 1346 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1347 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1348 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1349 | LocationSummary* locations = condition->GetLocations(); |
| 1350 | Location left = locations->InAt(0); |
| 1351 | Location right = locations->InAt(1); |
| 1352 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1353 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1354 | switch (type) { |
| 1355 | case Primitive::kPrimLong: |
| 1356 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1357 | break; |
| 1358 | case Primitive::kPrimFloat: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1359 | GenerateFPCompare(left, right, condition, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1360 | GenerateFPJumps(condition, true_target, false_target); |
| 1361 | break; |
| 1362 | case Primitive::kPrimDouble: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1363 | GenerateFPCompare(left, right, condition, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1364 | GenerateFPJumps(condition, true_target, false_target); |
| 1365 | break; |
| 1366 | default: |
| 1367 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1368 | } |
| 1369 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1370 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1371 | __ jmp(false_target); |
| 1372 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1373 | |
| 1374 | if (fallthrough_target.IsLinked()) { |
| 1375 | __ Bind(&fallthrough_target); |
| 1376 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1377 | } |
| 1378 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1379 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1380 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1381 | // are set only strictly before `branch`. We can't use the eflags on long/FP |
| 1382 | // conditions if they are materialized due to the complex branching. |
| 1383 | return cond->IsCondition() && |
| 1384 | cond->GetNext() == branch && |
| 1385 | cond->InputAt(0)->GetType() != Primitive::kPrimLong && |
| 1386 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1387 | } |
| 1388 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1389 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1390 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1391 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1392 | LabelType* true_target, |
| 1393 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1394 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1395 | |
| 1396 | if (true_target == nullptr && false_target == nullptr) { |
| 1397 | // Nothing to do. The code always falls through. |
| 1398 | return; |
| 1399 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1400 | // Constant condition, statically compared against "true" (integer value 1). |
| 1401 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1402 | if (true_target != nullptr) { |
| 1403 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1404 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1405 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1406 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1407 | if (false_target != nullptr) { |
| 1408 | __ jmp(false_target); |
| 1409 | } |
| 1410 | } |
| 1411 | return; |
| 1412 | } |
| 1413 | |
| 1414 | // The following code generates these patterns: |
| 1415 | // (1) true_target == nullptr && false_target != nullptr |
| 1416 | // - opposite condition true => branch to false_target |
| 1417 | // (2) true_target != nullptr && false_target == nullptr |
| 1418 | // - condition true => branch to true_target |
| 1419 | // (3) true_target != nullptr && false_target != nullptr |
| 1420 | // - condition true => branch to true_target |
| 1421 | // - branch to false_target |
| 1422 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1423 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1424 | if (true_target == nullptr) { |
| 1425 | __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1426 | } else { |
| 1427 | __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); |
| 1428 | } |
| 1429 | } else { |
| 1430 | // Materialized condition, compare against 0. |
| 1431 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1432 | if (lhs.IsRegister()) { |
| 1433 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1434 | } else { |
| 1435 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1436 | } |
| 1437 | if (true_target == nullptr) { |
| 1438 | __ j(kEqual, false_target); |
| 1439 | } else { |
| 1440 | __ j(kNotEqual, true_target); |
| 1441 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1442 | } |
| 1443 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1444 | // Condition has not been materialized, use its inputs as the comparison and |
| 1445 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1446 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1447 | |
| 1448 | // If this is a long or FP comparison that has been folded into |
| 1449 | // the HCondition, generate the comparison directly. |
| 1450 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1451 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1452 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1453 | return; |
| 1454 | } |
| 1455 | |
| 1456 | Location lhs = condition->GetLocations()->InAt(0); |
| 1457 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1458 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition). |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1459 | if (rhs.IsRegister()) { |
| 1460 | __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>()); |
| 1461 | } else if (rhs.IsConstant()) { |
| 1462 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1463 | codegen_->Compare32BitValue(lhs.AsRegister<Register>(), constant); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1464 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1465 | __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex())); |
| 1466 | } |
| 1467 | if (true_target == nullptr) { |
| 1468 | __ j(X86Condition(condition->GetOppositeCondition()), false_target); |
| 1469 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1470 | __ j(X86Condition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1471 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1472 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1473 | |
| 1474 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1475 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1476 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1477 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1478 | } |
| 1479 | } |
| 1480 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1481 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1482 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1483 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1484 | locations->SetInAt(0, Location::Any()); |
| 1485 | } |
| 1486 | } |
| 1487 | |
| 1488 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1489 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1490 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1491 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1492 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1493 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1494 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1495 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1496 | } |
| 1497 | |
| 1498 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1499 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1500 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 239d6ea | 2016-09-05 10:44:04 +0100 | [diff] [blame] | 1501 | locations->SetCustomSlowPathCallerSaves(RegisterSet()); // No caller-save registers. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1502 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1503 | locations->SetInAt(0, Location::Any()); |
| 1504 | } |
| 1505 | } |
| 1506 | |
| 1507 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1508 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1509 | GenerateTestAndBranch<Label>(deoptimize, |
| 1510 | /* condition_input_index */ 0, |
| 1511 | slow_path->GetEntryLabel(), |
| 1512 | /* false_target */ nullptr); |
| 1513 | } |
| 1514 | |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1515 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1516 | // There are no conditional move instructions for XMMs. |
| 1517 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1518 | return false; |
| 1519 | } |
| 1520 | |
| 1521 | // A FP condition doesn't generate the single CC that we need. |
| 1522 | // In 32 bit mode, a long condition doesn't generate a single CC either. |
| 1523 | HInstruction* condition = select->GetCondition(); |
| 1524 | if (condition->IsCondition()) { |
| 1525 | Primitive::Type compare_type = condition->InputAt(0)->GetType(); |
| 1526 | if (compare_type == Primitive::kPrimLong || |
| 1527 | Primitive::IsFloatingPointType(compare_type)) { |
| 1528 | return false; |
| 1529 | } |
| 1530 | } |
| 1531 | |
| 1532 | // We can generate a CMOV for this Select. |
| 1533 | return true; |
| 1534 | } |
| 1535 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1536 | void LocationsBuilderX86::VisitSelect(HSelect* select) { |
| 1537 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1538 | if (Primitive::IsFloatingPointType(select->GetType())) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1539 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1540 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1541 | } else { |
| 1542 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1543 | if (SelectCanUseCMOV(select)) { |
| 1544 | if (select->InputAt(1)->IsConstant()) { |
| 1545 | // Cmov can't handle a constant value. |
| 1546 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1547 | } else { |
| 1548 | locations->SetInAt(1, Location::Any()); |
| 1549 | } |
| 1550 | } else { |
| 1551 | locations->SetInAt(1, Location::Any()); |
| 1552 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1553 | } |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1554 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1555 | locations->SetInAt(2, Location::RequiresRegister()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1556 | } |
| 1557 | locations->SetOut(Location::SameAsFirstInput()); |
| 1558 | } |
| 1559 | |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1560 | void CodeGeneratorX86::GenerateIntCompare(Location lhs, Location rhs) { |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1561 | Register lhs_reg = lhs.AsRegister<Register>(); |
| 1562 | if (rhs.IsConstant()) { |
| 1563 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1564 | Compare32BitValue(lhs_reg, value); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1565 | } else if (rhs.IsStackSlot()) { |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1566 | assembler_.cmpl(lhs_reg, Address(ESP, rhs.GetStackIndex())); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1567 | } else { |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1568 | assembler_.cmpl(lhs_reg, rhs.AsRegister<Register>()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1569 | } |
| 1570 | } |
| 1571 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1572 | void InstructionCodeGeneratorX86::VisitSelect(HSelect* select) { |
| 1573 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1574 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1575 | if (SelectCanUseCMOV(select)) { |
| 1576 | // If both the condition and the source types are integer, we can generate |
| 1577 | // a CMOV to implement Select. |
| 1578 | |
| 1579 | HInstruction* select_condition = select->GetCondition(); |
| 1580 | Condition cond = kNotEqual; |
| 1581 | |
| 1582 | // Figure out how to test the 'condition'. |
| 1583 | if (select_condition->IsCondition()) { |
| 1584 | HCondition* condition = select_condition->AsCondition(); |
| 1585 | if (!condition->IsEmittedAtUseSite()) { |
| 1586 | // This was a previously materialized condition. |
| 1587 | // Can we use the existing condition code? |
| 1588 | if (AreEflagsSetFrom(condition, select)) { |
| 1589 | // Materialization was the previous instruction. Condition codes are right. |
| 1590 | cond = X86Condition(condition->GetCondition()); |
| 1591 | } else { |
| 1592 | // No, we have to recreate the condition code. |
| 1593 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1594 | __ testl(cond_reg, cond_reg); |
| 1595 | } |
| 1596 | } else { |
| 1597 | // We can't handle FP or long here. |
| 1598 | DCHECK_NE(condition->InputAt(0)->GetType(), Primitive::kPrimLong); |
| 1599 | DCHECK(!Primitive::IsFloatingPointType(condition->InputAt(0)->GetType())); |
| 1600 | LocationSummary* cond_locations = condition->GetLocations(); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1601 | codegen_->GenerateIntCompare(cond_locations->InAt(0), cond_locations->InAt(1)); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1602 | cond = X86Condition(condition->GetCondition()); |
| 1603 | } |
| 1604 | } else { |
| 1605 | // Must be a boolean condition, which needs to be compared to 0. |
| 1606 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1607 | __ testl(cond_reg, cond_reg); |
| 1608 | } |
| 1609 | |
| 1610 | // If the condition is true, overwrite the output, which already contains false. |
| 1611 | Location false_loc = locations->InAt(0); |
| 1612 | Location true_loc = locations->InAt(1); |
| 1613 | if (select->GetType() == Primitive::kPrimLong) { |
| 1614 | // 64 bit conditional move. |
| 1615 | Register false_high = false_loc.AsRegisterPairHigh<Register>(); |
| 1616 | Register false_low = false_loc.AsRegisterPairLow<Register>(); |
| 1617 | if (true_loc.IsRegisterPair()) { |
| 1618 | __ cmovl(cond, false_high, true_loc.AsRegisterPairHigh<Register>()); |
| 1619 | __ cmovl(cond, false_low, true_loc.AsRegisterPairLow<Register>()); |
| 1620 | } else { |
| 1621 | __ cmovl(cond, false_high, Address(ESP, true_loc.GetHighStackIndex(kX86WordSize))); |
| 1622 | __ cmovl(cond, false_low, Address(ESP, true_loc.GetStackIndex())); |
| 1623 | } |
| 1624 | } else { |
| 1625 | // 32 bit conditional move. |
| 1626 | Register false_reg = false_loc.AsRegister<Register>(); |
| 1627 | if (true_loc.IsRegister()) { |
| 1628 | __ cmovl(cond, false_reg, true_loc.AsRegister<Register>()); |
| 1629 | } else { |
| 1630 | __ cmovl(cond, false_reg, Address(ESP, true_loc.GetStackIndex())); |
| 1631 | } |
| 1632 | } |
| 1633 | } else { |
| 1634 | NearLabel false_target; |
| 1635 | GenerateTestAndBranch<NearLabel>( |
| 1636 | select, /* condition_input_index */ 2, /* true_target */ nullptr, &false_target); |
| 1637 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1638 | __ Bind(&false_target); |
| 1639 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1640 | } |
| 1641 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1642 | void LocationsBuilderX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1643 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1644 | } |
| 1645 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1646 | void InstructionCodeGeneratorX86::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1647 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1648 | } |
| 1649 | |
| 1650 | void CodeGeneratorX86::GenerateNop() { |
| 1651 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1652 | } |
| 1653 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1654 | void LocationsBuilderX86::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1655 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1656 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1657 | // Handle the long/FP comparisons made in instruction simplification. |
| 1658 | switch (cond->InputAt(0)->GetType()) { |
| 1659 | case Primitive::kPrimLong: { |
| 1660 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1661 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1662 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1663 | locations->SetOut(Location::RequiresRegister()); |
| 1664 | } |
| 1665 | break; |
| 1666 | } |
| 1667 | case Primitive::kPrimFloat: |
| 1668 | case Primitive::kPrimDouble: { |
| 1669 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1670 | if (cond->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 1671 | DCHECK(cond->InputAt(1)->IsEmittedAtUseSite()); |
| 1672 | } else if (cond->InputAt(1)->IsConstant()) { |
| 1673 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1674 | } else { |
| 1675 | locations->SetInAt(1, Location::Any()); |
| 1676 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1677 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1678 | locations->SetOut(Location::RequiresRegister()); |
| 1679 | } |
| 1680 | break; |
| 1681 | } |
| 1682 | default: |
| 1683 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1684 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1685 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1686 | // We need a byte register. |
| 1687 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1688 | } |
| 1689 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1690 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1691 | } |
| 1692 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1693 | void InstructionCodeGeneratorX86::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1694 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1695 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1696 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1697 | |
| 1698 | LocationSummary* locations = cond->GetLocations(); |
| 1699 | Location lhs = locations->InAt(0); |
| 1700 | Location rhs = locations->InAt(1); |
| 1701 | Register reg = locations->Out().AsRegister<Register>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1702 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1703 | |
| 1704 | switch (cond->InputAt(0)->GetType()) { |
| 1705 | default: { |
| 1706 | // Integer case. |
| 1707 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 1708 | // Clear output register: setb only sets the low byte. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1709 | __ xorl(reg, reg); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1710 | codegen_->GenerateIntCompare(lhs, rhs); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1711 | __ setb(X86Condition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1712 | return; |
| 1713 | } |
| 1714 | case Primitive::kPrimLong: |
| 1715 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1716 | break; |
| 1717 | case Primitive::kPrimFloat: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1718 | GenerateFPCompare(lhs, rhs, cond, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1719 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1720 | break; |
| 1721 | case Primitive::kPrimDouble: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1722 | GenerateFPCompare(lhs, rhs, cond, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1723 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1724 | break; |
| 1725 | } |
| 1726 | |
| 1727 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1728 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1729 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1730 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1731 | __ Bind(&false_label); |
| 1732 | __ xorl(reg, reg); |
| 1733 | __ jmp(&done_label); |
| 1734 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1735 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1736 | __ Bind(&true_label); |
| 1737 | __ movl(reg, Immediate(1)); |
| 1738 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1739 | } |
| 1740 | |
| 1741 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1742 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1743 | } |
| 1744 | |
| 1745 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1746 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1747 | } |
| 1748 | |
| 1749 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1750 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1751 | } |
| 1752 | |
| 1753 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1754 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1755 | } |
| 1756 | |
| 1757 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1758 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1759 | } |
| 1760 | |
| 1761 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1762 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1763 | } |
| 1764 | |
| 1765 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1766 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1767 | } |
| 1768 | |
| 1769 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1770 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1771 | } |
| 1772 | |
| 1773 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1774 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1775 | } |
| 1776 | |
| 1777 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1778 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1779 | } |
| 1780 | |
| 1781 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1782 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1783 | } |
| 1784 | |
| 1785 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1786 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1787 | } |
| 1788 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1789 | void LocationsBuilderX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1790 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1791 | } |
| 1792 | |
| 1793 | void InstructionCodeGeneratorX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1794 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1795 | } |
| 1796 | |
| 1797 | void LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1798 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1799 | } |
| 1800 | |
| 1801 | void InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1802 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1803 | } |
| 1804 | |
| 1805 | void LocationsBuilderX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1806 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1807 | } |
| 1808 | |
| 1809 | void InstructionCodeGeneratorX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1810 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1811 | } |
| 1812 | |
| 1813 | void LocationsBuilderX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1814 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1815 | } |
| 1816 | |
| 1817 | void InstructionCodeGeneratorX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1818 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1819 | } |
| 1820 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1821 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1822 | LocationSummary* locations = |
| 1823 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1824 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1825 | } |
| 1826 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1827 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1828 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1829 | } |
| 1830 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1831 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 1832 | LocationSummary* locations = |
| 1833 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1834 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1835 | } |
| 1836 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1837 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1838 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1839 | } |
| 1840 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1841 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1842 | LocationSummary* locations = |
| 1843 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1844 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1845 | } |
| 1846 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1847 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1848 | // Will be generated at use site. |
| 1849 | } |
| 1850 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1851 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 1852 | LocationSummary* locations = |
| 1853 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1854 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1855 | } |
| 1856 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1857 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1858 | // Will be generated at use site. |
| 1859 | } |
| 1860 | |
| 1861 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1862 | LocationSummary* locations = |
| 1863 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1864 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1865 | } |
| 1866 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1867 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1868 | // Will be generated at use site. |
| 1869 | } |
| 1870 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1871 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1872 | memory_barrier->SetLocations(nullptr); |
| 1873 | } |
| 1874 | |
| 1875 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 1876 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1877 | } |
| 1878 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1879 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1880 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1881 | } |
| 1882 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1883 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1884 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1885 | } |
| 1886 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1887 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1888 | LocationSummary* locations = |
| 1889 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1890 | switch (ret->InputAt(0)->GetType()) { |
| 1891 | case Primitive::kPrimBoolean: |
| 1892 | case Primitive::kPrimByte: |
| 1893 | case Primitive::kPrimChar: |
| 1894 | case Primitive::kPrimShort: |
| 1895 | case Primitive::kPrimInt: |
| 1896 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1897 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1898 | break; |
| 1899 | |
| 1900 | case Primitive::kPrimLong: |
| 1901 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1902 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1903 | break; |
| 1904 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1905 | case Primitive::kPrimFloat: |
| 1906 | case Primitive::kPrimDouble: |
| 1907 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1908 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1909 | break; |
| 1910 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1911 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1912 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1913 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1914 | } |
| 1915 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1916 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1917 | if (kIsDebugBuild) { |
| 1918 | switch (ret->InputAt(0)->GetType()) { |
| 1919 | case Primitive::kPrimBoolean: |
| 1920 | case Primitive::kPrimByte: |
| 1921 | case Primitive::kPrimChar: |
| 1922 | case Primitive::kPrimShort: |
| 1923 | case Primitive::kPrimInt: |
| 1924 | case Primitive::kPrimNot: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1925 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1926 | break; |
| 1927 | |
| 1928 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1929 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 1930 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1931 | break; |
| 1932 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1933 | case Primitive::kPrimFloat: |
| 1934 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1935 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1936 | break; |
| 1937 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1938 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1939 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1940 | } |
| 1941 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1942 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1943 | } |
| 1944 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1945 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1946 | // The trampoline uses the same calling convention as dex calling conventions, |
| 1947 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 1948 | // the method_idx. |
| 1949 | HandleInvoke(invoke); |
| 1950 | } |
| 1951 | |
| 1952 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1953 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 1954 | } |
| 1955 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1956 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1957 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 1958 | // art::PrepareForRegisterAllocation. |
| 1959 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1960 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1961 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1962 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1963 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 1964 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1965 | } |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1966 | return; |
| 1967 | } |
| 1968 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1969 | HandleInvoke(invoke); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1970 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1971 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 1972 | if (invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1973 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1974 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1975 | } |
| 1976 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1977 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 1978 | if (invoke->GetLocations()->Intrinsified()) { |
| 1979 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 1980 | intrinsic.Dispatch(invoke); |
| 1981 | return true; |
| 1982 | } |
| 1983 | return false; |
| 1984 | } |
| 1985 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1986 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1987 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 1988 | // art::PrepareForRegisterAllocation. |
| 1989 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1990 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1991 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1992 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1993 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1994 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1995 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1996 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1997 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Mingyao Yang | 8693fe1 | 2015-04-17 16:51:08 -0700 | [diff] [blame] | 1998 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1999 | } |
| 2000 | |
| 2001 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 2002 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 2003 | if (intrinsic.TryDispatch(invoke)) { |
| 2004 | return; |
| 2005 | } |
| 2006 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2007 | HandleInvoke(invoke); |
| 2008 | } |
| 2009 | |
| 2010 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2011 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2012 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2013 | } |
| 2014 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2015 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2016 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2017 | return; |
| 2018 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2019 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2020 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2021 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2022 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2023 | } |
| 2024 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2025 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2026 | // This call to HandleInvoke allocates a temporary (core) register |
| 2027 | // which is also used to transfer the hidden argument from FP to |
| 2028 | // core register. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2029 | HandleInvoke(invoke); |
| 2030 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2031 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2032 | } |
| 2033 | |
| 2034 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2035 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2036 | LocationSummary* locations = invoke->GetLocations(); |
| 2037 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2038 | XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2039 | Location receiver = locations->InAt(0); |
| 2040 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2041 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2042 | // Set the hidden argument. This is safe to do this here, as XMM7 |
| 2043 | // won't be modified thereafter, before the `call` instruction. |
| 2044 | DCHECK_EQ(XMM7, hidden_reg); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2045 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2046 | __ movd(hidden_reg, temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2047 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2048 | if (receiver.IsStackSlot()) { |
| 2049 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2050 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2051 | __ movl(temp, Address(temp, class_offset)); |
| 2052 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2053 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2054 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2055 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2056 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2057 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2058 | // emit a read barrier for the previous class reference load. |
| 2059 | // However this is not required in practice, as this is an |
| 2060 | // intermediate/temporary reference and because the current |
| 2061 | // concurrent copying collector keeps the from-space memory |
| 2062 | // intact/accessible until the end of the marking phase (the |
| 2063 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2064 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2065 | // temp = temp->GetAddressOfIMT() |
| 2066 | __ movl(temp, |
| 2067 | Address(temp, mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2068 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2069 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2070 | invoke->GetImtIndex(), kX86PointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2071 | __ movl(temp, Address(temp, method_offset)); |
| 2072 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2073 | __ call(Address(temp, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2074 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2075 | |
| 2076 | DCHECK(!codegen_->IsLeafMethod()); |
| 2077 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2078 | } |
| 2079 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2080 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 2081 | LocationSummary* locations = |
| 2082 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2083 | switch (neg->GetResultType()) { |
| 2084 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2085 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2086 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2087 | locations->SetOut(Location::SameAsFirstInput()); |
| 2088 | break; |
| 2089 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2090 | case Primitive::kPrimFloat: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2091 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2092 | locations->SetOut(Location::SameAsFirstInput()); |
| 2093 | locations->AddTemp(Location::RequiresRegister()); |
| 2094 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2095 | break; |
| 2096 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2097 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2098 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2099 | locations->SetOut(Location::SameAsFirstInput()); |
| 2100 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2101 | break; |
| 2102 | |
| 2103 | default: |
| 2104 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2105 | } |
| 2106 | } |
| 2107 | |
| 2108 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 2109 | LocationSummary* locations = neg->GetLocations(); |
| 2110 | Location out = locations->Out(); |
| 2111 | Location in = locations->InAt(0); |
| 2112 | switch (neg->GetResultType()) { |
| 2113 | case Primitive::kPrimInt: |
| 2114 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2115 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2116 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2117 | break; |
| 2118 | |
| 2119 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2120 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2121 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2122 | __ negl(out.AsRegisterPairLow<Register>()); |
| 2123 | // Negation is similar to subtraction from zero. The least |
| 2124 | // significant byte triggers a borrow when it is different from |
| 2125 | // zero; to take it into account, add 1 to the most significant |
| 2126 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 2127 | // operation. |
| 2128 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2129 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 2130 | break; |
| 2131 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2132 | case Primitive::kPrimFloat: { |
| 2133 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2134 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 2135 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2136 | // Implement float negation with an exclusive or with value |
| 2137 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2138 | // single-precision floating-point number). |
| 2139 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 2140 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2141 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2142 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2143 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2144 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2145 | case Primitive::kPrimDouble: { |
| 2146 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2147 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2148 | // Implement double negation with an exclusive or with value |
| 2149 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 2150 | // a double-precision floating-point number). |
| 2151 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2152 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2153 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2154 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2155 | |
| 2156 | default: |
| 2157 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2158 | } |
| 2159 | } |
| 2160 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2161 | void LocationsBuilderX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2162 | LocationSummary* locations = |
| 2163 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2164 | DCHECK(Primitive::IsFloatingPointType(neg->GetType())); |
| 2165 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2166 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2167 | locations->SetOut(Location::SameAsFirstInput()); |
| 2168 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2169 | } |
| 2170 | |
| 2171 | void InstructionCodeGeneratorX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2172 | LocationSummary* locations = neg->GetLocations(); |
| 2173 | Location out = locations->Out(); |
| 2174 | DCHECK(locations->InAt(0).Equals(out)); |
| 2175 | |
| 2176 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 2177 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 2178 | if (neg->GetType() == Primitive::kPrimFloat) { |
| 2179 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x80000000), constant_area)); |
| 2180 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| 2181 | } else { |
| 2182 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000), constant_area)); |
| 2183 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| 2184 | } |
| 2185 | } |
| 2186 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2187 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2188 | Primitive::Type result_type = conversion->GetResultType(); |
| 2189 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2190 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2191 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2192 | // The float-to-long and double-to-long type conversions rely on a |
| 2193 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2194 | LocationSummary::CallKind call_kind = |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2195 | ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2196 | && result_type == Primitive::kPrimLong) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2197 | ? LocationSummary::kCallOnMainOnly |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2198 | : LocationSummary::kNoCall; |
| 2199 | LocationSummary* locations = |
| 2200 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2201 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2202 | // The Java language does not allow treating boolean as an integral type but |
| 2203 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2204 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2205 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2206 | case Primitive::kPrimByte: |
| 2207 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2208 | case Primitive::kPrimLong: { |
| 2209 | // Type conversion from long to byte is a result of code transformations. |
| 2210 | HInstruction* input = conversion->InputAt(0); |
| 2211 | Location input_location = input->IsConstant() |
| 2212 | ? Location::ConstantLocation(input->AsConstant()) |
| 2213 | : Location::RegisterPairLocation(EAX, EDX); |
| 2214 | locations->SetInAt(0, input_location); |
| 2215 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2216 | // the validation of the linear scan implementation |
| 2217 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2218 | break; |
| 2219 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2220 | case Primitive::kPrimBoolean: |
| 2221 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2222 | case Primitive::kPrimShort: |
| 2223 | case Primitive::kPrimInt: |
| 2224 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2225 | // Processing a Dex `int-to-byte' instruction. |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 2226 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 2227 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2228 | // the validation of the linear scan implementation |
| 2229 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2230 | break; |
| 2231 | |
| 2232 | default: |
| 2233 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2234 | << " to " << result_type; |
| 2235 | } |
| 2236 | break; |
| 2237 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2238 | case Primitive::kPrimShort: |
| 2239 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2240 | case Primitive::kPrimLong: |
| 2241 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2242 | case Primitive::kPrimBoolean: |
| 2243 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2244 | case Primitive::kPrimByte: |
| 2245 | case Primitive::kPrimInt: |
| 2246 | case Primitive::kPrimChar: |
| 2247 | // Processing a Dex `int-to-short' instruction. |
| 2248 | locations->SetInAt(0, Location::Any()); |
| 2249 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2250 | break; |
| 2251 | |
| 2252 | default: |
| 2253 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2254 | << " to " << result_type; |
| 2255 | } |
| 2256 | break; |
| 2257 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2258 | case Primitive::kPrimInt: |
| 2259 | switch (input_type) { |
| 2260 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2261 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2262 | locations->SetInAt(0, Location::Any()); |
| 2263 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2264 | break; |
| 2265 | |
| 2266 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2267 | // Processing a Dex `float-to-int' instruction. |
| 2268 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2269 | locations->SetOut(Location::RequiresRegister()); |
| 2270 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2271 | break; |
| 2272 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2273 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2274 | // Processing a Dex `double-to-int' instruction. |
| 2275 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2276 | locations->SetOut(Location::RequiresRegister()); |
| 2277 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2278 | break; |
| 2279 | |
| 2280 | default: |
| 2281 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2282 | << " to " << result_type; |
| 2283 | } |
| 2284 | break; |
| 2285 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2286 | case Primitive::kPrimLong: |
| 2287 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2288 | case Primitive::kPrimBoolean: |
| 2289 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2290 | case Primitive::kPrimByte: |
| 2291 | case Primitive::kPrimShort: |
| 2292 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2293 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2294 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2295 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 2296 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2297 | break; |
| 2298 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2299 | case Primitive::kPrimFloat: |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2300 | case Primitive::kPrimDouble: { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2301 | // Processing a Dex `float-to-long' or 'double-to-long' instruction. |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2302 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2303 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 2304 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 2305 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2306 | // The runtime helper puts the result in EAX, EDX. |
| 2307 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2308 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2309 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2310 | |
| 2311 | default: |
| 2312 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2313 | << " to " << result_type; |
| 2314 | } |
| 2315 | break; |
| 2316 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2317 | case Primitive::kPrimChar: |
| 2318 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2319 | case Primitive::kPrimLong: |
| 2320 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2321 | case Primitive::kPrimBoolean: |
| 2322 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2323 | case Primitive::kPrimByte: |
| 2324 | case Primitive::kPrimShort: |
| 2325 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2326 | // Processing a Dex `int-to-char' instruction. |
| 2327 | locations->SetInAt(0, Location::Any()); |
| 2328 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2329 | break; |
| 2330 | |
| 2331 | default: |
| 2332 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2333 | << " to " << result_type; |
| 2334 | } |
| 2335 | break; |
| 2336 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2337 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2338 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2339 | case Primitive::kPrimBoolean: |
| 2340 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2341 | case Primitive::kPrimByte: |
| 2342 | case Primitive::kPrimShort: |
| 2343 | case Primitive::kPrimInt: |
| 2344 | case Primitive::kPrimChar: |
| 2345 | // Processing a Dex `int-to-float' instruction. |
| 2346 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2347 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2348 | break; |
| 2349 | |
| 2350 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2351 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2352 | locations->SetInAt(0, Location::Any()); |
| 2353 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2354 | break; |
| 2355 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2356 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2357 | // Processing a Dex `double-to-float' instruction. |
| 2358 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2359 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2360 | break; |
| 2361 | |
| 2362 | default: |
| 2363 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2364 | << " to " << result_type; |
| 2365 | }; |
| 2366 | break; |
| 2367 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2368 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2369 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2370 | case Primitive::kPrimBoolean: |
| 2371 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2372 | case Primitive::kPrimByte: |
| 2373 | case Primitive::kPrimShort: |
| 2374 | case Primitive::kPrimInt: |
| 2375 | case Primitive::kPrimChar: |
| 2376 | // Processing a Dex `int-to-double' instruction. |
| 2377 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2378 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2379 | break; |
| 2380 | |
| 2381 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2382 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2383 | locations->SetInAt(0, Location::Any()); |
| 2384 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2385 | break; |
| 2386 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2387 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2388 | // Processing a Dex `float-to-double' instruction. |
| 2389 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2390 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2391 | break; |
| 2392 | |
| 2393 | default: |
| 2394 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2395 | << " to " << result_type; |
| 2396 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2397 | break; |
| 2398 | |
| 2399 | default: |
| 2400 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2401 | << " to " << result_type; |
| 2402 | } |
| 2403 | } |
| 2404 | |
| 2405 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 2406 | LocationSummary* locations = conversion->GetLocations(); |
| 2407 | Location out = locations->Out(); |
| 2408 | Location in = locations->InAt(0); |
| 2409 | Primitive::Type result_type = conversion->GetResultType(); |
| 2410 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2411 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2412 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2413 | case Primitive::kPrimByte: |
| 2414 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2415 | case Primitive::kPrimLong: |
| 2416 | // Type conversion from long to byte is a result of code transformations. |
| 2417 | if (in.IsRegisterPair()) { |
| 2418 | __ movsxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 2419 | } else { |
| 2420 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2421 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2422 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2423 | } |
| 2424 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2425 | case Primitive::kPrimBoolean: |
| 2426 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2427 | case Primitive::kPrimShort: |
| 2428 | case Primitive::kPrimInt: |
| 2429 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2430 | // Processing a Dex `int-to-byte' instruction. |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2431 | if (in.IsRegister()) { |
| 2432 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2433 | } else { |
| 2434 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2435 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2436 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2437 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2438 | break; |
| 2439 | |
| 2440 | default: |
| 2441 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2442 | << " to " << result_type; |
| 2443 | } |
| 2444 | break; |
| 2445 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2446 | case Primitive::kPrimShort: |
| 2447 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2448 | case Primitive::kPrimLong: |
| 2449 | // Type conversion from long to short is a result of code transformations. |
| 2450 | if (in.IsRegisterPair()) { |
| 2451 | __ movsxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2452 | } else if (in.IsDoubleStackSlot()) { |
| 2453 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2454 | } else { |
| 2455 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2456 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2457 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
| 2458 | } |
| 2459 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2460 | case Primitive::kPrimBoolean: |
| 2461 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2462 | case Primitive::kPrimByte: |
| 2463 | case Primitive::kPrimInt: |
| 2464 | case Primitive::kPrimChar: |
| 2465 | // Processing a Dex `int-to-short' instruction. |
| 2466 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2467 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2468 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2469 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2470 | } else { |
| 2471 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2472 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2473 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2474 | } |
| 2475 | break; |
| 2476 | |
| 2477 | default: |
| 2478 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2479 | << " to " << result_type; |
| 2480 | } |
| 2481 | break; |
| 2482 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2483 | case Primitive::kPrimInt: |
| 2484 | switch (input_type) { |
| 2485 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2486 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2487 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2488 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2489 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2490 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2491 | } else { |
| 2492 | DCHECK(in.IsConstant()); |
| 2493 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2494 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2495 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2496 | } |
| 2497 | break; |
| 2498 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2499 | case Primitive::kPrimFloat: { |
| 2500 | // Processing a Dex `float-to-int' instruction. |
| 2501 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2502 | Register output = out.AsRegister<Register>(); |
| 2503 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2504 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2505 | |
| 2506 | __ movl(output, Immediate(kPrimIntMax)); |
| 2507 | // temp = int-to-float(output) |
| 2508 | __ cvtsi2ss(temp, output); |
| 2509 | // if input >= temp goto done |
| 2510 | __ comiss(input, temp); |
| 2511 | __ j(kAboveEqual, &done); |
| 2512 | // if input == NaN goto nan |
| 2513 | __ j(kUnordered, &nan); |
| 2514 | // output = float-to-int-truncate(input) |
| 2515 | __ cvttss2si(output, input); |
| 2516 | __ jmp(&done); |
| 2517 | __ Bind(&nan); |
| 2518 | // output = 0 |
| 2519 | __ xorl(output, output); |
| 2520 | __ Bind(&done); |
| 2521 | break; |
| 2522 | } |
| 2523 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2524 | case Primitive::kPrimDouble: { |
| 2525 | // Processing a Dex `double-to-int' instruction. |
| 2526 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2527 | Register output = out.AsRegister<Register>(); |
| 2528 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2529 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2530 | |
| 2531 | __ movl(output, Immediate(kPrimIntMax)); |
| 2532 | // temp = int-to-double(output) |
| 2533 | __ cvtsi2sd(temp, output); |
| 2534 | // if input >= temp goto done |
| 2535 | __ comisd(input, temp); |
| 2536 | __ j(kAboveEqual, &done); |
| 2537 | // if input == NaN goto nan |
| 2538 | __ j(kUnordered, &nan); |
| 2539 | // output = double-to-int-truncate(input) |
| 2540 | __ cvttsd2si(output, input); |
| 2541 | __ jmp(&done); |
| 2542 | __ Bind(&nan); |
| 2543 | // output = 0 |
| 2544 | __ xorl(output, output); |
| 2545 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2546 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2547 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2548 | |
| 2549 | default: |
| 2550 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2551 | << " to " << result_type; |
| 2552 | } |
| 2553 | break; |
| 2554 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2555 | case Primitive::kPrimLong: |
| 2556 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2557 | case Primitive::kPrimBoolean: |
| 2558 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2559 | case Primitive::kPrimByte: |
| 2560 | case Primitive::kPrimShort: |
| 2561 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2562 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2563 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2564 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2565 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2566 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2567 | __ cdq(); |
| 2568 | break; |
| 2569 | |
| 2570 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2571 | // Processing a Dex `float-to-long' instruction. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2572 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2573 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2574 | break; |
| 2575 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2576 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2577 | // Processing a Dex `double-to-long' instruction. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2578 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2579 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2580 | break; |
| 2581 | |
| 2582 | default: |
| 2583 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2584 | << " to " << result_type; |
| 2585 | } |
| 2586 | break; |
| 2587 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2588 | case Primitive::kPrimChar: |
| 2589 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2590 | case Primitive::kPrimLong: |
| 2591 | // Type conversion from long to short is a result of code transformations. |
| 2592 | if (in.IsRegisterPair()) { |
| 2593 | __ movzxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2594 | } else if (in.IsDoubleStackSlot()) { |
| 2595 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2596 | } else { |
| 2597 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2598 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2599 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
| 2600 | } |
| 2601 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2602 | case Primitive::kPrimBoolean: |
| 2603 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2604 | case Primitive::kPrimByte: |
| 2605 | case Primitive::kPrimShort: |
| 2606 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2607 | // Processing a Dex `Process a Dex `int-to-char'' instruction. |
| 2608 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2609 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2610 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2611 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2612 | } else { |
| 2613 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2614 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2615 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2616 | } |
| 2617 | break; |
| 2618 | |
| 2619 | default: |
| 2620 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2621 | << " to " << result_type; |
| 2622 | } |
| 2623 | break; |
| 2624 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2625 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2626 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2627 | case Primitive::kPrimBoolean: |
| 2628 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2629 | case Primitive::kPrimByte: |
| 2630 | case Primitive::kPrimShort: |
| 2631 | case Primitive::kPrimInt: |
| 2632 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2633 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2634 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2635 | break; |
| 2636 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2637 | case Primitive::kPrimLong: { |
| 2638 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2639 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2640 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2641 | // Create stack space for the call to |
| 2642 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2643 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2644 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
| 2645 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2646 | __ subl(ESP, Immediate(adjustment)); |
| 2647 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2648 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2649 | // Load the value to the FP stack, using temporaries if needed. |
| 2650 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2651 | |
| 2652 | if (out.IsStackSlot()) { |
| 2653 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2654 | } else { |
| 2655 | __ fstps(Address(ESP, 0)); |
| 2656 | Location stack_temp = Location::StackSlot(0); |
| 2657 | codegen_->Move32(out, stack_temp); |
| 2658 | } |
| 2659 | |
| 2660 | // Remove the temporary stack space we allocated. |
| 2661 | if (adjustment != 0) { |
| 2662 | __ addl(ESP, Immediate(adjustment)); |
| 2663 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2664 | break; |
| 2665 | } |
| 2666 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2667 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2668 | // Processing a Dex `double-to-float' instruction. |
| 2669 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2670 | break; |
| 2671 | |
| 2672 | default: |
| 2673 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2674 | << " to " << result_type; |
| 2675 | }; |
| 2676 | break; |
| 2677 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2678 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2679 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2680 | case Primitive::kPrimBoolean: |
| 2681 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2682 | case Primitive::kPrimByte: |
| 2683 | case Primitive::kPrimShort: |
| 2684 | case Primitive::kPrimInt: |
| 2685 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2686 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2687 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2688 | break; |
| 2689 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2690 | case Primitive::kPrimLong: { |
| 2691 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2692 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2693 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2694 | // Create stack space for the call to |
| 2695 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2696 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2697 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
| 2698 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2699 | __ subl(ESP, Immediate(adjustment)); |
| 2700 | } |
| 2701 | |
| 2702 | // Load the value to the FP stack, using temporaries if needed. |
| 2703 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2704 | |
| 2705 | if (out.IsDoubleStackSlot()) { |
| 2706 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2707 | } else { |
| 2708 | __ fstpl(Address(ESP, 0)); |
| 2709 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2710 | codegen_->Move64(out, stack_temp); |
| 2711 | } |
| 2712 | |
| 2713 | // Remove the temporary stack space we allocated. |
| 2714 | if (adjustment != 0) { |
| 2715 | __ addl(ESP, Immediate(adjustment)); |
| 2716 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2717 | break; |
| 2718 | } |
| 2719 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2720 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2721 | // Processing a Dex `float-to-double' instruction. |
| 2722 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2723 | break; |
| 2724 | |
| 2725 | default: |
| 2726 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2727 | << " to " << result_type; |
| 2728 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2729 | break; |
| 2730 | |
| 2731 | default: |
| 2732 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2733 | << " to " << result_type; |
| 2734 | } |
| 2735 | } |
| 2736 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2737 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2738 | LocationSummary* locations = |
| 2739 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2740 | switch (add->GetResultType()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2741 | case Primitive::kPrimInt: { |
| 2742 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2743 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2744 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2745 | break; |
| 2746 | } |
| 2747 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2748 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2749 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2750 | locations->SetInAt(1, Location::Any()); |
| 2751 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2752 | break; |
| 2753 | } |
| 2754 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2755 | case Primitive::kPrimFloat: |
| 2756 | case Primitive::kPrimDouble: { |
| 2757 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2758 | if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2759 | DCHECK(add->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2760 | } else if (add->InputAt(1)->IsConstant()) { |
| 2761 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2762 | } else { |
| 2763 | locations->SetInAt(1, Location::Any()); |
| 2764 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2765 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2766 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2767 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2768 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2769 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2770 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2771 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2772 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2773 | } |
| 2774 | |
| 2775 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 2776 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2777 | Location first = locations->InAt(0); |
| 2778 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2779 | Location out = locations->Out(); |
| 2780 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2781 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2782 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2783 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2784 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2785 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2786 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2787 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2788 | } else { |
| 2789 | __ leal(out.AsRegister<Register>(), Address( |
| 2790 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 2791 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2792 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2793 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2794 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2795 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 2796 | } else { |
| 2797 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 2798 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2799 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2800 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2801 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2802 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2803 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2804 | } |
| 2805 | |
| 2806 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2807 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2808 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2809 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2810 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2811 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 2812 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2813 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2814 | } else { |
| 2815 | DCHECK(second.IsConstant()) << second; |
| 2816 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2817 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2818 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2819 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2820 | break; |
| 2821 | } |
| 2822 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2823 | case Primitive::kPrimFloat: { |
| 2824 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2825 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2826 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2827 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2828 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2829 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2830 | codegen_->LiteralFloatAddress( |
| 2831 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2832 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2833 | } else { |
| 2834 | DCHECK(second.IsStackSlot()); |
| 2835 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2836 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2837 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2838 | } |
| 2839 | |
| 2840 | case Primitive::kPrimDouble: { |
| 2841 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2842 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2843 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2844 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2845 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2846 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2847 | codegen_->LiteralDoubleAddress( |
| 2848 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2849 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2850 | } else { |
| 2851 | DCHECK(second.IsDoubleStackSlot()); |
| 2852 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2853 | } |
| 2854 | break; |
| 2855 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2856 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2857 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2858 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2859 | } |
| 2860 | } |
| 2861 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2862 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2863 | LocationSummary* locations = |
| 2864 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2865 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2866 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2867 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2868 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2869 | locations->SetInAt(1, Location::Any()); |
| 2870 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2871 | break; |
| 2872 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2873 | case Primitive::kPrimFloat: |
| 2874 | case Primitive::kPrimDouble: { |
| 2875 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2876 | if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2877 | DCHECK(sub->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2878 | } else if (sub->InputAt(1)->IsConstant()) { |
| 2879 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2880 | } else { |
| 2881 | locations->SetInAt(1, Location::Any()); |
| 2882 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2883 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2884 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2885 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2886 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2887 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2888 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2889 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2890 | } |
| 2891 | |
| 2892 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 2893 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2894 | Location first = locations->InAt(0); |
| 2895 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2896 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2897 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2898 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2899 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2900 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2901 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2902 | __ subl(first.AsRegister<Register>(), |
| 2903 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2904 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2905 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2906 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2907 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2908 | } |
| 2909 | |
| 2910 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2911 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2912 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2913 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2914 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2915 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2916 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 2917 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2918 | } else { |
| 2919 | DCHECK(second.IsConstant()) << second; |
| 2920 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2921 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2922 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2923 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2924 | break; |
| 2925 | } |
| 2926 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2927 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2928 | if (second.IsFpuRegister()) { |
| 2929 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2930 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2931 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2932 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2933 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2934 | codegen_->LiteralFloatAddress( |
| 2935 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2936 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2937 | } else { |
| 2938 | DCHECK(second.IsStackSlot()); |
| 2939 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2940 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2941 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2942 | } |
| 2943 | |
| 2944 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2945 | if (second.IsFpuRegister()) { |
| 2946 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2947 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2948 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2949 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2950 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 2951 | codegen_->LiteralDoubleAddress( |
| 2952 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2953 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2954 | } else { |
| 2955 | DCHECK(second.IsDoubleStackSlot()); |
| 2956 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2957 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2958 | break; |
| 2959 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2960 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2961 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2962 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2963 | } |
| 2964 | } |
| 2965 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2966 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 2967 | LocationSummary* locations = |
| 2968 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2969 | switch (mul->GetResultType()) { |
| 2970 | case Primitive::kPrimInt: |
| 2971 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2972 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2973 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2974 | // Can use 3 operand multiply. |
| 2975 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2976 | } else { |
| 2977 | locations->SetOut(Location::SameAsFirstInput()); |
| 2978 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2979 | break; |
| 2980 | case Primitive::kPrimLong: { |
| 2981 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2982 | locations->SetInAt(1, Location::Any()); |
| 2983 | locations->SetOut(Location::SameAsFirstInput()); |
| 2984 | // Needed for imul on 32bits with 64bits output. |
| 2985 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 2986 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 2987 | break; |
| 2988 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2989 | case Primitive::kPrimFloat: |
| 2990 | case Primitive::kPrimDouble: { |
| 2991 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2992 | if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2993 | DCHECK(mul->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2994 | } else if (mul->InputAt(1)->IsConstant()) { |
| 2995 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2996 | } else { |
| 2997 | locations->SetInAt(1, Location::Any()); |
| 2998 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2999 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3000 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3001 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3002 | |
| 3003 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3004 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3005 | } |
| 3006 | } |
| 3007 | |
| 3008 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 3009 | LocationSummary* locations = mul->GetLocations(); |
| 3010 | Location first = locations->InAt(0); |
| 3011 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3012 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3013 | |
| 3014 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3015 | case Primitive::kPrimInt: |
| 3016 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3017 | // problems where the output may not be the same as the first operand. |
| 3018 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3019 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3020 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 3021 | } else if (second.IsRegister()) { |
| 3022 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3023 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3024 | } else { |
| 3025 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3026 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3027 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3028 | } |
| 3029 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3030 | |
| 3031 | case Primitive::kPrimLong: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3032 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 3033 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3034 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 3035 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3036 | |
| 3037 | DCHECK_EQ(EAX, eax); |
| 3038 | DCHECK_EQ(EDX, edx); |
| 3039 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3040 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3041 | // output: in1 |
| 3042 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3043 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3044 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3045 | if (second.IsConstant()) { |
| 3046 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3047 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3048 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3049 | int32_t low_value = Low32Bits(value); |
| 3050 | int32_t high_value = High32Bits(value); |
| 3051 | Immediate low(low_value); |
| 3052 | Immediate high(high_value); |
| 3053 | |
| 3054 | __ movl(eax, high); |
| 3055 | // eax <- in1.lo * in2.hi |
| 3056 | __ imull(eax, in1_lo); |
| 3057 | // in1.hi <- in1.hi * in2.lo |
| 3058 | __ imull(in1_hi, low); |
| 3059 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3060 | __ addl(in1_hi, eax); |
| 3061 | // move in2_lo to eax to prepare for double precision |
| 3062 | __ movl(eax, low); |
| 3063 | // edx:eax <- in1.lo * in2.lo |
| 3064 | __ mull(in1_lo); |
| 3065 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3066 | __ addl(in1_hi, edx); |
| 3067 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3068 | __ movl(in1_lo, eax); |
| 3069 | } else if (second.IsRegisterPair()) { |
| 3070 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3071 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3072 | |
| 3073 | __ movl(eax, in2_hi); |
| 3074 | // eax <- in1.lo * in2.hi |
| 3075 | __ imull(eax, in1_lo); |
| 3076 | // in1.hi <- in1.hi * in2.lo |
| 3077 | __ imull(in1_hi, in2_lo); |
| 3078 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3079 | __ addl(in1_hi, eax); |
| 3080 | // move in1_lo to eax to prepare for double precision |
| 3081 | __ movl(eax, in1_lo); |
| 3082 | // edx:eax <- in1.lo * in2.lo |
| 3083 | __ mull(in2_lo); |
| 3084 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3085 | __ addl(in1_hi, edx); |
| 3086 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3087 | __ movl(in1_lo, eax); |
| 3088 | } else { |
| 3089 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 3090 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 3091 | Address in2_lo(ESP, second.GetStackIndex()); |
| 3092 | |
| 3093 | __ movl(eax, in2_hi); |
| 3094 | // eax <- in1.lo * in2.hi |
| 3095 | __ imull(eax, in1_lo); |
| 3096 | // in1.hi <- in1.hi * in2.lo |
| 3097 | __ imull(in1_hi, in2_lo); |
| 3098 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3099 | __ addl(in1_hi, eax); |
| 3100 | // move in1_lo to eax to prepare for double precision |
| 3101 | __ movl(eax, in1_lo); |
| 3102 | // edx:eax <- in1.lo * in2.lo |
| 3103 | __ mull(in2_lo); |
| 3104 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3105 | __ addl(in1_hi, edx); |
| 3106 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3107 | __ movl(in1_lo, eax); |
| 3108 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3109 | |
| 3110 | break; |
| 3111 | } |
| 3112 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3113 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3114 | DCHECK(first.Equals(locations->Out())); |
| 3115 | if (second.IsFpuRegister()) { |
| 3116 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3117 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3118 | HX86LoadFromConstantTable* const_area = mul->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 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3121 | codegen_->LiteralFloatAddress( |
| 3122 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3123 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3124 | } else { |
| 3125 | DCHECK(second.IsStackSlot()); |
| 3126 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3127 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3128 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3129 | } |
| 3130 | |
| 3131 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3132 | DCHECK(first.Equals(locations->Out())); |
| 3133 | if (second.IsFpuRegister()) { |
| 3134 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3135 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3136 | HX86LoadFromConstantTable* const_area = mul->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 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3139 | codegen_->LiteralDoubleAddress( |
| 3140 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3141 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3142 | } else { |
| 3143 | DCHECK(second.IsDoubleStackSlot()); |
| 3144 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3145 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3146 | break; |
| 3147 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3148 | |
| 3149 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3150 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3151 | } |
| 3152 | } |
| 3153 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3154 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 3155 | uint32_t temp_offset, |
| 3156 | uint32_t stack_adjustment, |
| 3157 | bool is_fp, |
| 3158 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3159 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3160 | DCHECK(!is_wide); |
| 3161 | if (is_fp) { |
| 3162 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3163 | } else { |
| 3164 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3165 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3166 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3167 | DCHECK(is_wide); |
| 3168 | if (is_fp) { |
| 3169 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3170 | } else { |
| 3171 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3172 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3173 | } else { |
| 3174 | // 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] | 3175 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3176 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3177 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3178 | if (is_fp) { |
| 3179 | __ flds(Address(ESP, temp_offset)); |
| 3180 | } else { |
| 3181 | __ filds(Address(ESP, temp_offset)); |
| 3182 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3183 | } else { |
| 3184 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3185 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3186 | if (is_fp) { |
| 3187 | __ fldl(Address(ESP, temp_offset)); |
| 3188 | } else { |
| 3189 | __ fildl(Address(ESP, temp_offset)); |
| 3190 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3191 | } |
| 3192 | } |
| 3193 | } |
| 3194 | |
| 3195 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
| 3196 | Primitive::Type type = rem->GetResultType(); |
| 3197 | bool is_float = type == Primitive::kPrimFloat; |
| 3198 | size_t elem_size = Primitive::ComponentSize(type); |
| 3199 | LocationSummary* locations = rem->GetLocations(); |
| 3200 | Location first = locations->InAt(0); |
| 3201 | Location second = locations->InAt(1); |
| 3202 | Location out = locations->Out(); |
| 3203 | |
| 3204 | // Create stack space for 2 elements. |
| 3205 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3206 | __ subl(ESP, Immediate(2 * elem_size)); |
| 3207 | |
| 3208 | // 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] | 3209 | const bool is_wide = !is_float; |
| 3210 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); |
| 3211 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3212 | |
| 3213 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3214 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3215 | __ Bind(&retry); |
| 3216 | __ fprem(); |
| 3217 | |
| 3218 | // Move FP status to AX. |
| 3219 | __ fstsw(); |
| 3220 | |
| 3221 | // And see if the argument reduction is complete. This is signaled by the |
| 3222 | // C2 FPU flag bit set to 0. |
| 3223 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 3224 | __ j(kNotEqual, &retry); |
| 3225 | |
| 3226 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3227 | // Store FP top of stack to real stack. |
| 3228 | if (is_float) { |
| 3229 | __ fsts(Address(ESP, 0)); |
| 3230 | } else { |
| 3231 | __ fstl(Address(ESP, 0)); |
| 3232 | } |
| 3233 | |
| 3234 | // Pop the 2 items from the FP stack. |
| 3235 | __ fucompp(); |
| 3236 | |
| 3237 | // Load the value from the stack into an XMM register. |
| 3238 | DCHECK(out.IsFpuRegister()) << out; |
| 3239 | if (is_float) { |
| 3240 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3241 | } else { |
| 3242 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3243 | } |
| 3244 | |
| 3245 | // And remove the temporary stack space we allocated. |
| 3246 | __ addl(ESP, Immediate(2 * elem_size)); |
| 3247 | } |
| 3248 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3249 | |
| 3250 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3251 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3252 | |
| 3253 | LocationSummary* locations = instruction->GetLocations(); |
| 3254 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3255 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3256 | |
| 3257 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3258 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3259 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3260 | |
| 3261 | DCHECK(imm == 1 || imm == -1); |
| 3262 | |
| 3263 | if (instruction->IsRem()) { |
| 3264 | __ xorl(out_register, out_register); |
| 3265 | } else { |
| 3266 | __ movl(out_register, input_register); |
| 3267 | if (imm == -1) { |
| 3268 | __ negl(out_register); |
| 3269 | } |
| 3270 | } |
| 3271 | } |
| 3272 | |
| 3273 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3274 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3275 | LocationSummary* locations = instruction->GetLocations(); |
| 3276 | |
| 3277 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3278 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3279 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3280 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3281 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3282 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3283 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 3284 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3285 | __ leal(num, Address(input_register, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3286 | __ testl(input_register, input_register); |
| 3287 | __ cmovl(kGreaterEqual, num, input_register); |
| 3288 | int shift = CTZ(imm); |
| 3289 | __ sarl(num, Immediate(shift)); |
| 3290 | |
| 3291 | if (imm < 0) { |
| 3292 | __ negl(num); |
| 3293 | } |
| 3294 | |
| 3295 | __ movl(out_register, num); |
| 3296 | } |
| 3297 | |
| 3298 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3299 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3300 | |
| 3301 | LocationSummary* locations = instruction->GetLocations(); |
| 3302 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 3303 | |
| 3304 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 3305 | Register out = locations->Out().AsRegister<Register>(); |
| 3306 | Register num; |
| 3307 | Register edx; |
| 3308 | |
| 3309 | if (instruction->IsDiv()) { |
| 3310 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 3311 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 3312 | } else { |
| 3313 | edx = locations->Out().AsRegister<Register>(); |
| 3314 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 3315 | } |
| 3316 | |
| 3317 | DCHECK_EQ(EAX, eax); |
| 3318 | DCHECK_EQ(EDX, edx); |
| 3319 | if (instruction->IsDiv()) { |
| 3320 | DCHECK_EQ(EAX, out); |
| 3321 | } else { |
| 3322 | DCHECK_EQ(EDX, out); |
| 3323 | } |
| 3324 | |
| 3325 | int64_t magic; |
| 3326 | int shift; |
| 3327 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3328 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3329 | // Save the numerator. |
| 3330 | __ movl(num, eax); |
| 3331 | |
| 3332 | // EAX = magic |
| 3333 | __ movl(eax, Immediate(magic)); |
| 3334 | |
| 3335 | // EDX:EAX = magic * numerator |
| 3336 | __ imull(num); |
| 3337 | |
| 3338 | if (imm > 0 && magic < 0) { |
| 3339 | // EDX += num |
| 3340 | __ addl(edx, num); |
| 3341 | } else if (imm < 0 && magic > 0) { |
| 3342 | __ subl(edx, num); |
| 3343 | } |
| 3344 | |
| 3345 | // Shift if needed. |
| 3346 | if (shift != 0) { |
| 3347 | __ sarl(edx, Immediate(shift)); |
| 3348 | } |
| 3349 | |
| 3350 | // EDX += 1 if EDX < 0 |
| 3351 | __ movl(eax, edx); |
| 3352 | __ shrl(edx, Immediate(31)); |
| 3353 | __ addl(edx, eax); |
| 3354 | |
| 3355 | if (instruction->IsRem()) { |
| 3356 | __ movl(eax, num); |
| 3357 | __ imull(edx, Immediate(imm)); |
| 3358 | __ subl(eax, edx); |
| 3359 | __ movl(edx, eax); |
| 3360 | } else { |
| 3361 | __ movl(eax, edx); |
| 3362 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3363 | } |
| 3364 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3365 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3366 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3367 | |
| 3368 | LocationSummary* locations = instruction->GetLocations(); |
| 3369 | Location out = locations->Out(); |
| 3370 | Location first = locations->InAt(0); |
| 3371 | Location second = locations->InAt(1); |
| 3372 | bool is_div = instruction->IsDiv(); |
| 3373 | |
| 3374 | switch (instruction->GetResultType()) { |
| 3375 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3376 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 3377 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3378 | |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3379 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3380 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3381 | |
| 3382 | if (imm == 0) { |
| 3383 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 3384 | } else if (imm == 1 || imm == -1) { |
| 3385 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3386 | } else if (is_div && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3387 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3388 | } else { |
| 3389 | DCHECK(imm <= -2 || imm >= 2); |
| 3390 | GenerateDivRemWithAnyConstant(instruction); |
| 3391 | } |
| 3392 | } else { |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3393 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86( |
| 3394 | instruction, out.AsRegister<Register>(), is_div); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3395 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3396 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3397 | Register second_reg = second.AsRegister<Register>(); |
| 3398 | // 0x80000000/-1 triggers an arithmetic exception! |
| 3399 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 3400 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3401 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3402 | __ cmpl(second_reg, Immediate(-1)); |
| 3403 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3404 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3405 | // edx:eax <- sign-extended of eax |
| 3406 | __ cdq(); |
| 3407 | // eax = quotient, edx = remainder |
| 3408 | __ idivl(second_reg); |
| 3409 | __ Bind(slow_path->GetExitLabel()); |
| 3410 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3411 | break; |
| 3412 | } |
| 3413 | |
| 3414 | case Primitive::kPrimLong: { |
| 3415 | InvokeRuntimeCallingConvention calling_convention; |
| 3416 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3417 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3418 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3419 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3420 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 3421 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 3422 | |
| 3423 | if (is_div) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3424 | codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3425 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3426 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3427 | codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3428 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3429 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3430 | break; |
| 3431 | } |
| 3432 | |
| 3433 | default: |
| 3434 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 3435 | } |
| 3436 | } |
| 3437 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3438 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3439 | LocationSummary::CallKind call_kind = (div->GetResultType() == Primitive::kPrimLong) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3440 | ? LocationSummary::kCallOnMainOnly |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3441 | : LocationSummary::kNoCall; |
| 3442 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 3443 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3444 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3445 | case Primitive::kPrimInt: { |
| 3446 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3447 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3448 | locations->SetOut(Location::SameAsFirstInput()); |
| 3449 | // Intel uses edx:eax as the dividend. |
| 3450 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3451 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3452 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 3453 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3454 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3455 | locations->AddTemp(Location::RequiresRegister()); |
| 3456 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3457 | break; |
| 3458 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3459 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3460 | InvokeRuntimeCallingConvention calling_convention; |
| 3461 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3462 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3463 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3464 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3465 | // Runtime helper puts the result in EAX, EDX. |
| 3466 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3467 | break; |
| 3468 | } |
| 3469 | case Primitive::kPrimFloat: |
| 3470 | case Primitive::kPrimDouble: { |
| 3471 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3472 | if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3473 | DCHECK(div->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3474 | } else if (div->InputAt(1)->IsConstant()) { |
| 3475 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3476 | } else { |
| 3477 | locations->SetInAt(1, Location::Any()); |
| 3478 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3479 | locations->SetOut(Location::SameAsFirstInput()); |
| 3480 | break; |
| 3481 | } |
| 3482 | |
| 3483 | default: |
| 3484 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3485 | } |
| 3486 | } |
| 3487 | |
| 3488 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 3489 | LocationSummary* locations = div->GetLocations(); |
| 3490 | Location first = locations->InAt(0); |
| 3491 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3492 | |
| 3493 | switch (div->GetResultType()) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3494 | case Primitive::kPrimInt: |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3495 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3496 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3497 | break; |
| 3498 | } |
| 3499 | |
| 3500 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3501 | if (second.IsFpuRegister()) { |
| 3502 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3503 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3504 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3505 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3506 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3507 | codegen_->LiteralFloatAddress( |
| 3508 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3509 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3510 | } else { |
| 3511 | DCHECK(second.IsStackSlot()); |
| 3512 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3513 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3514 | break; |
| 3515 | } |
| 3516 | |
| 3517 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3518 | if (second.IsFpuRegister()) { |
| 3519 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3520 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3521 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3522 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3523 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3524 | codegen_->LiteralDoubleAddress( |
| 3525 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3526 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3527 | } else { |
| 3528 | DCHECK(second.IsDoubleStackSlot()); |
| 3529 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3530 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3531 | break; |
| 3532 | } |
| 3533 | |
| 3534 | default: |
| 3535 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3536 | } |
| 3537 | } |
| 3538 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3539 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3540 | Primitive::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3541 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3542 | LocationSummary::CallKind call_kind = (rem->GetResultType() == Primitive::kPrimLong) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3543 | ? LocationSummary::kCallOnMainOnly |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3544 | : LocationSummary::kNoCall; |
| 3545 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3546 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3547 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3548 | case Primitive::kPrimInt: { |
| 3549 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3550 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3551 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3552 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3553 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 3554 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3555 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3556 | locations->AddTemp(Location::RequiresRegister()); |
| 3557 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3558 | break; |
| 3559 | } |
| 3560 | case Primitive::kPrimLong: { |
| 3561 | InvokeRuntimeCallingConvention calling_convention; |
| 3562 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3563 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3564 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3565 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3566 | // Runtime helper puts the result in EAX, EDX. |
| 3567 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3568 | break; |
| 3569 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3570 | case Primitive::kPrimDouble: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3571 | case Primitive::kPrimFloat: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3572 | locations->SetInAt(0, Location::Any()); |
| 3573 | locations->SetInAt(1, Location::Any()); |
| 3574 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3575 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3576 | break; |
| 3577 | } |
| 3578 | |
| 3579 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3580 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3581 | } |
| 3582 | } |
| 3583 | |
| 3584 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
| 3585 | Primitive::Type type = rem->GetResultType(); |
| 3586 | switch (type) { |
| 3587 | case Primitive::kPrimInt: |
| 3588 | case Primitive::kPrimLong: { |
| 3589 | GenerateDivRemIntegral(rem); |
| 3590 | break; |
| 3591 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3592 | case Primitive::kPrimFloat: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3593 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3594 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3595 | break; |
| 3596 | } |
| 3597 | default: |
| 3598 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3599 | } |
| 3600 | } |
| 3601 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3602 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3603 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3604 | ? LocationSummary::kCallOnSlowPath |
| 3605 | : LocationSummary::kNoCall; |
| 3606 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3607 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3608 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3609 | case Primitive::kPrimByte: |
| 3610 | case Primitive::kPrimChar: |
| 3611 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3612 | case Primitive::kPrimInt: { |
| 3613 | locations->SetInAt(0, Location::Any()); |
| 3614 | break; |
| 3615 | } |
| 3616 | case Primitive::kPrimLong: { |
| 3617 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 3618 | if (!instruction->IsConstant()) { |
| 3619 | locations->AddTemp(Location::RequiresRegister()); |
| 3620 | } |
| 3621 | break; |
| 3622 | } |
| 3623 | default: |
| 3624 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3625 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3626 | if (instruction->HasUses()) { |
| 3627 | locations->SetOut(Location::SameAsFirstInput()); |
| 3628 | } |
| 3629 | } |
| 3630 | |
| 3631 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3632 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3633 | codegen_->AddSlowPath(slow_path); |
| 3634 | |
| 3635 | LocationSummary* locations = instruction->GetLocations(); |
| 3636 | Location value = locations->InAt(0); |
| 3637 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3638 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3639 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3640 | case Primitive::kPrimByte: |
| 3641 | case Primitive::kPrimChar: |
| 3642 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3643 | case Primitive::kPrimInt: { |
| 3644 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3645 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3646 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3647 | } else if (value.IsStackSlot()) { |
| 3648 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 3649 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3650 | } else { |
| 3651 | DCHECK(value.IsConstant()) << value; |
| 3652 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3653 | __ jmp(slow_path->GetEntryLabel()); |
| 3654 | } |
| 3655 | } |
| 3656 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3657 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3658 | case Primitive::kPrimLong: { |
| 3659 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3660 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3661 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 3662 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 3663 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3664 | } else { |
| 3665 | DCHECK(value.IsConstant()) << value; |
| 3666 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3667 | __ jmp(slow_path->GetEntryLabel()); |
| 3668 | } |
| 3669 | } |
| 3670 | break; |
| 3671 | } |
| 3672 | default: |
| 3673 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3674 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3675 | } |
| 3676 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3677 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 3678 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3679 | |
| 3680 | LocationSummary* locations = |
| 3681 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3682 | |
| 3683 | switch (op->GetResultType()) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3684 | case Primitive::kPrimInt: |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3685 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3686 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3687 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3688 | // The shift count needs to be in CL or a constant. |
| 3689 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3690 | locations->SetOut(Location::SameAsFirstInput()); |
| 3691 | break; |
| 3692 | } |
| 3693 | default: |
| 3694 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3695 | } |
| 3696 | } |
| 3697 | |
| 3698 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 3699 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3700 | |
| 3701 | LocationSummary* locations = op->GetLocations(); |
| 3702 | Location first = locations->InAt(0); |
| 3703 | Location second = locations->InAt(1); |
| 3704 | DCHECK(first.Equals(locations->Out())); |
| 3705 | |
| 3706 | switch (op->GetResultType()) { |
| 3707 | case Primitive::kPrimInt: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3708 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3709 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3710 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3711 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3712 | DCHECK_EQ(ECX, second_reg); |
| 3713 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3714 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3715 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3716 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3717 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3718 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3719 | } |
| 3720 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3721 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3722 | if (shift == 0) { |
| 3723 | return; |
| 3724 | } |
| 3725 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3726 | if (op->IsShl()) { |
| 3727 | __ shll(first_reg, imm); |
| 3728 | } else if (op->IsShr()) { |
| 3729 | __ sarl(first_reg, imm); |
| 3730 | } else { |
| 3731 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3732 | } |
| 3733 | } |
| 3734 | break; |
| 3735 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3736 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3737 | if (second.IsRegister()) { |
| 3738 | Register second_reg = second.AsRegister<Register>(); |
| 3739 | DCHECK_EQ(ECX, second_reg); |
| 3740 | if (op->IsShl()) { |
| 3741 | GenerateShlLong(first, second_reg); |
| 3742 | } else if (op->IsShr()) { |
| 3743 | GenerateShrLong(first, second_reg); |
| 3744 | } else { |
| 3745 | GenerateUShrLong(first, second_reg); |
| 3746 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3747 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3748 | // Shift by a constant. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3749 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3750 | // Nothing to do if the shift is 0, as the input is already the output. |
| 3751 | if (shift != 0) { |
| 3752 | if (op->IsShl()) { |
| 3753 | GenerateShlLong(first, shift); |
| 3754 | } else if (op->IsShr()) { |
| 3755 | GenerateShrLong(first, shift); |
| 3756 | } else { |
| 3757 | GenerateUShrLong(first, shift); |
| 3758 | } |
| 3759 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3760 | } |
| 3761 | break; |
| 3762 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3763 | default: |
| 3764 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3765 | } |
| 3766 | } |
| 3767 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3768 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 3769 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3770 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 3771 | if (shift == 1) { |
| 3772 | // This is just an addition. |
| 3773 | __ addl(low, low); |
| 3774 | __ adcl(high, high); |
| 3775 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3776 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 3777 | codegen_->EmitParallelMoves( |
| 3778 | loc.ToLow(), |
| 3779 | loc.ToHigh(), |
| 3780 | Primitive::kPrimInt, |
| 3781 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3782 | loc.ToLow(), |
| 3783 | Primitive::kPrimInt); |
| 3784 | } else if (shift > 32) { |
| 3785 | // Low part becomes 0. High part is low part << (shift-32). |
| 3786 | __ movl(high, low); |
| 3787 | __ shll(high, Immediate(shift - 32)); |
| 3788 | __ xorl(low, low); |
| 3789 | } else { |
| 3790 | // Between 1 and 31. |
| 3791 | __ shld(high, low, Immediate(shift)); |
| 3792 | __ shll(low, Immediate(shift)); |
| 3793 | } |
| 3794 | } |
| 3795 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3796 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3797 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3798 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 3799 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 3800 | __ testl(shifter, Immediate(32)); |
| 3801 | __ j(kEqual, &done); |
| 3802 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 3803 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 3804 | __ Bind(&done); |
| 3805 | } |
| 3806 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3807 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 3808 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3809 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3810 | if (shift == 32) { |
| 3811 | // Need to copy the sign. |
| 3812 | DCHECK_NE(low, high); |
| 3813 | __ movl(low, high); |
| 3814 | __ sarl(high, Immediate(31)); |
| 3815 | } else if (shift > 32) { |
| 3816 | DCHECK_NE(low, high); |
| 3817 | // High part becomes sign. Low part is shifted by shift - 32. |
| 3818 | __ movl(low, high); |
| 3819 | __ sarl(high, Immediate(31)); |
| 3820 | __ sarl(low, Immediate(shift - 32)); |
| 3821 | } else { |
| 3822 | // Between 1 and 31. |
| 3823 | __ shrd(low, high, Immediate(shift)); |
| 3824 | __ sarl(high, Immediate(shift)); |
| 3825 | } |
| 3826 | } |
| 3827 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3828 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3829 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3830 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3831 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3832 | __ testl(shifter, Immediate(32)); |
| 3833 | __ j(kEqual, &done); |
| 3834 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3835 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 3836 | __ Bind(&done); |
| 3837 | } |
| 3838 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3839 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 3840 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3841 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3842 | if (shift == 32) { |
| 3843 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 3844 | codegen_->EmitParallelMoves( |
| 3845 | loc.ToHigh(), |
| 3846 | loc.ToLow(), |
| 3847 | Primitive::kPrimInt, |
| 3848 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3849 | loc.ToHigh(), |
| 3850 | Primitive::kPrimInt); |
| 3851 | } else if (shift > 32) { |
| 3852 | // Low part is high >> (shift - 32). High part becomes 0. |
| 3853 | __ movl(low, high); |
| 3854 | __ shrl(low, Immediate(shift - 32)); |
| 3855 | __ xorl(high, high); |
| 3856 | } else { |
| 3857 | // Between 1 and 31. |
| 3858 | __ shrd(low, high, Immediate(shift)); |
| 3859 | __ shrl(high, Immediate(shift)); |
| 3860 | } |
| 3861 | } |
| 3862 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3863 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3864 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3865 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3866 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3867 | __ testl(shifter, Immediate(32)); |
| 3868 | __ j(kEqual, &done); |
| 3869 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3870 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 3871 | __ Bind(&done); |
| 3872 | } |
| 3873 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3874 | void LocationsBuilderX86::VisitRor(HRor* ror) { |
| 3875 | LocationSummary* locations = |
| 3876 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3877 | |
| 3878 | switch (ror->GetResultType()) { |
| 3879 | case Primitive::kPrimLong: |
| 3880 | // Add the temporary needed. |
| 3881 | locations->AddTemp(Location::RequiresRegister()); |
| 3882 | FALLTHROUGH_INTENDED; |
| 3883 | case Primitive::kPrimInt: |
| 3884 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3885 | // The shift count needs to be in CL (unless it is a constant). |
| 3886 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); |
| 3887 | locations->SetOut(Location::SameAsFirstInput()); |
| 3888 | break; |
| 3889 | default: |
| 3890 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3891 | UNREACHABLE(); |
| 3892 | } |
| 3893 | } |
| 3894 | |
| 3895 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { |
| 3896 | LocationSummary* locations = ror->GetLocations(); |
| 3897 | Location first = locations->InAt(0); |
| 3898 | Location second = locations->InAt(1); |
| 3899 | |
| 3900 | if (ror->GetResultType() == Primitive::kPrimInt) { |
| 3901 | Register first_reg = first.AsRegister<Register>(); |
| 3902 | if (second.IsRegister()) { |
| 3903 | Register second_reg = second.AsRegister<Register>(); |
| 3904 | __ rorl(first_reg, second_reg); |
| 3905 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3906 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3907 | __ rorl(first_reg, imm); |
| 3908 | } |
| 3909 | return; |
| 3910 | } |
| 3911 | |
| 3912 | DCHECK_EQ(ror->GetResultType(), Primitive::kPrimLong); |
| 3913 | Register first_reg_lo = first.AsRegisterPairLow<Register>(); |
| 3914 | Register first_reg_hi = first.AsRegisterPairHigh<Register>(); |
| 3915 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 3916 | if (second.IsRegister()) { |
| 3917 | Register second_reg = second.AsRegister<Register>(); |
| 3918 | DCHECK_EQ(second_reg, ECX); |
| 3919 | __ movl(temp_reg, first_reg_hi); |
| 3920 | __ shrd(first_reg_hi, first_reg_lo, second_reg); |
| 3921 | __ shrd(first_reg_lo, temp_reg, second_reg); |
| 3922 | __ movl(temp_reg, first_reg_hi); |
| 3923 | __ testl(second_reg, Immediate(32)); |
| 3924 | __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); |
| 3925 | __ cmovl(kNotEqual, first_reg_lo, temp_reg); |
| 3926 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3927 | int32_t shift_amt = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3928 | if (shift_amt == 0) { |
| 3929 | // Already fine. |
| 3930 | return; |
| 3931 | } |
| 3932 | if (shift_amt == 32) { |
| 3933 | // Just swap. |
| 3934 | __ movl(temp_reg, first_reg_lo); |
| 3935 | __ movl(first_reg_lo, first_reg_hi); |
| 3936 | __ movl(first_reg_hi, temp_reg); |
| 3937 | return; |
| 3938 | } |
| 3939 | |
| 3940 | Immediate imm(shift_amt); |
| 3941 | // Save the constents of the low value. |
| 3942 | __ movl(temp_reg, first_reg_lo); |
| 3943 | |
| 3944 | // Shift right into low, feeding bits from high. |
| 3945 | __ shrd(first_reg_lo, first_reg_hi, imm); |
| 3946 | |
| 3947 | // Shift right into high, feeding bits from the original low. |
| 3948 | __ shrd(first_reg_hi, temp_reg, imm); |
| 3949 | |
| 3950 | // Swap if needed. |
| 3951 | if (shift_amt > 32) { |
| 3952 | __ movl(temp_reg, first_reg_lo); |
| 3953 | __ movl(first_reg_lo, first_reg_hi); |
| 3954 | __ movl(first_reg_hi, temp_reg); |
| 3955 | } |
| 3956 | } |
| 3957 | } |
| 3958 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3959 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 3960 | HandleShift(shl); |
| 3961 | } |
| 3962 | |
| 3963 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 3964 | HandleShift(shl); |
| 3965 | } |
| 3966 | |
| 3967 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 3968 | HandleShift(shr); |
| 3969 | } |
| 3970 | |
| 3971 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 3972 | HandleShift(shr); |
| 3973 | } |
| 3974 | |
| 3975 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 3976 | HandleShift(ushr); |
| 3977 | } |
| 3978 | |
| 3979 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 3980 | HandleShift(ushr); |
| 3981 | } |
| 3982 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3983 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3984 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3985 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3986 | locations->SetOut(Location::RegisterLocation(EAX)); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3987 | if (instruction->IsStringAlloc()) { |
| 3988 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3989 | } else { |
| 3990 | InvokeRuntimeCallingConvention calling_convention; |
| 3991 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3992 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3993 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3994 | } |
| 3995 | |
| 3996 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3997 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3998 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3999 | if (instruction->IsStringAlloc()) { |
| 4000 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4001 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4002 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4003 | __ fs()->movl(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString))); |
| 4004 | __ call(Address(temp, code_offset.Int32Value())); |
| 4005 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4006 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 4007 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4008 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 4009 | DCHECK(!codegen_->IsLeafMethod()); |
| 4010 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4011 | } |
| 4012 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4013 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| 4014 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4015 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4016 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 4017 | InvokeRuntimeCallingConvention calling_convention; |
| 4018 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 4019 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4020 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4021 | } |
| 4022 | |
| 4023 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
| 4024 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4025 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4026 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4027 | // of poisoning the reference. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 4028 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4029 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4030 | DCHECK(!codegen_->IsLeafMethod()); |
| 4031 | } |
| 4032 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4033 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4034 | LocationSummary* locations = |
| 4035 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4036 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4037 | if (location.IsStackSlot()) { |
| 4038 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4039 | } else if (location.IsDoubleStackSlot()) { |
| 4040 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4041 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4042 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4043 | } |
| 4044 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4045 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 4046 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 4047 | } |
| 4048 | |
| 4049 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4050 | LocationSummary* locations = |
| 4051 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4052 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4053 | } |
| 4054 | |
| 4055 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4056 | } |
| 4057 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4058 | void LocationsBuilderX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4059 | LocationSummary* locations = |
| 4060 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4061 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4062 | locations->SetOut(Location::RequiresRegister()); |
| 4063 | } |
| 4064 | |
| 4065 | void InstructionCodeGeneratorX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4066 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4067 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4068 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4069 | instruction->GetIndex(), kX86PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4070 | __ movl(locations->Out().AsRegister<Register>(), |
| 4071 | Address(locations->InAt(0).AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4072 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4073 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4074 | instruction->GetIndex(), kX86PointerSize)); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4075 | __ movl(locations->Out().AsRegister<Register>(), |
| 4076 | Address(locations->InAt(0).AsRegister<Register>(), |
| 4077 | mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
| 4078 | // temp = temp->GetImtEntryAt(method_offset); |
| 4079 | __ movl(locations->Out().AsRegister<Register>(), |
| 4080 | Address(locations->Out().AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4081 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4082 | } |
| 4083 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4084 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4085 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4086 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4087 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4088 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4089 | } |
| 4090 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4091 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 4092 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4093 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4094 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4095 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4096 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4097 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4098 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4099 | break; |
| 4100 | |
| 4101 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4102 | __ notl(out.AsRegisterPairLow<Register>()); |
| 4103 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4104 | break; |
| 4105 | |
| 4106 | default: |
| 4107 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4108 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4109 | } |
| 4110 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4111 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4112 | LocationSummary* locations = |
| 4113 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4114 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4115 | locations->SetOut(Location::SameAsFirstInput()); |
| 4116 | } |
| 4117 | |
| 4118 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4119 | LocationSummary* locations = bool_not->GetLocations(); |
| 4120 | Location in = locations->InAt(0); |
| 4121 | Location out = locations->Out(); |
| 4122 | DCHECK(in.Equals(out)); |
| 4123 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 4124 | } |
| 4125 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4126 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4127 | LocationSummary* locations = |
| 4128 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4129 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4130 | case Primitive::kPrimBoolean: |
| 4131 | case Primitive::kPrimByte: |
| 4132 | case Primitive::kPrimShort: |
| 4133 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4134 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4135 | case Primitive::kPrimLong: { |
| 4136 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4137 | locations->SetInAt(1, Location::Any()); |
| 4138 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4139 | break; |
| 4140 | } |
| 4141 | case Primitive::kPrimFloat: |
| 4142 | case Primitive::kPrimDouble: { |
| 4143 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4144 | if (compare->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4145 | DCHECK(compare->InputAt(1)->IsEmittedAtUseSite()); |
| 4146 | } else if (compare->InputAt(1)->IsConstant()) { |
| 4147 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4148 | } else { |
| 4149 | locations->SetInAt(1, Location::Any()); |
| 4150 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4151 | locations->SetOut(Location::RequiresRegister()); |
| 4152 | break; |
| 4153 | } |
| 4154 | default: |
| 4155 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4156 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4157 | } |
| 4158 | |
| 4159 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4160 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4161 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4162 | Location left = locations->InAt(0); |
| 4163 | Location right = locations->InAt(1); |
| 4164 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4165 | NearLabel less, greater, done; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4166 | Condition less_cond = kLess; |
| 4167 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4168 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4169 | case Primitive::kPrimBoolean: |
| 4170 | case Primitive::kPrimByte: |
| 4171 | case Primitive::kPrimShort: |
| 4172 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4173 | case Primitive::kPrimInt: { |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 4174 | codegen_->GenerateIntCompare(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4175 | break; |
| 4176 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4177 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4178 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 4179 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 4180 | int32_t val_low = 0; |
| 4181 | int32_t val_high = 0; |
| 4182 | bool right_is_const = false; |
| 4183 | |
| 4184 | if (right.IsConstant()) { |
| 4185 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 4186 | right_is_const = true; |
| 4187 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 4188 | val_low = Low32Bits(val); |
| 4189 | val_high = High32Bits(val); |
| 4190 | } |
| 4191 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4192 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4193 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4194 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4195 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4196 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4197 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4198 | codegen_->Compare32BitValue(left_high, val_high); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4199 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4200 | __ j(kLess, &less); // Signed compare. |
| 4201 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4202 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4203 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4204 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4205 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4206 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4207 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4208 | codegen_->Compare32BitValue(left_low, val_low); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4209 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4210 | less_cond = kBelow; // for CF (unsigned). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4211 | break; |
| 4212 | } |
| 4213 | case Primitive::kPrimFloat: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4214 | GenerateFPCompare(left, right, compare, false); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4215 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4216 | less_cond = kBelow; // for CF (floats). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4217 | break; |
| 4218 | } |
| 4219 | case Primitive::kPrimDouble: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4220 | GenerateFPCompare(left, right, compare, true); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4221 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4222 | less_cond = kBelow; // for CF (floats). |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4223 | break; |
| 4224 | } |
| 4225 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4226 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4227 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4228 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4229 | __ movl(out, Immediate(0)); |
| 4230 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4231 | __ j(less_cond, &less); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4232 | |
| 4233 | __ Bind(&greater); |
| 4234 | __ movl(out, Immediate(1)); |
| 4235 | __ jmp(&done); |
| 4236 | |
| 4237 | __ Bind(&less); |
| 4238 | __ movl(out, Immediate(-1)); |
| 4239 | |
| 4240 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4241 | } |
| 4242 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4243 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4244 | LocationSummary* locations = |
| 4245 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4246 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4247 | locations->SetInAt(i, Location::Any()); |
| 4248 | } |
| 4249 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4250 | } |
| 4251 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4252 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4253 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4254 | } |
| 4255 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4256 | void CodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4257 | /* |
| 4258 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 4259 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 4260 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4261 | */ |
| 4262 | switch (kind) { |
| 4263 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4264 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4265 | break; |
| 4266 | } |
| 4267 | case MemBarrierKind::kAnyStore: |
| 4268 | case MemBarrierKind::kLoadAny: |
| 4269 | case MemBarrierKind::kStoreStore: { |
| 4270 | // nop |
| 4271 | break; |
| 4272 | } |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4273 | case MemBarrierKind::kNTStoreStore: |
| 4274 | // Non-Temporal Store/Store needs an explicit fence. |
| 4275 | MemoryFence(/* non-temporal */ true); |
| 4276 | break; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4277 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4278 | } |
| 4279 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4280 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( |
| 4281 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| 4282 | MethodReference target_method ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4283 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info; |
| 4284 | |
| 4285 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 4286 | // is incompatible with it. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4287 | // TODO: Create as many X86ComputeBaseMethodAddress instructions |
| 4288 | // as needed for methods with irreducible loops. |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4289 | if (GetGraph()->HasIrreducibleLoops() && |
| 4290 | (dispatch_info.method_load_kind == |
| 4291 | HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative)) { |
| 4292 | dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod; |
| 4293 | } |
| 4294 | switch (dispatch_info.code_ptr_location) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4295 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4296 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 4297 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 4298 | // (Though the direct CALL ptr16:32 is available for consideration). |
| 4299 | return HInvokeStaticOrDirect::DispatchInfo { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4300 | dispatch_info.method_load_kind, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4301 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4302 | dispatch_info.method_load_data, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4303 | 0u |
| 4304 | }; |
| 4305 | default: |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4306 | return dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4307 | } |
| 4308 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4309 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4310 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 4311 | Register temp) { |
| 4312 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4313 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4314 | if (!invoke->GetLocations()->Intrinsified()) { |
| 4315 | return location.AsRegister<Register>(); |
| 4316 | } |
| 4317 | // For intrinsics we allow any location, so it may be on the stack. |
| 4318 | if (!location.IsRegister()) { |
| 4319 | __ movl(temp, Address(ESP, location.GetStackIndex())); |
| 4320 | return temp; |
| 4321 | } |
| 4322 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 4323 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 4324 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 4325 | // simple and more robust approach rather that trying to determine if that's the case. |
| 4326 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 4327 | if (slow_path != nullptr) { |
| 4328 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 4329 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 4330 | __ movl(temp, Address(ESP, stack_offset)); |
| 4331 | return temp; |
| 4332 | } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4333 | } |
| 4334 | return location.AsRegister<Register>(); |
| 4335 | } |
| 4336 | |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 4337 | Location CodeGeneratorX86::GenerateCalleeMethodStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 4338 | Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4339 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4340 | switch (invoke->GetMethodLoadKind()) { |
| 4341 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 4342 | // temp = thread->string_init_entrypoint |
| 4343 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(invoke->GetStringInitOffset())); |
| 4344 | break; |
| 4345 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4346 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4347 | break; |
| 4348 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4349 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 4350 | break; |
| 4351 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4352 | __ movl(temp.AsRegister<Register>(), Immediate(/* placeholder */ 0)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4353 | method_patches_.emplace_back(invoke->GetTargetMethod()); |
| 4354 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 4355 | break; |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4356 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 4357 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4358 | temp.AsRegister<Register>()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4359 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4360 | // Bind a new fixup label at the end of the "movl" insn. |
| 4361 | uint32_t offset = invoke->GetDexCacheArrayOffset(); |
| 4362 | __ Bind(NewPcRelativeDexCacheArrayPatch(*invoke->GetTargetMethod().dex_file, offset)); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4363 | break; |
| 4364 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4365 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4366 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4367 | Register method_reg; |
| 4368 | Register reg = temp.AsRegister<Register>(); |
| 4369 | if (current_method.IsRegister()) { |
| 4370 | method_reg = current_method.AsRegister<Register>(); |
| 4371 | } else { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4372 | DCHECK(invoke->GetLocations()->Intrinsified()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4373 | DCHECK(!current_method.IsValid()); |
| 4374 | method_reg = reg; |
| 4375 | __ movl(reg, Address(ESP, kCurrentMethodStackOffset)); |
| 4376 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4377 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4378 | __ movl(reg, Address(method_reg, |
| 4379 | ArtMethod::DexCacheResolvedMethodsOffset(kX86PointerSize).Int32Value())); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 4380 | // temp = temp[index_in_cache]; |
| 4381 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 4382 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4383 | __ movl(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 4384 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4385 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4386 | } |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 4387 | return callee_method; |
| 4388 | } |
| 4389 | |
| 4390 | void CodeGeneratorX86::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 4391 | Location callee_method = GenerateCalleeMethodStaticOrDirectCall(invoke, temp); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4392 | |
| 4393 | switch (invoke->GetCodePtrLocation()) { |
| 4394 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 4395 | __ call(GetFrameEntryLabel()); |
| 4396 | break; |
| 4397 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 4398 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 4399 | Label* label = &relative_call_patches_.back().label; |
| 4400 | __ call(label); // Bind to the patch label, override at link time. |
| 4401 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 4402 | break; |
| 4403 | } |
| 4404 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4405 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4406 | // Filtered out by GetSupportedInvokeStaticOrDirectDispatch(). |
| 4407 | LOG(FATAL) << "Unsupported"; |
| 4408 | UNREACHABLE(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4409 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4410 | // (callee_method + offset_of_quick_compiled_code)() |
| 4411 | __ call(Address(callee_method.AsRegister<Register>(), |
| 4412 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4413 | kX86PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4414 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4415 | } |
| 4416 | |
| 4417 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4418 | } |
| 4419 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4420 | void CodeGeneratorX86::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 4421 | Register temp = temp_in.AsRegister<Register>(); |
| 4422 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4423 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4424 | |
| 4425 | // Use the calling convention instead of the location of the receiver, as |
| 4426 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4427 | // slow path, the arguments have been moved to the right place, so here we are |
| 4428 | // guaranteed that the receiver is the first register of the calling convention. |
| 4429 | InvokeDexCallingConvention calling_convention; |
| 4430 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4431 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4432 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4433 | __ movl(temp, Address(receiver, class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4434 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4435 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4436 | // emit a read barrier for the previous class reference load. |
| 4437 | // However this is not required in practice, as this is an |
| 4438 | // intermediate/temporary reference and because the current |
| 4439 | // concurrent copying collector keeps the from-space memory |
| 4440 | // intact/accessible until the end of the marking phase (the |
| 4441 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4442 | __ MaybeUnpoisonHeapReference(temp); |
| 4443 | // temp = temp->GetMethodAt(method_offset); |
| 4444 | __ movl(temp, Address(temp, method_offset)); |
| 4445 | // call temp->GetEntryPoint(); |
| 4446 | __ call(Address( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4447 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4448 | } |
| 4449 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4450 | void CodeGeneratorX86::RecordSimplePatch() { |
| 4451 | if (GetCompilerOptions().GetIncludePatchInformation()) { |
| 4452 | simple_patches_.emplace_back(); |
| 4453 | __ Bind(&simple_patches_.back()); |
| 4454 | } |
| 4455 | } |
| 4456 | |
| 4457 | void CodeGeneratorX86::RecordStringPatch(HLoadString* load_string) { |
| 4458 | string_patches_.emplace_back(load_string->GetDexFile(), load_string->GetStringIndex()); |
| 4459 | __ Bind(&string_patches_.back().label); |
| 4460 | } |
| 4461 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4462 | void CodeGeneratorX86::RecordTypePatch(HLoadClass* load_class) { |
| 4463 | type_patches_.emplace_back(load_class->GetDexFile(), load_class->GetTypeIndex()); |
| 4464 | __ Bind(&type_patches_.back().label); |
| 4465 | } |
| 4466 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4467 | Label* CodeGeneratorX86::NewPcRelativeDexCacheArrayPatch(const DexFile& dex_file, |
| 4468 | uint32_t element_offset) { |
| 4469 | // Add the patch entry and bind its label at the end of the instruction. |
| 4470 | pc_relative_dex_cache_patches_.emplace_back(dex_file, element_offset); |
| 4471 | return &pc_relative_dex_cache_patches_.back().label; |
| 4472 | } |
| 4473 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4474 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 4475 | DCHECK(linker_patches->empty()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4476 | size_t size = |
| 4477 | method_patches_.size() + |
| 4478 | relative_call_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4479 | pc_relative_dex_cache_patches_.size() + |
| 4480 | simple_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4481 | string_patches_.size() + |
| 4482 | type_patches_.size(); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4483 | linker_patches->reserve(size); |
| 4484 | // The label points to the end of the "movl" insn but the literal offset for method |
| 4485 | // patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 4486 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4487 | for (const MethodPatchInfo<Label>& info : method_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4488 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4489 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 4490 | info.target_method.dex_file, |
| 4491 | info.target_method.dex_method_index)); |
| 4492 | } |
| 4493 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4494 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4495 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 4496 | info.target_method.dex_file, |
| 4497 | info.target_method.dex_method_index)); |
| 4498 | } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4499 | for (const PcRelativeDexCacheAccessInfo& info : pc_relative_dex_cache_patches_) { |
| 4500 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4501 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(literal_offset, |
| 4502 | &info.target_dex_file, |
| 4503 | GetMethodAddressOffset(), |
| 4504 | info.element_offset)); |
| 4505 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4506 | for (const Label& label : simple_patches_) { |
| 4507 | uint32_t literal_offset = label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4508 | linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset)); |
| 4509 | } |
| 4510 | if (GetCompilerOptions().GetCompilePic()) { |
| 4511 | for (const StringPatchInfo<Label>& info : string_patches_) { |
| 4512 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4513 | linker_patches->push_back(LinkerPatch::RelativeStringPatch(literal_offset, |
| 4514 | &info.dex_file, |
| 4515 | GetMethodAddressOffset(), |
| 4516 | info.string_index)); |
| 4517 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4518 | for (const TypePatchInfo<Label>& info : type_patches_) { |
| 4519 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4520 | linker_patches->push_back(LinkerPatch::RelativeTypePatch(literal_offset, |
| 4521 | &info.dex_file, |
| 4522 | GetMethodAddressOffset(), |
| 4523 | info.type_index)); |
| 4524 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4525 | } else { |
| 4526 | for (const StringPatchInfo<Label>& info : string_patches_) { |
| 4527 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4528 | linker_patches->push_back(LinkerPatch::StringPatch(literal_offset, |
| 4529 | &info.dex_file, |
| 4530 | info.string_index)); |
| 4531 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4532 | for (const TypePatchInfo<Label>& info : type_patches_) { |
| 4533 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4534 | linker_patches->push_back(LinkerPatch::TypePatch(literal_offset, |
| 4535 | &info.dex_file, |
| 4536 | info.type_index)); |
| 4537 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4538 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4539 | } |
| 4540 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4541 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 4542 | Register card, |
| 4543 | Register object, |
| 4544 | Register value, |
| 4545 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4546 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4547 | if (value_can_be_null) { |
| 4548 | __ testl(value, value); |
| 4549 | __ j(kEqual, &is_null); |
| 4550 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4551 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86PointerSize>().Int32Value())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4552 | __ movl(temp, object); |
| 4553 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4554 | __ movb(Address(temp, card, TIMES_1, 0), |
| 4555 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4556 | if (value_can_be_null) { |
| 4557 | __ Bind(&is_null); |
| 4558 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4559 | } |
| 4560 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4561 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4562 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4563 | |
| 4564 | bool object_field_get_with_read_barrier = |
| 4565 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4566 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4567 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4568 | kEmitCompilerReadBarrier ? |
| 4569 | LocationSummary::kCallOnSlowPath : |
| 4570 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4571 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4572 | locations->SetCustomSlowPathCallerSaves(RegisterSet()); // No caller-save registers. |
| 4573 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4574 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4575 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4576 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4577 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4578 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4579 | // The output overlaps in case of long: we don't want the low move |
| 4580 | // to overwrite the object's location. Likewise, in the case of |
| 4581 | // an object field get with read barriers enabled, we do not want |
| 4582 | // the move to overwrite the object's location, as we need it to emit |
| 4583 | // the read barrier. |
| 4584 | locations->SetOut( |
| 4585 | Location::RequiresRegister(), |
| 4586 | (object_field_get_with_read_barrier || instruction->GetType() == Primitive::kPrimLong) ? |
| 4587 | Location::kOutputOverlap : |
| 4588 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4589 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4590 | |
| 4591 | if (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) { |
| 4592 | // Long values can be loaded atomically into an XMM using movsd. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4593 | // So we use an XMM register as a temp to achieve atomicity (first |
| 4594 | // load the temp into the XMM and then copy the XMM into the |
| 4595 | // output, 32 bits at a time). |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4596 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4597 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4598 | } |
| 4599 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4600 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 4601 | const FieldInfo& field_info) { |
| 4602 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4603 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4604 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4605 | Location base_loc = locations->InAt(0); |
| 4606 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4607 | Location out = locations->Out(); |
| 4608 | bool is_volatile = field_info.IsVolatile(); |
| 4609 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4610 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4611 | |
| 4612 | switch (field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4613 | case Primitive::kPrimBoolean: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4614 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4615 | break; |
| 4616 | } |
| 4617 | |
| 4618 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4619 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4620 | break; |
| 4621 | } |
| 4622 | |
| 4623 | case Primitive::kPrimShort: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4624 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4625 | break; |
| 4626 | } |
| 4627 | |
| 4628 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4629 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4630 | break; |
| 4631 | } |
| 4632 | |
| 4633 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4634 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4635 | break; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4636 | |
| 4637 | case Primitive::kPrimNot: { |
| 4638 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4639 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4640 | // Note that a potential implicit null check is handled in this |
| 4641 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 4642 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 4643 | instruction, out, base, offset, /* needs_null_check */ true); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4644 | if (is_volatile) { |
| 4645 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4646 | } |
| 4647 | } else { |
| 4648 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| 4649 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4650 | if (is_volatile) { |
| 4651 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4652 | } |
| 4653 | // If read barriers are enabled, emit read barriers other than |
| 4654 | // Baker's using a slow path (and also unpoison the loaded |
| 4655 | // reference, if heap poisoning is enabled). |
| 4656 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4657 | } |
| 4658 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4659 | } |
| 4660 | |
| 4661 | case Primitive::kPrimLong: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4662 | if (is_volatile) { |
| 4663 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4664 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4665 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4666 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 4667 | __ psrlq(temp, Immediate(32)); |
| 4668 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 4669 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4670 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4671 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4672 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4673 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 4674 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4675 | break; |
| 4676 | } |
| 4677 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4678 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4679 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4680 | break; |
| 4681 | } |
| 4682 | |
| 4683 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4684 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4685 | break; |
| 4686 | } |
| 4687 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4688 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4689 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4690 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4691 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4692 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4693 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimLong) { |
| 4694 | // Potential implicit null checks, in the case of reference or |
| 4695 | // long fields, are handled in the previous switch statement. |
| 4696 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4697 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4698 | } |
| 4699 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4700 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4701 | if (field_type == Primitive::kPrimNot) { |
| 4702 | // Memory barriers, in the case of references, are also handled |
| 4703 | // in the previous switch statement. |
| 4704 | } else { |
| 4705 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4706 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4707 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4708 | } |
| 4709 | |
| 4710 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4711 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4712 | |
| 4713 | LocationSummary* locations = |
| 4714 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4715 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4716 | bool is_volatile = field_info.IsVolatile(); |
| 4717 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4718 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 4719 | || (field_type == Primitive::kPrimByte); |
| 4720 | |
| 4721 | // The register allocator does not support multiple |
| 4722 | // inputs that die at entry with one in a specific register. |
| 4723 | if (is_byte_type) { |
| 4724 | // Ensure the value is in a byte register. |
| 4725 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4726 | } else if (Primitive::IsFloatingPointType(field_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4727 | if (is_volatile && field_type == Primitive::kPrimDouble) { |
| 4728 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4729 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4730 | } else { |
| 4731 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4732 | } |
| 4733 | } else if (is_volatile && field_type == Primitive::kPrimLong) { |
| 4734 | // 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] | 4735 | locations->SetInAt(1, Location::RequiresRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4736 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4737 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 4738 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 4739 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 4740 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 4741 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 4742 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4743 | locations->AddTemp(Location::RequiresFpuRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4744 | } else { |
| 4745 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4746 | |
| 4747 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4748 | // Temporary registers for the write barrier. |
| 4749 | locations->AddTemp(Location::RequiresRegister()); // May be used for reference poisoning too. |
| 4750 | // Ensure the card is in a byte register. |
| 4751 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 4752 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4753 | } |
| 4754 | } |
| 4755 | |
| 4756 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4757 | const FieldInfo& field_info, |
| 4758 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4759 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4760 | |
| 4761 | LocationSummary* locations = instruction->GetLocations(); |
| 4762 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 4763 | Location value = locations->InAt(1); |
| 4764 | bool is_volatile = field_info.IsVolatile(); |
| 4765 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4766 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4767 | bool needs_write_barrier = |
| 4768 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4769 | |
| 4770 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4771 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4772 | } |
| 4773 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4774 | bool maybe_record_implicit_null_check_done = false; |
| 4775 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4776 | switch (field_type) { |
| 4777 | case Primitive::kPrimBoolean: |
| 4778 | case Primitive::kPrimByte: { |
| 4779 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 4780 | break; |
| 4781 | } |
| 4782 | |
| 4783 | case Primitive::kPrimShort: |
| 4784 | case Primitive::kPrimChar: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4785 | if (value.IsConstant()) { |
| 4786 | int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4787 | __ movw(Address(base, offset), Immediate(v)); |
| 4788 | } else { |
| 4789 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 4790 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4791 | break; |
| 4792 | } |
| 4793 | |
| 4794 | case Primitive::kPrimInt: |
| 4795 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4796 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4797 | // Note that in the case where `value` is a null reference, |
| 4798 | // we do not enter this block, as the reference does not |
| 4799 | // need poisoning. |
| 4800 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 4801 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4802 | __ movl(temp, value.AsRegister<Register>()); |
| 4803 | __ PoisonHeapReference(temp); |
| 4804 | __ movl(Address(base, offset), temp); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4805 | } else if (value.IsConstant()) { |
| 4806 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4807 | __ movl(Address(base, offset), Immediate(v)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4808 | } else { |
Nicolas Geoffray | 0397163 | 2016-03-17 10:44:24 +0000 | [diff] [blame] | 4809 | DCHECK(value.IsRegister()) << value; |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4810 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 4811 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4812 | break; |
| 4813 | } |
| 4814 | |
| 4815 | case Primitive::kPrimLong: { |
| 4816 | if (is_volatile) { |
| 4817 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4818 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 4819 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 4820 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 4821 | __ punpckldq(temp1, temp2); |
| 4822 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4823 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4824 | } else if (value.IsConstant()) { |
| 4825 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4826 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4827 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4828 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4829 | } else { |
| 4830 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4831 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4832 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 4833 | } |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4834 | maybe_record_implicit_null_check_done = true; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4835 | break; |
| 4836 | } |
| 4837 | |
| 4838 | case Primitive::kPrimFloat: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4839 | if (value.IsConstant()) { |
| 4840 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4841 | __ movl(Address(base, offset), Immediate(v)); |
| 4842 | } else { |
| 4843 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4844 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4845 | break; |
| 4846 | } |
| 4847 | |
| 4848 | case Primitive::kPrimDouble: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4849 | if (value.IsConstant()) { |
| 4850 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4851 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4852 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4853 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
| 4854 | maybe_record_implicit_null_check_done = true; |
| 4855 | } else { |
| 4856 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4857 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4858 | break; |
| 4859 | } |
| 4860 | |
| 4861 | case Primitive::kPrimVoid: |
| 4862 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4863 | UNREACHABLE(); |
| 4864 | } |
| 4865 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4866 | if (!maybe_record_implicit_null_check_done) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4867 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4868 | } |
| 4869 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4870 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4871 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4872 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4873 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4874 | } |
| 4875 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4876 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4877 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4878 | } |
| 4879 | } |
| 4880 | |
| 4881 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4882 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4883 | } |
| 4884 | |
| 4885 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4886 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4887 | } |
| 4888 | |
| 4889 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4890 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4891 | } |
| 4892 | |
| 4893 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4894 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4895 | } |
| 4896 | |
| 4897 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4898 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4899 | } |
| 4900 | |
| 4901 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4902 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4903 | } |
| 4904 | |
| 4905 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4906 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4907 | } |
| 4908 | |
| 4909 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4910 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4911 | } |
| 4912 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4913 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 4914 | HUnresolvedInstanceFieldGet* instruction) { |
| 4915 | FieldAccessCallingConventionX86 calling_convention; |
| 4916 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4917 | instruction, instruction->GetFieldType(), calling_convention); |
| 4918 | } |
| 4919 | |
| 4920 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 4921 | HUnresolvedInstanceFieldGet* instruction) { |
| 4922 | FieldAccessCallingConventionX86 calling_convention; |
| 4923 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4924 | instruction->GetFieldType(), |
| 4925 | instruction->GetFieldIndex(), |
| 4926 | instruction->GetDexPc(), |
| 4927 | calling_convention); |
| 4928 | } |
| 4929 | |
| 4930 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 4931 | HUnresolvedInstanceFieldSet* instruction) { |
| 4932 | FieldAccessCallingConventionX86 calling_convention; |
| 4933 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4934 | instruction, instruction->GetFieldType(), calling_convention); |
| 4935 | } |
| 4936 | |
| 4937 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 4938 | HUnresolvedInstanceFieldSet* instruction) { |
| 4939 | FieldAccessCallingConventionX86 calling_convention; |
| 4940 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4941 | instruction->GetFieldType(), |
| 4942 | instruction->GetFieldIndex(), |
| 4943 | instruction->GetDexPc(), |
| 4944 | calling_convention); |
| 4945 | } |
| 4946 | |
| 4947 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 4948 | HUnresolvedStaticFieldGet* instruction) { |
| 4949 | FieldAccessCallingConventionX86 calling_convention; |
| 4950 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4951 | instruction, instruction->GetFieldType(), calling_convention); |
| 4952 | } |
| 4953 | |
| 4954 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 4955 | HUnresolvedStaticFieldGet* instruction) { |
| 4956 | FieldAccessCallingConventionX86 calling_convention; |
| 4957 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4958 | instruction->GetFieldType(), |
| 4959 | instruction->GetFieldIndex(), |
| 4960 | instruction->GetDexPc(), |
| 4961 | calling_convention); |
| 4962 | } |
| 4963 | |
| 4964 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 4965 | HUnresolvedStaticFieldSet* instruction) { |
| 4966 | FieldAccessCallingConventionX86 calling_convention; |
| 4967 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4968 | instruction, instruction->GetFieldType(), calling_convention); |
| 4969 | } |
| 4970 | |
| 4971 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 4972 | HUnresolvedStaticFieldSet* instruction) { |
| 4973 | FieldAccessCallingConventionX86 calling_convention; |
| 4974 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4975 | instruction->GetFieldType(), |
| 4976 | instruction->GetFieldIndex(), |
| 4977 | instruction->GetDexPc(), |
| 4978 | calling_convention); |
| 4979 | } |
| 4980 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4981 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4982 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4983 | ? LocationSummary::kCallOnSlowPath |
| 4984 | : LocationSummary::kNoCall; |
| 4985 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4986 | Location loc = codegen_->IsImplicitNullCheckAllowed(instruction) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4987 | ? Location::RequiresRegister() |
| 4988 | : Location::Any(); |
| 4989 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4990 | if (instruction->HasUses()) { |
| 4991 | locations->SetOut(Location::SameAsFirstInput()); |
| 4992 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4993 | } |
| 4994 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4995 | void CodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4996 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4997 | return; |
| 4998 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4999 | LocationSummary* locations = instruction->GetLocations(); |
| 5000 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5001 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5002 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5003 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5004 | } |
| 5005 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5006 | void CodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5007 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5008 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5009 | |
| 5010 | LocationSummary* locations = instruction->GetLocations(); |
| 5011 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5012 | |
| 5013 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 5014 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5015 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5016 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5017 | } else { |
| 5018 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5019 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5020 | __ jmp(slow_path->GetEntryLabel()); |
| 5021 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5022 | } |
| 5023 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5024 | } |
| 5025 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5026 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5027 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5028 | } |
| 5029 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5030 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5031 | bool object_array_get_with_read_barrier = |
| 5032 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5033 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5034 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 5035 | object_array_get_with_read_barrier ? |
| 5036 | LocationSummary::kCallOnSlowPath : |
| 5037 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5038 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 5039 | locations->SetCustomSlowPathCallerSaves(RegisterSet()); // No caller-save registers. |
| 5040 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5041 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5042 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5043 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 5044 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5045 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5046 | // The output overlaps in case of long: we don't want the low move |
| 5047 | // to overwrite the array's location. Likewise, in the case of an |
| 5048 | // object array get with read barriers enabled, we do not want the |
| 5049 | // move to overwrite the array's location, as we need it to emit |
| 5050 | // the read barrier. |
| 5051 | locations->SetOut( |
| 5052 | Location::RequiresRegister(), |
| 5053 | (instruction->GetType() == Primitive::kPrimLong || object_array_get_with_read_barrier) ? |
| 5054 | Location::kOutputOverlap : |
| 5055 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5056 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5057 | } |
| 5058 | |
| 5059 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 5060 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5061 | Location obj_loc = locations->InAt(0); |
| 5062 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5063 | Location index = locations->InAt(1); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5064 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5065 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5066 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5067 | Primitive::Type type = instruction->GetType(); |
| 5068 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5069 | case Primitive::kPrimBoolean: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5070 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5071 | if (index.IsConstant()) { |
| 5072 | __ movzxb(out, Address(obj, |
| 5073 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 5074 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5075 | __ movzxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5076 | } |
| 5077 | break; |
| 5078 | } |
| 5079 | |
| 5080 | case Primitive::kPrimByte: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5081 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5082 | if (index.IsConstant()) { |
| 5083 | __ movsxb(out, Address(obj, |
| 5084 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 5085 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5086 | __ movsxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5087 | } |
| 5088 | break; |
| 5089 | } |
| 5090 | |
| 5091 | case Primitive::kPrimShort: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5092 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5093 | if (index.IsConstant()) { |
| 5094 | __ movsxw(out, Address(obj, |
| 5095 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 5096 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5097 | __ movsxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5098 | } |
| 5099 | break; |
| 5100 | } |
| 5101 | |
| 5102 | case Primitive::kPrimChar: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5103 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5104 | if (index.IsConstant()) { |
| 5105 | __ movzxw(out, Address(obj, |
| 5106 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 5107 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5108 | __ movzxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5109 | } |
| 5110 | break; |
| 5111 | } |
| 5112 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5113 | case Primitive::kPrimInt: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5114 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5115 | if (index.IsConstant()) { |
| 5116 | __ movl(out, Address(obj, |
| 5117 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 5118 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5119 | __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5120 | } |
| 5121 | break; |
| 5122 | } |
| 5123 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5124 | case Primitive::kPrimNot: { |
| 5125 | static_assert( |
| 5126 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5127 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5128 | // /* HeapReference<Object> */ out = |
| 5129 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5130 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5131 | // Note that a potential implicit null check is handled in this |
| 5132 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 5133 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5134 | instruction, out_loc, obj, data_offset, index, /* needs_null_check */ true); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5135 | } else { |
| 5136 | Register out = out_loc.AsRegister<Register>(); |
| 5137 | if (index.IsConstant()) { |
| 5138 | uint32_t offset = |
| 5139 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5140 | __ movl(out, Address(obj, offset)); |
| 5141 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5142 | // If read barriers are enabled, emit read barriers other than |
| 5143 | // Baker's using a slow path (and also unpoison the loaded |
| 5144 | // reference, if heap poisoning is enabled). |
| 5145 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5146 | } else { |
| 5147 | __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
| 5148 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5149 | // If read barriers are enabled, emit read barriers other than |
| 5150 | // Baker's using a slow path (and also unpoison the loaded |
| 5151 | // reference, if heap poisoning is enabled). |
| 5152 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5153 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5154 | } |
| 5155 | } |
| 5156 | break; |
| 5157 | } |
| 5158 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5159 | case Primitive::kPrimLong: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5160 | DCHECK_NE(obj, out_loc.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5161 | if (index.IsConstant()) { |
| 5162 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5163 | __ movl(out_loc.AsRegisterPairLow<Register>(), Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5164 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5165 | __ movl(out_loc.AsRegisterPairHigh<Register>(), Address(obj, offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5166 | } else { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5167 | __ movl(out_loc.AsRegisterPairLow<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5168 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5169 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5170 | __ movl(out_loc.AsRegisterPairHigh<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5171 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5172 | } |
| 5173 | break; |
| 5174 | } |
| 5175 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5176 | case Primitive::kPrimFloat: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5177 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5178 | if (index.IsConstant()) { |
| 5179 | __ movss(out, Address(obj, |
| 5180 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 5181 | } else { |
| 5182 | __ movss(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
| 5183 | } |
| 5184 | break; |
| 5185 | } |
| 5186 | |
| 5187 | case Primitive::kPrimDouble: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5188 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5189 | if (index.IsConstant()) { |
| 5190 | __ movsd(out, Address(obj, |
| 5191 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 5192 | } else { |
| 5193 | __ movsd(out, Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
| 5194 | } |
| 5195 | break; |
| 5196 | } |
| 5197 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5198 | case Primitive::kPrimVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5199 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5200 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5201 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5202 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5203 | if (type == Primitive::kPrimNot || type == Primitive::kPrimLong) { |
| 5204 | // Potential implicit null checks, in the case of reference or |
| 5205 | // long arrays, are handled in the previous switch statement. |
| 5206 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5207 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5208 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5209 | } |
| 5210 | |
| 5211 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5212 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5213 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5214 | bool needs_write_barrier = |
| 5215 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5216 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5217 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5218 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 5219 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 5220 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5221 | LocationSummary::kCallOnSlowPath : |
| 5222 | LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5223 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5224 | bool is_byte_type = (value_type == Primitive::kPrimBoolean) |
| 5225 | || (value_type == Primitive::kPrimByte); |
| 5226 | // We need the inputs to be different than the output in case of long operation. |
| 5227 | // In case of a byte operation, the register allocator does not support multiple |
| 5228 | // inputs that die at entry with one in a specific register. |
| 5229 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5230 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5231 | if (is_byte_type) { |
| 5232 | // Ensure the value is in a byte register. |
| 5233 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
| 5234 | } else if (Primitive::IsFloatingPointType(value_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5235 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5236 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5237 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 5238 | } |
| 5239 | if (needs_write_barrier) { |
| 5240 | // Temporary registers for the write barrier. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5241 | // These registers may be used for Baker read barriers too. |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5242 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 5243 | // Ensure the card is in a byte register. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5244 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5245 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5246 | } |
| 5247 | |
| 5248 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 5249 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5250 | Location array_loc = locations->InAt(0); |
| 5251 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5252 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5253 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5254 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5255 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5256 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5257 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5258 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5259 | bool needs_write_barrier = |
| 5260 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5261 | |
| 5262 | switch (value_type) { |
| 5263 | case Primitive::kPrimBoolean: |
| 5264 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5265 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| 5266 | Address address = index.IsConstant() |
| 5267 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + offset) |
| 5268 | : Address(array, index.AsRegister<Register>(), TIMES_1, offset); |
| 5269 | if (value.IsRegister()) { |
| 5270 | __ movb(address, value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5271 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5272 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5273 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5274 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5275 | break; |
| 5276 | } |
| 5277 | |
| 5278 | case Primitive::kPrimShort: |
| 5279 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5280 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| 5281 | Address address = index.IsConstant() |
| 5282 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + offset) |
| 5283 | : Address(array, index.AsRegister<Register>(), TIMES_2, offset); |
| 5284 | if (value.IsRegister()) { |
| 5285 | __ movw(address, value.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5286 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5287 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5288 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5289 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5290 | break; |
| 5291 | } |
| 5292 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5293 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5294 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 5295 | Address address = index.IsConstant() |
| 5296 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5297 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5298 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5299 | if (!value.IsRegister()) { |
| 5300 | // Just setting null. |
| 5301 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5302 | DCHECK(value.IsConstant()) << value; |
| 5303 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5304 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5305 | DCHECK(!needs_write_barrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5306 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5307 | break; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5308 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5309 | |
| 5310 | DCHECK(needs_write_barrier); |
| 5311 | Register register_value = value.AsRegister<Register>(); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5312 | // We cannot use a NearLabel for `done`, as its range may be too |
| 5313 | // short when Baker read barriers are enabled. |
| 5314 | Label done; |
| 5315 | NearLabel not_null, do_put; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5316 | SlowPathCode* slow_path = nullptr; |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5317 | Location temp_loc = locations->GetTemp(0); |
| 5318 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5319 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5320 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86(instruction); |
| 5321 | codegen_->AddSlowPath(slow_path); |
| 5322 | if (instruction->GetValueCanBeNull()) { |
| 5323 | __ testl(register_value, register_value); |
| 5324 | __ j(kNotEqual, ¬_null); |
| 5325 | __ movl(address, Immediate(0)); |
| 5326 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5327 | __ jmp(&done); |
| 5328 | __ Bind(¬_null); |
| 5329 | } |
| 5330 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5331 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5332 | if (!kUseBakerReadBarrier) { |
| 5333 | // When (non-Baker) read barriers are enabled, the type |
| 5334 | // checking instrumentation requires two read barriers |
| 5335 | // generated by CodeGeneratorX86::GenerateReadBarrierSlow: |
| 5336 | // |
| 5337 | // __ movl(temp2, temp); |
| 5338 | // // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5339 | // __ movl(temp, Address(temp, component_offset)); |
| 5340 | // codegen_->GenerateReadBarrierSlow( |
| 5341 | // instruction, temp_loc, temp_loc, temp2_loc, component_offset); |
| 5342 | // |
| 5343 | // // /* HeapReference<Class> */ temp2 = register_value->klass_ |
| 5344 | // __ movl(temp2, Address(register_value, class_offset)); |
| 5345 | // codegen_->GenerateReadBarrierSlow( |
| 5346 | // instruction, temp2_loc, temp2_loc, value, class_offset, temp_loc); |
| 5347 | // |
| 5348 | // __ cmpl(temp, temp2); |
| 5349 | // |
| 5350 | // However, the second read barrier may trash `temp`, as it |
| 5351 | // is a temporary register, and as such would not be saved |
| 5352 | // along with live registers before calling the runtime (nor |
| 5353 | // restored afterwards). So in this case, we bail out and |
| 5354 | // delegate the work to the array set slow path. |
| 5355 | // |
| 5356 | // TODO: Extend the register allocator to support a new |
| 5357 | // "(locally) live temp" location so as to avoid always |
| 5358 | // going into the slow path when read barriers are enabled? |
| 5359 | // |
| 5360 | // There is no such problem with Baker read barriers (see below). |
| 5361 | __ jmp(slow_path->GetEntryLabel()); |
| 5362 | } else { |
| 5363 | Location temp2_loc = locations->GetTemp(1); |
| 5364 | Register temp2 = temp2_loc.AsRegister<Register>(); |
| 5365 | // /* HeapReference<Class> */ temp = array->klass_ |
| 5366 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 5367 | instruction, temp_loc, array, class_offset, /* needs_null_check */ true); |
| 5368 | |
| 5369 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5370 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 5371 | instruction, temp_loc, temp, component_offset, /* needs_null_check */ false); |
| 5372 | // Register `temp` is not trashed by the read barrier |
| 5373 | // emitted by GenerateFieldLoadWithBakerReadBarrier below, |
| 5374 | // as that method produces a call to a ReadBarrierMarkRegX |
| 5375 | // entry point, which saves all potentially live registers, |
| 5376 | // including temporaries such a `temp`. |
| 5377 | // /* HeapReference<Class> */ temp2 = register_value->klass_ |
| 5378 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 5379 | instruction, temp2_loc, register_value, class_offset, /* needs_null_check */ false); |
| 5380 | // If heap poisoning is enabled, `temp` and `temp2` have |
| 5381 | // been unpoisoned by the the previous calls to |
| 5382 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier. |
| 5383 | __ cmpl(temp, temp2); |
| 5384 | |
| 5385 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5386 | __ j(kEqual, &do_put); |
| 5387 | // We do not need to emit a read barrier for the |
| 5388 | // following heap reference load, as `temp` is only used |
| 5389 | // in a comparison with null below, and this reference |
| 5390 | // is not kept afterwards. Also, if heap poisoning is |
| 5391 | // enabled, there is no need to unpoison that heap |
| 5392 | // reference for the same reason (comparison with null). |
| 5393 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 5394 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5395 | __ Bind(&do_put); |
| 5396 | } else { |
| 5397 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5398 | } |
| 5399 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5400 | } else { |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5401 | // Non read barrier code. |
| 5402 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5403 | // /* HeapReference<Class> */ temp = array->klass_ |
| 5404 | __ movl(temp, Address(array, class_offset)); |
| 5405 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5406 | __ MaybeUnpoisonHeapReference(temp); |
| 5407 | |
| 5408 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5409 | __ movl(temp, Address(temp, component_offset)); |
| 5410 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 5411 | // nor the object reference in `register_value->klass`, as |
| 5412 | // we are comparing two poisoned references. |
| 5413 | __ cmpl(temp, Address(register_value, class_offset)); |
| 5414 | |
| 5415 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5416 | __ j(kEqual, &do_put); |
| 5417 | // If heap poisoning is enabled, the `temp` reference has |
| 5418 | // not been unpoisoned yet; unpoison it now. |
| 5419 | __ MaybeUnpoisonHeapReference(temp); |
| 5420 | |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5421 | // If heap poisoning is enabled, no need to unpoison the |
| 5422 | // heap reference loaded below, as it is only used for a |
| 5423 | // comparison with null. |
| 5424 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5425 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5426 | __ Bind(&do_put); |
| 5427 | } else { |
| 5428 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5429 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5430 | } |
| 5431 | } |
| 5432 | |
| 5433 | if (kPoisonHeapReferences) { |
| 5434 | __ movl(temp, register_value); |
| 5435 | __ PoisonHeapReference(temp); |
| 5436 | __ movl(address, temp); |
| 5437 | } else { |
| 5438 | __ movl(address, register_value); |
| 5439 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5440 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5441 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5442 | } |
| 5443 | |
| 5444 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 5445 | codegen_->MarkGCCard( |
| 5446 | temp, card, array, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); |
| 5447 | __ Bind(&done); |
| 5448 | |
| 5449 | if (slow_path != nullptr) { |
| 5450 | __ Bind(slow_path->GetExitLabel()); |
| 5451 | } |
| 5452 | |
| 5453 | break; |
| 5454 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5455 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5456 | case Primitive::kPrimInt: { |
| 5457 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 5458 | Address address = index.IsConstant() |
| 5459 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5460 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
| 5461 | if (value.IsRegister()) { |
| 5462 | __ movl(address, value.AsRegister<Register>()); |
| 5463 | } else { |
| 5464 | DCHECK(value.IsConstant()) << value; |
| 5465 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5466 | __ movl(address, Immediate(v)); |
| 5467 | } |
| 5468 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5469 | break; |
| 5470 | } |
| 5471 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5472 | case Primitive::kPrimLong: { |
| 5473 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5474 | if (index.IsConstant()) { |
| 5475 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5476 | if (value.IsRegisterPair()) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5477 | __ movl(Address(array, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5478 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5479 | __ movl(Address(array, offset + kX86WordSize), value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5480 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5481 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5482 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5483 | __ movl(Address(array, offset), Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5484 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5485 | __ movl(Address(array, offset + kX86WordSize), Immediate(High32Bits(val))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5486 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5487 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5488 | if (value.IsRegisterPair()) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5489 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5490 | value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5491 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5492 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5493 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5494 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5495 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5496 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5497 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5498 | Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5499 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5500 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5501 | Immediate(High32Bits(val))); |
| 5502 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5503 | } |
| 5504 | break; |
| 5505 | } |
| 5506 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5507 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5508 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 5509 | Address address = index.IsConstant() |
| 5510 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5511 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5512 | if (value.IsFpuRegister()) { |
| 5513 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5514 | } else { |
| 5515 | DCHECK(value.IsConstant()); |
| 5516 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 5517 | __ movl(address, Immediate(v)); |
| 5518 | } |
| 5519 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5520 | break; |
| 5521 | } |
| 5522 | |
| 5523 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5524 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 5525 | Address address = index.IsConstant() |
| 5526 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 5527 | : Address(array, index.AsRegister<Register>(), TIMES_8, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5528 | if (value.IsFpuRegister()) { |
| 5529 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5530 | } else { |
| 5531 | DCHECK(value.IsConstant()); |
| 5532 | Address address_hi = index.IsConstant() ? |
| 5533 | Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + |
| 5534 | offset + kX86WordSize) : |
| 5535 | Address(array, index.AsRegister<Register>(), TIMES_8, offset + kX86WordSize); |
| 5536 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 5537 | __ movl(address, Immediate(Low32Bits(v))); |
| 5538 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5539 | __ movl(address_hi, Immediate(High32Bits(v))); |
| 5540 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5541 | break; |
| 5542 | } |
| 5543 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5544 | case Primitive::kPrimVoid: |
| 5545 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5546 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5547 | } |
| 5548 | } |
| 5549 | |
| 5550 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| 5551 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5552 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5553 | if (!instruction->IsEmittedAtUseSite()) { |
| 5554 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5555 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5556 | } |
| 5557 | |
| 5558 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5559 | if (instruction->IsEmittedAtUseSite()) { |
| 5560 | return; |
| 5561 | } |
| 5562 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5563 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5564 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5565 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5566 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5567 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5568 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5569 | } |
| 5570 | |
| 5571 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5572 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 5573 | ? LocationSummary::kCallOnSlowPath |
| 5574 | : LocationSummary::kNoCall; |
| 5575 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5576 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5577 | HInstruction* length = instruction->InputAt(1); |
| 5578 | if (!length->IsEmittedAtUseSite()) { |
| 5579 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5580 | } |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5581 | if (instruction->HasUses()) { |
| 5582 | locations->SetOut(Location::SameAsFirstInput()); |
| 5583 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5584 | } |
| 5585 | |
| 5586 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5587 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5588 | Location index_loc = locations->InAt(0); |
| 5589 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5590 | SlowPathCode* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5591 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5592 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5593 | if (length_loc.IsConstant()) { |
| 5594 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5595 | if (index_loc.IsConstant()) { |
| 5596 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5597 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5598 | if (index < 0 || index >= length) { |
| 5599 | codegen_->AddSlowPath(slow_path); |
| 5600 | __ jmp(slow_path->GetEntryLabel()); |
| 5601 | } else { |
| 5602 | // Some optimization after BCE may have generated this, and we should not |
| 5603 | // generate a bounds check if it is a valid range. |
| 5604 | } |
| 5605 | return; |
| 5606 | } |
| 5607 | |
| 5608 | // We have to reverse the jump condition because the length is the constant. |
| 5609 | Register index_reg = index_loc.AsRegister<Register>(); |
| 5610 | __ cmpl(index_reg, Immediate(length)); |
| 5611 | codegen_->AddSlowPath(slow_path); |
| 5612 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5613 | } else { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5614 | HInstruction* array_length = instruction->InputAt(1); |
| 5615 | if (array_length->IsEmittedAtUseSite()) { |
| 5616 | // Address the length field in the array. |
| 5617 | DCHECK(array_length->IsArrayLength()); |
| 5618 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 5619 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 5620 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
| 5621 | if (index_loc.IsConstant()) { |
| 5622 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5623 | __ cmpl(array_len, Immediate(value)); |
| 5624 | } else { |
| 5625 | __ cmpl(array_len, index_loc.AsRegister<Register>()); |
| 5626 | } |
| 5627 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5628 | } else { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5629 | Register length = length_loc.AsRegister<Register>(); |
| 5630 | if (index_loc.IsConstant()) { |
| 5631 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5632 | __ cmpl(length, Immediate(value)); |
| 5633 | } else { |
| 5634 | __ cmpl(length, index_loc.AsRegister<Register>()); |
| 5635 | } |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5636 | } |
| 5637 | codegen_->AddSlowPath(slow_path); |
| 5638 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5639 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5640 | } |
| 5641 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5642 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5643 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5644 | } |
| 5645 | |
| 5646 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5647 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5648 | } |
| 5649 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5650 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5651 | LocationSummary* locations = |
| 5652 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 5653 | locations->SetCustomSlowPathCallerSaves(RegisterSet()); // No caller-save registers. |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5654 | } |
| 5655 | |
| 5656 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5657 | HBasicBlock* block = instruction->GetBlock(); |
| 5658 | if (block->GetLoopInformation() != nullptr) { |
| 5659 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5660 | // The back edge will generate the suspend check. |
| 5661 | return; |
| 5662 | } |
| 5663 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5664 | // The goto will generate the suspend check. |
| 5665 | return; |
| 5666 | } |
| 5667 | GenerateSuspendCheck(instruction, nullptr); |
| 5668 | } |
| 5669 | |
| 5670 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5671 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5672 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5673 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 5674 | if (slow_path == nullptr) { |
| 5675 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); |
| 5676 | instruction->SetSlowPath(slow_path); |
| 5677 | codegen_->AddSlowPath(slow_path); |
| 5678 | if (successor != nullptr) { |
| 5679 | DCHECK(successor->IsLoopHeader()); |
| 5680 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5681 | } |
| 5682 | } else { |
| 5683 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5684 | } |
| 5685 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5686 | __ fs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86PointerSize>().Int32Value()), |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5687 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5688 | if (successor == nullptr) { |
| 5689 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5690 | __ Bind(slow_path->GetReturnLabel()); |
| 5691 | } else { |
| 5692 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5693 | __ jmp(slow_path->GetEntryLabel()); |
| 5694 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5695 | } |
| 5696 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5697 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 5698 | return codegen_->GetAssembler(); |
| 5699 | } |
| 5700 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5701 | void ParallelMoveResolverX86::MoveMemoryToMemory32(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5702 | ScratchRegisterScope ensure_scratch( |
| 5703 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5704 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5705 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5706 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5707 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5708 | } |
| 5709 | |
| 5710 | void ParallelMoveResolverX86::MoveMemoryToMemory64(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5711 | ScratchRegisterScope ensure_scratch( |
| 5712 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5713 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5714 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5715 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5716 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 5717 | __ movl(temp_reg, Address(ESP, src + stack_offset + kX86WordSize)); |
| 5718 | __ movl(Address(ESP, dst + stack_offset + kX86WordSize), temp_reg); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5719 | } |
| 5720 | |
| 5721 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5722 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5723 | Location source = move->GetSource(); |
| 5724 | Location destination = move->GetDestination(); |
| 5725 | |
| 5726 | if (source.IsRegister()) { |
| 5727 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5728 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5729 | } else if (destination.IsFpuRegister()) { |
| 5730 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5731 | } else { |
| 5732 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5733 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5734 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5735 | } else if (source.IsRegisterPair()) { |
| 5736 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 5737 | // Create stack space for 2 elements. |
| 5738 | __ subl(ESP, Immediate(2 * elem_size)); |
| 5739 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 5740 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 5741 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 5742 | // And remove the temporary stack space we allocated. |
| 5743 | __ addl(ESP, Immediate(2 * elem_size)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5744 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5745 | if (destination.IsRegister()) { |
| 5746 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
| 5747 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5748 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5749 | } else if (destination.IsRegisterPair()) { |
| 5750 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 5751 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 5752 | __ psrlq(src_reg, Immediate(32)); |
| 5753 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5754 | } else if (destination.IsStackSlot()) { |
| 5755 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5756 | } else { |
| 5757 | DCHECK(destination.IsDoubleStackSlot()); |
| 5758 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5759 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5760 | } else if (source.IsStackSlot()) { |
| 5761 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5762 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5763 | } else if (destination.IsFpuRegister()) { |
| 5764 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5765 | } else { |
| 5766 | DCHECK(destination.IsStackSlot()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5767 | MoveMemoryToMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5768 | } |
| 5769 | } else if (source.IsDoubleStackSlot()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5770 | if (destination.IsRegisterPair()) { |
| 5771 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 5772 | __ movl(destination.AsRegisterPairHigh<Register>(), |
| 5773 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 5774 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5775 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 5776 | } else { |
| 5777 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5778 | MoveMemoryToMemory64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5779 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5780 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5781 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5782 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5783 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5784 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5785 | if (value == 0) { |
| 5786 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5787 | } else { |
| 5788 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 5789 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5790 | } else { |
| 5791 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5792 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5793 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5794 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5795 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5796 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5797 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5798 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5799 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5800 | if (value == 0) { |
| 5801 | // Easy handling of 0.0. |
| 5802 | __ xorps(dest, dest); |
| 5803 | } else { |
| 5804 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5805 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5806 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5807 | __ movl(temp, Immediate(value)); |
| 5808 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5809 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5810 | } else { |
| 5811 | DCHECK(destination.IsStackSlot()) << destination; |
| 5812 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 5813 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5814 | } else if (constant->IsLongConstant()) { |
| 5815 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5816 | int32_t low_value = Low32Bits(value); |
| 5817 | int32_t high_value = High32Bits(value); |
| 5818 | Immediate low(low_value); |
| 5819 | Immediate high(high_value); |
| 5820 | if (destination.IsDoubleStackSlot()) { |
| 5821 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5822 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5823 | } else { |
| 5824 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 5825 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 5826 | } |
| 5827 | } else { |
| 5828 | DCHECK(constant->IsDoubleConstant()); |
| 5829 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5830 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5831 | int32_t low_value = Low32Bits(value); |
| 5832 | int32_t high_value = High32Bits(value); |
| 5833 | Immediate low(low_value); |
| 5834 | Immediate high(high_value); |
| 5835 | if (destination.IsFpuRegister()) { |
| 5836 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5837 | if (value == 0) { |
| 5838 | // Easy handling of 0.0. |
| 5839 | __ xorpd(dest, dest); |
| 5840 | } else { |
| 5841 | __ pushl(high); |
| 5842 | __ pushl(low); |
| 5843 | __ movsd(dest, Address(ESP, 0)); |
| 5844 | __ addl(ESP, Immediate(8)); |
| 5845 | } |
| 5846 | } else { |
| 5847 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5848 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5849 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5850 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5851 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5852 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5853 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5854 | } |
| 5855 | } |
| 5856 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 5857 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5858 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 5859 | ScratchRegisterScope ensure_scratch( |
| 5860 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 5861 | |
| 5862 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5863 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 5864 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 5865 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5866 | } |
| 5867 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5868 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5869 | ScratchRegisterScope ensure_scratch( |
| 5870 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5871 | |
| 5872 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5873 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5874 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 5875 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 5876 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5877 | } |
| 5878 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5879 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5880 | ScratchRegisterScope ensure_scratch1( |
| 5881 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5882 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5883 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 5884 | ScratchRegisterScope ensure_scratch2( |
| 5885 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5886 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5887 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 5888 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 5889 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 5890 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 5891 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 5892 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5893 | } |
| 5894 | |
| 5895 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5896 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5897 | Location source = move->GetSource(); |
| 5898 | Location destination = move->GetDestination(); |
| 5899 | |
| 5900 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 5901 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 5902 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5903 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5904 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5905 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5906 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5907 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5908 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5909 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5910 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 5911 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5912 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 5913 | // Use XOR Swap algorithm to avoid a temporary. |
| 5914 | DCHECK_NE(source.reg(), destination.reg()); |
| 5915 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5916 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5917 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5918 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 5919 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 5920 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 5921 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5922 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 5923 | // Take advantage of the 16 bytes in the XMM register. |
| 5924 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 5925 | Address stack(ESP, destination.GetStackIndex()); |
| 5926 | // Load the double into the high doubleword. |
| 5927 | __ movhpd(reg, stack); |
| 5928 | |
| 5929 | // Store the low double into the destination. |
| 5930 | __ movsd(stack, reg); |
| 5931 | |
| 5932 | // Move the high double to the low double. |
| 5933 | __ psrldq(reg, Immediate(8)); |
| 5934 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 5935 | // Take advantage of the 16 bytes in the XMM register. |
| 5936 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 5937 | Address stack(ESP, source.GetStackIndex()); |
| 5938 | // Load the double into the high doubleword. |
| 5939 | __ movhpd(reg, stack); |
| 5940 | |
| 5941 | // Store the low double into the destination. |
| 5942 | __ movsd(stack, reg); |
| 5943 | |
| 5944 | // Move the high double to the low double. |
| 5945 | __ psrldq(reg, Immediate(8)); |
| 5946 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
| 5947 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 5948 | Exchange(destination.GetHighStackIndex(kX86WordSize), source.GetHighStackIndex(kX86WordSize)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5949 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5950 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5951 | } |
| 5952 | } |
| 5953 | |
| 5954 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 5955 | __ pushl(static_cast<Register>(reg)); |
| 5956 | } |
| 5957 | |
| 5958 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 5959 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5960 | } |
| 5961 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5962 | HLoadClass::LoadKind CodeGeneratorX86::GetSupportedLoadClassKind( |
| 5963 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5964 | switch (desired_class_load_kind) { |
| 5965 | case HLoadClass::LoadKind::kReferrersClass: |
| 5966 | break; |
| 5967 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5968 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5969 | break; |
| 5970 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5971 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5972 | FALLTHROUGH_INTENDED; |
| 5973 | case HLoadClass::LoadKind::kDexCachePcRelative: |
| 5974 | DCHECK(!Runtime::Current()->UseJitCompilation()); // Note: boot image is also non-JIT. |
| 5975 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 5976 | // is incompatible with it. |
| 5977 | // TODO: Create as many X86ComputeBaseMethodAddress instructions as needed for methods |
| 5978 | // with irreducible loops. |
| 5979 | if (GetGraph()->HasIrreducibleLoops()) { |
| 5980 | return HLoadClass::LoadKind::kDexCacheViaMethod; |
| 5981 | } |
| 5982 | break; |
| 5983 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5984 | break; |
| 5985 | case HLoadClass::LoadKind::kDexCacheAddress: |
| 5986 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5987 | break; |
| 5988 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 5989 | break; |
| 5990 | } |
| 5991 | return desired_class_load_kind; |
| 5992 | } |
| 5993 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5994 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5995 | if (cls->NeedsAccessCheck()) { |
| 5996 | InvokeRuntimeCallingConvention calling_convention; |
| 5997 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5998 | cls, |
| 5999 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 6000 | Location::RegisterLocation(EAX), |
| 6001 | /* code_generator_supports_read_barrier */ true); |
| 6002 | return; |
| 6003 | } |
| 6004 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame^] | 6005 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 6006 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6007 | ? LocationSummary::kCallOnSlowPath |
| 6008 | : LocationSummary::kNoCall; |
| 6009 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame^] | 6010 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6011 | locations->SetCustomSlowPathCallerSaves(RegisterSet()); // No caller-save registers. |
| 6012 | } |
| 6013 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6014 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 6015 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
| 6016 | load_kind == HLoadClass::LoadKind::kDexCacheViaMethod || |
| 6017 | load_kind == HLoadClass::LoadKind::kBootImageLinkTimePcRelative || |
| 6018 | load_kind == HLoadClass::LoadKind::kDexCachePcRelative) { |
| 6019 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6020 | } |
| 6021 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6022 | } |
| 6023 | |
| 6024 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 6025 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6026 | if (cls->NeedsAccessCheck()) { |
| 6027 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6028 | codegen_->InvokeRuntime(kQuickInitializeTypeAndVerifyAccess, cls, cls->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6029 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6030 | return; |
| 6031 | } |
| 6032 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6033 | Location out_loc = locations->Out(); |
| 6034 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6035 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6036 | bool generate_null_check = false; |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame^] | 6037 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6038 | switch (cls->GetLoadKind()) { |
| 6039 | case HLoadClass::LoadKind::kReferrersClass: { |
| 6040 | DCHECK(!cls->CanCallRuntime()); |
| 6041 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 6042 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6043 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 6044 | GenerateGcRootFieldLoad( |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame^] | 6045 | cls, |
| 6046 | out_loc, |
| 6047 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), |
| 6048 | /*fixup_label*/ nullptr, |
| 6049 | requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6050 | break; |
| 6051 | } |
| 6052 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame^] | 6053 | DCHECK(!requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6054 | __ movl(out, Immediate(/* placeholder */ 0)); |
| 6055 | codegen_->RecordTypePatch(cls); |
| 6056 | break; |
| 6057 | } |
| 6058 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame^] | 6059 | DCHECK(!requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6060 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6061 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
| 6062 | codegen_->RecordTypePatch(cls); |
| 6063 | break; |
| 6064 | } |
| 6065 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame^] | 6066 | DCHECK(!requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6067 | DCHECK_NE(cls->GetAddress(), 0u); |
| 6068 | uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress()); |
| 6069 | __ movl(out, Immediate(address)); |
| 6070 | codegen_->RecordSimplePatch(); |
| 6071 | break; |
| 6072 | } |
| 6073 | case HLoadClass::LoadKind::kDexCacheAddress: { |
| 6074 | DCHECK_NE(cls->GetAddress(), 0u); |
| 6075 | uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress()); |
| 6076 | // /* GcRoot<mirror::Class> */ out = *address |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame^] | 6077 | GenerateGcRootFieldLoad(cls, |
| 6078 | out_loc, |
| 6079 | Address::Absolute(address), |
| 6080 | /*fixup_label*/ nullptr, |
| 6081 | requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6082 | generate_null_check = !cls->IsInDexCache(); |
| 6083 | break; |
| 6084 | } |
| 6085 | case HLoadClass::LoadKind::kDexCachePcRelative: { |
| 6086 | Register base_reg = locations->InAt(0).AsRegister<Register>(); |
| 6087 | uint32_t offset = cls->GetDexCacheElementOffset(); |
| 6088 | Label* fixup_label = codegen_->NewPcRelativeDexCacheArrayPatch(cls->GetDexFile(), offset); |
| 6089 | // /* GcRoot<mirror::Class> */ out = *(base + offset) /* PC-relative */ |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame^] | 6090 | GenerateGcRootFieldLoad(cls, |
| 6091 | out_loc, |
| 6092 | Address(base_reg, CodeGeneratorX86::kDummy32BitOffset), |
| 6093 | fixup_label, |
| 6094 | requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6095 | generate_null_check = !cls->IsInDexCache(); |
| 6096 | break; |
| 6097 | } |
| 6098 | case HLoadClass::LoadKind::kDexCacheViaMethod: { |
| 6099 | // /* GcRoot<mirror::Class>[] */ out = |
| 6100 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 6101 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 6102 | __ movl(out, Address(current_method, |
| 6103 | ArtMethod::DexCacheResolvedTypesOffset(kX86PointerSize).Int32Value())); |
| 6104 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame^] | 6105 | GenerateGcRootFieldLoad(cls, |
| 6106 | out_loc, |
| 6107 | Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())), |
| 6108 | /*fixup_label*/ nullptr, |
| 6109 | requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6110 | generate_null_check = !cls->IsInDexCache(); |
| 6111 | break; |
| 6112 | } |
| 6113 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6114 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6115 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6116 | DCHECK(cls->CanCallRuntime()); |
| 6117 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 6118 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 6119 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6120 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6121 | if (generate_null_check) { |
| 6122 | __ testl(out, out); |
| 6123 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6124 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6125 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6126 | if (cls->MustGenerateClinitCheck()) { |
| 6127 | GenerateClassInitializationCheck(slow_path, out); |
| 6128 | } else { |
| 6129 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6130 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6131 | } |
| 6132 | } |
| 6133 | |
| 6134 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 6135 | LocationSummary* locations = |
| 6136 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 6137 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6138 | if (check->HasUses()) { |
| 6139 | locations->SetOut(Location::SameAsFirstInput()); |
| 6140 | } |
| 6141 | } |
| 6142 | |
| 6143 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6144 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6145 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6146 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6147 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6148 | GenerateClassInitializationCheck(slow_path, |
| 6149 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6150 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6151 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6152 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6153 | SlowPathCode* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6154 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 6155 | Immediate(mirror::Class::kStatusInitialized)); |
| 6156 | __ j(kLess, slow_path->GetEntryLabel()); |
| 6157 | __ Bind(slow_path->GetExitLabel()); |
| 6158 | // No need for memory fence, thanks to the X86 memory model. |
| 6159 | } |
| 6160 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6161 | HLoadString::LoadKind CodeGeneratorX86::GetSupportedLoadStringKind( |
| 6162 | HLoadString::LoadKind desired_string_load_kind) { |
| 6163 | if (kEmitCompilerReadBarrier) { |
| 6164 | switch (desired_string_load_kind) { |
| 6165 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 6166 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 6167 | case HLoadString::LoadKind::kBootImageAddress: |
| 6168 | // TODO: Implement for read barrier. |
| 6169 | return HLoadString::LoadKind::kDexCacheViaMethod; |
| 6170 | default: |
| 6171 | break; |
| 6172 | } |
| 6173 | } |
| 6174 | switch (desired_string_load_kind) { |
| 6175 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 6176 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 6177 | break; |
| 6178 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 6179 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 6180 | FALLTHROUGH_INTENDED; |
| 6181 | case HLoadString::LoadKind::kDexCachePcRelative: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 6182 | DCHECK(!Runtime::Current()->UseJitCompilation()); // Note: boot image is also non-JIT. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6183 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 6184 | // is incompatible with it. |
| 6185 | // TODO: Create as many X86ComputeBaseMethodAddress instructions as needed for methods |
| 6186 | // with irreducible loops. |
| 6187 | if (GetGraph()->HasIrreducibleLoops()) { |
| 6188 | return HLoadString::LoadKind::kDexCacheViaMethod; |
| 6189 | } |
| 6190 | break; |
| 6191 | case HLoadString::LoadKind::kBootImageAddress: |
| 6192 | break; |
| 6193 | case HLoadString::LoadKind::kDexCacheAddress: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 6194 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6195 | break; |
| 6196 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 6197 | break; |
| 6198 | } |
| 6199 | return desired_string_load_kind; |
| 6200 | } |
| 6201 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6202 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6203 | LocationSummary::CallKind call_kind = (load->NeedsEnvironment() || kEmitCompilerReadBarrier) |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 6204 | ? LocationSummary::kCallOnSlowPath |
| 6205 | : LocationSummary::kNoCall; |
| 6206 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6207 | if (kUseBakerReadBarrier && !load->NeedsEnvironment()) { |
| 6208 | locations->SetCustomSlowPathCallerSaves(RegisterSet()); // No caller-save registers. |
| 6209 | } |
| 6210 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6211 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 6212 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod || |
| 6213 | load_kind == HLoadString::LoadKind::kBootImageLinkTimePcRelative || |
| 6214 | load_kind == HLoadString::LoadKind::kDexCachePcRelative) { |
| 6215 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6216 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6217 | locations->SetOut(Location::RequiresRegister()); |
| 6218 | } |
| 6219 | |
| 6220 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6221 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6222 | Location out_loc = locations->Out(); |
| 6223 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6224 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6225 | switch (load->GetLoadKind()) { |
| 6226 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: { |
| 6227 | DCHECK(!kEmitCompilerReadBarrier); |
| 6228 | __ movl(out, Immediate(/* placeholder */ 0)); |
| 6229 | codegen_->RecordStringPatch(load); |
| 6230 | return; // No dex cache slow path. |
| 6231 | } |
| 6232 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| 6233 | DCHECK(!kEmitCompilerReadBarrier); |
| 6234 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6235 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
| 6236 | codegen_->RecordStringPatch(load); |
| 6237 | return; // No dex cache slow path. |
| 6238 | } |
| 6239 | case HLoadString::LoadKind::kBootImageAddress: { |
| 6240 | DCHECK(!kEmitCompilerReadBarrier); |
| 6241 | DCHECK_NE(load->GetAddress(), 0u); |
| 6242 | uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress()); |
| 6243 | __ movl(out, Immediate(address)); |
| 6244 | codegen_->RecordSimplePatch(); |
| 6245 | return; // No dex cache slow path. |
| 6246 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6247 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6248 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6249 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6250 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6251 | // TODO: Re-add the compiler code to do string dex cache lookup again. |
| 6252 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86(load); |
| 6253 | codegen_->AddSlowPath(slow_path); |
| 6254 | __ jmp(slow_path->GetEntryLabel()); |
| 6255 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6256 | } |
| 6257 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6258 | static Address GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6259 | return Address::Absolute(Thread::ExceptionOffset<kX86PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6260 | } |
| 6261 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6262 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 6263 | LocationSummary* locations = |
| 6264 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 6265 | locations->SetOut(Location::RequiresRegister()); |
| 6266 | } |
| 6267 | |
| 6268 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6269 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 6270 | } |
| 6271 | |
| 6272 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
| 6273 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 6274 | } |
| 6275 | |
| 6276 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6277 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6278 | } |
| 6279 | |
| 6280 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| 6281 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6282 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6283 | InvokeRuntimeCallingConvention calling_convention; |
| 6284 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6285 | } |
| 6286 | |
| 6287 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6288 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6289 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6290 | } |
| 6291 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6292 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 6293 | return kEmitCompilerReadBarrier && |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6294 | !kUseBakerReadBarrier && |
| 6295 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6296 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6297 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 6298 | } |
| 6299 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6300 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6301 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6302 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6303 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6304 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6305 | case TypeCheckKind::kExactCheck: |
| 6306 | case TypeCheckKind::kAbstractClassCheck: |
| 6307 | case TypeCheckKind::kClassHierarchyCheck: |
| 6308 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6309 | call_kind = |
| 6310 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6311 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6312 | break; |
| 6313 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6314 | case TypeCheckKind::kUnresolvedCheck: |
| 6315 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6316 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6317 | break; |
| 6318 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6319 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6320 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6321 | if (baker_read_barrier_slow_path) { |
| 6322 | locations->SetCustomSlowPathCallerSaves(RegisterSet()); // No caller-save registers. |
| 6323 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6324 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6325 | locations->SetInAt(1, Location::Any()); |
| 6326 | // Note that TypeCheckSlowPathX86 uses this "out" register too. |
| 6327 | locations->SetOut(Location::RequiresRegister()); |
| 6328 | // When read barriers are enabled, we need a temporary register for |
| 6329 | // some cases. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6330 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6331 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6332 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6333 | } |
| 6334 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6335 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6336 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6337 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6338 | Location obj_loc = locations->InAt(0); |
| 6339 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6340 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6341 | Location out_loc = locations->Out(); |
| 6342 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6343 | Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6344 | locations->GetTemp(0) : |
| 6345 | Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6346 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6347 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6348 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6349 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6350 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6351 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6352 | |
| 6353 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6354 | // Avoid null check if we know obj is not null. |
| 6355 | if (instruction->MustDoNullCheck()) { |
| 6356 | __ testl(obj, obj); |
| 6357 | __ j(kEqual, &zero); |
| 6358 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6359 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6360 | // /* HeapReference<Class> */ out = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6361 | GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6362 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6363 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6364 | case TypeCheckKind::kExactCheck: { |
| 6365 | if (cls.IsRegister()) { |
| 6366 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6367 | } else { |
| 6368 | DCHECK(cls.IsStackSlot()) << cls; |
| 6369 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6370 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6371 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6372 | // Classes must be equal for the instanceof to succeed. |
| 6373 | __ j(kNotEqual, &zero); |
| 6374 | __ movl(out, Immediate(1)); |
| 6375 | __ jmp(&done); |
| 6376 | break; |
| 6377 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6378 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6379 | case TypeCheckKind::kAbstractClassCheck: { |
| 6380 | // If the class is abstract, we eagerly fetch the super class of the |
| 6381 | // object to avoid doing a comparison we know will fail. |
| 6382 | NearLabel loop; |
| 6383 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6384 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6385 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6386 | __ testl(out, out); |
| 6387 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6388 | __ j(kEqual, &done); |
| 6389 | if (cls.IsRegister()) { |
| 6390 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6391 | } else { |
| 6392 | DCHECK(cls.IsStackSlot()) << cls; |
| 6393 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6394 | } |
| 6395 | __ j(kNotEqual, &loop); |
| 6396 | __ movl(out, Immediate(1)); |
| 6397 | if (zero.IsLinked()) { |
| 6398 | __ jmp(&done); |
| 6399 | } |
| 6400 | break; |
| 6401 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6402 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6403 | case TypeCheckKind::kClassHierarchyCheck: { |
| 6404 | // Walk over the class hierarchy to find a match. |
| 6405 | NearLabel loop, success; |
| 6406 | __ Bind(&loop); |
| 6407 | if (cls.IsRegister()) { |
| 6408 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6409 | } else { |
| 6410 | DCHECK(cls.IsStackSlot()) << cls; |
| 6411 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6412 | } |
| 6413 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6414 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6415 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6416 | __ testl(out, out); |
| 6417 | __ j(kNotEqual, &loop); |
| 6418 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6419 | __ jmp(&done); |
| 6420 | __ Bind(&success); |
| 6421 | __ movl(out, Immediate(1)); |
| 6422 | if (zero.IsLinked()) { |
| 6423 | __ jmp(&done); |
| 6424 | } |
| 6425 | break; |
| 6426 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6427 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6428 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6429 | // Do an exact check. |
| 6430 | NearLabel exact_check; |
| 6431 | if (cls.IsRegister()) { |
| 6432 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6433 | } else { |
| 6434 | DCHECK(cls.IsStackSlot()) << cls; |
| 6435 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6436 | } |
| 6437 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6438 | // 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] | 6439 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6440 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6441 | __ testl(out, out); |
| 6442 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6443 | __ j(kEqual, &done); |
| 6444 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 6445 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6446 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6447 | __ movl(out, Immediate(1)); |
| 6448 | __ jmp(&done); |
| 6449 | break; |
| 6450 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6451 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6452 | case TypeCheckKind::kArrayCheck: { |
| 6453 | if (cls.IsRegister()) { |
| 6454 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6455 | } else { |
| 6456 | DCHECK(cls.IsStackSlot()) << cls; |
| 6457 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6458 | } |
| 6459 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6460 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6461 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6462 | codegen_->AddSlowPath(slow_path); |
| 6463 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6464 | __ movl(out, Immediate(1)); |
| 6465 | if (zero.IsLinked()) { |
| 6466 | __ jmp(&done); |
| 6467 | } |
| 6468 | break; |
| 6469 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6470 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6471 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6472 | case TypeCheckKind::kInterfaceCheck: { |
| 6473 | // 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] | 6474 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6475 | // cases. |
| 6476 | // |
| 6477 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6478 | // entry point without resorting to a type checking slow path |
| 6479 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6480 | // require to assign fixed registers for the inputs of this |
| 6481 | // HInstanceOf instruction (following the runtime calling |
| 6482 | // convention), which might be cluttered by the potential first |
| 6483 | // read barrier emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6484 | // |
| 6485 | // TODO: Introduce a new runtime entry point taking the object |
| 6486 | // to test (instead of its class) as argument, and let it deal |
| 6487 | // with the read barrier issues. This will let us refactor this |
| 6488 | // case of the `switch` code as it was previously (with a direct |
| 6489 | // call to the runtime not using a type checking slow path). |
| 6490 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6491 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6492 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6493 | /* is_fatal */ false); |
| 6494 | codegen_->AddSlowPath(slow_path); |
| 6495 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6496 | if (zero.IsLinked()) { |
| 6497 | __ jmp(&done); |
| 6498 | } |
| 6499 | break; |
| 6500 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6501 | } |
| 6502 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6503 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6504 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6505 | __ xorl(out, out); |
| 6506 | } |
| 6507 | |
| 6508 | if (done.IsLinked()) { |
| 6509 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6510 | } |
| 6511 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6512 | if (slow_path != nullptr) { |
| 6513 | __ Bind(slow_path->GetExitLabel()); |
| 6514 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6515 | } |
| 6516 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6517 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6518 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 6519 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6520 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6521 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6522 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6523 | case TypeCheckKind::kExactCheck: |
| 6524 | case TypeCheckKind::kAbstractClassCheck: |
| 6525 | case TypeCheckKind::kClassHierarchyCheck: |
| 6526 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6527 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 6528 | LocationSummary::kCallOnSlowPath : |
| 6529 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6530 | baker_read_barrier_slow_path = kUseBakerReadBarrier && !throws_into_catch; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6531 | break; |
| 6532 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6533 | case TypeCheckKind::kUnresolvedCheck: |
| 6534 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6535 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6536 | break; |
| 6537 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6538 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6539 | if (baker_read_barrier_slow_path) { |
| 6540 | locations->SetCustomSlowPathCallerSaves(RegisterSet()); // No caller-save registers. |
| 6541 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6542 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6543 | locations->SetInAt(1, Location::Any()); |
| 6544 | // Note that TypeCheckSlowPathX86 uses this "temp" register too. |
| 6545 | locations->AddTemp(Location::RequiresRegister()); |
| 6546 | // When read barriers are enabled, we need an additional temporary |
| 6547 | // register for some cases. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6548 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6549 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6550 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6551 | } |
| 6552 | |
| 6553 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6554 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6555 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6556 | Location obj_loc = locations->InAt(0); |
| 6557 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6558 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6559 | Location temp_loc = locations->GetTemp(0); |
| 6560 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6561 | Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6562 | locations->GetTemp(1) : |
| 6563 | Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6564 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6565 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6566 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6567 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6568 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6569 | bool is_type_check_slow_path_fatal = |
| 6570 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 6571 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6572 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6573 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 6574 | !instruction->CanThrowIntoCatchBlock(); |
| 6575 | SlowPathCode* type_check_slow_path = |
| 6576 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6577 | is_type_check_slow_path_fatal); |
| 6578 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6579 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6580 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6581 | // Avoid null check if we know obj is not null. |
| 6582 | if (instruction->MustDoNullCheck()) { |
| 6583 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6584 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6585 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6586 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6587 | // /* HeapReference<Class> */ temp = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6588 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6589 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6590 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6591 | case TypeCheckKind::kExactCheck: |
| 6592 | case TypeCheckKind::kArrayCheck: { |
| 6593 | if (cls.IsRegister()) { |
| 6594 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6595 | } else { |
| 6596 | DCHECK(cls.IsStackSlot()) << cls; |
| 6597 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6598 | } |
| 6599 | // Jump to slow path for throwing the exception or doing a |
| 6600 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6601 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6602 | break; |
| 6603 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6604 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6605 | case TypeCheckKind::kAbstractClassCheck: { |
| 6606 | // If the class is abstract, we eagerly fetch the super class of the |
| 6607 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6608 | NearLabel loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6609 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6610 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6611 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6612 | |
| 6613 | // If the class reference currently in `temp` is not null, jump |
| 6614 | // to the `compare_classes` label to compare it with the checked |
| 6615 | // class. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6616 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6617 | __ j(kNotEqual, &compare_classes); |
| 6618 | // Otherwise, jump to the slow path to throw the exception. |
| 6619 | // |
| 6620 | // But before, move back the object's class into `temp` before |
| 6621 | // going into the slow path, as it has been overwritten in the |
| 6622 | // meantime. |
| 6623 | // /* HeapReference<Class> */ temp = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6624 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6625 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6626 | |
| 6627 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6628 | if (cls.IsRegister()) { |
| 6629 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6630 | } else { |
| 6631 | DCHECK(cls.IsStackSlot()) << cls; |
| 6632 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6633 | } |
| 6634 | __ j(kNotEqual, &loop); |
| 6635 | break; |
| 6636 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6637 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6638 | case TypeCheckKind::kClassHierarchyCheck: { |
| 6639 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6640 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6641 | __ Bind(&loop); |
| 6642 | if (cls.IsRegister()) { |
| 6643 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6644 | } else { |
| 6645 | DCHECK(cls.IsStackSlot()) << cls; |
| 6646 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6647 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6648 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6649 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6650 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6651 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6652 | |
| 6653 | // If the class reference currently in `temp` is not null, jump |
| 6654 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6655 | __ testl(temp, temp); |
| 6656 | __ j(kNotEqual, &loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6657 | // Otherwise, jump to the slow path to throw the exception. |
| 6658 | // |
| 6659 | // But before, move back the object's class into `temp` before |
| 6660 | // going into the slow path, as it has been overwritten in the |
| 6661 | // meantime. |
| 6662 | // /* HeapReference<Class> */ temp = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6663 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6664 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6665 | break; |
| 6666 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6667 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6668 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6669 | // Do an exact check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6670 | NearLabel check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6671 | if (cls.IsRegister()) { |
| 6672 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6673 | } else { |
| 6674 | DCHECK(cls.IsStackSlot()) << cls; |
| 6675 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6676 | } |
| 6677 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6678 | |
| 6679 | // 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] | 6680 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6681 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6682 | |
| 6683 | // If the component type is not null (i.e. the object is indeed |
| 6684 | // an array), jump to label `check_non_primitive_component_type` |
| 6685 | // to further check that this component type is not a primitive |
| 6686 | // type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6687 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6688 | __ j(kNotEqual, &check_non_primitive_component_type); |
| 6689 | // Otherwise, jump to the slow path to throw the exception. |
| 6690 | // |
| 6691 | // But before, move back the object's class into `temp` before |
| 6692 | // going into the slow path, as it has been overwritten in the |
| 6693 | // meantime. |
| 6694 | // /* HeapReference<Class> */ temp = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6695 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6696 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6697 | |
| 6698 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6699 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6700 | __ j(kEqual, &done); |
| 6701 | // Same comment as above regarding `temp` and the slow path. |
| 6702 | // /* HeapReference<Class> */ temp = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6703 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6704 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6705 | break; |
| 6706 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6707 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6708 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6709 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6710 | // We always go into the type check slow path for the unresolved |
| 6711 | // and interface check cases. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6712 | // |
| 6713 | // We cannot directly call the CheckCast runtime entry point |
| 6714 | // without resorting to a type checking slow path here (i.e. by |
| 6715 | // calling InvokeRuntime directly), as it would require to |
| 6716 | // assign fixed registers for the inputs of this HInstanceOf |
| 6717 | // instruction (following the runtime calling convention), which |
| 6718 | // might be cluttered by the potential first read barrier |
| 6719 | // emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6720 | // |
| 6721 | // TODO: Introduce a new runtime entry point taking the object |
| 6722 | // to test (instead of its class) as argument, and let it deal |
| 6723 | // with the read barrier issues. This will let us refactor this |
| 6724 | // case of the `switch` code as it was previously (with a direct |
| 6725 | // call to the runtime not using a type checking slow path). |
| 6726 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6727 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6728 | break; |
| 6729 | } |
| 6730 | __ Bind(&done); |
| 6731 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6732 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6733 | } |
| 6734 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6735 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6736 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6737 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6738 | InvokeRuntimeCallingConvention calling_convention; |
| 6739 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6740 | } |
| 6741 | |
| 6742 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6743 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject |
| 6744 | : kQuickUnlockObject, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6745 | instruction, |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6746 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6747 | if (instruction->IsEnter()) { |
| 6748 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6749 | } else { |
| 6750 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6751 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6752 | } |
| 6753 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6754 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6755 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6756 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6757 | |
| 6758 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6759 | LocationSummary* locations = |
| 6760 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6761 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6762 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6763 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6764 | locations->SetInAt(1, Location::Any()); |
| 6765 | locations->SetOut(Location::SameAsFirstInput()); |
| 6766 | } |
| 6767 | |
| 6768 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 6769 | HandleBitwiseOperation(instruction); |
| 6770 | } |
| 6771 | |
| 6772 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 6773 | HandleBitwiseOperation(instruction); |
| 6774 | } |
| 6775 | |
| 6776 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 6777 | HandleBitwiseOperation(instruction); |
| 6778 | } |
| 6779 | |
| 6780 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6781 | LocationSummary* locations = instruction->GetLocations(); |
| 6782 | Location first = locations->InAt(0); |
| 6783 | Location second = locations->InAt(1); |
| 6784 | DCHECK(first.Equals(locations->Out())); |
| 6785 | |
| 6786 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6787 | if (second.IsRegister()) { |
| 6788 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6789 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6790 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6791 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6792 | } else { |
| 6793 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6794 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6795 | } |
| 6796 | } else if (second.IsConstant()) { |
| 6797 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6798 | __ andl(first.AsRegister<Register>(), |
| 6799 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6800 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6801 | __ orl(first.AsRegister<Register>(), |
| 6802 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6803 | } else { |
| 6804 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6805 | __ xorl(first.AsRegister<Register>(), |
| 6806 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6807 | } |
| 6808 | } else { |
| 6809 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6810 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6811 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6812 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6813 | } else { |
| 6814 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6815 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6816 | } |
| 6817 | } |
| 6818 | } else { |
| 6819 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6820 | if (second.IsRegisterPair()) { |
| 6821 | if (instruction->IsAnd()) { |
| 6822 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6823 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6824 | } else if (instruction->IsOr()) { |
| 6825 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6826 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6827 | } else { |
| 6828 | DCHECK(instruction->IsXor()); |
| 6829 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6830 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6831 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6832 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6833 | if (instruction->IsAnd()) { |
| 6834 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6835 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 6836 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6837 | } else if (instruction->IsOr()) { |
| 6838 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6839 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 6840 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6841 | } else { |
| 6842 | DCHECK(instruction->IsXor()); |
| 6843 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6844 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 6845 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6846 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6847 | } else { |
| 6848 | DCHECK(second.IsConstant()) << second; |
| 6849 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6850 | int32_t low_value = Low32Bits(value); |
| 6851 | int32_t high_value = High32Bits(value); |
| 6852 | Immediate low(low_value); |
| 6853 | Immediate high(high_value); |
| 6854 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6855 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6856 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6857 | if (low_value == 0) { |
| 6858 | __ xorl(first_low, first_low); |
| 6859 | } else if (low_value != -1) { |
| 6860 | __ andl(first_low, low); |
| 6861 | } |
| 6862 | if (high_value == 0) { |
| 6863 | __ xorl(first_high, first_high); |
| 6864 | } else if (high_value != -1) { |
| 6865 | __ andl(first_high, high); |
| 6866 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6867 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6868 | if (low_value != 0) { |
| 6869 | __ orl(first_low, low); |
| 6870 | } |
| 6871 | if (high_value != 0) { |
| 6872 | __ orl(first_high, high); |
| 6873 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6874 | } else { |
| 6875 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6876 | if (low_value != 0) { |
| 6877 | __ xorl(first_low, low); |
| 6878 | } |
| 6879 | if (high_value != 0) { |
| 6880 | __ xorl(first_high, high); |
| 6881 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6882 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6883 | } |
| 6884 | } |
| 6885 | } |
| 6886 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6887 | void InstructionCodeGeneratorX86::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 6888 | Location out, |
| 6889 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6890 | Location maybe_temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6891 | Register out_reg = out.AsRegister<Register>(); |
| 6892 | if (kEmitCompilerReadBarrier) { |
| 6893 | if (kUseBakerReadBarrier) { |
| 6894 | // Load with fast path based Baker's read barrier. |
| 6895 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6896 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6897 | instruction, out, out_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6898 | } else { |
| 6899 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6900 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6901 | // in the following move operation, as we will need it for the |
| 6902 | // read barrier below. |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6903 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6904 | __ movl(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6905 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6906 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6907 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6908 | } |
| 6909 | } else { |
| 6910 | // Plain load with no read barrier. |
| 6911 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6912 | __ movl(out_reg, Address(out_reg, offset)); |
| 6913 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6914 | } |
| 6915 | } |
| 6916 | |
| 6917 | void InstructionCodeGeneratorX86::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 6918 | Location out, |
| 6919 | Location obj, |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6920 | uint32_t offset) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6921 | Register out_reg = out.AsRegister<Register>(); |
| 6922 | Register obj_reg = obj.AsRegister<Register>(); |
| 6923 | if (kEmitCompilerReadBarrier) { |
| 6924 | if (kUseBakerReadBarrier) { |
| 6925 | // Load with fast path based Baker's read barrier. |
| 6926 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6927 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6928 | instruction, out, obj_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6929 | } else { |
| 6930 | // Load with slow path based read barrier. |
| 6931 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6932 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6933 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6934 | } |
| 6935 | } else { |
| 6936 | // Plain load with no read barrier. |
| 6937 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6938 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6939 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6940 | } |
| 6941 | } |
| 6942 | |
| 6943 | void InstructionCodeGeneratorX86::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6944 | Location root, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6945 | const Address& address, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame^] | 6946 | Label* fixup_label, |
| 6947 | bool requires_read_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6948 | Register root_reg = root.AsRegister<Register>(); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame^] | 6949 | if (requires_read_barrier) { |
| 6950 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6951 | if (kUseBakerReadBarrier) { |
| 6952 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6953 | // Baker's read barrier are used: |
| 6954 | // |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6955 | // root = *address; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6956 | // if (Thread::Current()->GetIsGcMarking()) { |
| 6957 | // root = ReadBarrier::Mark(root) |
| 6958 | // } |
| 6959 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6960 | // /* GcRoot<mirror::Object> */ root = *address |
| 6961 | __ movl(root_reg, address); |
| 6962 | if (fixup_label != nullptr) { |
| 6963 | __ Bind(fixup_label); |
| 6964 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6965 | static_assert( |
| 6966 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6967 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6968 | "have different sizes."); |
| 6969 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6970 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6971 | "have different sizes."); |
| 6972 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6973 | // Slow path marking the GC root `root`. |
| 6974 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86( |
| 6975 | instruction, root, /* unpoison */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6976 | codegen_->AddSlowPath(slow_path); |
| 6977 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6978 | __ fs()->cmpl(Address::Absolute(Thread::IsGcMarkingOffset<kX86PointerSize>().Int32Value()), |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6979 | Immediate(0)); |
| 6980 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6981 | __ Bind(slow_path->GetExitLabel()); |
| 6982 | } else { |
| 6983 | // GC root loaded through a slow path for read barriers other |
| 6984 | // than Baker's. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6985 | // /* GcRoot<mirror::Object>* */ root = address |
| 6986 | __ leal(root_reg, address); |
| 6987 | if (fixup_label != nullptr) { |
| 6988 | __ Bind(fixup_label); |
| 6989 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6990 | // /* mirror::Object* */ root = root->Read() |
| 6991 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6992 | } |
| 6993 | } else { |
| 6994 | // Plain GC root load with no read barrier. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6995 | // /* GcRoot<mirror::Object> */ root = *address |
| 6996 | __ movl(root_reg, address); |
| 6997 | if (fixup_label != nullptr) { |
| 6998 | __ Bind(fixup_label); |
| 6999 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7000 | // Note that GC roots are not affected by heap poisoning, thus we |
| 7001 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7002 | } |
| 7003 | } |
| 7004 | |
| 7005 | void CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7006 | Location ref, |
| 7007 | Register obj, |
| 7008 | uint32_t offset, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7009 | bool needs_null_check) { |
| 7010 | DCHECK(kEmitCompilerReadBarrier); |
| 7011 | DCHECK(kUseBakerReadBarrier); |
| 7012 | |
| 7013 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7014 | Address src(obj, offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7015 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7016 | } |
| 7017 | |
| 7018 | void CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7019 | Location ref, |
| 7020 | Register obj, |
| 7021 | uint32_t data_offset, |
| 7022 | Location index, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7023 | bool needs_null_check) { |
| 7024 | DCHECK(kEmitCompilerReadBarrier); |
| 7025 | DCHECK(kUseBakerReadBarrier); |
| 7026 | |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 7027 | static_assert( |
| 7028 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 7029 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7030 | // /* HeapReference<Object> */ ref = |
| 7031 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 7032 | Address src = index.IsConstant() ? |
| 7033 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset) : |
| 7034 | Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7035 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7036 | } |
| 7037 | |
| 7038 | void CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7039 | Location ref, |
| 7040 | Register obj, |
| 7041 | const Address& src, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7042 | bool needs_null_check) { |
| 7043 | DCHECK(kEmitCompilerReadBarrier); |
| 7044 | DCHECK(kUseBakerReadBarrier); |
| 7045 | |
| 7046 | // In slow path based read barriers, the read barrier call is |
| 7047 | // inserted after the original load. However, in fast path based |
| 7048 | // Baker's read barriers, we need to perform the load of |
| 7049 | // mirror::Object::monitor_ *before* the original reference load. |
| 7050 | // This load-load ordering is required by the read barrier. |
| 7051 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 7052 | // |
| 7053 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7054 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7055 | // HeapReference<Object> ref = *src; // Original reference load. |
| 7056 | // bool is_gray = (rb_state == ReadBarrier::gray_ptr_); |
| 7057 | // if (is_gray) { |
| 7058 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 7059 | // } |
| 7060 | // |
| 7061 | // Note: the original implementation in ReadBarrier::Barrier is |
| 7062 | // slightly more complex as: |
| 7063 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7064 | // the high-bits of rb_state, which are expected to be all zeroes |
| 7065 | // (we use CodeGeneratorX86::GenerateMemoryBarrier instead here, |
| 7066 | // which is a no-op thanks to the x86 memory model); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7067 | // - it performs additional checks that we do not do here for |
| 7068 | // performance reasons. |
| 7069 | |
| 7070 | Register ref_reg = ref.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7071 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 7072 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7073 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| 7074 | static_assert(ReadBarrier::white_ptr_ == 0, "Expecting white to have value 0"); |
| 7075 | static_assert(ReadBarrier::gray_ptr_ == 1, "Expecting gray to have value 1"); |
| 7076 | static_assert(ReadBarrier::black_ptr_ == 2, "Expecting black to have value 2"); |
| 7077 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 7078 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 7079 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 7080 | |
| 7081 | // if (rb_state == ReadBarrier::gray_ptr_) |
| 7082 | // ref = ReadBarrier::Mark(ref); |
| 7083 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 7084 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7085 | if (needs_null_check) { |
| 7086 | MaybeRecordImplicitNullCheck(instruction); |
| 7087 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7088 | |
| 7089 | // Load fence to prevent load-load reordering. |
| 7090 | // Note that this is a no-op, thanks to the x86 memory model. |
| 7091 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 7092 | |
| 7093 | // The actual reference load. |
| 7094 | // /* HeapReference<Object> */ ref = *src |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7095 | __ movl(ref_reg, src); // Flags are unaffected. |
| 7096 | |
| 7097 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 7098 | // Slow path marking the object `ref` when it is gray. |
| 7099 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86( |
| 7100 | instruction, ref, /* unpoison */ true); |
| 7101 | AddSlowPath(slow_path); |
| 7102 | |
| 7103 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 7104 | __ j(kNotZero, slow_path->GetEntryLabel()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7105 | |
| 7106 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7107 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7108 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7109 | __ Bind(slow_path->GetExitLabel()); |
| 7110 | } |
| 7111 | |
| 7112 | void CodeGeneratorX86::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7113 | Location out, |
| 7114 | Location ref, |
| 7115 | Location obj, |
| 7116 | uint32_t offset, |
| 7117 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7118 | DCHECK(kEmitCompilerReadBarrier); |
| 7119 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7120 | // Insert a slow path based read barrier *after* the reference load. |
| 7121 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7122 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7123 | // reference will be carried out by the runtime within the slow |
| 7124 | // path. |
| 7125 | // |
| 7126 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7127 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7128 | // not used by the artReadBarrierSlow entry point. |
| 7129 | // |
| 7130 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 7131 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 7132 | ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); |
| 7133 | AddSlowPath(slow_path); |
| 7134 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7135 | __ jmp(slow_path->GetEntryLabel()); |
| 7136 | __ Bind(slow_path->GetExitLabel()); |
| 7137 | } |
| 7138 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7139 | void CodeGeneratorX86::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 7140 | Location out, |
| 7141 | Location ref, |
| 7142 | Location obj, |
| 7143 | uint32_t offset, |
| 7144 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7145 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7146 | // Baker's read barriers shall be handled by the fast path |
| 7147 | // (CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier). |
| 7148 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7149 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7150 | // by the runtime within the slow path. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7151 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7152 | } else if (kPoisonHeapReferences) { |
| 7153 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 7154 | } |
| 7155 | } |
| 7156 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7157 | void CodeGeneratorX86::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7158 | Location out, |
| 7159 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7160 | DCHECK(kEmitCompilerReadBarrier); |
| 7161 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7162 | // Insert a slow path based read barrier *after* the GC root load. |
| 7163 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7164 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7165 | // not need to do anything special for this here. |
| 7166 | SlowPathCode* slow_path = |
| 7167 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86(instruction, out, root); |
| 7168 | AddSlowPath(slow_path); |
| 7169 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7170 | __ jmp(slow_path->GetEntryLabel()); |
| 7171 | __ Bind(slow_path->GetExitLabel()); |
| 7172 | } |
| 7173 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7174 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7175 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7176 | LOG(FATAL) << "Unreachable"; |
| 7177 | } |
| 7178 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7179 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7180 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7181 | LOG(FATAL) << "Unreachable"; |
| 7182 | } |
| 7183 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7184 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7185 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7186 | LocationSummary* locations = |
| 7187 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7188 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7189 | } |
| 7190 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7191 | void InstructionCodeGeneratorX86::GenPackedSwitchWithCompares(Register value_reg, |
| 7192 | int32_t lower_bound, |
| 7193 | uint32_t num_entries, |
| 7194 | HBasicBlock* switch_block, |
| 7195 | HBasicBlock* default_block) { |
| 7196 | // Figure out the correct compare values and jump conditions. |
| 7197 | // Handle the first compare/branch as a special case because it might |
| 7198 | // jump to the default case. |
| 7199 | DCHECK_GT(num_entries, 2u); |
| 7200 | Condition first_condition; |
| 7201 | uint32_t index; |
| 7202 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 7203 | if (lower_bound != 0) { |
| 7204 | first_condition = kLess; |
| 7205 | __ cmpl(value_reg, Immediate(lower_bound)); |
| 7206 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 7207 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7208 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7209 | index = 1; |
| 7210 | } else { |
| 7211 | // Handle all the compare/jumps below. |
| 7212 | first_condition = kBelow; |
| 7213 | index = 0; |
| 7214 | } |
| 7215 | |
| 7216 | // Handle the rest of the compare/jumps. |
| 7217 | for (; index + 1 < num_entries; index += 2) { |
| 7218 | int32_t compare_to_value = lower_bound + index + 1; |
| 7219 | __ cmpl(value_reg, Immediate(compare_to_value)); |
| 7220 | // Jump to successors[index] if value < case_value[index]. |
| 7221 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 7222 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 7223 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 7224 | } |
| 7225 | |
| 7226 | if (index != num_entries) { |
| 7227 | // There are an odd number of entries. Handle the last one. |
| 7228 | DCHECK_EQ(index + 1, num_entries); |
| 7229 | __ cmpl(value_reg, Immediate(lower_bound + index)); |
| 7230 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7231 | } |
| 7232 | |
| 7233 | // And the default for any other value. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7234 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
| 7235 | __ jmp(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7236 | } |
| 7237 | } |
| 7238 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7239 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7240 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 7241 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 7242 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7243 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7244 | |
| 7245 | GenPackedSwitchWithCompares(value_reg, |
| 7246 | lower_bound, |
| 7247 | num_entries, |
| 7248 | switch_instr->GetBlock(), |
| 7249 | switch_instr->GetDefaultBlock()); |
| 7250 | } |
| 7251 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7252 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7253 | LocationSummary* locations = |
| 7254 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7255 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7256 | |
| 7257 | // Constant area pointer. |
| 7258 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7259 | |
| 7260 | // And the temporary we need. |
| 7261 | locations->AddTemp(Location::RequiresRegister()); |
| 7262 | } |
| 7263 | |
| 7264 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7265 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7266 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7267 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7268 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7269 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7270 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7271 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 7272 | GenPackedSwitchWithCompares(value_reg, |
| 7273 | lower_bound, |
| 7274 | num_entries, |
| 7275 | switch_instr->GetBlock(), |
| 7276 | default_block); |
| 7277 | return; |
| 7278 | } |
| 7279 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7280 | // Optimizing has a jump area. |
| 7281 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 7282 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 7283 | |
| 7284 | // Remove the bias, if needed. |
| 7285 | if (lower_bound != 0) { |
| 7286 | __ leal(temp_reg, Address(value_reg, -lower_bound)); |
| 7287 | value_reg = temp_reg; |
| 7288 | } |
| 7289 | |
| 7290 | // Is the value in range? |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7291 | DCHECK_GE(num_entries, 1u); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7292 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 7293 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| 7294 | |
| 7295 | // We are in the range of the table. |
| 7296 | // Load (target-constant_area) from the jump table, indexing by the value. |
| 7297 | __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); |
| 7298 | |
| 7299 | // Compute the actual target address by adding in constant_area. |
| 7300 | __ addl(temp_reg, constant_area); |
| 7301 | |
| 7302 | // And jump. |
| 7303 | __ jmp(temp_reg); |
| 7304 | } |
| 7305 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7306 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 7307 | HX86ComputeBaseMethodAddress* insn) { |
| 7308 | LocationSummary* locations = |
| 7309 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 7310 | locations->SetOut(Location::RequiresRegister()); |
| 7311 | } |
| 7312 | |
| 7313 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 7314 | HX86ComputeBaseMethodAddress* insn) { |
| 7315 | LocationSummary* locations = insn->GetLocations(); |
| 7316 | Register reg = locations->Out().AsRegister<Register>(); |
| 7317 | |
| 7318 | // Generate call to next instruction. |
| 7319 | Label next_instruction; |
| 7320 | __ call(&next_instruction); |
| 7321 | __ Bind(&next_instruction); |
| 7322 | |
| 7323 | // Remember this offset for later use with constant area. |
| 7324 | codegen_->SetMethodAddressOffset(GetAssembler()->CodeSize()); |
| 7325 | |
| 7326 | // Grab the return address off the stack. |
| 7327 | __ popl(reg); |
| 7328 | } |
| 7329 | |
| 7330 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 7331 | HX86LoadFromConstantTable* insn) { |
| 7332 | LocationSummary* locations = |
| 7333 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 7334 | |
| 7335 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7336 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 7337 | |
| 7338 | // 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] | 7339 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7340 | return; |
| 7341 | } |
| 7342 | |
| 7343 | switch (insn->GetType()) { |
| 7344 | case Primitive::kPrimFloat: |
| 7345 | case Primitive::kPrimDouble: |
| 7346 | locations->SetOut(Location::RequiresFpuRegister()); |
| 7347 | break; |
| 7348 | |
| 7349 | case Primitive::kPrimInt: |
| 7350 | locations->SetOut(Location::RequiresRegister()); |
| 7351 | break; |
| 7352 | |
| 7353 | default: |
| 7354 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7355 | } |
| 7356 | } |
| 7357 | |
| 7358 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 7359 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7360 | return; |
| 7361 | } |
| 7362 | |
| 7363 | LocationSummary* locations = insn->GetLocations(); |
| 7364 | Location out = locations->Out(); |
| 7365 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 7366 | HConstant *value = insn->GetConstant(); |
| 7367 | |
| 7368 | switch (insn->GetType()) { |
| 7369 | case Primitive::kPrimFloat: |
| 7370 | __ movss(out.AsFpuRegister<XmmRegister>(), |
| 7371 | codegen_->LiteralFloatAddress(value->AsFloatConstant()->GetValue(), const_area)); |
| 7372 | break; |
| 7373 | |
| 7374 | case Primitive::kPrimDouble: |
| 7375 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
| 7376 | codegen_->LiteralDoubleAddress(value->AsDoubleConstant()->GetValue(), const_area)); |
| 7377 | break; |
| 7378 | |
| 7379 | case Primitive::kPrimInt: |
| 7380 | __ movl(out.AsRegister<Register>(), |
| 7381 | codegen_->LiteralInt32Address(value->AsIntConstant()->GetValue(), const_area)); |
| 7382 | break; |
| 7383 | |
| 7384 | default: |
| 7385 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7386 | } |
| 7387 | } |
| 7388 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7389 | /** |
| 7390 | * Class to handle late fixup of offsets into constant area. |
| 7391 | */ |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 7392 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7393 | public: |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7394 | RIPFixup(CodeGeneratorX86& codegen, size_t offset) |
| 7395 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 7396 | |
| 7397 | protected: |
| 7398 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 7399 | |
| 7400 | CodeGeneratorX86* codegen_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7401 | |
| 7402 | private: |
| 7403 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 7404 | // Patch the correct offset for the instruction. The place to patch is the |
| 7405 | // last 4 bytes of the instruction. |
| 7406 | // The value to patch is the distance from the offset in the constant area |
| 7407 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7408 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 7409 | int32_t relative_position = constant_offset - codegen_->GetMethodAddressOffset();; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7410 | |
| 7411 | // Patch in the right value. |
| 7412 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 7413 | } |
| 7414 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7415 | // Location in constant area that the fixup refers to. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7416 | int32_t offset_into_constant_area_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7417 | }; |
| 7418 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7419 | /** |
| 7420 | * Class to handle late fixup of offsets to a jump table that will be created in the |
| 7421 | * constant area. |
| 7422 | */ |
| 7423 | class JumpTableRIPFixup : public RIPFixup { |
| 7424 | public: |
| 7425 | JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) |
| 7426 | : RIPFixup(codegen, static_cast<size_t>(-1)), switch_instr_(switch_instr) {} |
| 7427 | |
| 7428 | void CreateJumpTable() { |
| 7429 | X86Assembler* assembler = codegen_->GetAssembler(); |
| 7430 | |
| 7431 | // Ensure that the reference to the jump table has the correct offset. |
| 7432 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 7433 | SetOffset(offset_in_constant_table); |
| 7434 | |
| 7435 | // The label values in the jump table are computed relative to the |
| 7436 | // instruction addressing the constant area. |
| 7437 | const int32_t relative_offset = codegen_->GetMethodAddressOffset(); |
| 7438 | |
| 7439 | // Populate the jump table with the correct values for the jump table. |
| 7440 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 7441 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 7442 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 7443 | // The value that we want is the target offset - the position of the table. |
| 7444 | for (int32_t i = 0; i < num_entries; i++) { |
| 7445 | HBasicBlock* b = successors[i]; |
| 7446 | Label* l = codegen_->GetLabelOf(b); |
| 7447 | DCHECK(l->IsBound()); |
| 7448 | int32_t offset_to_block = l->Position() - relative_offset; |
| 7449 | assembler->AppendInt32(offset_to_block); |
| 7450 | } |
| 7451 | } |
| 7452 | |
| 7453 | private: |
| 7454 | const HX86PackedSwitch* switch_instr_; |
| 7455 | }; |
| 7456 | |
| 7457 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 7458 | // Generate the constant area if needed. |
| 7459 | X86Assembler* assembler = GetAssembler(); |
| 7460 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7461 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 7462 | // byte values. |
| 7463 | assembler->Align(4, 0); |
| 7464 | constant_area_start_ = assembler->CodeSize(); |
| 7465 | |
| 7466 | // Populate any jump tables. |
| 7467 | for (auto jump_table : fixups_to_jump_tables_) { |
| 7468 | jump_table->CreateJumpTable(); |
| 7469 | } |
| 7470 | |
| 7471 | // And now add the constant area to the generated code. |
| 7472 | assembler->AddConstantArea(); |
| 7473 | } |
| 7474 | |
| 7475 | // And finish up. |
| 7476 | CodeGenerator::Finalize(allocator); |
| 7477 | } |
| 7478 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7479 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, Register reg) { |
| 7480 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 7481 | return Address(reg, kDummy32BitOffset, fixup); |
| 7482 | } |
| 7483 | |
| 7484 | Address CodeGeneratorX86::LiteralFloatAddress(float v, Register reg) { |
| 7485 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 7486 | return Address(reg, kDummy32BitOffset, fixup); |
| 7487 | } |
| 7488 | |
| 7489 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, Register reg) { |
| 7490 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 7491 | return Address(reg, kDummy32BitOffset, fixup); |
| 7492 | } |
| 7493 | |
| 7494 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, Register reg) { |
| 7495 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 7496 | return Address(reg, kDummy32BitOffset, fixup); |
| 7497 | } |
| 7498 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 7499 | void CodeGeneratorX86::Load32BitValue(Register dest, int32_t value) { |
| 7500 | if (value == 0) { |
| 7501 | __ xorl(dest, dest); |
| 7502 | } else { |
| 7503 | __ movl(dest, Immediate(value)); |
| 7504 | } |
| 7505 | } |
| 7506 | |
| 7507 | void CodeGeneratorX86::Compare32BitValue(Register dest, int32_t value) { |
| 7508 | if (value == 0) { |
| 7509 | __ testl(dest, dest); |
| 7510 | } else { |
| 7511 | __ cmpl(dest, Immediate(value)); |
| 7512 | } |
| 7513 | } |
| 7514 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7515 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, |
| 7516 | Register reg, |
| 7517 | Register value) { |
| 7518 | // Create a fixup to be used to create and address the jump table. |
| 7519 | JumpTableRIPFixup* table_fixup = |
| 7520 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 7521 | |
| 7522 | // We have to populate the jump tables. |
| 7523 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7524 | |
| 7525 | // We want a scaled address, as we are extracting the correct offset from the table. |
| 7526 | return Address(reg, value, TIMES_4, kDummy32BitOffset, table_fixup); |
| 7527 | } |
| 7528 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7529 | // TODO: target as memory. |
| 7530 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, Primitive::Type type) { |
| 7531 | if (!target.IsValid()) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7532 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7533 | return; |
| 7534 | } |
| 7535 | |
| 7536 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7537 | |
| 7538 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 7539 | if (target.Equals(return_loc)) { |
| 7540 | return; |
| 7541 | } |
| 7542 | |
| 7543 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 7544 | // with the else branch. |
| 7545 | if (type == Primitive::kPrimLong) { |
| 7546 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7547 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), Primitive::kPrimInt, nullptr); |
| 7548 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), Primitive::kPrimInt, nullptr); |
| 7549 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7550 | } else { |
| 7551 | // Let the parallel move resolver take care of all of this. |
| 7552 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7553 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 7554 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7555 | } |
| 7556 | } |
| 7557 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7558 | #undef __ |
| 7559 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7560 | } // namespace x86 |
| 7561 | } // namespace art |