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()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 87 | x86_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 88 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 89 | } |
| 90 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 91 | bool IsFatal() const OVERRIDE { return true; } |
| 92 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 93 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86"; } |
| 94 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 95 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 96 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86); |
| 97 | }; |
| 98 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 99 | class DivRemMinusOneSlowPathX86 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 100 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 101 | DivRemMinusOneSlowPathX86(HInstruction* instruction, Register reg, bool is_div) |
| 102 | : SlowPathCode(instruction), reg_(reg), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 103 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 104 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 105 | __ Bind(GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 106 | if (is_div_) { |
| 107 | __ negl(reg_); |
| 108 | } else { |
| 109 | __ movl(reg_, Immediate(0)); |
| 110 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 111 | __ jmp(GetExitLabel()); |
| 112 | } |
| 113 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 114 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86"; } |
| 115 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 116 | private: |
| 117 | Register reg_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 118 | bool is_div_; |
| 119 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 120 | }; |
| 121 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 122 | class BoundsCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 123 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 124 | explicit BoundsCheckSlowPathX86(HBoundsCheck* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 125 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 126 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 127 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 128 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 129 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 130 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 131 | // move resolver. |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 132 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 133 | // Live registers will be restored in the catch block if caught. |
| 134 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 135 | } |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 136 | |
| 137 | // Are we using an array length from memory? |
| 138 | HInstruction* array_length = instruction_->InputAt(1); |
| 139 | Location length_loc = locations->InAt(1); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 140 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 141 | if (array_length->IsArrayLength() && array_length->IsEmittedAtUseSite()) { |
| 142 | // Load the array length into our temporary. |
| 143 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 144 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 145 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
| 146 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(1)); |
| 147 | // Check for conflicts with index. |
| 148 | if (length_loc.Equals(locations->InAt(0))) { |
| 149 | // We know we aren't using parameter 2. |
| 150 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(2)); |
| 151 | } |
| 152 | __ movl(length_loc.AsRegister<Register>(), array_len); |
| 153 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 154 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 155 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 156 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 157 | Primitive::kPrimInt, |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 158 | length_loc, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 159 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 160 | Primitive::kPrimInt); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 161 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 162 | ? kQuickThrowStringBounds |
| 163 | : kQuickThrowArrayBounds; |
| 164 | x86_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 165 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 166 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 167 | } |
| 168 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 169 | bool IsFatal() const OVERRIDE { return true; } |
| 170 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 171 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86"; } |
| 172 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 173 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 174 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86); |
| 175 | }; |
| 176 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 177 | class SuspendCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 178 | public: |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 179 | SuspendCheckSlowPathX86(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 180 | : SlowPathCode(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 181 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 182 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 183 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 184 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 185 | x86_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 186 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 187 | if (successor_ == nullptr) { |
| 188 | __ jmp(GetReturnLabel()); |
| 189 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 190 | __ jmp(x86_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 191 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 192 | } |
| 193 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 194 | Label* GetReturnLabel() { |
| 195 | DCHECK(successor_ == nullptr); |
| 196 | return &return_label_; |
| 197 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 198 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 199 | HBasicBlock* GetSuccessor() const { |
| 200 | return successor_; |
| 201 | } |
| 202 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 203 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86"; } |
| 204 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 205 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 206 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 207 | Label return_label_; |
| 208 | |
| 209 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86); |
| 210 | }; |
| 211 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 212 | class LoadClassSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 213 | public: |
| 214 | LoadClassSlowPathX86(HLoadClass* cls, |
| 215 | HInstruction* at, |
| 216 | uint32_t dex_pc, |
| 217 | bool do_clinit) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 218 | : 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] | 219 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 220 | } |
| 221 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 222 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 223 | LocationSummary* locations = at_->GetLocations(); |
| 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 | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 227 | |
| 228 | InvokeRuntimeCallingConvention calling_convention; |
| 229 | __ movl(calling_convention.GetRegisterAt(0), Immediate(cls_->GetTypeIndex())); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 230 | x86_codegen->InvokeRuntime(do_clinit_ ? kQuickInitializeStaticStorage |
| 231 | : kQuickInitializeType, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 232 | at_, dex_pc_, this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 233 | if (do_clinit_) { |
| 234 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 235 | } else { |
| 236 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 237 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 238 | |
| 239 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 240 | Location out = locations->Out(); |
| 241 | if (out.IsValid()) { |
| 242 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 243 | x86_codegen->Move32(out, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 244 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 245 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 246 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 247 | __ jmp(GetExitLabel()); |
| 248 | } |
| 249 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 250 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86"; } |
| 251 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 252 | private: |
| 253 | // The class this slow path will load. |
| 254 | HLoadClass* const cls_; |
| 255 | |
| 256 | // The instruction where this slow path is happening. |
| 257 | // (Might be the load class or an initialization check). |
| 258 | HInstruction* const at_; |
| 259 | |
| 260 | // The dex PC of `at_`. |
| 261 | const uint32_t dex_pc_; |
| 262 | |
| 263 | // Whether to initialize the class. |
| 264 | const bool do_clinit_; |
| 265 | |
| 266 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86); |
| 267 | }; |
| 268 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 269 | class TypeCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 270 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 271 | TypeCheckSlowPathX86(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 272 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 273 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 274 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 275 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 276 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 277 | : locations->Out(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 278 | DCHECK(instruction_->IsCheckCast() |
| 279 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 280 | |
| 281 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 282 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 283 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 284 | if (!is_fatal_) { |
| 285 | SaveLiveRegisters(codegen, locations); |
| 286 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 287 | |
| 288 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 289 | // move resolver. |
| 290 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 291 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 292 | locations->InAt(1), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 293 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 294 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 295 | object_class, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 296 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 297 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 298 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 299 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 300 | x86_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 301 | instruction_, |
| 302 | instruction_->GetDexPc(), |
| 303 | this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 304 | CheckEntrypointTypes< |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 305 | kQuickInstanceofNonTrivial, size_t, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 306 | } else { |
| 307 | DCHECK(instruction_->IsCheckCast()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 308 | x86_codegen->InvokeRuntime(kQuickCheckCast, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 309 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 310 | } |
| 311 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 312 | if (!is_fatal_) { |
| 313 | if (instruction_->IsInstanceOf()) { |
| 314 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 315 | } |
| 316 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 317 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 318 | __ jmp(GetExitLabel()); |
| 319 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 320 | } |
| 321 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 322 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86"; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 323 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 324 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 325 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 326 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 327 | |
| 328 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86); |
| 329 | }; |
| 330 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 331 | class DeoptimizationSlowPathX86 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 332 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 333 | explicit DeoptimizationSlowPathX86(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 334 | : SlowPathCode(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 335 | |
| 336 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 337 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 338 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 339 | x86_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 340 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 341 | } |
| 342 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 343 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86"; } |
| 344 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 345 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 346 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86); |
| 347 | }; |
| 348 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 349 | class ArraySetSlowPathX86 : public SlowPathCode { |
| 350 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 351 | explicit ArraySetSlowPathX86(HInstruction* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 352 | |
| 353 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 354 | LocationSummary* locations = instruction_->GetLocations(); |
| 355 | __ Bind(GetEntryLabel()); |
| 356 | SaveLiveRegisters(codegen, locations); |
| 357 | |
| 358 | InvokeRuntimeCallingConvention calling_convention; |
| 359 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 360 | parallel_move.AddMove( |
| 361 | locations->InAt(0), |
| 362 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 363 | Primitive::kPrimNot, |
| 364 | nullptr); |
| 365 | parallel_move.AddMove( |
| 366 | locations->InAt(1), |
| 367 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 368 | Primitive::kPrimInt, |
| 369 | nullptr); |
| 370 | parallel_move.AddMove( |
| 371 | locations->InAt(2), |
| 372 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 373 | Primitive::kPrimNot, |
| 374 | nullptr); |
| 375 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 376 | |
| 377 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 378 | x86_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 379 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 380 | RestoreLiveRegisters(codegen, locations); |
| 381 | __ jmp(GetExitLabel()); |
| 382 | } |
| 383 | |
| 384 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86"; } |
| 385 | |
| 386 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 387 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86); |
| 388 | }; |
| 389 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 390 | // Slow path marking an object during a read barrier. |
| 391 | class ReadBarrierMarkSlowPathX86 : public SlowPathCode { |
| 392 | public: |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 393 | ReadBarrierMarkSlowPathX86(HInstruction* instruction, Location obj, bool unpoison) |
| 394 | : SlowPathCode(instruction), obj_(obj), unpoison_(unpoison) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 395 | DCHECK(kEmitCompilerReadBarrier); |
| 396 | } |
| 397 | |
| 398 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathX86"; } |
| 399 | |
| 400 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 401 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 402 | Register reg = obj_.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 403 | DCHECK(locations->CanCall()); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 404 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 405 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 406 | instruction_->IsStaticFieldGet() || |
| 407 | instruction_->IsArrayGet() || |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 408 | instruction_->IsArraySet() || |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 409 | instruction_->IsLoadClass() || |
| 410 | instruction_->IsLoadString() || |
| 411 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 412 | instruction_->IsCheckCast() || |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 413 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 414 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 415 | << "Unexpected instruction in read barrier marking slow path: " |
| 416 | << instruction_->DebugName(); |
| 417 | |
| 418 | __ Bind(GetEntryLabel()); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 419 | if (unpoison_) { |
| 420 | // Object* ref = ref_addr->AsMirrorPtr() |
| 421 | __ MaybeUnpoisonHeapReference(reg); |
| 422 | } |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 423 | // No need to save live registers; it's taken care of by the |
| 424 | // entrypoint. Also, there is no need to update the stack mask, |
| 425 | // as this runtime call will not trigger a garbage collection. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 426 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 427 | DCHECK_NE(reg, ESP); |
| 428 | DCHECK(0 <= reg && reg < kNumberOfCpuRegisters) << reg; |
| 429 | // "Compact" slow path, saving two moves. |
| 430 | // |
| 431 | // Instead of using the standard runtime calling convention (input |
| 432 | // and output in EAX): |
| 433 | // |
| 434 | // EAX <- obj |
| 435 | // EAX <- ReadBarrierMark(EAX) |
| 436 | // obj <- EAX |
| 437 | // |
| 438 | // we just use rX (the register holding `obj`) as input and output |
| 439 | // of a dedicated entrypoint: |
| 440 | // |
| 441 | // rX <- ReadBarrierMarkRegX(rX) |
| 442 | // |
| 443 | int32_t entry_point_offset = |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 444 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kX86PointerSize>(reg); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 445 | // This runtime call does not require a stack map. |
| 446 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 447 | __ jmp(GetExitLabel()); |
| 448 | } |
| 449 | |
| 450 | private: |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 451 | const Location obj_; |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 452 | const bool unpoison_; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 453 | |
| 454 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86); |
| 455 | }; |
| 456 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 457 | // Slow path generating a read barrier for a heap reference. |
| 458 | class ReadBarrierForHeapReferenceSlowPathX86 : public SlowPathCode { |
| 459 | public: |
| 460 | ReadBarrierForHeapReferenceSlowPathX86(HInstruction* instruction, |
| 461 | Location out, |
| 462 | Location ref, |
| 463 | Location obj, |
| 464 | uint32_t offset, |
| 465 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 466 | : SlowPathCode(instruction), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 467 | out_(out), |
| 468 | ref_(ref), |
| 469 | obj_(obj), |
| 470 | offset_(offset), |
| 471 | index_(index) { |
| 472 | DCHECK(kEmitCompilerReadBarrier); |
| 473 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 474 | // has been overwritten by (or after) the heap object reference load |
| 475 | // to be instrumented, e.g.: |
| 476 | // |
| 477 | // __ movl(out, Address(out, offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 478 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 479 | // |
| 480 | // In that case, we have lost the information about the original |
| 481 | // object, and the emitted read barrier cannot work properly. |
| 482 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 483 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 484 | } |
| 485 | |
| 486 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 487 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 488 | LocationSummary* locations = instruction_->GetLocations(); |
| 489 | Register reg_out = out_.AsRegister<Register>(); |
| 490 | DCHECK(locations->CanCall()); |
| 491 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 492 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 493 | instruction_->IsStaticFieldGet() || |
| 494 | instruction_->IsArrayGet() || |
| 495 | instruction_->IsInstanceOf() || |
| 496 | instruction_->IsCheckCast() || |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 497 | (instruction_->IsInvokeVirtual()) && instruction_->GetLocations()->Intrinsified()) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 498 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 499 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 500 | |
| 501 | __ Bind(GetEntryLabel()); |
| 502 | SaveLiveRegisters(codegen, locations); |
| 503 | |
| 504 | // We may have to change the index's value, but as `index_` is a |
| 505 | // constant member (like other "inputs" of this slow path), |
| 506 | // introduce a copy of it, `index`. |
| 507 | Location index = index_; |
| 508 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 509 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 510 | if (instruction_->IsArrayGet()) { |
| 511 | // Compute the actual memory offset and store it in `index`. |
| 512 | Register index_reg = index_.AsRegister<Register>(); |
| 513 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 514 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 515 | // We are about to change the value of `index_reg` (see the |
| 516 | // calls to art::x86::X86Assembler::shll and |
| 517 | // art::x86::X86Assembler::AddImmediate below), but it has |
| 518 | // not been saved by the previous call to |
| 519 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 520 | // callee-save register -- |
| 521 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 522 | // callee-save registers, as it has been designed with the |
| 523 | // assumption that callee-save registers are supposed to be |
| 524 | // handled by the called function. So, as a callee-save |
| 525 | // register, `index_reg` _would_ eventually be saved onto |
| 526 | // the stack, but it would be too late: we would have |
| 527 | // changed its value earlier. Therefore, we manually save |
| 528 | // it here into another freely available register, |
| 529 | // `free_reg`, chosen of course among the caller-save |
| 530 | // registers (as a callee-save `free_reg` register would |
| 531 | // exhibit the same problem). |
| 532 | // |
| 533 | // Note we could have requested a temporary register from |
| 534 | // the register allocator instead; but we prefer not to, as |
| 535 | // this is a slow path, and we know we can find a |
| 536 | // caller-save register that is available. |
| 537 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 538 | __ movl(free_reg, index_reg); |
| 539 | index_reg = free_reg; |
| 540 | index = Location::RegisterLocation(index_reg); |
| 541 | } else { |
| 542 | // The initial register stored in `index_` has already been |
| 543 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 544 | // (as it is not a callee-save register), so we can freely |
| 545 | // use it. |
| 546 | } |
| 547 | // Shifting the index value contained in `index_reg` by the scale |
| 548 | // factor (2) cannot overflow in practice, as the runtime is |
| 549 | // unable to allocate object arrays with a size larger than |
| 550 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 551 | __ shll(index_reg, Immediate(TIMES_4)); |
| 552 | static_assert( |
| 553 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 554 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 555 | __ AddImmediate(index_reg, Immediate(offset_)); |
| 556 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 557 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 558 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 559 | // (as in the case of ArrayGet), as it is actually an offset |
| 560 | // to an object field within an object. |
| 561 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 562 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 563 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 564 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 565 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 566 | DCHECK_EQ(offset_, 0U); |
| 567 | DCHECK(index_.IsRegisterPair()); |
| 568 | // UnsafeGet's offset location is a register pair, the low |
| 569 | // part contains the correct offset. |
| 570 | index = index_.ToLow(); |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | // We're moving two or three locations to locations that could |
| 575 | // overlap, so we need a parallel move resolver. |
| 576 | InvokeRuntimeCallingConvention calling_convention; |
| 577 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 578 | parallel_move.AddMove(ref_, |
| 579 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 580 | Primitive::kPrimNot, |
| 581 | nullptr); |
| 582 | parallel_move.AddMove(obj_, |
| 583 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 584 | Primitive::kPrimNot, |
| 585 | nullptr); |
| 586 | if (index.IsValid()) { |
| 587 | parallel_move.AddMove(index, |
| 588 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 589 | Primitive::kPrimInt, |
| 590 | nullptr); |
| 591 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 592 | } else { |
| 593 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 594 | __ movl(calling_convention.GetRegisterAt(2), Immediate(offset_)); |
| 595 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 596 | x86_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 597 | CheckEntrypointTypes< |
| 598 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 599 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 600 | |
| 601 | RestoreLiveRegisters(codegen, locations); |
| 602 | __ jmp(GetExitLabel()); |
| 603 | } |
| 604 | |
| 605 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathX86"; } |
| 606 | |
| 607 | private: |
| 608 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 609 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 610 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 611 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 612 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 613 | return static_cast<Register>(i); |
| 614 | } |
| 615 | } |
| 616 | // We shall never fail to find a free caller-save register, as |
| 617 | // there are more than two core caller-save registers on x86 |
| 618 | // (meaning it is possible to find one which is different from |
| 619 | // `ref` and `obj`). |
| 620 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 621 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 622 | UNREACHABLE(); |
| 623 | } |
| 624 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 625 | const Location out_; |
| 626 | const Location ref_; |
| 627 | const Location obj_; |
| 628 | const uint32_t offset_; |
| 629 | // An additional location containing an index to an array. |
| 630 | // Only used for HArrayGet and the UnsafeGetObject & |
| 631 | // UnsafeGetObjectVolatile intrinsics. |
| 632 | const Location index_; |
| 633 | |
| 634 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86); |
| 635 | }; |
| 636 | |
| 637 | // Slow path generating a read barrier for a GC root. |
| 638 | class ReadBarrierForRootSlowPathX86 : public SlowPathCode { |
| 639 | public: |
| 640 | ReadBarrierForRootSlowPathX86(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 641 | : SlowPathCode(instruction), out_(out), root_(root) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 642 | DCHECK(kEmitCompilerReadBarrier); |
| 643 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 644 | |
| 645 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 646 | LocationSummary* locations = instruction_->GetLocations(); |
| 647 | Register reg_out = out_.AsRegister<Register>(); |
| 648 | DCHECK(locations->CanCall()); |
| 649 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 650 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 651 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 652 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 653 | |
| 654 | __ Bind(GetEntryLabel()); |
| 655 | SaveLiveRegisters(codegen, locations); |
| 656 | |
| 657 | InvokeRuntimeCallingConvention calling_convention; |
| 658 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 659 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 660 | x86_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 661 | instruction_, |
| 662 | instruction_->GetDexPc(), |
| 663 | this); |
| 664 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 665 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 666 | |
| 667 | RestoreLiveRegisters(codegen, locations); |
| 668 | __ jmp(GetExitLabel()); |
| 669 | } |
| 670 | |
| 671 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathX86"; } |
| 672 | |
| 673 | private: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 674 | const Location out_; |
| 675 | const Location root_; |
| 676 | |
| 677 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86); |
| 678 | }; |
| 679 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 680 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 681 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 682 | #define __ down_cast<X86Assembler*>(GetAssembler())-> // NOLINT |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 683 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 684 | inline Condition X86Condition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 685 | switch (cond) { |
| 686 | case kCondEQ: return kEqual; |
| 687 | case kCondNE: return kNotEqual; |
| 688 | case kCondLT: return kLess; |
| 689 | case kCondLE: return kLessEqual; |
| 690 | case kCondGT: return kGreater; |
| 691 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 692 | case kCondB: return kBelow; |
| 693 | case kCondBE: return kBelowEqual; |
| 694 | case kCondA: return kAbove; |
| 695 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 696 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 697 | LOG(FATAL) << "Unreachable"; |
| 698 | UNREACHABLE(); |
| 699 | } |
| 700 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 701 | // Maps signed condition to unsigned condition and FP condition to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 702 | inline Condition X86UnsignedOrFPCondition(IfCondition cond) { |
| 703 | switch (cond) { |
| 704 | case kCondEQ: return kEqual; |
| 705 | case kCondNE: return kNotEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 706 | // Signed to unsigned, and FP to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 707 | case kCondLT: return kBelow; |
| 708 | case kCondLE: return kBelowEqual; |
| 709 | case kCondGT: return kAbove; |
| 710 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 711 | // Unsigned remain unchanged. |
| 712 | case kCondB: return kBelow; |
| 713 | case kCondBE: return kBelowEqual; |
| 714 | case kCondA: return kAbove; |
| 715 | case kCondAE: return kAboveEqual; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 716 | } |
| 717 | LOG(FATAL) << "Unreachable"; |
| 718 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 719 | } |
| 720 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 721 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 722 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 726 | stream << XmmRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 727 | } |
| 728 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 729 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 730 | __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); |
| 731 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 732 | } |
| 733 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 734 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 735 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); |
| 736 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 737 | } |
| 738 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 739 | size_t CodeGeneratorX86::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 740 | __ movsd(Address(ESP, stack_index), XmmRegister(reg_id)); |
| 741 | return GetFloatingPointSpillSlotSize(); |
| 742 | } |
| 743 | |
| 744 | size_t CodeGeneratorX86::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 745 | __ movsd(XmmRegister(reg_id), Address(ESP, stack_index)); |
| 746 | return GetFloatingPointSpillSlotSize(); |
| 747 | } |
| 748 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 749 | void CodeGeneratorX86::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 750 | HInstruction* instruction, |
| 751 | uint32_t dex_pc, |
| 752 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 753 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 754 | GenerateInvokeRuntime(GetThreadOffset<kX86PointerSize>(entrypoint).Int32Value()); |
| 755 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 756 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 757 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 758 | } |
| 759 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 760 | void CodeGeneratorX86::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 761 | HInstruction* instruction, |
| 762 | SlowPathCode* slow_path) { |
| 763 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 764 | GenerateInvokeRuntime(entry_point_offset); |
| 765 | } |
| 766 | |
| 767 | void CodeGeneratorX86::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 768 | __ fs()->call(Address::Absolute(entry_point_offset)); |
| 769 | } |
| 770 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 771 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 772 | const X86InstructionSetFeatures& isa_features, |
| 773 | const CompilerOptions& compiler_options, |
| 774 | OptimizingCompilerStats* stats) |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 775 | : CodeGenerator(graph, |
| 776 | kNumberOfCpuRegisters, |
| 777 | kNumberOfXmmRegisters, |
| 778 | kNumberOfRegisterPairs, |
| 779 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 780 | arraysize(kCoreCalleeSaves)) |
| 781 | | (1 << kFakeReturnRegister), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 782 | 0, |
| 783 | compiler_options, |
| 784 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 785 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 786 | location_builder_(graph, this), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 787 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 788 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 789 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 790 | isa_features_(isa_features), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 791 | method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 792 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 793 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 794 | simple_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 795 | string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 796 | type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 797 | constant_area_start_(-1), |
| 798 | fixups_to_jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 799 | method_address_offset_(-1) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 800 | // Use a fake return address register to mimic Quick. |
| 801 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 802 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 803 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 804 | void CodeGeneratorX86::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 805 | // Don't allocate the dalvik style register pair passing. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 806 | blocked_register_pairs_[ECX_EDX] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 807 | |
| 808 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 809 | blocked_core_registers_[ESP] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 810 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 811 | UpdateBlockedPairRegisters(); |
| 812 | } |
| 813 | |
| 814 | void CodeGeneratorX86::UpdateBlockedPairRegisters() const { |
| 815 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 816 | X86ManagedRegister current = |
| 817 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 818 | if (blocked_core_registers_[current.AsRegisterPairLow()] |
| 819 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { |
| 820 | blocked_register_pairs_[i] = true; |
| 821 | } |
| 822 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 823 | } |
| 824 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 825 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 826 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 827 | assembler_(codegen->GetAssembler()), |
| 828 | codegen_(codegen) {} |
| 829 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 830 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 831 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 832 | } |
| 833 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 834 | void CodeGeneratorX86::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 835 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 836 | __ Bind(&frame_entry_label_); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 837 | bool skip_overflow_check = |
| 838 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 839 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 840 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 841 | if (!skip_overflow_check) { |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 842 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 843 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 844 | } |
| 845 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 846 | if (HasEmptyFrame()) { |
| 847 | return; |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 848 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 849 | |
| 850 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 851 | Register reg = kCoreCalleeSaves[i]; |
| 852 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 853 | __ pushl(reg); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 854 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 855 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 856 | } |
| 857 | } |
| 858 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 859 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 860 | __ subl(ESP, Immediate(adjust)); |
| 861 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 862 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | void CodeGeneratorX86::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 866 | __ cfi().RememberState(); |
| 867 | if (!HasEmptyFrame()) { |
| 868 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 869 | __ addl(ESP, Immediate(adjust)); |
| 870 | __ cfi().AdjustCFAOffset(-adjust); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 871 | |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 872 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 873 | Register reg = kCoreCalleeSaves[i]; |
| 874 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 875 | __ popl(reg); |
| 876 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 877 | __ cfi().Restore(DWARFReg(reg)); |
| 878 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 879 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 880 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 881 | __ ret(); |
| 882 | __ cfi().RestoreState(); |
| 883 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 884 | } |
| 885 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 886 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 887 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 888 | } |
| 889 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 890 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(Primitive::Type type) const { |
| 891 | switch (type) { |
| 892 | case Primitive::kPrimBoolean: |
| 893 | case Primitive::kPrimByte: |
| 894 | case Primitive::kPrimChar: |
| 895 | case Primitive::kPrimShort: |
| 896 | case Primitive::kPrimInt: |
| 897 | case Primitive::kPrimNot: |
| 898 | return Location::RegisterLocation(EAX); |
| 899 | |
| 900 | case Primitive::kPrimLong: |
| 901 | return Location::RegisterPairLocation(EAX, EDX); |
| 902 | |
| 903 | case Primitive::kPrimVoid: |
| 904 | return Location::NoLocation(); |
| 905 | |
| 906 | case Primitive::kPrimDouble: |
| 907 | case Primitive::kPrimFloat: |
| 908 | return Location::FpuRegisterLocation(XMM0); |
| 909 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 910 | |
| 911 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 912 | } |
| 913 | |
| 914 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 915 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 916 | } |
| 917 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 918 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 919 | switch (type) { |
| 920 | case Primitive::kPrimBoolean: |
| 921 | case Primitive::kPrimByte: |
| 922 | case Primitive::kPrimChar: |
| 923 | case Primitive::kPrimShort: |
| 924 | case Primitive::kPrimInt: |
| 925 | case Primitive::kPrimNot: { |
| 926 | uint32_t index = gp_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 927 | stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 928 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 929 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 930 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 931 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 932 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 933 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 934 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 935 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 936 | uint32_t index = gp_index_; |
| 937 | gp_index_ += 2; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 938 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 939 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 940 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 941 | calling_convention.GetRegisterPairAt(index)); |
| 942 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 943 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 944 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 945 | } |
| 946 | } |
| 947 | |
| 948 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 949 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 950 | stack_index_++; |
| 951 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 952 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 953 | } else { |
| 954 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 955 | } |
| 956 | } |
| 957 | |
| 958 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 959 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 960 | stack_index_ += 2; |
| 961 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 962 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 963 | } else { |
| 964 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 965 | } |
| 966 | } |
| 967 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 968 | case Primitive::kPrimVoid: |
| 969 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 970 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 971 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 972 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 973 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 974 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 975 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 976 | if (source.Equals(destination)) { |
| 977 | return; |
| 978 | } |
| 979 | if (destination.IsRegister()) { |
| 980 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 981 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 982 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 983 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 984 | } else { |
| 985 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 986 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 987 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 988 | } else if (destination.IsFpuRegister()) { |
| 989 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 990 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 991 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 992 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 993 | } else { |
| 994 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 995 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 996 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 997 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 998 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 999 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1000 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1001 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1002 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1003 | } else if (source.IsConstant()) { |
| 1004 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1005 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1006 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1007 | } else { |
| 1008 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1009 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 1010 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1011 | } |
| 1012 | } |
| 1013 | } |
| 1014 | |
| 1015 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 1016 | if (source.Equals(destination)) { |
| 1017 | return; |
| 1018 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1019 | if (destination.IsRegisterPair()) { |
| 1020 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1021 | EmitParallelMoves( |
| 1022 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1023 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1024 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1025 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1026 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 1027 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1028 | } else if (source.IsFpuRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1029 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 1030 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 1031 | __ psrlq(src_reg, Immediate(32)); |
| 1032 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1033 | } else { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1034 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1035 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1036 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 1037 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1038 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 1039 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1040 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1041 | if (source.IsFpuRegister()) { |
| 1042 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 1043 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1044 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1045 | } else if (source.IsRegisterPair()) { |
| 1046 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 1047 | // Create stack space for 2 elements. |
| 1048 | __ subl(ESP, Immediate(2 * elem_size)); |
| 1049 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 1050 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 1051 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 1052 | // And remove the temporary stack space we allocated. |
| 1053 | __ addl(ESP, Immediate(2 * elem_size)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1054 | } else { |
| 1055 | LOG(FATAL) << "Unimplemented"; |
| 1056 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1057 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1058 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1059 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1060 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1061 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1062 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1063 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1064 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1065 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1066 | } else if (source.IsConstant()) { |
| 1067 | HConstant* constant = source.GetConstant(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1068 | DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant()); |
| 1069 | int64_t value = GetInt64ValueOf(constant); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1070 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1071 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
| 1072 | Immediate(High32Bits(value))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1073 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1074 | DCHECK(source.IsDoubleStackSlot()) << source; |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1075 | EmitParallelMoves( |
| 1076 | Location::StackSlot(source.GetStackIndex()), |
| 1077 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1078 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1079 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1080 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
| 1081 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1082 | } |
| 1083 | } |
| 1084 | } |
| 1085 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1086 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { |
| 1087 | DCHECK(location.IsRegister()); |
| 1088 | __ movl(location.AsRegister<Register>(), Immediate(value)); |
| 1089 | } |
| 1090 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1091 | void CodeGeneratorX86::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1092 | HParallelMove move(GetGraph()->GetArena()); |
| 1093 | if (dst_type == Primitive::kPrimLong && !src.IsConstant() && !src.IsFpuRegister()) { |
| 1094 | move.AddMove(src.ToLow(), dst.ToLow(), Primitive::kPrimInt, nullptr); |
| 1095 | move.AddMove(src.ToHigh(), dst.ToHigh(), Primitive::kPrimInt, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1096 | } else { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1097 | move.AddMove(src, dst, dst_type, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1098 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1099 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1100 | } |
| 1101 | |
| 1102 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1103 | if (location.IsRegister()) { |
| 1104 | locations->AddTemp(location); |
| 1105 | } else if (location.IsRegisterPair()) { |
| 1106 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1107 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1108 | } else { |
| 1109 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1110 | } |
| 1111 | } |
| 1112 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1113 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1114 | DCHECK(!successor->IsExitBlock()); |
| 1115 | |
| 1116 | HBasicBlock* block = got->GetBlock(); |
| 1117 | HInstruction* previous = got->GetPrevious(); |
| 1118 | |
| 1119 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1120 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1121 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1122 | return; |
| 1123 | } |
| 1124 | |
| 1125 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1126 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1127 | } |
| 1128 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1129 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1130 | } |
| 1131 | } |
| 1132 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1133 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 1134 | got->SetLocations(nullptr); |
| 1135 | } |
| 1136 | |
| 1137 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 1138 | HandleGoto(got, got->GetSuccessor()); |
| 1139 | } |
| 1140 | |
| 1141 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1142 | try_boundary->SetLocations(nullptr); |
| 1143 | } |
| 1144 | |
| 1145 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1146 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1147 | if (!successor->IsExitBlock()) { |
| 1148 | HandleGoto(try_boundary, successor); |
| 1149 | } |
| 1150 | } |
| 1151 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1152 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1153 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1154 | } |
| 1155 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1156 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1157 | } |
| 1158 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1159 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1160 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1161 | LabelType* true_label, |
| 1162 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1163 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1164 | __ j(kUnordered, true_label); |
| 1165 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1166 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1167 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1168 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1169 | } |
| 1170 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1171 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1172 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1173 | LabelType* true_label, |
| 1174 | LabelType* false_label) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1175 | LocationSummary* locations = cond->GetLocations(); |
| 1176 | Location left = locations->InAt(0); |
| 1177 | Location right = locations->InAt(1); |
| 1178 | IfCondition if_cond = cond->GetCondition(); |
| 1179 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1180 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1181 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1182 | IfCondition true_high_cond = if_cond; |
| 1183 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1184 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); // unsigned on lower part |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1185 | |
| 1186 | // Set the conditions for the test, remembering that == needs to be |
| 1187 | // decided using the low words. |
| 1188 | switch (if_cond) { |
| 1189 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1190 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1191 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1192 | break; |
| 1193 | case kCondLT: |
| 1194 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1195 | break; |
| 1196 | case kCondLE: |
| 1197 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1198 | break; |
| 1199 | case kCondGT: |
| 1200 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1201 | break; |
| 1202 | case kCondGE: |
| 1203 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1204 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1205 | case kCondB: |
| 1206 | false_high_cond = kCondA; |
| 1207 | break; |
| 1208 | case kCondBE: |
| 1209 | true_high_cond = kCondB; |
| 1210 | break; |
| 1211 | case kCondA: |
| 1212 | false_high_cond = kCondB; |
| 1213 | break; |
| 1214 | case kCondAE: |
| 1215 | true_high_cond = kCondA; |
| 1216 | break; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1217 | } |
| 1218 | |
| 1219 | if (right.IsConstant()) { |
| 1220 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1221 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1222 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1223 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1224 | codegen_->Compare32BitValue(left_high, val_high); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1225 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1226 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1227 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1228 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1229 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1230 | __ j(X86Condition(true_high_cond), true_label); |
| 1231 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1232 | } |
| 1233 | // Must be equal high, so compare the lows. |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1234 | codegen_->Compare32BitValue(left_low, val_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1235 | } else if (right.IsRegisterPair()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1236 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1237 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1238 | |
| 1239 | __ cmpl(left_high, right_high); |
| 1240 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1241 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1242 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1243 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1244 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1245 | __ j(X86Condition(true_high_cond), true_label); |
| 1246 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1247 | } |
| 1248 | // Must be equal high, so compare the lows. |
| 1249 | __ cmpl(left_low, right_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1250 | } else { |
| 1251 | DCHECK(right.IsDoubleStackSlot()); |
| 1252 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
| 1253 | if (if_cond == kCondNE) { |
| 1254 | __ j(X86Condition(true_high_cond), true_label); |
| 1255 | } else if (if_cond == kCondEQ) { |
| 1256 | __ j(X86Condition(false_high_cond), false_label); |
| 1257 | } else { |
| 1258 | __ j(X86Condition(true_high_cond), true_label); |
| 1259 | __ j(X86Condition(false_high_cond), false_label); |
| 1260 | } |
| 1261 | // Must be equal high, so compare the lows. |
| 1262 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1263 | } |
| 1264 | // The last comparison might be unsigned. |
| 1265 | __ j(final_condition, true_label); |
| 1266 | } |
| 1267 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1268 | void InstructionCodeGeneratorX86::GenerateFPCompare(Location lhs, |
| 1269 | Location rhs, |
| 1270 | HInstruction* insn, |
| 1271 | bool is_double) { |
| 1272 | HX86LoadFromConstantTable* const_area = insn->InputAt(1)->AsX86LoadFromConstantTable(); |
| 1273 | if (is_double) { |
| 1274 | if (rhs.IsFpuRegister()) { |
| 1275 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1276 | } else if (const_area != nullptr) { |
| 1277 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1278 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), |
| 1279 | codegen_->LiteralDoubleAddress( |
| 1280 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 1281 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 1282 | } else { |
| 1283 | DCHECK(rhs.IsDoubleStackSlot()); |
| 1284 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1285 | } |
| 1286 | } else { |
| 1287 | if (rhs.IsFpuRegister()) { |
| 1288 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1289 | } else if (const_area != nullptr) { |
| 1290 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1291 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), |
| 1292 | codegen_->LiteralFloatAddress( |
| 1293 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 1294 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 1295 | } else { |
| 1296 | DCHECK(rhs.IsStackSlot()); |
| 1297 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1298 | } |
| 1299 | } |
| 1300 | } |
| 1301 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1302 | template<class LabelType> |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1303 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1304 | LabelType* true_target_in, |
| 1305 | LabelType* false_target_in) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1306 | // Generated branching requires both targets to be explicit. If either of the |
| 1307 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1308 | LabelType fallthrough_target; |
| 1309 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1310 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1311 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1312 | LocationSummary* locations = condition->GetLocations(); |
| 1313 | Location left = locations->InAt(0); |
| 1314 | Location right = locations->InAt(1); |
| 1315 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1316 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1317 | switch (type) { |
| 1318 | case Primitive::kPrimLong: |
| 1319 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1320 | break; |
| 1321 | case Primitive::kPrimFloat: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1322 | GenerateFPCompare(left, right, condition, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1323 | GenerateFPJumps(condition, true_target, false_target); |
| 1324 | break; |
| 1325 | case Primitive::kPrimDouble: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1326 | GenerateFPCompare(left, right, condition, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1327 | GenerateFPJumps(condition, true_target, false_target); |
| 1328 | break; |
| 1329 | default: |
| 1330 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1331 | } |
| 1332 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1333 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1334 | __ jmp(false_target); |
| 1335 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1336 | |
| 1337 | if (fallthrough_target.IsLinked()) { |
| 1338 | __ Bind(&fallthrough_target); |
| 1339 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1340 | } |
| 1341 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1342 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1343 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1344 | // are set only strictly before `branch`. We can't use the eflags on long/FP |
| 1345 | // conditions if they are materialized due to the complex branching. |
| 1346 | return cond->IsCondition() && |
| 1347 | cond->GetNext() == branch && |
| 1348 | cond->InputAt(0)->GetType() != Primitive::kPrimLong && |
| 1349 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1350 | } |
| 1351 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1352 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1353 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1354 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1355 | LabelType* true_target, |
| 1356 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1357 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1358 | |
| 1359 | if (true_target == nullptr && false_target == nullptr) { |
| 1360 | // Nothing to do. The code always falls through. |
| 1361 | return; |
| 1362 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1363 | // Constant condition, statically compared against "true" (integer value 1). |
| 1364 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1365 | if (true_target != nullptr) { |
| 1366 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1367 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1368 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1369 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1370 | if (false_target != nullptr) { |
| 1371 | __ jmp(false_target); |
| 1372 | } |
| 1373 | } |
| 1374 | return; |
| 1375 | } |
| 1376 | |
| 1377 | // The following code generates these patterns: |
| 1378 | // (1) true_target == nullptr && false_target != nullptr |
| 1379 | // - opposite condition true => branch to false_target |
| 1380 | // (2) true_target != nullptr && false_target == nullptr |
| 1381 | // - condition true => branch to true_target |
| 1382 | // (3) true_target != nullptr && false_target != nullptr |
| 1383 | // - condition true => branch to true_target |
| 1384 | // - branch to false_target |
| 1385 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1386 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1387 | if (true_target == nullptr) { |
| 1388 | __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1389 | } else { |
| 1390 | __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); |
| 1391 | } |
| 1392 | } else { |
| 1393 | // Materialized condition, compare against 0. |
| 1394 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1395 | if (lhs.IsRegister()) { |
| 1396 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1397 | } else { |
| 1398 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1399 | } |
| 1400 | if (true_target == nullptr) { |
| 1401 | __ j(kEqual, false_target); |
| 1402 | } else { |
| 1403 | __ j(kNotEqual, true_target); |
| 1404 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1405 | } |
| 1406 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1407 | // Condition has not been materialized, use its inputs as the comparison and |
| 1408 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1409 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1410 | |
| 1411 | // If this is a long or FP comparison that has been folded into |
| 1412 | // the HCondition, generate the comparison directly. |
| 1413 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1414 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1415 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1416 | return; |
| 1417 | } |
| 1418 | |
| 1419 | Location lhs = condition->GetLocations()->InAt(0); |
| 1420 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1421 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition). |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1422 | codegen_->GenerateIntCompare(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1423 | if (true_target == nullptr) { |
| 1424 | __ j(X86Condition(condition->GetOppositeCondition()), false_target); |
| 1425 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1426 | __ j(X86Condition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1427 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1428 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1429 | |
| 1430 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1431 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1432 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1433 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1434 | } |
| 1435 | } |
| 1436 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1437 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1438 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1439 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1440 | locations->SetInAt(0, Location::Any()); |
| 1441 | } |
| 1442 | } |
| 1443 | |
| 1444 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1445 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1446 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1447 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1448 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1449 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1450 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1451 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1452 | } |
| 1453 | |
| 1454 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1455 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1456 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 1457 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1458 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1459 | locations->SetInAt(0, Location::Any()); |
| 1460 | } |
| 1461 | } |
| 1462 | |
| 1463 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1464 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1465 | GenerateTestAndBranch<Label>(deoptimize, |
| 1466 | /* condition_input_index */ 0, |
| 1467 | slow_path->GetEntryLabel(), |
| 1468 | /* false_target */ nullptr); |
| 1469 | } |
| 1470 | |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1471 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1472 | // There are no conditional move instructions for XMMs. |
| 1473 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1474 | return false; |
| 1475 | } |
| 1476 | |
| 1477 | // A FP condition doesn't generate the single CC that we need. |
| 1478 | // In 32 bit mode, a long condition doesn't generate a single CC either. |
| 1479 | HInstruction* condition = select->GetCondition(); |
| 1480 | if (condition->IsCondition()) { |
| 1481 | Primitive::Type compare_type = condition->InputAt(0)->GetType(); |
| 1482 | if (compare_type == Primitive::kPrimLong || |
| 1483 | Primitive::IsFloatingPointType(compare_type)) { |
| 1484 | return false; |
| 1485 | } |
| 1486 | } |
| 1487 | |
| 1488 | // We can generate a CMOV for this Select. |
| 1489 | return true; |
| 1490 | } |
| 1491 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1492 | void LocationsBuilderX86::VisitSelect(HSelect* select) { |
| 1493 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1494 | if (Primitive::IsFloatingPointType(select->GetType())) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1495 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1496 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1497 | } else { |
| 1498 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1499 | if (SelectCanUseCMOV(select)) { |
| 1500 | if (select->InputAt(1)->IsConstant()) { |
| 1501 | // Cmov can't handle a constant value. |
| 1502 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1503 | } else { |
| 1504 | locations->SetInAt(1, Location::Any()); |
| 1505 | } |
| 1506 | } else { |
| 1507 | locations->SetInAt(1, Location::Any()); |
| 1508 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1509 | } |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1510 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1511 | locations->SetInAt(2, Location::RequiresRegister()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1512 | } |
| 1513 | locations->SetOut(Location::SameAsFirstInput()); |
| 1514 | } |
| 1515 | |
| 1516 | void InstructionCodeGeneratorX86::VisitSelect(HSelect* select) { |
| 1517 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1518 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1519 | if (SelectCanUseCMOV(select)) { |
| 1520 | // If both the condition and the source types are integer, we can generate |
| 1521 | // a CMOV to implement Select. |
| 1522 | |
| 1523 | HInstruction* select_condition = select->GetCondition(); |
| 1524 | Condition cond = kNotEqual; |
| 1525 | |
| 1526 | // Figure out how to test the 'condition'. |
| 1527 | if (select_condition->IsCondition()) { |
| 1528 | HCondition* condition = select_condition->AsCondition(); |
| 1529 | if (!condition->IsEmittedAtUseSite()) { |
| 1530 | // This was a previously materialized condition. |
| 1531 | // Can we use the existing condition code? |
| 1532 | if (AreEflagsSetFrom(condition, select)) { |
| 1533 | // Materialization was the previous instruction. Condition codes are right. |
| 1534 | cond = X86Condition(condition->GetCondition()); |
| 1535 | } else { |
| 1536 | // No, we have to recreate the condition code. |
| 1537 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1538 | __ testl(cond_reg, cond_reg); |
| 1539 | } |
| 1540 | } else { |
| 1541 | // We can't handle FP or long here. |
| 1542 | DCHECK_NE(condition->InputAt(0)->GetType(), Primitive::kPrimLong); |
| 1543 | DCHECK(!Primitive::IsFloatingPointType(condition->InputAt(0)->GetType())); |
| 1544 | LocationSummary* cond_locations = condition->GetLocations(); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1545 | codegen_->GenerateIntCompare(cond_locations->InAt(0), cond_locations->InAt(1)); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1546 | cond = X86Condition(condition->GetCondition()); |
| 1547 | } |
| 1548 | } else { |
| 1549 | // Must be a boolean condition, which needs to be compared to 0. |
| 1550 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1551 | __ testl(cond_reg, cond_reg); |
| 1552 | } |
| 1553 | |
| 1554 | // If the condition is true, overwrite the output, which already contains false. |
| 1555 | Location false_loc = locations->InAt(0); |
| 1556 | Location true_loc = locations->InAt(1); |
| 1557 | if (select->GetType() == Primitive::kPrimLong) { |
| 1558 | // 64 bit conditional move. |
| 1559 | Register false_high = false_loc.AsRegisterPairHigh<Register>(); |
| 1560 | Register false_low = false_loc.AsRegisterPairLow<Register>(); |
| 1561 | if (true_loc.IsRegisterPair()) { |
| 1562 | __ cmovl(cond, false_high, true_loc.AsRegisterPairHigh<Register>()); |
| 1563 | __ cmovl(cond, false_low, true_loc.AsRegisterPairLow<Register>()); |
| 1564 | } else { |
| 1565 | __ cmovl(cond, false_high, Address(ESP, true_loc.GetHighStackIndex(kX86WordSize))); |
| 1566 | __ cmovl(cond, false_low, Address(ESP, true_loc.GetStackIndex())); |
| 1567 | } |
| 1568 | } else { |
| 1569 | // 32 bit conditional move. |
| 1570 | Register false_reg = false_loc.AsRegister<Register>(); |
| 1571 | if (true_loc.IsRegister()) { |
| 1572 | __ cmovl(cond, false_reg, true_loc.AsRegister<Register>()); |
| 1573 | } else { |
| 1574 | __ cmovl(cond, false_reg, Address(ESP, true_loc.GetStackIndex())); |
| 1575 | } |
| 1576 | } |
| 1577 | } else { |
| 1578 | NearLabel false_target; |
| 1579 | GenerateTestAndBranch<NearLabel>( |
| 1580 | select, /* condition_input_index */ 2, /* true_target */ nullptr, &false_target); |
| 1581 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1582 | __ Bind(&false_target); |
| 1583 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1584 | } |
| 1585 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1586 | void LocationsBuilderX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1587 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1588 | } |
| 1589 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1590 | void InstructionCodeGeneratorX86::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1591 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1592 | } |
| 1593 | |
| 1594 | void CodeGeneratorX86::GenerateNop() { |
| 1595 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1596 | } |
| 1597 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1598 | void LocationsBuilderX86::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1599 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1600 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1601 | // Handle the long/FP comparisons made in instruction simplification. |
| 1602 | switch (cond->InputAt(0)->GetType()) { |
| 1603 | case Primitive::kPrimLong: { |
| 1604 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1605 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1606 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1607 | locations->SetOut(Location::RequiresRegister()); |
| 1608 | } |
| 1609 | break; |
| 1610 | } |
| 1611 | case Primitive::kPrimFloat: |
| 1612 | case Primitive::kPrimDouble: { |
| 1613 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1614 | if (cond->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 1615 | DCHECK(cond->InputAt(1)->IsEmittedAtUseSite()); |
| 1616 | } else if (cond->InputAt(1)->IsConstant()) { |
| 1617 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1618 | } else { |
| 1619 | locations->SetInAt(1, Location::Any()); |
| 1620 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1621 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1622 | locations->SetOut(Location::RequiresRegister()); |
| 1623 | } |
| 1624 | break; |
| 1625 | } |
| 1626 | default: |
| 1627 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1628 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1629 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1630 | // We need a byte register. |
| 1631 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1632 | } |
| 1633 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1634 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1635 | } |
| 1636 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1637 | void InstructionCodeGeneratorX86::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1638 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1639 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1640 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1641 | |
| 1642 | LocationSummary* locations = cond->GetLocations(); |
| 1643 | Location lhs = locations->InAt(0); |
| 1644 | Location rhs = locations->InAt(1); |
| 1645 | Register reg = locations->Out().AsRegister<Register>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1646 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1647 | |
| 1648 | switch (cond->InputAt(0)->GetType()) { |
| 1649 | default: { |
| 1650 | // Integer case. |
| 1651 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 1652 | // Clear output register: setb only sets the low byte. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1653 | __ xorl(reg, reg); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1654 | codegen_->GenerateIntCompare(lhs, rhs); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1655 | __ setb(X86Condition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1656 | return; |
| 1657 | } |
| 1658 | case Primitive::kPrimLong: |
| 1659 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1660 | break; |
| 1661 | case Primitive::kPrimFloat: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1662 | GenerateFPCompare(lhs, rhs, cond, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1663 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1664 | break; |
| 1665 | case Primitive::kPrimDouble: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1666 | GenerateFPCompare(lhs, rhs, cond, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1667 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1668 | break; |
| 1669 | } |
| 1670 | |
| 1671 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1672 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1673 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1674 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1675 | __ Bind(&false_label); |
| 1676 | __ xorl(reg, reg); |
| 1677 | __ jmp(&done_label); |
| 1678 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1679 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1680 | __ Bind(&true_label); |
| 1681 | __ movl(reg, Immediate(1)); |
| 1682 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1683 | } |
| 1684 | |
| 1685 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1686 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1687 | } |
| 1688 | |
| 1689 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1690 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1691 | } |
| 1692 | |
| 1693 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1694 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1695 | } |
| 1696 | |
| 1697 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1698 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1699 | } |
| 1700 | |
| 1701 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1702 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1703 | } |
| 1704 | |
| 1705 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1706 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1707 | } |
| 1708 | |
| 1709 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1710 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1711 | } |
| 1712 | |
| 1713 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1714 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1715 | } |
| 1716 | |
| 1717 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1718 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1719 | } |
| 1720 | |
| 1721 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1722 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1723 | } |
| 1724 | |
| 1725 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1726 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1727 | } |
| 1728 | |
| 1729 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1730 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1731 | } |
| 1732 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1733 | void LocationsBuilderX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1734 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1735 | } |
| 1736 | |
| 1737 | void InstructionCodeGeneratorX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1738 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1739 | } |
| 1740 | |
| 1741 | void LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1742 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1743 | } |
| 1744 | |
| 1745 | void InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1746 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1747 | } |
| 1748 | |
| 1749 | void LocationsBuilderX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1750 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1751 | } |
| 1752 | |
| 1753 | void InstructionCodeGeneratorX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1754 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1755 | } |
| 1756 | |
| 1757 | void LocationsBuilderX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1758 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1759 | } |
| 1760 | |
| 1761 | void InstructionCodeGeneratorX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1762 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1763 | } |
| 1764 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1765 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1766 | LocationSummary* locations = |
| 1767 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1768 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1769 | } |
| 1770 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1771 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1772 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1773 | } |
| 1774 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1775 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 1776 | LocationSummary* locations = |
| 1777 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1778 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1779 | } |
| 1780 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1781 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1782 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1783 | } |
| 1784 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1785 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1786 | LocationSummary* locations = |
| 1787 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1788 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1789 | } |
| 1790 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1791 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1792 | // Will be generated at use site. |
| 1793 | } |
| 1794 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1795 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 1796 | LocationSummary* locations = |
| 1797 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1798 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1799 | } |
| 1800 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1801 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1802 | // Will be generated at use site. |
| 1803 | } |
| 1804 | |
| 1805 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1806 | LocationSummary* locations = |
| 1807 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1808 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1809 | } |
| 1810 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1811 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1812 | // Will be generated at use site. |
| 1813 | } |
| 1814 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1815 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1816 | memory_barrier->SetLocations(nullptr); |
| 1817 | } |
| 1818 | |
| 1819 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 1820 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1821 | } |
| 1822 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1823 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1824 | ret->SetLocations(nullptr); |
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::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1828 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1829 | } |
| 1830 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1831 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1832 | LocationSummary* locations = |
| 1833 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1834 | switch (ret->InputAt(0)->GetType()) { |
| 1835 | case Primitive::kPrimBoolean: |
| 1836 | case Primitive::kPrimByte: |
| 1837 | case Primitive::kPrimChar: |
| 1838 | case Primitive::kPrimShort: |
| 1839 | case Primitive::kPrimInt: |
| 1840 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1841 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1842 | break; |
| 1843 | |
| 1844 | case Primitive::kPrimLong: |
| 1845 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1846 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1847 | break; |
| 1848 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1849 | case Primitive::kPrimFloat: |
| 1850 | case Primitive::kPrimDouble: |
| 1851 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1852 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1853 | break; |
| 1854 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1855 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1856 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1857 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1858 | } |
| 1859 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1860 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1861 | if (kIsDebugBuild) { |
| 1862 | switch (ret->InputAt(0)->GetType()) { |
| 1863 | case Primitive::kPrimBoolean: |
| 1864 | case Primitive::kPrimByte: |
| 1865 | case Primitive::kPrimChar: |
| 1866 | case Primitive::kPrimShort: |
| 1867 | case Primitive::kPrimInt: |
| 1868 | case Primitive::kPrimNot: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1869 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1870 | break; |
| 1871 | |
| 1872 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1873 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 1874 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1875 | break; |
| 1876 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1877 | case Primitive::kPrimFloat: |
| 1878 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1879 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1880 | break; |
| 1881 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1882 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1883 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1884 | } |
| 1885 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1886 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1887 | } |
| 1888 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1889 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1890 | // The trampoline uses the same calling convention as dex calling conventions, |
| 1891 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 1892 | // the method_idx. |
| 1893 | HandleInvoke(invoke); |
| 1894 | } |
| 1895 | |
| 1896 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1897 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 1898 | } |
| 1899 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1900 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1901 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 1902 | // art::PrepareForRegisterAllocation. |
| 1903 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1904 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1905 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1906 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1907 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 1908 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1909 | } |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1910 | return; |
| 1911 | } |
| 1912 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1913 | HandleInvoke(invoke); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1914 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1915 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 1916 | if (invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1917 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1918 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1919 | } |
| 1920 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1921 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 1922 | if (invoke->GetLocations()->Intrinsified()) { |
| 1923 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 1924 | intrinsic.Dispatch(invoke); |
| 1925 | return true; |
| 1926 | } |
| 1927 | return false; |
| 1928 | } |
| 1929 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1930 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1931 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 1932 | // art::PrepareForRegisterAllocation. |
| 1933 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1934 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1935 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1936 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1937 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1938 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1939 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1940 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1941 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Mingyao Yang | 8693fe1 | 2015-04-17 16:51:08 -0700 | [diff] [blame] | 1942 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1943 | } |
| 1944 | |
| 1945 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1946 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 1947 | if (intrinsic.TryDispatch(invoke)) { |
| 1948 | return; |
| 1949 | } |
| 1950 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1951 | HandleInvoke(invoke); |
| 1952 | } |
| 1953 | |
| 1954 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1955 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1956 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1957 | } |
| 1958 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1959 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1960 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1961 | return; |
| 1962 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1963 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1964 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1965 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1966 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1967 | } |
| 1968 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1969 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1970 | // This call to HandleInvoke allocates a temporary (core) register |
| 1971 | // which is also used to transfer the hidden argument from FP to |
| 1972 | // core register. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1973 | HandleInvoke(invoke); |
| 1974 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1975 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1976 | } |
| 1977 | |
| 1978 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1979 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1980 | LocationSummary* locations = invoke->GetLocations(); |
| 1981 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 1982 | XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1983 | Location receiver = locations->InAt(0); |
| 1984 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 1985 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1986 | // Set the hidden argument. This is safe to do this here, as XMM7 |
| 1987 | // won't be modified thereafter, before the `call` instruction. |
| 1988 | DCHECK_EQ(XMM7, hidden_reg); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1989 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1990 | __ movd(hidden_reg, temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1991 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1992 | if (receiver.IsStackSlot()) { |
| 1993 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1994 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1995 | __ movl(temp, Address(temp, class_offset)); |
| 1996 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1997 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1998 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1999 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2000 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2001 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2002 | // emit a read barrier for the previous class reference load. |
| 2003 | // However this is not required in practice, as this is an |
| 2004 | // intermediate/temporary reference and because the current |
| 2005 | // concurrent copying collector keeps the from-space memory |
| 2006 | // intact/accessible until the end of the marking phase (the |
| 2007 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2008 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2009 | // temp = temp->GetAddressOfIMT() |
| 2010 | __ movl(temp, |
| 2011 | Address(temp, mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2012 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2013 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2014 | invoke->GetImtIndex(), kX86PointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2015 | __ movl(temp, Address(temp, method_offset)); |
| 2016 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2017 | __ call(Address(temp, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2018 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2019 | |
| 2020 | DCHECK(!codegen_->IsLeafMethod()); |
| 2021 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2022 | } |
| 2023 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2024 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 2025 | LocationSummary* locations = |
| 2026 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2027 | switch (neg->GetResultType()) { |
| 2028 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2029 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2030 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2031 | locations->SetOut(Location::SameAsFirstInput()); |
| 2032 | break; |
| 2033 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2034 | case Primitive::kPrimFloat: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2035 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2036 | locations->SetOut(Location::SameAsFirstInput()); |
| 2037 | locations->AddTemp(Location::RequiresRegister()); |
| 2038 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2039 | break; |
| 2040 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2041 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2042 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2043 | locations->SetOut(Location::SameAsFirstInput()); |
| 2044 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2045 | break; |
| 2046 | |
| 2047 | default: |
| 2048 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2049 | } |
| 2050 | } |
| 2051 | |
| 2052 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 2053 | LocationSummary* locations = neg->GetLocations(); |
| 2054 | Location out = locations->Out(); |
| 2055 | Location in = locations->InAt(0); |
| 2056 | switch (neg->GetResultType()) { |
| 2057 | case Primitive::kPrimInt: |
| 2058 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2059 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2060 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2061 | break; |
| 2062 | |
| 2063 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2064 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2065 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2066 | __ negl(out.AsRegisterPairLow<Register>()); |
| 2067 | // Negation is similar to subtraction from zero. The least |
| 2068 | // significant byte triggers a borrow when it is different from |
| 2069 | // zero; to take it into account, add 1 to the most significant |
| 2070 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 2071 | // operation. |
| 2072 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2073 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 2074 | break; |
| 2075 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2076 | case Primitive::kPrimFloat: { |
| 2077 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2078 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 2079 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2080 | // Implement float negation with an exclusive or with value |
| 2081 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2082 | // single-precision floating-point number). |
| 2083 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 2084 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2085 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2086 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2087 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2088 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2089 | case Primitive::kPrimDouble: { |
| 2090 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2091 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2092 | // Implement double negation with an exclusive or with value |
| 2093 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 2094 | // a double-precision floating-point number). |
| 2095 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2096 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2097 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2098 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2099 | |
| 2100 | default: |
| 2101 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2102 | } |
| 2103 | } |
| 2104 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2105 | void LocationsBuilderX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2106 | LocationSummary* locations = |
| 2107 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2108 | DCHECK(Primitive::IsFloatingPointType(neg->GetType())); |
| 2109 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2110 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2111 | locations->SetOut(Location::SameAsFirstInput()); |
| 2112 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2113 | } |
| 2114 | |
| 2115 | void InstructionCodeGeneratorX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2116 | LocationSummary* locations = neg->GetLocations(); |
| 2117 | Location out = locations->Out(); |
| 2118 | DCHECK(locations->InAt(0).Equals(out)); |
| 2119 | |
| 2120 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 2121 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 2122 | if (neg->GetType() == Primitive::kPrimFloat) { |
| 2123 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x80000000), constant_area)); |
| 2124 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| 2125 | } else { |
| 2126 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000), constant_area)); |
| 2127 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| 2128 | } |
| 2129 | } |
| 2130 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2131 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2132 | Primitive::Type result_type = conversion->GetResultType(); |
| 2133 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2134 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2135 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2136 | // The float-to-long and double-to-long type conversions rely on a |
| 2137 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2138 | LocationSummary::CallKind call_kind = |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2139 | ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2140 | && result_type == Primitive::kPrimLong) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2141 | ? LocationSummary::kCallOnMainOnly |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2142 | : LocationSummary::kNoCall; |
| 2143 | LocationSummary* locations = |
| 2144 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2145 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2146 | // The Java language does not allow treating boolean as an integral type but |
| 2147 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2148 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2149 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2150 | case Primitive::kPrimByte: |
| 2151 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2152 | case Primitive::kPrimLong: { |
| 2153 | // Type conversion from long to byte is a result of code transformations. |
| 2154 | HInstruction* input = conversion->InputAt(0); |
| 2155 | Location input_location = input->IsConstant() |
| 2156 | ? Location::ConstantLocation(input->AsConstant()) |
| 2157 | : Location::RegisterPairLocation(EAX, EDX); |
| 2158 | locations->SetInAt(0, input_location); |
| 2159 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2160 | // the validation of the linear scan implementation |
| 2161 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2162 | break; |
| 2163 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2164 | case Primitive::kPrimBoolean: |
| 2165 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2166 | case Primitive::kPrimShort: |
| 2167 | case Primitive::kPrimInt: |
| 2168 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2169 | // Processing a Dex `int-to-byte' instruction. |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 2170 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 2171 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2172 | // the validation of the linear scan implementation |
| 2173 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2174 | break; |
| 2175 | |
| 2176 | default: |
| 2177 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2178 | << " to " << result_type; |
| 2179 | } |
| 2180 | break; |
| 2181 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2182 | case Primitive::kPrimShort: |
| 2183 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2184 | case Primitive::kPrimLong: |
| 2185 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2186 | case Primitive::kPrimBoolean: |
| 2187 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2188 | case Primitive::kPrimByte: |
| 2189 | case Primitive::kPrimInt: |
| 2190 | case Primitive::kPrimChar: |
| 2191 | // Processing a Dex `int-to-short' instruction. |
| 2192 | locations->SetInAt(0, Location::Any()); |
| 2193 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2194 | break; |
| 2195 | |
| 2196 | default: |
| 2197 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2198 | << " to " << result_type; |
| 2199 | } |
| 2200 | break; |
| 2201 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2202 | case Primitive::kPrimInt: |
| 2203 | switch (input_type) { |
| 2204 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2205 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2206 | locations->SetInAt(0, Location::Any()); |
| 2207 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2208 | break; |
| 2209 | |
| 2210 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2211 | // Processing a Dex `float-to-int' instruction. |
| 2212 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2213 | locations->SetOut(Location::RequiresRegister()); |
| 2214 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2215 | break; |
| 2216 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2217 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2218 | // Processing a Dex `double-to-int' instruction. |
| 2219 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2220 | locations->SetOut(Location::RequiresRegister()); |
| 2221 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2222 | break; |
| 2223 | |
| 2224 | default: |
| 2225 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2226 | << " to " << result_type; |
| 2227 | } |
| 2228 | break; |
| 2229 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2230 | case Primitive::kPrimLong: |
| 2231 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2232 | case Primitive::kPrimBoolean: |
| 2233 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2234 | case Primitive::kPrimByte: |
| 2235 | case Primitive::kPrimShort: |
| 2236 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2237 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2238 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2239 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 2240 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2241 | break; |
| 2242 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2243 | case Primitive::kPrimFloat: |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2244 | case Primitive::kPrimDouble: { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2245 | // Processing a Dex `float-to-long' or 'double-to-long' instruction. |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2246 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2247 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 2248 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 2249 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2250 | // The runtime helper puts the result in EAX, EDX. |
| 2251 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2252 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2253 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2254 | |
| 2255 | default: |
| 2256 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2257 | << " to " << result_type; |
| 2258 | } |
| 2259 | break; |
| 2260 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2261 | case Primitive::kPrimChar: |
| 2262 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2263 | case Primitive::kPrimLong: |
| 2264 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2265 | case Primitive::kPrimBoolean: |
| 2266 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2267 | case Primitive::kPrimByte: |
| 2268 | case Primitive::kPrimShort: |
| 2269 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2270 | // Processing a Dex `int-to-char' instruction. |
| 2271 | locations->SetInAt(0, Location::Any()); |
| 2272 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2273 | break; |
| 2274 | |
| 2275 | default: |
| 2276 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2277 | << " to " << result_type; |
| 2278 | } |
| 2279 | break; |
| 2280 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2281 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2282 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2283 | case Primitive::kPrimBoolean: |
| 2284 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2285 | case Primitive::kPrimByte: |
| 2286 | case Primitive::kPrimShort: |
| 2287 | case Primitive::kPrimInt: |
| 2288 | case Primitive::kPrimChar: |
| 2289 | // Processing a Dex `int-to-float' instruction. |
| 2290 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2291 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2292 | break; |
| 2293 | |
| 2294 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2295 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2296 | locations->SetInAt(0, Location::Any()); |
| 2297 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2298 | break; |
| 2299 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2300 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2301 | // Processing a Dex `double-to-float' instruction. |
| 2302 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2303 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2304 | break; |
| 2305 | |
| 2306 | default: |
| 2307 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2308 | << " to " << result_type; |
| 2309 | }; |
| 2310 | break; |
| 2311 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2312 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2313 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2314 | case Primitive::kPrimBoolean: |
| 2315 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2316 | case Primitive::kPrimByte: |
| 2317 | case Primitive::kPrimShort: |
| 2318 | case Primitive::kPrimInt: |
| 2319 | case Primitive::kPrimChar: |
| 2320 | // Processing a Dex `int-to-double' instruction. |
| 2321 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2322 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2323 | break; |
| 2324 | |
| 2325 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2326 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2327 | locations->SetInAt(0, Location::Any()); |
| 2328 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2329 | break; |
| 2330 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2331 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2332 | // Processing a Dex `float-to-double' instruction. |
| 2333 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2334 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2335 | break; |
| 2336 | |
| 2337 | default: |
| 2338 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2339 | << " to " << result_type; |
| 2340 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2341 | break; |
| 2342 | |
| 2343 | default: |
| 2344 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2345 | << " to " << result_type; |
| 2346 | } |
| 2347 | } |
| 2348 | |
| 2349 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 2350 | LocationSummary* locations = conversion->GetLocations(); |
| 2351 | Location out = locations->Out(); |
| 2352 | Location in = locations->InAt(0); |
| 2353 | Primitive::Type result_type = conversion->GetResultType(); |
| 2354 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2355 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2356 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2357 | case Primitive::kPrimByte: |
| 2358 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2359 | case Primitive::kPrimLong: |
| 2360 | // Type conversion from long to byte is a result of code transformations. |
| 2361 | if (in.IsRegisterPair()) { |
| 2362 | __ movsxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 2363 | } else { |
| 2364 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2365 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2366 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2367 | } |
| 2368 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2369 | case Primitive::kPrimBoolean: |
| 2370 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2371 | case Primitive::kPrimShort: |
| 2372 | case Primitive::kPrimInt: |
| 2373 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2374 | // Processing a Dex `int-to-byte' instruction. |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2375 | if (in.IsRegister()) { |
| 2376 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2377 | } else { |
| 2378 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2379 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2380 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2381 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2382 | break; |
| 2383 | |
| 2384 | default: |
| 2385 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2386 | << " to " << result_type; |
| 2387 | } |
| 2388 | break; |
| 2389 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2390 | case Primitive::kPrimShort: |
| 2391 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2392 | case Primitive::kPrimLong: |
| 2393 | // Type conversion from long to short is a result of code transformations. |
| 2394 | if (in.IsRegisterPair()) { |
| 2395 | __ movsxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2396 | } else if (in.IsDoubleStackSlot()) { |
| 2397 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2398 | } else { |
| 2399 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2400 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2401 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
| 2402 | } |
| 2403 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2404 | case Primitive::kPrimBoolean: |
| 2405 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2406 | case Primitive::kPrimByte: |
| 2407 | case Primitive::kPrimInt: |
| 2408 | case Primitive::kPrimChar: |
| 2409 | // Processing a Dex `int-to-short' instruction. |
| 2410 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2411 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2412 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2413 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2414 | } else { |
| 2415 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2416 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2417 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2418 | } |
| 2419 | break; |
| 2420 | |
| 2421 | default: |
| 2422 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2423 | << " to " << result_type; |
| 2424 | } |
| 2425 | break; |
| 2426 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2427 | case Primitive::kPrimInt: |
| 2428 | switch (input_type) { |
| 2429 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2430 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2431 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2432 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2433 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2434 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2435 | } else { |
| 2436 | DCHECK(in.IsConstant()); |
| 2437 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2438 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2439 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2440 | } |
| 2441 | break; |
| 2442 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2443 | case Primitive::kPrimFloat: { |
| 2444 | // Processing a Dex `float-to-int' instruction. |
| 2445 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2446 | Register output = out.AsRegister<Register>(); |
| 2447 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2448 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2449 | |
| 2450 | __ movl(output, Immediate(kPrimIntMax)); |
| 2451 | // temp = int-to-float(output) |
| 2452 | __ cvtsi2ss(temp, output); |
| 2453 | // if input >= temp goto done |
| 2454 | __ comiss(input, temp); |
| 2455 | __ j(kAboveEqual, &done); |
| 2456 | // if input == NaN goto nan |
| 2457 | __ j(kUnordered, &nan); |
| 2458 | // output = float-to-int-truncate(input) |
| 2459 | __ cvttss2si(output, input); |
| 2460 | __ jmp(&done); |
| 2461 | __ Bind(&nan); |
| 2462 | // output = 0 |
| 2463 | __ xorl(output, output); |
| 2464 | __ Bind(&done); |
| 2465 | break; |
| 2466 | } |
| 2467 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2468 | case Primitive::kPrimDouble: { |
| 2469 | // Processing a Dex `double-to-int' instruction. |
| 2470 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2471 | Register output = out.AsRegister<Register>(); |
| 2472 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2473 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2474 | |
| 2475 | __ movl(output, Immediate(kPrimIntMax)); |
| 2476 | // temp = int-to-double(output) |
| 2477 | __ cvtsi2sd(temp, output); |
| 2478 | // if input >= temp goto done |
| 2479 | __ comisd(input, temp); |
| 2480 | __ j(kAboveEqual, &done); |
| 2481 | // if input == NaN goto nan |
| 2482 | __ j(kUnordered, &nan); |
| 2483 | // output = double-to-int-truncate(input) |
| 2484 | __ cvttsd2si(output, input); |
| 2485 | __ jmp(&done); |
| 2486 | __ Bind(&nan); |
| 2487 | // output = 0 |
| 2488 | __ xorl(output, output); |
| 2489 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2490 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2491 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2492 | |
| 2493 | default: |
| 2494 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2495 | << " to " << result_type; |
| 2496 | } |
| 2497 | break; |
| 2498 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2499 | case Primitive::kPrimLong: |
| 2500 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2501 | case Primitive::kPrimBoolean: |
| 2502 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2503 | case Primitive::kPrimByte: |
| 2504 | case Primitive::kPrimShort: |
| 2505 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2506 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2507 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2508 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2509 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2510 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2511 | __ cdq(); |
| 2512 | break; |
| 2513 | |
| 2514 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2515 | // Processing a Dex `float-to-long' instruction. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2516 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2517 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2518 | break; |
| 2519 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2520 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2521 | // Processing a Dex `double-to-long' instruction. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2522 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2523 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2524 | break; |
| 2525 | |
| 2526 | default: |
| 2527 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2528 | << " to " << result_type; |
| 2529 | } |
| 2530 | break; |
| 2531 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2532 | case Primitive::kPrimChar: |
| 2533 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2534 | case Primitive::kPrimLong: |
| 2535 | // Type conversion from long to short is a result of code transformations. |
| 2536 | if (in.IsRegisterPair()) { |
| 2537 | __ movzxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2538 | } else if (in.IsDoubleStackSlot()) { |
| 2539 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2540 | } else { |
| 2541 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2542 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2543 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
| 2544 | } |
| 2545 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2546 | case Primitive::kPrimBoolean: |
| 2547 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2548 | case Primitive::kPrimByte: |
| 2549 | case Primitive::kPrimShort: |
| 2550 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2551 | // Processing a Dex `Process a Dex `int-to-char'' instruction. |
| 2552 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2553 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2554 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2555 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2556 | } else { |
| 2557 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2558 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2559 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2560 | } |
| 2561 | break; |
| 2562 | |
| 2563 | default: |
| 2564 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2565 | << " to " << result_type; |
| 2566 | } |
| 2567 | break; |
| 2568 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2569 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2570 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2571 | case Primitive::kPrimBoolean: |
| 2572 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2573 | case Primitive::kPrimByte: |
| 2574 | case Primitive::kPrimShort: |
| 2575 | case Primitive::kPrimInt: |
| 2576 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2577 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2578 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2579 | break; |
| 2580 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2581 | case Primitive::kPrimLong: { |
| 2582 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2583 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2584 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2585 | // Create stack space for the call to |
| 2586 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2587 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2588 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
| 2589 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2590 | __ subl(ESP, Immediate(adjustment)); |
| 2591 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2592 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2593 | // Load the value to the FP stack, using temporaries if needed. |
| 2594 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2595 | |
| 2596 | if (out.IsStackSlot()) { |
| 2597 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2598 | } else { |
| 2599 | __ fstps(Address(ESP, 0)); |
| 2600 | Location stack_temp = Location::StackSlot(0); |
| 2601 | codegen_->Move32(out, stack_temp); |
| 2602 | } |
| 2603 | |
| 2604 | // Remove the temporary stack space we allocated. |
| 2605 | if (adjustment != 0) { |
| 2606 | __ addl(ESP, Immediate(adjustment)); |
| 2607 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2608 | break; |
| 2609 | } |
| 2610 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2611 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2612 | // Processing a Dex `double-to-float' instruction. |
| 2613 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2614 | break; |
| 2615 | |
| 2616 | default: |
| 2617 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2618 | << " to " << result_type; |
| 2619 | }; |
| 2620 | break; |
| 2621 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2622 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2623 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2624 | case Primitive::kPrimBoolean: |
| 2625 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2626 | case Primitive::kPrimByte: |
| 2627 | case Primitive::kPrimShort: |
| 2628 | case Primitive::kPrimInt: |
| 2629 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2630 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2631 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2632 | break; |
| 2633 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2634 | case Primitive::kPrimLong: { |
| 2635 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2636 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2637 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2638 | // Create stack space for the call to |
| 2639 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2640 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2641 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
| 2642 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2643 | __ subl(ESP, Immediate(adjustment)); |
| 2644 | } |
| 2645 | |
| 2646 | // Load the value to the FP stack, using temporaries if needed. |
| 2647 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2648 | |
| 2649 | if (out.IsDoubleStackSlot()) { |
| 2650 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2651 | } else { |
| 2652 | __ fstpl(Address(ESP, 0)); |
| 2653 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2654 | codegen_->Move64(out, stack_temp); |
| 2655 | } |
| 2656 | |
| 2657 | // Remove the temporary stack space we allocated. |
| 2658 | if (adjustment != 0) { |
| 2659 | __ addl(ESP, Immediate(adjustment)); |
| 2660 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2661 | break; |
| 2662 | } |
| 2663 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2664 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2665 | // Processing a Dex `float-to-double' instruction. |
| 2666 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2667 | break; |
| 2668 | |
| 2669 | default: |
| 2670 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2671 | << " to " << result_type; |
| 2672 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2673 | break; |
| 2674 | |
| 2675 | default: |
| 2676 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2677 | << " to " << result_type; |
| 2678 | } |
| 2679 | } |
| 2680 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2681 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2682 | LocationSummary* locations = |
| 2683 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2684 | switch (add->GetResultType()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2685 | case Primitive::kPrimInt: { |
| 2686 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2687 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2688 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2689 | break; |
| 2690 | } |
| 2691 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2692 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2693 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2694 | locations->SetInAt(1, Location::Any()); |
| 2695 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2696 | break; |
| 2697 | } |
| 2698 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2699 | case Primitive::kPrimFloat: |
| 2700 | case Primitive::kPrimDouble: { |
| 2701 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2702 | if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2703 | DCHECK(add->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2704 | } else if (add->InputAt(1)->IsConstant()) { |
| 2705 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2706 | } else { |
| 2707 | locations->SetInAt(1, Location::Any()); |
| 2708 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2709 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2710 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2711 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2712 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2713 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2714 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2715 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2716 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2717 | } |
| 2718 | |
| 2719 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 2720 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2721 | Location first = locations->InAt(0); |
| 2722 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2723 | Location out = locations->Out(); |
| 2724 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2725 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2726 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2727 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2728 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2729 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2730 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2731 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2732 | } else { |
| 2733 | __ leal(out.AsRegister<Register>(), Address( |
| 2734 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 2735 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2736 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2737 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2738 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2739 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 2740 | } else { |
| 2741 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 2742 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2743 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2744 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2745 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2746 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2747 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2748 | } |
| 2749 | |
| 2750 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2751 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2752 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2753 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2754 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2755 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 2756 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2757 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2758 | } else { |
| 2759 | DCHECK(second.IsConstant()) << second; |
| 2760 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2761 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2762 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2763 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2764 | break; |
| 2765 | } |
| 2766 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2767 | case Primitive::kPrimFloat: { |
| 2768 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2769 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2770 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2771 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2772 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2773 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2774 | codegen_->LiteralFloatAddress( |
| 2775 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2776 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2777 | } else { |
| 2778 | DCHECK(second.IsStackSlot()); |
| 2779 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2780 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2781 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2782 | } |
| 2783 | |
| 2784 | case Primitive::kPrimDouble: { |
| 2785 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2786 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2787 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2788 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2789 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2790 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2791 | codegen_->LiteralDoubleAddress( |
| 2792 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2793 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2794 | } else { |
| 2795 | DCHECK(second.IsDoubleStackSlot()); |
| 2796 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2797 | } |
| 2798 | break; |
| 2799 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2800 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2801 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2802 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2803 | } |
| 2804 | } |
| 2805 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2806 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2807 | LocationSummary* locations = |
| 2808 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2809 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2810 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2811 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2812 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2813 | locations->SetInAt(1, Location::Any()); |
| 2814 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2815 | break; |
| 2816 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2817 | case Primitive::kPrimFloat: |
| 2818 | case Primitive::kPrimDouble: { |
| 2819 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2820 | if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2821 | DCHECK(sub->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2822 | } else if (sub->InputAt(1)->IsConstant()) { |
| 2823 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2824 | } else { |
| 2825 | locations->SetInAt(1, Location::Any()); |
| 2826 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2827 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2828 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2829 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2830 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2831 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2832 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2833 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2834 | } |
| 2835 | |
| 2836 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 2837 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2838 | Location first = locations->InAt(0); |
| 2839 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2840 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2841 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2842 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2843 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2844 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2845 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2846 | __ subl(first.AsRegister<Register>(), |
| 2847 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2848 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2849 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2850 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2851 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2852 | } |
| 2853 | |
| 2854 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2855 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2856 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2857 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2858 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2859 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2860 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 2861 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2862 | } else { |
| 2863 | DCHECK(second.IsConstant()) << second; |
| 2864 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2865 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2866 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2867 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2868 | break; |
| 2869 | } |
| 2870 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2871 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2872 | if (second.IsFpuRegister()) { |
| 2873 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2874 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2875 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2876 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2877 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2878 | codegen_->LiteralFloatAddress( |
| 2879 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2880 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2881 | } else { |
| 2882 | DCHECK(second.IsStackSlot()); |
| 2883 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2884 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2885 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2886 | } |
| 2887 | |
| 2888 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2889 | if (second.IsFpuRegister()) { |
| 2890 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2891 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2892 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2893 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2894 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 2895 | codegen_->LiteralDoubleAddress( |
| 2896 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2897 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2898 | } else { |
| 2899 | DCHECK(second.IsDoubleStackSlot()); |
| 2900 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2901 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2902 | break; |
| 2903 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2904 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2905 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2906 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2907 | } |
| 2908 | } |
| 2909 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2910 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 2911 | LocationSummary* locations = |
| 2912 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2913 | switch (mul->GetResultType()) { |
| 2914 | case Primitive::kPrimInt: |
| 2915 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2916 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2917 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2918 | // Can use 3 operand multiply. |
| 2919 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2920 | } else { |
| 2921 | locations->SetOut(Location::SameAsFirstInput()); |
| 2922 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2923 | break; |
| 2924 | case Primitive::kPrimLong: { |
| 2925 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2926 | locations->SetInAt(1, Location::Any()); |
| 2927 | locations->SetOut(Location::SameAsFirstInput()); |
| 2928 | // Needed for imul on 32bits with 64bits output. |
| 2929 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 2930 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 2931 | break; |
| 2932 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2933 | case Primitive::kPrimFloat: |
| 2934 | case Primitive::kPrimDouble: { |
| 2935 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2936 | if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2937 | DCHECK(mul->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2938 | } else if (mul->InputAt(1)->IsConstant()) { |
| 2939 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2940 | } else { |
| 2941 | locations->SetInAt(1, Location::Any()); |
| 2942 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2943 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2944 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2945 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2946 | |
| 2947 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2948 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2949 | } |
| 2950 | } |
| 2951 | |
| 2952 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 2953 | LocationSummary* locations = mul->GetLocations(); |
| 2954 | Location first = locations->InAt(0); |
| 2955 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2956 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2957 | |
| 2958 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2959 | case Primitive::kPrimInt: |
| 2960 | // The constant may have ended up in a register, so test explicitly to avoid |
| 2961 | // problems where the output may not be the same as the first operand. |
| 2962 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2963 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 2964 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 2965 | } else if (second.IsRegister()) { |
| 2966 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2967 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2968 | } else { |
| 2969 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2970 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2971 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2972 | } |
| 2973 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2974 | |
| 2975 | case Primitive::kPrimLong: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2976 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 2977 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2978 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 2979 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2980 | |
| 2981 | DCHECK_EQ(EAX, eax); |
| 2982 | DCHECK_EQ(EDX, edx); |
| 2983 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2984 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2985 | // output: in1 |
| 2986 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 2987 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 2988 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2989 | if (second.IsConstant()) { |
| 2990 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2991 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2992 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2993 | int32_t low_value = Low32Bits(value); |
| 2994 | int32_t high_value = High32Bits(value); |
| 2995 | Immediate low(low_value); |
| 2996 | Immediate high(high_value); |
| 2997 | |
| 2998 | __ movl(eax, high); |
| 2999 | // eax <- in1.lo * in2.hi |
| 3000 | __ imull(eax, in1_lo); |
| 3001 | // in1.hi <- in1.hi * in2.lo |
| 3002 | __ imull(in1_hi, low); |
| 3003 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3004 | __ addl(in1_hi, eax); |
| 3005 | // move in2_lo to eax to prepare for double precision |
| 3006 | __ movl(eax, low); |
| 3007 | // edx:eax <- in1.lo * in2.lo |
| 3008 | __ mull(in1_lo); |
| 3009 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3010 | __ addl(in1_hi, edx); |
| 3011 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3012 | __ movl(in1_lo, eax); |
| 3013 | } else if (second.IsRegisterPair()) { |
| 3014 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3015 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3016 | |
| 3017 | __ movl(eax, in2_hi); |
| 3018 | // eax <- in1.lo * in2.hi |
| 3019 | __ imull(eax, in1_lo); |
| 3020 | // in1.hi <- in1.hi * in2.lo |
| 3021 | __ imull(in1_hi, in2_lo); |
| 3022 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3023 | __ addl(in1_hi, eax); |
| 3024 | // move in1_lo to eax to prepare for double precision |
| 3025 | __ movl(eax, in1_lo); |
| 3026 | // edx:eax <- in1.lo * in2.lo |
| 3027 | __ mull(in2_lo); |
| 3028 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3029 | __ addl(in1_hi, edx); |
| 3030 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3031 | __ movl(in1_lo, eax); |
| 3032 | } else { |
| 3033 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 3034 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 3035 | Address in2_lo(ESP, second.GetStackIndex()); |
| 3036 | |
| 3037 | __ movl(eax, in2_hi); |
| 3038 | // eax <- in1.lo * in2.hi |
| 3039 | __ imull(eax, in1_lo); |
| 3040 | // in1.hi <- in1.hi * in2.lo |
| 3041 | __ imull(in1_hi, in2_lo); |
| 3042 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3043 | __ addl(in1_hi, eax); |
| 3044 | // move in1_lo to eax to prepare for double precision |
| 3045 | __ movl(eax, in1_lo); |
| 3046 | // edx:eax <- in1.lo * in2.lo |
| 3047 | __ mull(in2_lo); |
| 3048 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3049 | __ addl(in1_hi, edx); |
| 3050 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3051 | __ movl(in1_lo, eax); |
| 3052 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3053 | |
| 3054 | break; |
| 3055 | } |
| 3056 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3057 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3058 | DCHECK(first.Equals(locations->Out())); |
| 3059 | if (second.IsFpuRegister()) { |
| 3060 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3061 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3062 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3063 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3064 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3065 | codegen_->LiteralFloatAddress( |
| 3066 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3067 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3068 | } else { |
| 3069 | DCHECK(second.IsStackSlot()); |
| 3070 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3071 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3072 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3073 | } |
| 3074 | |
| 3075 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3076 | DCHECK(first.Equals(locations->Out())); |
| 3077 | if (second.IsFpuRegister()) { |
| 3078 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3079 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3080 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3081 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3082 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3083 | codegen_->LiteralDoubleAddress( |
| 3084 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3085 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3086 | } else { |
| 3087 | DCHECK(second.IsDoubleStackSlot()); |
| 3088 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3089 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3090 | break; |
| 3091 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3092 | |
| 3093 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3094 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3095 | } |
| 3096 | } |
| 3097 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3098 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 3099 | uint32_t temp_offset, |
| 3100 | uint32_t stack_adjustment, |
| 3101 | bool is_fp, |
| 3102 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3103 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3104 | DCHECK(!is_wide); |
| 3105 | if (is_fp) { |
| 3106 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3107 | } else { |
| 3108 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3109 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3110 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3111 | DCHECK(is_wide); |
| 3112 | if (is_fp) { |
| 3113 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3114 | } else { |
| 3115 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3116 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3117 | } else { |
| 3118 | // 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] | 3119 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3120 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3121 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3122 | if (is_fp) { |
| 3123 | __ flds(Address(ESP, temp_offset)); |
| 3124 | } else { |
| 3125 | __ filds(Address(ESP, temp_offset)); |
| 3126 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3127 | } else { |
| 3128 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3129 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3130 | if (is_fp) { |
| 3131 | __ fldl(Address(ESP, temp_offset)); |
| 3132 | } else { |
| 3133 | __ fildl(Address(ESP, temp_offset)); |
| 3134 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3135 | } |
| 3136 | } |
| 3137 | } |
| 3138 | |
| 3139 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
| 3140 | Primitive::Type type = rem->GetResultType(); |
| 3141 | bool is_float = type == Primitive::kPrimFloat; |
| 3142 | size_t elem_size = Primitive::ComponentSize(type); |
| 3143 | LocationSummary* locations = rem->GetLocations(); |
| 3144 | Location first = locations->InAt(0); |
| 3145 | Location second = locations->InAt(1); |
| 3146 | Location out = locations->Out(); |
| 3147 | |
| 3148 | // Create stack space for 2 elements. |
| 3149 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3150 | __ subl(ESP, Immediate(2 * elem_size)); |
| 3151 | |
| 3152 | // 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] | 3153 | const bool is_wide = !is_float; |
| 3154 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); |
| 3155 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3156 | |
| 3157 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3158 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3159 | __ Bind(&retry); |
| 3160 | __ fprem(); |
| 3161 | |
| 3162 | // Move FP status to AX. |
| 3163 | __ fstsw(); |
| 3164 | |
| 3165 | // And see if the argument reduction is complete. This is signaled by the |
| 3166 | // C2 FPU flag bit set to 0. |
| 3167 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 3168 | __ j(kNotEqual, &retry); |
| 3169 | |
| 3170 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3171 | // Store FP top of stack to real stack. |
| 3172 | if (is_float) { |
| 3173 | __ fsts(Address(ESP, 0)); |
| 3174 | } else { |
| 3175 | __ fstl(Address(ESP, 0)); |
| 3176 | } |
| 3177 | |
| 3178 | // Pop the 2 items from the FP stack. |
| 3179 | __ fucompp(); |
| 3180 | |
| 3181 | // Load the value from the stack into an XMM register. |
| 3182 | DCHECK(out.IsFpuRegister()) << out; |
| 3183 | if (is_float) { |
| 3184 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3185 | } else { |
| 3186 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3187 | } |
| 3188 | |
| 3189 | // And remove the temporary stack space we allocated. |
| 3190 | __ addl(ESP, Immediate(2 * elem_size)); |
| 3191 | } |
| 3192 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3193 | |
| 3194 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3195 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3196 | |
| 3197 | LocationSummary* locations = instruction->GetLocations(); |
| 3198 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3199 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3200 | |
| 3201 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3202 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3203 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3204 | |
| 3205 | DCHECK(imm == 1 || imm == -1); |
| 3206 | |
| 3207 | if (instruction->IsRem()) { |
| 3208 | __ xorl(out_register, out_register); |
| 3209 | } else { |
| 3210 | __ movl(out_register, input_register); |
| 3211 | if (imm == -1) { |
| 3212 | __ negl(out_register); |
| 3213 | } |
| 3214 | } |
| 3215 | } |
| 3216 | |
| 3217 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3218 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3219 | LocationSummary* locations = instruction->GetLocations(); |
| 3220 | |
| 3221 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3222 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3223 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3224 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3225 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3226 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3227 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 3228 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3229 | __ leal(num, Address(input_register, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3230 | __ testl(input_register, input_register); |
| 3231 | __ cmovl(kGreaterEqual, num, input_register); |
| 3232 | int shift = CTZ(imm); |
| 3233 | __ sarl(num, Immediate(shift)); |
| 3234 | |
| 3235 | if (imm < 0) { |
| 3236 | __ negl(num); |
| 3237 | } |
| 3238 | |
| 3239 | __ movl(out_register, num); |
| 3240 | } |
| 3241 | |
| 3242 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3243 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3244 | |
| 3245 | LocationSummary* locations = instruction->GetLocations(); |
| 3246 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 3247 | |
| 3248 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 3249 | Register out = locations->Out().AsRegister<Register>(); |
| 3250 | Register num; |
| 3251 | Register edx; |
| 3252 | |
| 3253 | if (instruction->IsDiv()) { |
| 3254 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 3255 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 3256 | } else { |
| 3257 | edx = locations->Out().AsRegister<Register>(); |
| 3258 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 3259 | } |
| 3260 | |
| 3261 | DCHECK_EQ(EAX, eax); |
| 3262 | DCHECK_EQ(EDX, edx); |
| 3263 | if (instruction->IsDiv()) { |
| 3264 | DCHECK_EQ(EAX, out); |
| 3265 | } else { |
| 3266 | DCHECK_EQ(EDX, out); |
| 3267 | } |
| 3268 | |
| 3269 | int64_t magic; |
| 3270 | int shift; |
| 3271 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3272 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3273 | // Save the numerator. |
| 3274 | __ movl(num, eax); |
| 3275 | |
| 3276 | // EAX = magic |
| 3277 | __ movl(eax, Immediate(magic)); |
| 3278 | |
| 3279 | // EDX:EAX = magic * numerator |
| 3280 | __ imull(num); |
| 3281 | |
| 3282 | if (imm > 0 && magic < 0) { |
| 3283 | // EDX += num |
| 3284 | __ addl(edx, num); |
| 3285 | } else if (imm < 0 && magic > 0) { |
| 3286 | __ subl(edx, num); |
| 3287 | } |
| 3288 | |
| 3289 | // Shift if needed. |
| 3290 | if (shift != 0) { |
| 3291 | __ sarl(edx, Immediate(shift)); |
| 3292 | } |
| 3293 | |
| 3294 | // EDX += 1 if EDX < 0 |
| 3295 | __ movl(eax, edx); |
| 3296 | __ shrl(edx, Immediate(31)); |
| 3297 | __ addl(edx, eax); |
| 3298 | |
| 3299 | if (instruction->IsRem()) { |
| 3300 | __ movl(eax, num); |
| 3301 | __ imull(edx, Immediate(imm)); |
| 3302 | __ subl(eax, edx); |
| 3303 | __ movl(edx, eax); |
| 3304 | } else { |
| 3305 | __ movl(eax, edx); |
| 3306 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3307 | } |
| 3308 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3309 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3310 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3311 | |
| 3312 | LocationSummary* locations = instruction->GetLocations(); |
| 3313 | Location out = locations->Out(); |
| 3314 | Location first = locations->InAt(0); |
| 3315 | Location second = locations->InAt(1); |
| 3316 | bool is_div = instruction->IsDiv(); |
| 3317 | |
| 3318 | switch (instruction->GetResultType()) { |
| 3319 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3320 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 3321 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3322 | |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3323 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3324 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3325 | |
| 3326 | if (imm == 0) { |
| 3327 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 3328 | } else if (imm == 1 || imm == -1) { |
| 3329 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3330 | } else if (is_div && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3331 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3332 | } else { |
| 3333 | DCHECK(imm <= -2 || imm >= 2); |
| 3334 | GenerateDivRemWithAnyConstant(instruction); |
| 3335 | } |
| 3336 | } else { |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3337 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86( |
| 3338 | instruction, out.AsRegister<Register>(), is_div); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3339 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3340 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3341 | Register second_reg = second.AsRegister<Register>(); |
| 3342 | // 0x80000000/-1 triggers an arithmetic exception! |
| 3343 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 3344 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3345 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3346 | __ cmpl(second_reg, Immediate(-1)); |
| 3347 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3348 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3349 | // edx:eax <- sign-extended of eax |
| 3350 | __ cdq(); |
| 3351 | // eax = quotient, edx = remainder |
| 3352 | __ idivl(second_reg); |
| 3353 | __ Bind(slow_path->GetExitLabel()); |
| 3354 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3355 | break; |
| 3356 | } |
| 3357 | |
| 3358 | case Primitive::kPrimLong: { |
| 3359 | InvokeRuntimeCallingConvention calling_convention; |
| 3360 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3361 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3362 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3363 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3364 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 3365 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 3366 | |
| 3367 | if (is_div) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3368 | codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3369 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3370 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3371 | codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3372 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3373 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3374 | break; |
| 3375 | } |
| 3376 | |
| 3377 | default: |
| 3378 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 3379 | } |
| 3380 | } |
| 3381 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3382 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3383 | LocationSummary::CallKind call_kind = (div->GetResultType() == Primitive::kPrimLong) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3384 | ? LocationSummary::kCallOnMainOnly |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3385 | : LocationSummary::kNoCall; |
| 3386 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 3387 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3388 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3389 | case Primitive::kPrimInt: { |
| 3390 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3391 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3392 | locations->SetOut(Location::SameAsFirstInput()); |
| 3393 | // Intel uses edx:eax as the dividend. |
| 3394 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3395 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3396 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 3397 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3398 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3399 | locations->AddTemp(Location::RequiresRegister()); |
| 3400 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3401 | break; |
| 3402 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3403 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3404 | InvokeRuntimeCallingConvention calling_convention; |
| 3405 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3406 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3407 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3408 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3409 | // Runtime helper puts the result in EAX, EDX. |
| 3410 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3411 | break; |
| 3412 | } |
| 3413 | case Primitive::kPrimFloat: |
| 3414 | case Primitive::kPrimDouble: { |
| 3415 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3416 | if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3417 | DCHECK(div->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3418 | } else if (div->InputAt(1)->IsConstant()) { |
| 3419 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3420 | } else { |
| 3421 | locations->SetInAt(1, Location::Any()); |
| 3422 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3423 | locations->SetOut(Location::SameAsFirstInput()); |
| 3424 | break; |
| 3425 | } |
| 3426 | |
| 3427 | default: |
| 3428 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3429 | } |
| 3430 | } |
| 3431 | |
| 3432 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 3433 | LocationSummary* locations = div->GetLocations(); |
| 3434 | Location first = locations->InAt(0); |
| 3435 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3436 | |
| 3437 | switch (div->GetResultType()) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3438 | case Primitive::kPrimInt: |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3439 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3440 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3441 | break; |
| 3442 | } |
| 3443 | |
| 3444 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3445 | if (second.IsFpuRegister()) { |
| 3446 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3447 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3448 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3449 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3450 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3451 | codegen_->LiteralFloatAddress( |
| 3452 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3453 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3454 | } else { |
| 3455 | DCHECK(second.IsStackSlot()); |
| 3456 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3457 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3458 | break; |
| 3459 | } |
| 3460 | |
| 3461 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3462 | if (second.IsFpuRegister()) { |
| 3463 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3464 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3465 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3466 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3467 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3468 | codegen_->LiteralDoubleAddress( |
| 3469 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3470 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3471 | } else { |
| 3472 | DCHECK(second.IsDoubleStackSlot()); |
| 3473 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3474 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3475 | break; |
| 3476 | } |
| 3477 | |
| 3478 | default: |
| 3479 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3480 | } |
| 3481 | } |
| 3482 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3483 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3484 | Primitive::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3485 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3486 | LocationSummary::CallKind call_kind = (rem->GetResultType() == Primitive::kPrimLong) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3487 | ? LocationSummary::kCallOnMainOnly |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3488 | : LocationSummary::kNoCall; |
| 3489 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3490 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3491 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3492 | case Primitive::kPrimInt: { |
| 3493 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3494 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3495 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3496 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3497 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 3498 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3499 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3500 | locations->AddTemp(Location::RequiresRegister()); |
| 3501 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3502 | break; |
| 3503 | } |
| 3504 | case Primitive::kPrimLong: { |
| 3505 | InvokeRuntimeCallingConvention calling_convention; |
| 3506 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3507 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3508 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3509 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3510 | // Runtime helper puts the result in EAX, EDX. |
| 3511 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3512 | break; |
| 3513 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3514 | case Primitive::kPrimDouble: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3515 | case Primitive::kPrimFloat: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3516 | locations->SetInAt(0, Location::Any()); |
| 3517 | locations->SetInAt(1, Location::Any()); |
| 3518 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3519 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3520 | break; |
| 3521 | } |
| 3522 | |
| 3523 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3524 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3525 | } |
| 3526 | } |
| 3527 | |
| 3528 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
| 3529 | Primitive::Type type = rem->GetResultType(); |
| 3530 | switch (type) { |
| 3531 | case Primitive::kPrimInt: |
| 3532 | case Primitive::kPrimLong: { |
| 3533 | GenerateDivRemIntegral(rem); |
| 3534 | break; |
| 3535 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3536 | case Primitive::kPrimFloat: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3537 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3538 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3539 | break; |
| 3540 | } |
| 3541 | default: |
| 3542 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3543 | } |
| 3544 | } |
| 3545 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3546 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3547 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3548 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3549 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3550 | case Primitive::kPrimByte: |
| 3551 | case Primitive::kPrimChar: |
| 3552 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3553 | case Primitive::kPrimInt: { |
| 3554 | locations->SetInAt(0, Location::Any()); |
| 3555 | break; |
| 3556 | } |
| 3557 | case Primitive::kPrimLong: { |
| 3558 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 3559 | if (!instruction->IsConstant()) { |
| 3560 | locations->AddTemp(Location::RequiresRegister()); |
| 3561 | } |
| 3562 | break; |
| 3563 | } |
| 3564 | default: |
| 3565 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3566 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3567 | } |
| 3568 | |
| 3569 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3570 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3571 | codegen_->AddSlowPath(slow_path); |
| 3572 | |
| 3573 | LocationSummary* locations = instruction->GetLocations(); |
| 3574 | Location value = locations->InAt(0); |
| 3575 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3576 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3577 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3578 | case Primitive::kPrimByte: |
| 3579 | case Primitive::kPrimChar: |
| 3580 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3581 | case Primitive::kPrimInt: { |
| 3582 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3583 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3584 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3585 | } else if (value.IsStackSlot()) { |
| 3586 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 3587 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3588 | } else { |
| 3589 | DCHECK(value.IsConstant()) << value; |
| 3590 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 3591 | __ jmp(slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3592 | } |
| 3593 | } |
| 3594 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3595 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3596 | case Primitive::kPrimLong: { |
| 3597 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3598 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3599 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 3600 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 3601 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3602 | } else { |
| 3603 | DCHECK(value.IsConstant()) << value; |
| 3604 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3605 | __ jmp(slow_path->GetEntryLabel()); |
| 3606 | } |
| 3607 | } |
| 3608 | break; |
| 3609 | } |
| 3610 | default: |
| 3611 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3612 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3613 | } |
| 3614 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3615 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 3616 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3617 | |
| 3618 | LocationSummary* locations = |
| 3619 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3620 | |
| 3621 | switch (op->GetResultType()) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3622 | case Primitive::kPrimInt: |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3623 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3624 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3625 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3626 | // The shift count needs to be in CL or a constant. |
| 3627 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3628 | locations->SetOut(Location::SameAsFirstInput()); |
| 3629 | break; |
| 3630 | } |
| 3631 | default: |
| 3632 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3633 | } |
| 3634 | } |
| 3635 | |
| 3636 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 3637 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3638 | |
| 3639 | LocationSummary* locations = op->GetLocations(); |
| 3640 | Location first = locations->InAt(0); |
| 3641 | Location second = locations->InAt(1); |
| 3642 | DCHECK(first.Equals(locations->Out())); |
| 3643 | |
| 3644 | switch (op->GetResultType()) { |
| 3645 | case Primitive::kPrimInt: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3646 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3647 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3648 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3649 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3650 | DCHECK_EQ(ECX, second_reg); |
| 3651 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3652 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3653 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3654 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3655 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3656 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3657 | } |
| 3658 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3659 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3660 | if (shift == 0) { |
| 3661 | return; |
| 3662 | } |
| 3663 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3664 | if (op->IsShl()) { |
| 3665 | __ shll(first_reg, imm); |
| 3666 | } else if (op->IsShr()) { |
| 3667 | __ sarl(first_reg, imm); |
| 3668 | } else { |
| 3669 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3670 | } |
| 3671 | } |
| 3672 | break; |
| 3673 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3674 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3675 | if (second.IsRegister()) { |
| 3676 | Register second_reg = second.AsRegister<Register>(); |
| 3677 | DCHECK_EQ(ECX, second_reg); |
| 3678 | if (op->IsShl()) { |
| 3679 | GenerateShlLong(first, second_reg); |
| 3680 | } else if (op->IsShr()) { |
| 3681 | GenerateShrLong(first, second_reg); |
| 3682 | } else { |
| 3683 | GenerateUShrLong(first, second_reg); |
| 3684 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3685 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3686 | // Shift by a constant. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3687 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3688 | // Nothing to do if the shift is 0, as the input is already the output. |
| 3689 | if (shift != 0) { |
| 3690 | if (op->IsShl()) { |
| 3691 | GenerateShlLong(first, shift); |
| 3692 | } else if (op->IsShr()) { |
| 3693 | GenerateShrLong(first, shift); |
| 3694 | } else { |
| 3695 | GenerateUShrLong(first, shift); |
| 3696 | } |
| 3697 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3698 | } |
| 3699 | break; |
| 3700 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3701 | default: |
| 3702 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3703 | } |
| 3704 | } |
| 3705 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3706 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 3707 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3708 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 3709 | if (shift == 1) { |
| 3710 | // This is just an addition. |
| 3711 | __ addl(low, low); |
| 3712 | __ adcl(high, high); |
| 3713 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3714 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 3715 | codegen_->EmitParallelMoves( |
| 3716 | loc.ToLow(), |
| 3717 | loc.ToHigh(), |
| 3718 | Primitive::kPrimInt, |
| 3719 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3720 | loc.ToLow(), |
| 3721 | Primitive::kPrimInt); |
| 3722 | } else if (shift > 32) { |
| 3723 | // Low part becomes 0. High part is low part << (shift-32). |
| 3724 | __ movl(high, low); |
| 3725 | __ shll(high, Immediate(shift - 32)); |
| 3726 | __ xorl(low, low); |
| 3727 | } else { |
| 3728 | // Between 1 and 31. |
| 3729 | __ shld(high, low, Immediate(shift)); |
| 3730 | __ shll(low, Immediate(shift)); |
| 3731 | } |
| 3732 | } |
| 3733 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3734 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3735 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3736 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 3737 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 3738 | __ testl(shifter, Immediate(32)); |
| 3739 | __ j(kEqual, &done); |
| 3740 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 3741 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 3742 | __ Bind(&done); |
| 3743 | } |
| 3744 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3745 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 3746 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3747 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3748 | if (shift == 32) { |
| 3749 | // Need to copy the sign. |
| 3750 | DCHECK_NE(low, high); |
| 3751 | __ movl(low, high); |
| 3752 | __ sarl(high, Immediate(31)); |
| 3753 | } else if (shift > 32) { |
| 3754 | DCHECK_NE(low, high); |
| 3755 | // High part becomes sign. Low part is shifted by shift - 32. |
| 3756 | __ movl(low, high); |
| 3757 | __ sarl(high, Immediate(31)); |
| 3758 | __ sarl(low, Immediate(shift - 32)); |
| 3759 | } else { |
| 3760 | // Between 1 and 31. |
| 3761 | __ shrd(low, high, Immediate(shift)); |
| 3762 | __ sarl(high, Immediate(shift)); |
| 3763 | } |
| 3764 | } |
| 3765 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3766 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3767 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3768 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3769 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3770 | __ testl(shifter, Immediate(32)); |
| 3771 | __ j(kEqual, &done); |
| 3772 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3773 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 3774 | __ Bind(&done); |
| 3775 | } |
| 3776 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3777 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 3778 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3779 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3780 | if (shift == 32) { |
| 3781 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 3782 | codegen_->EmitParallelMoves( |
| 3783 | loc.ToHigh(), |
| 3784 | loc.ToLow(), |
| 3785 | Primitive::kPrimInt, |
| 3786 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3787 | loc.ToHigh(), |
| 3788 | Primitive::kPrimInt); |
| 3789 | } else if (shift > 32) { |
| 3790 | // Low part is high >> (shift - 32). High part becomes 0. |
| 3791 | __ movl(low, high); |
| 3792 | __ shrl(low, Immediate(shift - 32)); |
| 3793 | __ xorl(high, high); |
| 3794 | } else { |
| 3795 | // Between 1 and 31. |
| 3796 | __ shrd(low, high, Immediate(shift)); |
| 3797 | __ shrl(high, Immediate(shift)); |
| 3798 | } |
| 3799 | } |
| 3800 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3801 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3802 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3803 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3804 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3805 | __ testl(shifter, Immediate(32)); |
| 3806 | __ j(kEqual, &done); |
| 3807 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3808 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 3809 | __ Bind(&done); |
| 3810 | } |
| 3811 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3812 | void LocationsBuilderX86::VisitRor(HRor* ror) { |
| 3813 | LocationSummary* locations = |
| 3814 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3815 | |
| 3816 | switch (ror->GetResultType()) { |
| 3817 | case Primitive::kPrimLong: |
| 3818 | // Add the temporary needed. |
| 3819 | locations->AddTemp(Location::RequiresRegister()); |
| 3820 | FALLTHROUGH_INTENDED; |
| 3821 | case Primitive::kPrimInt: |
| 3822 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3823 | // The shift count needs to be in CL (unless it is a constant). |
| 3824 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); |
| 3825 | locations->SetOut(Location::SameAsFirstInput()); |
| 3826 | break; |
| 3827 | default: |
| 3828 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3829 | UNREACHABLE(); |
| 3830 | } |
| 3831 | } |
| 3832 | |
| 3833 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { |
| 3834 | LocationSummary* locations = ror->GetLocations(); |
| 3835 | Location first = locations->InAt(0); |
| 3836 | Location second = locations->InAt(1); |
| 3837 | |
| 3838 | if (ror->GetResultType() == Primitive::kPrimInt) { |
| 3839 | Register first_reg = first.AsRegister<Register>(); |
| 3840 | if (second.IsRegister()) { |
| 3841 | Register second_reg = second.AsRegister<Register>(); |
| 3842 | __ rorl(first_reg, second_reg); |
| 3843 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3844 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3845 | __ rorl(first_reg, imm); |
| 3846 | } |
| 3847 | return; |
| 3848 | } |
| 3849 | |
| 3850 | DCHECK_EQ(ror->GetResultType(), Primitive::kPrimLong); |
| 3851 | Register first_reg_lo = first.AsRegisterPairLow<Register>(); |
| 3852 | Register first_reg_hi = first.AsRegisterPairHigh<Register>(); |
| 3853 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 3854 | if (second.IsRegister()) { |
| 3855 | Register second_reg = second.AsRegister<Register>(); |
| 3856 | DCHECK_EQ(second_reg, ECX); |
| 3857 | __ movl(temp_reg, first_reg_hi); |
| 3858 | __ shrd(first_reg_hi, first_reg_lo, second_reg); |
| 3859 | __ shrd(first_reg_lo, temp_reg, second_reg); |
| 3860 | __ movl(temp_reg, first_reg_hi); |
| 3861 | __ testl(second_reg, Immediate(32)); |
| 3862 | __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); |
| 3863 | __ cmovl(kNotEqual, first_reg_lo, temp_reg); |
| 3864 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3865 | int32_t shift_amt = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3866 | if (shift_amt == 0) { |
| 3867 | // Already fine. |
| 3868 | return; |
| 3869 | } |
| 3870 | if (shift_amt == 32) { |
| 3871 | // Just swap. |
| 3872 | __ movl(temp_reg, first_reg_lo); |
| 3873 | __ movl(first_reg_lo, first_reg_hi); |
| 3874 | __ movl(first_reg_hi, temp_reg); |
| 3875 | return; |
| 3876 | } |
| 3877 | |
| 3878 | Immediate imm(shift_amt); |
| 3879 | // Save the constents of the low value. |
| 3880 | __ movl(temp_reg, first_reg_lo); |
| 3881 | |
| 3882 | // Shift right into low, feeding bits from high. |
| 3883 | __ shrd(first_reg_lo, first_reg_hi, imm); |
| 3884 | |
| 3885 | // Shift right into high, feeding bits from the original low. |
| 3886 | __ shrd(first_reg_hi, temp_reg, imm); |
| 3887 | |
| 3888 | // Swap if needed. |
| 3889 | if (shift_amt > 32) { |
| 3890 | __ movl(temp_reg, first_reg_lo); |
| 3891 | __ movl(first_reg_lo, first_reg_hi); |
| 3892 | __ movl(first_reg_hi, temp_reg); |
| 3893 | } |
| 3894 | } |
| 3895 | } |
| 3896 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3897 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 3898 | HandleShift(shl); |
| 3899 | } |
| 3900 | |
| 3901 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 3902 | HandleShift(shl); |
| 3903 | } |
| 3904 | |
| 3905 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 3906 | HandleShift(shr); |
| 3907 | } |
| 3908 | |
| 3909 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 3910 | HandleShift(shr); |
| 3911 | } |
| 3912 | |
| 3913 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 3914 | HandleShift(ushr); |
| 3915 | } |
| 3916 | |
| 3917 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 3918 | HandleShift(ushr); |
| 3919 | } |
| 3920 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3921 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3922 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3923 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3924 | locations->SetOut(Location::RegisterLocation(EAX)); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3925 | if (instruction->IsStringAlloc()) { |
| 3926 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3927 | } else { |
| 3928 | InvokeRuntimeCallingConvention calling_convention; |
| 3929 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3930 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3931 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3932 | } |
| 3933 | |
| 3934 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3935 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3936 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3937 | if (instruction->IsStringAlloc()) { |
| 3938 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 3939 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3940 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3941 | __ fs()->movl(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString))); |
| 3942 | __ call(Address(temp, code_offset.Int32Value())); |
| 3943 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3944 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3945 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3946 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 3947 | DCHECK(!codegen_->IsLeafMethod()); |
| 3948 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3949 | } |
| 3950 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3951 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| 3952 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3953 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3954 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 3955 | InvokeRuntimeCallingConvention calling_convention; |
| 3956 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3957 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3958 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3959 | } |
| 3960 | |
| 3961 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
| 3962 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3963 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3964 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3965 | // of poisoning the reference. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3966 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3967 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3968 | DCHECK(!codegen_->IsLeafMethod()); |
| 3969 | } |
| 3970 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3971 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3972 | LocationSummary* locations = |
| 3973 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3974 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3975 | if (location.IsStackSlot()) { |
| 3976 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3977 | } else if (location.IsDoubleStackSlot()) { |
| 3978 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3979 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3980 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3981 | } |
| 3982 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3983 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 3984 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 3985 | } |
| 3986 | |
| 3987 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3988 | LocationSummary* locations = |
| 3989 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3990 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3991 | } |
| 3992 | |
| 3993 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3994 | } |
| 3995 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3996 | void LocationsBuilderX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 3997 | LocationSummary* locations = |
| 3998 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3999 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4000 | locations->SetOut(Location::RequiresRegister()); |
| 4001 | } |
| 4002 | |
| 4003 | void InstructionCodeGeneratorX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4004 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4005 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4006 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4007 | instruction->GetIndex(), kX86PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4008 | __ movl(locations->Out().AsRegister<Register>(), |
| 4009 | Address(locations->InAt(0).AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4010 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4011 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4012 | instruction->GetIndex(), kX86PointerSize)); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4013 | __ movl(locations->Out().AsRegister<Register>(), |
| 4014 | Address(locations->InAt(0).AsRegister<Register>(), |
| 4015 | mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
| 4016 | // temp = temp->GetImtEntryAt(method_offset); |
| 4017 | __ movl(locations->Out().AsRegister<Register>(), |
| 4018 | Address(locations->Out().AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4019 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4020 | } |
| 4021 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4022 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4023 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4024 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4025 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4026 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4027 | } |
| 4028 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4029 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 4030 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4031 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4032 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4033 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4034 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4035 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4036 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4037 | break; |
| 4038 | |
| 4039 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4040 | __ notl(out.AsRegisterPairLow<Register>()); |
| 4041 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4042 | break; |
| 4043 | |
| 4044 | default: |
| 4045 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4046 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4047 | } |
| 4048 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4049 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4050 | LocationSummary* locations = |
| 4051 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4052 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4053 | locations->SetOut(Location::SameAsFirstInput()); |
| 4054 | } |
| 4055 | |
| 4056 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4057 | LocationSummary* locations = bool_not->GetLocations(); |
| 4058 | Location in = locations->InAt(0); |
| 4059 | Location out = locations->Out(); |
| 4060 | DCHECK(in.Equals(out)); |
| 4061 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 4062 | } |
| 4063 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4064 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4065 | LocationSummary* locations = |
| 4066 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4067 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4068 | case Primitive::kPrimBoolean: |
| 4069 | case Primitive::kPrimByte: |
| 4070 | case Primitive::kPrimShort: |
| 4071 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4072 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4073 | case Primitive::kPrimLong: { |
| 4074 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4075 | locations->SetInAt(1, Location::Any()); |
| 4076 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4077 | break; |
| 4078 | } |
| 4079 | case Primitive::kPrimFloat: |
| 4080 | case Primitive::kPrimDouble: { |
| 4081 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4082 | if (compare->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4083 | DCHECK(compare->InputAt(1)->IsEmittedAtUseSite()); |
| 4084 | } else if (compare->InputAt(1)->IsConstant()) { |
| 4085 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4086 | } else { |
| 4087 | locations->SetInAt(1, Location::Any()); |
| 4088 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4089 | locations->SetOut(Location::RequiresRegister()); |
| 4090 | break; |
| 4091 | } |
| 4092 | default: |
| 4093 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4094 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4095 | } |
| 4096 | |
| 4097 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4098 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4099 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4100 | Location left = locations->InAt(0); |
| 4101 | Location right = locations->InAt(1); |
| 4102 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4103 | NearLabel less, greater, done; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4104 | Condition less_cond = kLess; |
| 4105 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4106 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4107 | case Primitive::kPrimBoolean: |
| 4108 | case Primitive::kPrimByte: |
| 4109 | case Primitive::kPrimShort: |
| 4110 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4111 | case Primitive::kPrimInt: { |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 4112 | codegen_->GenerateIntCompare(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4113 | break; |
| 4114 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4115 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4116 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 4117 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 4118 | int32_t val_low = 0; |
| 4119 | int32_t val_high = 0; |
| 4120 | bool right_is_const = false; |
| 4121 | |
| 4122 | if (right.IsConstant()) { |
| 4123 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 4124 | right_is_const = true; |
| 4125 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 4126 | val_low = Low32Bits(val); |
| 4127 | val_high = High32Bits(val); |
| 4128 | } |
| 4129 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4130 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4131 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4132 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4133 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4134 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4135 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4136 | codegen_->Compare32BitValue(left_high, val_high); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4137 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4138 | __ j(kLess, &less); // Signed compare. |
| 4139 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4140 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4141 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4142 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4143 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4144 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4145 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4146 | codegen_->Compare32BitValue(left_low, val_low); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4147 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4148 | less_cond = kBelow; // for CF (unsigned). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4149 | break; |
| 4150 | } |
| 4151 | case Primitive::kPrimFloat: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4152 | GenerateFPCompare(left, right, compare, false); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4153 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4154 | less_cond = kBelow; // for CF (floats). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4155 | break; |
| 4156 | } |
| 4157 | case Primitive::kPrimDouble: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4158 | GenerateFPCompare(left, right, compare, true); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4159 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4160 | less_cond = kBelow; // for CF (floats). |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4161 | break; |
| 4162 | } |
| 4163 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4164 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4165 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4166 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4167 | __ movl(out, Immediate(0)); |
| 4168 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4169 | __ j(less_cond, &less); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4170 | |
| 4171 | __ Bind(&greater); |
| 4172 | __ movl(out, Immediate(1)); |
| 4173 | __ jmp(&done); |
| 4174 | |
| 4175 | __ Bind(&less); |
| 4176 | __ movl(out, Immediate(-1)); |
| 4177 | |
| 4178 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4179 | } |
| 4180 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4181 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4182 | LocationSummary* locations = |
| 4183 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4184 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4185 | locations->SetInAt(i, Location::Any()); |
| 4186 | } |
| 4187 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4188 | } |
| 4189 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4190 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4191 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4192 | } |
| 4193 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4194 | void CodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4195 | /* |
| 4196 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 4197 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 4198 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4199 | */ |
| 4200 | switch (kind) { |
| 4201 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4202 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4203 | break; |
| 4204 | } |
| 4205 | case MemBarrierKind::kAnyStore: |
| 4206 | case MemBarrierKind::kLoadAny: |
| 4207 | case MemBarrierKind::kStoreStore: { |
| 4208 | // nop |
| 4209 | break; |
| 4210 | } |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4211 | case MemBarrierKind::kNTStoreStore: |
| 4212 | // Non-Temporal Store/Store needs an explicit fence. |
| 4213 | MemoryFence(/* non-temporal */ true); |
| 4214 | break; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4215 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4216 | } |
| 4217 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4218 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( |
| 4219 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame^] | 4220 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4221 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info; |
| 4222 | |
| 4223 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 4224 | // is incompatible with it. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4225 | // TODO: Create as many X86ComputeBaseMethodAddress instructions |
| 4226 | // as needed for methods with irreducible loops. |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4227 | if (GetGraph()->HasIrreducibleLoops() && |
| 4228 | (dispatch_info.method_load_kind == |
| 4229 | HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative)) { |
| 4230 | dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod; |
| 4231 | } |
| 4232 | switch (dispatch_info.code_ptr_location) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4233 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4234 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 4235 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 4236 | // (Though the direct CALL ptr16:32 is available for consideration). |
| 4237 | return HInvokeStaticOrDirect::DispatchInfo { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4238 | dispatch_info.method_load_kind, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4239 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4240 | dispatch_info.method_load_data, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4241 | 0u |
| 4242 | }; |
| 4243 | default: |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4244 | return dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4245 | } |
| 4246 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4247 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4248 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 4249 | Register temp) { |
| 4250 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4251 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4252 | if (!invoke->GetLocations()->Intrinsified()) { |
| 4253 | return location.AsRegister<Register>(); |
| 4254 | } |
| 4255 | // For intrinsics we allow any location, so it may be on the stack. |
| 4256 | if (!location.IsRegister()) { |
| 4257 | __ movl(temp, Address(ESP, location.GetStackIndex())); |
| 4258 | return temp; |
| 4259 | } |
| 4260 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 4261 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 4262 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 4263 | // simple and more robust approach rather that trying to determine if that's the case. |
| 4264 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 4265 | if (slow_path != nullptr) { |
| 4266 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 4267 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 4268 | __ movl(temp, Address(ESP, stack_offset)); |
| 4269 | return temp; |
| 4270 | } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4271 | } |
| 4272 | return location.AsRegister<Register>(); |
| 4273 | } |
| 4274 | |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 4275 | Location CodeGeneratorX86::GenerateCalleeMethodStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 4276 | Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4277 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4278 | switch (invoke->GetMethodLoadKind()) { |
| 4279 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 4280 | // temp = thread->string_init_entrypoint |
| 4281 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(invoke->GetStringInitOffset())); |
| 4282 | break; |
| 4283 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4284 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4285 | break; |
| 4286 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4287 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 4288 | break; |
| 4289 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4290 | __ movl(temp.AsRegister<Register>(), Immediate(/* placeholder */ 0)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4291 | method_patches_.emplace_back(invoke->GetTargetMethod()); |
| 4292 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 4293 | break; |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4294 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 4295 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4296 | temp.AsRegister<Register>()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4297 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4298 | // Bind a new fixup label at the end of the "movl" insn. |
| 4299 | uint32_t offset = invoke->GetDexCacheArrayOffset(); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame^] | 4300 | __ Bind(NewPcRelativeDexCacheArrayPatch(invoke->GetDexFile(), offset)); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4301 | break; |
| 4302 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4303 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4304 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4305 | Register method_reg; |
| 4306 | Register reg = temp.AsRegister<Register>(); |
| 4307 | if (current_method.IsRegister()) { |
| 4308 | method_reg = current_method.AsRegister<Register>(); |
| 4309 | } else { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4310 | DCHECK(invoke->GetLocations()->Intrinsified()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4311 | DCHECK(!current_method.IsValid()); |
| 4312 | method_reg = reg; |
| 4313 | __ movl(reg, Address(ESP, kCurrentMethodStackOffset)); |
| 4314 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4315 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4316 | __ movl(reg, Address(method_reg, |
| 4317 | ArtMethod::DexCacheResolvedMethodsOffset(kX86PointerSize).Int32Value())); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 4318 | // temp = temp[index_in_cache]; |
| 4319 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 4320 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4321 | __ movl(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 4322 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4323 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4324 | } |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 4325 | return callee_method; |
| 4326 | } |
| 4327 | |
| 4328 | void CodeGeneratorX86::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 4329 | Location callee_method = GenerateCalleeMethodStaticOrDirectCall(invoke, temp); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4330 | |
| 4331 | switch (invoke->GetCodePtrLocation()) { |
| 4332 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 4333 | __ call(GetFrameEntryLabel()); |
| 4334 | break; |
| 4335 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 4336 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 4337 | Label* label = &relative_call_patches_.back().label; |
| 4338 | __ call(label); // Bind to the patch label, override at link time. |
| 4339 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 4340 | break; |
| 4341 | } |
| 4342 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4343 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4344 | // Filtered out by GetSupportedInvokeStaticOrDirectDispatch(). |
| 4345 | LOG(FATAL) << "Unsupported"; |
| 4346 | UNREACHABLE(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4347 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4348 | // (callee_method + offset_of_quick_compiled_code)() |
| 4349 | __ call(Address(callee_method.AsRegister<Register>(), |
| 4350 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4351 | kX86PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4352 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4353 | } |
| 4354 | |
| 4355 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4356 | } |
| 4357 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4358 | void CodeGeneratorX86::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 4359 | Register temp = temp_in.AsRegister<Register>(); |
| 4360 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4361 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4362 | |
| 4363 | // Use the calling convention instead of the location of the receiver, as |
| 4364 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4365 | // slow path, the arguments have been moved to the right place, so here we are |
| 4366 | // guaranteed that the receiver is the first register of the calling convention. |
| 4367 | InvokeDexCallingConvention calling_convention; |
| 4368 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4369 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4370 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4371 | __ movl(temp, Address(receiver, class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4372 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4373 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4374 | // emit a read barrier for the previous class reference load. |
| 4375 | // However this is not required in practice, as this is an |
| 4376 | // intermediate/temporary reference and because the current |
| 4377 | // concurrent copying collector keeps the from-space memory |
| 4378 | // intact/accessible until the end of the marking phase (the |
| 4379 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4380 | __ MaybeUnpoisonHeapReference(temp); |
| 4381 | // temp = temp->GetMethodAt(method_offset); |
| 4382 | __ movl(temp, Address(temp, method_offset)); |
| 4383 | // call temp->GetEntryPoint(); |
| 4384 | __ call(Address( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4385 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4386 | } |
| 4387 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4388 | void CodeGeneratorX86::RecordSimplePatch() { |
| 4389 | if (GetCompilerOptions().GetIncludePatchInformation()) { |
| 4390 | simple_patches_.emplace_back(); |
| 4391 | __ Bind(&simple_patches_.back()); |
| 4392 | } |
| 4393 | } |
| 4394 | |
| 4395 | void CodeGeneratorX86::RecordStringPatch(HLoadString* load_string) { |
| 4396 | string_patches_.emplace_back(load_string->GetDexFile(), load_string->GetStringIndex()); |
| 4397 | __ Bind(&string_patches_.back().label); |
| 4398 | } |
| 4399 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4400 | void CodeGeneratorX86::RecordTypePatch(HLoadClass* load_class) { |
| 4401 | type_patches_.emplace_back(load_class->GetDexFile(), load_class->GetTypeIndex()); |
| 4402 | __ Bind(&type_patches_.back().label); |
| 4403 | } |
| 4404 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4405 | Label* CodeGeneratorX86::NewPcRelativeDexCacheArrayPatch(const DexFile& dex_file, |
| 4406 | uint32_t element_offset) { |
| 4407 | // Add the patch entry and bind its label at the end of the instruction. |
| 4408 | pc_relative_dex_cache_patches_.emplace_back(dex_file, element_offset); |
| 4409 | return &pc_relative_dex_cache_patches_.back().label; |
| 4410 | } |
| 4411 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4412 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 4413 | DCHECK(linker_patches->empty()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4414 | size_t size = |
| 4415 | method_patches_.size() + |
| 4416 | relative_call_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4417 | pc_relative_dex_cache_patches_.size() + |
| 4418 | simple_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4419 | string_patches_.size() + |
| 4420 | type_patches_.size(); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4421 | linker_patches->reserve(size); |
| 4422 | // The label points to the end of the "movl" insn but the literal offset for method |
| 4423 | // patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 4424 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4425 | for (const MethodPatchInfo<Label>& info : method_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4426 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4427 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 4428 | info.target_method.dex_file, |
| 4429 | info.target_method.dex_method_index)); |
| 4430 | } |
| 4431 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4432 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4433 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 4434 | info.target_method.dex_file, |
| 4435 | info.target_method.dex_method_index)); |
| 4436 | } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4437 | for (const PcRelativeDexCacheAccessInfo& info : pc_relative_dex_cache_patches_) { |
| 4438 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4439 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(literal_offset, |
| 4440 | &info.target_dex_file, |
| 4441 | GetMethodAddressOffset(), |
| 4442 | info.element_offset)); |
| 4443 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4444 | for (const Label& label : simple_patches_) { |
| 4445 | uint32_t literal_offset = label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4446 | linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset)); |
| 4447 | } |
| 4448 | if (GetCompilerOptions().GetCompilePic()) { |
| 4449 | for (const StringPatchInfo<Label>& info : string_patches_) { |
| 4450 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4451 | linker_patches->push_back(LinkerPatch::RelativeStringPatch(literal_offset, |
| 4452 | &info.dex_file, |
| 4453 | GetMethodAddressOffset(), |
| 4454 | info.string_index)); |
| 4455 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4456 | for (const TypePatchInfo<Label>& info : type_patches_) { |
| 4457 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4458 | linker_patches->push_back(LinkerPatch::RelativeTypePatch(literal_offset, |
| 4459 | &info.dex_file, |
| 4460 | GetMethodAddressOffset(), |
| 4461 | info.type_index)); |
| 4462 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4463 | } else { |
| 4464 | for (const StringPatchInfo<Label>& info : string_patches_) { |
| 4465 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4466 | linker_patches->push_back(LinkerPatch::StringPatch(literal_offset, |
| 4467 | &info.dex_file, |
| 4468 | info.string_index)); |
| 4469 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4470 | for (const TypePatchInfo<Label>& info : type_patches_) { |
| 4471 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4472 | linker_patches->push_back(LinkerPatch::TypePatch(literal_offset, |
| 4473 | &info.dex_file, |
| 4474 | info.type_index)); |
| 4475 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4476 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4477 | } |
| 4478 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4479 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 4480 | Register card, |
| 4481 | Register object, |
| 4482 | Register value, |
| 4483 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4484 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4485 | if (value_can_be_null) { |
| 4486 | __ testl(value, value); |
| 4487 | __ j(kEqual, &is_null); |
| 4488 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4489 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86PointerSize>().Int32Value())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4490 | __ movl(temp, object); |
| 4491 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4492 | __ movb(Address(temp, card, TIMES_1, 0), |
| 4493 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4494 | if (value_can_be_null) { |
| 4495 | __ Bind(&is_null); |
| 4496 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4497 | } |
| 4498 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4499 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4500 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4501 | |
| 4502 | bool object_field_get_with_read_barrier = |
| 4503 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4504 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4505 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4506 | kEmitCompilerReadBarrier ? |
| 4507 | LocationSummary::kCallOnSlowPath : |
| 4508 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4509 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4510 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4511 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4512 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4513 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4514 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4515 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4516 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4517 | // The output overlaps in case of long: we don't want the low move |
| 4518 | // to overwrite the object's location. Likewise, in the case of |
| 4519 | // an object field get with read barriers enabled, we do not want |
| 4520 | // the move to overwrite the object's location, as we need it to emit |
| 4521 | // the read barrier. |
| 4522 | locations->SetOut( |
| 4523 | Location::RequiresRegister(), |
| 4524 | (object_field_get_with_read_barrier || instruction->GetType() == Primitive::kPrimLong) ? |
| 4525 | Location::kOutputOverlap : |
| 4526 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4527 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4528 | |
| 4529 | if (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) { |
| 4530 | // Long values can be loaded atomically into an XMM using movsd. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4531 | // So we use an XMM register as a temp to achieve atomicity (first |
| 4532 | // load the temp into the XMM and then copy the XMM into the |
| 4533 | // output, 32 bits at a time). |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4534 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4535 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4536 | } |
| 4537 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4538 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 4539 | const FieldInfo& field_info) { |
| 4540 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4541 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4542 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4543 | Location base_loc = locations->InAt(0); |
| 4544 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4545 | Location out = locations->Out(); |
| 4546 | bool is_volatile = field_info.IsVolatile(); |
| 4547 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4548 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4549 | |
| 4550 | switch (field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4551 | case Primitive::kPrimBoolean: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4552 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4553 | break; |
| 4554 | } |
| 4555 | |
| 4556 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4557 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4558 | break; |
| 4559 | } |
| 4560 | |
| 4561 | case Primitive::kPrimShort: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4562 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4563 | break; |
| 4564 | } |
| 4565 | |
| 4566 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4567 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4568 | break; |
| 4569 | } |
| 4570 | |
| 4571 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4572 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4573 | break; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4574 | |
| 4575 | case Primitive::kPrimNot: { |
| 4576 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4577 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4578 | // Note that a potential implicit null check is handled in this |
| 4579 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 4580 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 4581 | instruction, out, base, offset, /* needs_null_check */ true); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4582 | if (is_volatile) { |
| 4583 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4584 | } |
| 4585 | } else { |
| 4586 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| 4587 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4588 | if (is_volatile) { |
| 4589 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4590 | } |
| 4591 | // If read barriers are enabled, emit read barriers other than |
| 4592 | // Baker's using a slow path (and also unpoison the loaded |
| 4593 | // reference, if heap poisoning is enabled). |
| 4594 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4595 | } |
| 4596 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4597 | } |
| 4598 | |
| 4599 | case Primitive::kPrimLong: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4600 | if (is_volatile) { |
| 4601 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4602 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4603 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4604 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 4605 | __ psrlq(temp, Immediate(32)); |
| 4606 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 4607 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4608 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4609 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4610 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4611 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 4612 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4613 | break; |
| 4614 | } |
| 4615 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4616 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4617 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4618 | break; |
| 4619 | } |
| 4620 | |
| 4621 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4622 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4623 | break; |
| 4624 | } |
| 4625 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4626 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4627 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4628 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4629 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4630 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4631 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimLong) { |
| 4632 | // Potential implicit null checks, in the case of reference or |
| 4633 | // long fields, are handled in the previous switch statement. |
| 4634 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4635 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4636 | } |
| 4637 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4638 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4639 | if (field_type == Primitive::kPrimNot) { |
| 4640 | // Memory barriers, in the case of references, are also handled |
| 4641 | // in the previous switch statement. |
| 4642 | } else { |
| 4643 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4644 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4645 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4646 | } |
| 4647 | |
| 4648 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4649 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4650 | |
| 4651 | LocationSummary* locations = |
| 4652 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4653 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4654 | bool is_volatile = field_info.IsVolatile(); |
| 4655 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4656 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 4657 | || (field_type == Primitive::kPrimByte); |
| 4658 | |
| 4659 | // The register allocator does not support multiple |
| 4660 | // inputs that die at entry with one in a specific register. |
| 4661 | if (is_byte_type) { |
| 4662 | // Ensure the value is in a byte register. |
| 4663 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4664 | } else if (Primitive::IsFloatingPointType(field_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4665 | if (is_volatile && field_type == Primitive::kPrimDouble) { |
| 4666 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4667 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4668 | } else { |
| 4669 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4670 | } |
| 4671 | } else if (is_volatile && field_type == Primitive::kPrimLong) { |
| 4672 | // 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] | 4673 | locations->SetInAt(1, Location::RequiresRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4674 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4675 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 4676 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 4677 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 4678 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 4679 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 4680 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4681 | locations->AddTemp(Location::RequiresFpuRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4682 | } else { |
| 4683 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4684 | |
| 4685 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4686 | // Temporary registers for the write barrier. |
| 4687 | locations->AddTemp(Location::RequiresRegister()); // May be used for reference poisoning too. |
| 4688 | // Ensure the card is in a byte register. |
| 4689 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 4690 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4691 | } |
| 4692 | } |
| 4693 | |
| 4694 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4695 | const FieldInfo& field_info, |
| 4696 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4697 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4698 | |
| 4699 | LocationSummary* locations = instruction->GetLocations(); |
| 4700 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 4701 | Location value = locations->InAt(1); |
| 4702 | bool is_volatile = field_info.IsVolatile(); |
| 4703 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4704 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4705 | bool needs_write_barrier = |
| 4706 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4707 | |
| 4708 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4709 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4710 | } |
| 4711 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4712 | bool maybe_record_implicit_null_check_done = false; |
| 4713 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4714 | switch (field_type) { |
| 4715 | case Primitive::kPrimBoolean: |
| 4716 | case Primitive::kPrimByte: { |
| 4717 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 4718 | break; |
| 4719 | } |
| 4720 | |
| 4721 | case Primitive::kPrimShort: |
| 4722 | case Primitive::kPrimChar: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4723 | if (value.IsConstant()) { |
| 4724 | int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4725 | __ movw(Address(base, offset), Immediate(v)); |
| 4726 | } else { |
| 4727 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 4728 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4729 | break; |
| 4730 | } |
| 4731 | |
| 4732 | case Primitive::kPrimInt: |
| 4733 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4734 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4735 | // Note that in the case where `value` is a null reference, |
| 4736 | // we do not enter this block, as the reference does not |
| 4737 | // need poisoning. |
| 4738 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 4739 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4740 | __ movl(temp, value.AsRegister<Register>()); |
| 4741 | __ PoisonHeapReference(temp); |
| 4742 | __ movl(Address(base, offset), temp); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4743 | } else if (value.IsConstant()) { |
| 4744 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4745 | __ movl(Address(base, offset), Immediate(v)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4746 | } else { |
Nicolas Geoffray | 0397163 | 2016-03-17 10:44:24 +0000 | [diff] [blame] | 4747 | DCHECK(value.IsRegister()) << value; |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4748 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 4749 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4750 | break; |
| 4751 | } |
| 4752 | |
| 4753 | case Primitive::kPrimLong: { |
| 4754 | if (is_volatile) { |
| 4755 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4756 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 4757 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 4758 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 4759 | __ punpckldq(temp1, temp2); |
| 4760 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4761 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4762 | } else if (value.IsConstant()) { |
| 4763 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4764 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4765 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4766 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4767 | } else { |
| 4768 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4769 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4770 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 4771 | } |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4772 | maybe_record_implicit_null_check_done = true; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4773 | break; |
| 4774 | } |
| 4775 | |
| 4776 | case Primitive::kPrimFloat: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4777 | if (value.IsConstant()) { |
| 4778 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4779 | __ movl(Address(base, offset), Immediate(v)); |
| 4780 | } else { |
| 4781 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4782 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4783 | break; |
| 4784 | } |
| 4785 | |
| 4786 | case Primitive::kPrimDouble: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4787 | if (value.IsConstant()) { |
| 4788 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4789 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4790 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4791 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
| 4792 | maybe_record_implicit_null_check_done = true; |
| 4793 | } else { |
| 4794 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4795 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4796 | break; |
| 4797 | } |
| 4798 | |
| 4799 | case Primitive::kPrimVoid: |
| 4800 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4801 | UNREACHABLE(); |
| 4802 | } |
| 4803 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4804 | if (!maybe_record_implicit_null_check_done) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4805 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4806 | } |
| 4807 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4808 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4809 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4810 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4811 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4812 | } |
| 4813 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4814 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4815 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4816 | } |
| 4817 | } |
| 4818 | |
| 4819 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4820 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4821 | } |
| 4822 | |
| 4823 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4824 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4825 | } |
| 4826 | |
| 4827 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4828 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4829 | } |
| 4830 | |
| 4831 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4832 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4833 | } |
| 4834 | |
| 4835 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4836 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4837 | } |
| 4838 | |
| 4839 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4840 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4841 | } |
| 4842 | |
| 4843 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4844 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4845 | } |
| 4846 | |
| 4847 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4848 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4849 | } |
| 4850 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4851 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 4852 | HUnresolvedInstanceFieldGet* instruction) { |
| 4853 | FieldAccessCallingConventionX86 calling_convention; |
| 4854 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4855 | instruction, instruction->GetFieldType(), calling_convention); |
| 4856 | } |
| 4857 | |
| 4858 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 4859 | HUnresolvedInstanceFieldGet* instruction) { |
| 4860 | FieldAccessCallingConventionX86 calling_convention; |
| 4861 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4862 | instruction->GetFieldType(), |
| 4863 | instruction->GetFieldIndex(), |
| 4864 | instruction->GetDexPc(), |
| 4865 | calling_convention); |
| 4866 | } |
| 4867 | |
| 4868 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 4869 | HUnresolvedInstanceFieldSet* instruction) { |
| 4870 | FieldAccessCallingConventionX86 calling_convention; |
| 4871 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4872 | instruction, instruction->GetFieldType(), calling_convention); |
| 4873 | } |
| 4874 | |
| 4875 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 4876 | HUnresolvedInstanceFieldSet* instruction) { |
| 4877 | FieldAccessCallingConventionX86 calling_convention; |
| 4878 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4879 | instruction->GetFieldType(), |
| 4880 | instruction->GetFieldIndex(), |
| 4881 | instruction->GetDexPc(), |
| 4882 | calling_convention); |
| 4883 | } |
| 4884 | |
| 4885 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 4886 | HUnresolvedStaticFieldGet* instruction) { |
| 4887 | FieldAccessCallingConventionX86 calling_convention; |
| 4888 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4889 | instruction, instruction->GetFieldType(), calling_convention); |
| 4890 | } |
| 4891 | |
| 4892 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 4893 | HUnresolvedStaticFieldGet* instruction) { |
| 4894 | FieldAccessCallingConventionX86 calling_convention; |
| 4895 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4896 | instruction->GetFieldType(), |
| 4897 | instruction->GetFieldIndex(), |
| 4898 | instruction->GetDexPc(), |
| 4899 | calling_convention); |
| 4900 | } |
| 4901 | |
| 4902 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 4903 | HUnresolvedStaticFieldSet* instruction) { |
| 4904 | FieldAccessCallingConventionX86 calling_convention; |
| 4905 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4906 | instruction, instruction->GetFieldType(), calling_convention); |
| 4907 | } |
| 4908 | |
| 4909 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 4910 | HUnresolvedStaticFieldSet* instruction) { |
| 4911 | FieldAccessCallingConventionX86 calling_convention; |
| 4912 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4913 | instruction->GetFieldType(), |
| 4914 | instruction->GetFieldIndex(), |
| 4915 | instruction->GetDexPc(), |
| 4916 | calling_convention); |
| 4917 | } |
| 4918 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4919 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4920 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 4921 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 4922 | ? Location::RequiresRegister() |
| 4923 | : Location::Any(); |
| 4924 | locations->SetInAt(0, loc); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4925 | } |
| 4926 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4927 | void CodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4928 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4929 | return; |
| 4930 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4931 | LocationSummary* locations = instruction->GetLocations(); |
| 4932 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4933 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4934 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4935 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4936 | } |
| 4937 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4938 | void CodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4939 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4940 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4941 | |
| 4942 | LocationSummary* locations = instruction->GetLocations(); |
| 4943 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4944 | |
| 4945 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 4946 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4947 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4948 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4949 | } else { |
| 4950 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4951 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4952 | __ jmp(slow_path->GetEntryLabel()); |
| 4953 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4954 | } |
| 4955 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4956 | } |
| 4957 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4958 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4959 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4960 | } |
| 4961 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4962 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4963 | bool object_array_get_with_read_barrier = |
| 4964 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4965 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4966 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4967 | object_array_get_with_read_barrier ? |
| 4968 | LocationSummary::kCallOnSlowPath : |
| 4969 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4970 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4971 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4972 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4973 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4974 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4975 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4976 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4977 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4978 | // The output overlaps in case of long: we don't want the low move |
| 4979 | // to overwrite the array's location. Likewise, in the case of an |
| 4980 | // object array get with read barriers enabled, we do not want the |
| 4981 | // move to overwrite the array's location, as we need it to emit |
| 4982 | // the read barrier. |
| 4983 | locations->SetOut( |
| 4984 | Location::RequiresRegister(), |
| 4985 | (instruction->GetType() == Primitive::kPrimLong || object_array_get_with_read_barrier) ? |
| 4986 | Location::kOutputOverlap : |
| 4987 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4988 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4989 | } |
| 4990 | |
| 4991 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 4992 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4993 | Location obj_loc = locations->InAt(0); |
| 4994 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4995 | Location index = locations->InAt(1); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4996 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 4997 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4998 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4999 | Primitive::Type type = instruction->GetType(); |
| 5000 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5001 | case Primitive::kPrimBoolean: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5002 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5003 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5004 | break; |
| 5005 | } |
| 5006 | |
| 5007 | case Primitive::kPrimByte: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5008 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5009 | __ movsxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5010 | break; |
| 5011 | } |
| 5012 | |
| 5013 | case Primitive::kPrimShort: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5014 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5015 | __ movsxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5016 | break; |
| 5017 | } |
| 5018 | |
| 5019 | case Primitive::kPrimChar: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5020 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5021 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5022 | break; |
| 5023 | } |
| 5024 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5025 | case Primitive::kPrimInt: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5026 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5027 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5028 | break; |
| 5029 | } |
| 5030 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5031 | case Primitive::kPrimNot: { |
| 5032 | static_assert( |
| 5033 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5034 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5035 | // /* HeapReference<Object> */ out = |
| 5036 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5037 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5038 | // Note that a potential implicit null check is handled in this |
| 5039 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 5040 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5041 | instruction, out_loc, obj, data_offset, index, /* needs_null_check */ true); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5042 | } else { |
| 5043 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5044 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| 5045 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5046 | // If read barriers are enabled, emit read barriers other than |
| 5047 | // Baker's using a slow path (and also unpoison the loaded |
| 5048 | // reference, if heap poisoning is enabled). |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5049 | if (index.IsConstant()) { |
| 5050 | uint32_t offset = |
| 5051 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5052 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5053 | } else { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5054 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5055 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5056 | } |
| 5057 | } |
| 5058 | break; |
| 5059 | } |
| 5060 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5061 | case Primitive::kPrimLong: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5062 | DCHECK_NE(obj, out_loc.AsRegisterPairLow<Register>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5063 | __ movl(out_loc.AsRegisterPairLow<Register>(), |
| 5064 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
| 5065 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5066 | __ movl(out_loc.AsRegisterPairHigh<Register>(), |
| 5067 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5068 | break; |
| 5069 | } |
| 5070 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5071 | case Primitive::kPrimFloat: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5072 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5073 | __ movss(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5074 | break; |
| 5075 | } |
| 5076 | |
| 5077 | case Primitive::kPrimDouble: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5078 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5079 | __ movsd(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5080 | break; |
| 5081 | } |
| 5082 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5083 | case Primitive::kPrimVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5084 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5085 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5086 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5087 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5088 | if (type == Primitive::kPrimNot || type == Primitive::kPrimLong) { |
| 5089 | // Potential implicit null checks, in the case of reference or |
| 5090 | // long arrays, are handled in the previous switch statement. |
| 5091 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5092 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5093 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5094 | } |
| 5095 | |
| 5096 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5097 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5098 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5099 | bool needs_write_barrier = |
| 5100 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5101 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5102 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5103 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 5104 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 5105 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5106 | LocationSummary::kCallOnSlowPath : |
| 5107 | LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5108 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5109 | bool is_byte_type = (value_type == Primitive::kPrimBoolean) |
| 5110 | || (value_type == Primitive::kPrimByte); |
| 5111 | // We need the inputs to be different than the output in case of long operation. |
| 5112 | // In case of a byte operation, the register allocator does not support multiple |
| 5113 | // inputs that die at entry with one in a specific register. |
| 5114 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5115 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5116 | if (is_byte_type) { |
| 5117 | // Ensure the value is in a byte register. |
| 5118 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
| 5119 | } else if (Primitive::IsFloatingPointType(value_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5120 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5121 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5122 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 5123 | } |
| 5124 | if (needs_write_barrier) { |
| 5125 | // Temporary registers for the write barrier. |
| 5126 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 5127 | // Ensure the card is in a byte register. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5128 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5129 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5130 | } |
| 5131 | |
| 5132 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 5133 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5134 | Location array_loc = locations->InAt(0); |
| 5135 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5136 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5137 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5138 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5139 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5140 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5141 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5142 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5143 | bool needs_write_barrier = |
| 5144 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5145 | |
| 5146 | switch (value_type) { |
| 5147 | case Primitive::kPrimBoolean: |
| 5148 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5149 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5150 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_1, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5151 | if (value.IsRegister()) { |
| 5152 | __ movb(address, value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5153 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5154 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5155 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5156 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5157 | break; |
| 5158 | } |
| 5159 | |
| 5160 | case Primitive::kPrimShort: |
| 5161 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5162 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5163 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_2, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5164 | if (value.IsRegister()) { |
| 5165 | __ movw(address, value.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5166 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5167 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5168 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5169 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5170 | break; |
| 5171 | } |
| 5172 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5173 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5174 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5175 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5176 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5177 | if (!value.IsRegister()) { |
| 5178 | // Just setting null. |
| 5179 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5180 | DCHECK(value.IsConstant()) << value; |
| 5181 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5182 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5183 | DCHECK(!needs_write_barrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5184 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5185 | break; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5186 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5187 | |
| 5188 | DCHECK(needs_write_barrier); |
| 5189 | Register register_value = value.AsRegister<Register>(); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5190 | // We cannot use a NearLabel for `done`, as its range may be too |
| 5191 | // short when Baker read barriers are enabled. |
| 5192 | Label done; |
| 5193 | NearLabel not_null, do_put; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5194 | SlowPathCode* slow_path = nullptr; |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5195 | Location temp_loc = locations->GetTemp(0); |
| 5196 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5197 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5198 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86(instruction); |
| 5199 | codegen_->AddSlowPath(slow_path); |
| 5200 | if (instruction->GetValueCanBeNull()) { |
| 5201 | __ testl(register_value, register_value); |
| 5202 | __ j(kNotEqual, ¬_null); |
| 5203 | __ movl(address, Immediate(0)); |
| 5204 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5205 | __ jmp(&done); |
| 5206 | __ Bind(¬_null); |
| 5207 | } |
| 5208 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5209 | // Note that when Baker read barriers are enabled, the type |
| 5210 | // checks are performed without read barriers. This is fine, |
| 5211 | // even in the case where a class object is in the from-space |
| 5212 | // after the flip, as a comparison involving such a type would |
| 5213 | // not produce a false positive; it may of course produce a |
| 5214 | // false negative, in which case we would take the ArraySet |
| 5215 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5216 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5217 | // /* HeapReference<Class> */ temp = array->klass_ |
| 5218 | __ movl(temp, Address(array, class_offset)); |
| 5219 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5220 | __ MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5221 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5222 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5223 | __ movl(temp, Address(temp, component_offset)); |
| 5224 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 5225 | // nor the object reference in `register_value->klass`, as |
| 5226 | // we are comparing two poisoned references. |
| 5227 | __ cmpl(temp, Address(register_value, class_offset)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5228 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5229 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5230 | __ j(kEqual, &do_put); |
| 5231 | // If heap poisoning is enabled, the `temp` reference has |
| 5232 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5233 | __ MaybeUnpoisonHeapReference(temp); |
| 5234 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5235 | // If heap poisoning is enabled, no need to unpoison the |
| 5236 | // heap reference loaded below, as it is only used for a |
| 5237 | // comparison with null. |
| 5238 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 5239 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5240 | __ Bind(&do_put); |
| 5241 | } else { |
| 5242 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5243 | } |
| 5244 | } |
| 5245 | |
| 5246 | if (kPoisonHeapReferences) { |
| 5247 | __ movl(temp, register_value); |
| 5248 | __ PoisonHeapReference(temp); |
| 5249 | __ movl(address, temp); |
| 5250 | } else { |
| 5251 | __ movl(address, register_value); |
| 5252 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5253 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5254 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5255 | } |
| 5256 | |
| 5257 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 5258 | codegen_->MarkGCCard( |
| 5259 | temp, card, array, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); |
| 5260 | __ Bind(&done); |
| 5261 | |
| 5262 | if (slow_path != nullptr) { |
| 5263 | __ Bind(slow_path->GetExitLabel()); |
| 5264 | } |
| 5265 | |
| 5266 | break; |
| 5267 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5268 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5269 | case Primitive::kPrimInt: { |
| 5270 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5271 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5272 | if (value.IsRegister()) { |
| 5273 | __ movl(address, value.AsRegister<Register>()); |
| 5274 | } else { |
| 5275 | DCHECK(value.IsConstant()) << value; |
| 5276 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5277 | __ movl(address, Immediate(v)); |
| 5278 | } |
| 5279 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5280 | break; |
| 5281 | } |
| 5282 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5283 | case Primitive::kPrimLong: { |
| 5284 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5285 | if (value.IsRegisterPair()) { |
| 5286 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 5287 | value.AsRegisterPairLow<Register>()); |
| 5288 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5289 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 5290 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5291 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5292 | DCHECK(value.IsConstant()); |
| 5293 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
| 5294 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 5295 | Immediate(Low32Bits(val))); |
| 5296 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5297 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 5298 | Immediate(High32Bits(val))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5299 | } |
| 5300 | break; |
| 5301 | } |
| 5302 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5303 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5304 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5305 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5306 | if (value.IsFpuRegister()) { |
| 5307 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5308 | } else { |
| 5309 | DCHECK(value.IsConstant()); |
| 5310 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 5311 | __ movl(address, Immediate(v)); |
| 5312 | } |
| 5313 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5314 | break; |
| 5315 | } |
| 5316 | |
| 5317 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5318 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5319 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5320 | if (value.IsFpuRegister()) { |
| 5321 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5322 | } else { |
| 5323 | DCHECK(value.IsConstant()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5324 | Address address_hi = |
| 5325 | CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset + kX86WordSize); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5326 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 5327 | __ movl(address, Immediate(Low32Bits(v))); |
| 5328 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5329 | __ movl(address_hi, Immediate(High32Bits(v))); |
| 5330 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5331 | break; |
| 5332 | } |
| 5333 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5334 | case Primitive::kPrimVoid: |
| 5335 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5336 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5337 | } |
| 5338 | } |
| 5339 | |
| 5340 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| 5341 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5342 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5343 | if (!instruction->IsEmittedAtUseSite()) { |
| 5344 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5345 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5346 | } |
| 5347 | |
| 5348 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5349 | if (instruction->IsEmittedAtUseSite()) { |
| 5350 | return; |
| 5351 | } |
| 5352 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5353 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5354 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5355 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5356 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5357 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5358 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5359 | } |
| 5360 | |
| 5361 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5362 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5363 | InvokeRuntimeCallingConvention calling_convention; |
| 5364 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5365 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5366 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5367 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5368 | HInstruction* length = instruction->InputAt(1); |
| 5369 | if (!length->IsEmittedAtUseSite()) { |
| 5370 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5371 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5372 | } |
| 5373 | |
| 5374 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5375 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5376 | Location index_loc = locations->InAt(0); |
| 5377 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5378 | SlowPathCode* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5379 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5380 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5381 | if (length_loc.IsConstant()) { |
| 5382 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5383 | if (index_loc.IsConstant()) { |
| 5384 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5385 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5386 | if (index < 0 || index >= length) { |
| 5387 | codegen_->AddSlowPath(slow_path); |
| 5388 | __ jmp(slow_path->GetEntryLabel()); |
| 5389 | } else { |
| 5390 | // Some optimization after BCE may have generated this, and we should not |
| 5391 | // generate a bounds check if it is a valid range. |
| 5392 | } |
| 5393 | return; |
| 5394 | } |
| 5395 | |
| 5396 | // We have to reverse the jump condition because the length is the constant. |
| 5397 | Register index_reg = index_loc.AsRegister<Register>(); |
| 5398 | __ cmpl(index_reg, Immediate(length)); |
| 5399 | codegen_->AddSlowPath(slow_path); |
| 5400 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5401 | } else { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5402 | HInstruction* array_length = instruction->InputAt(1); |
| 5403 | if (array_length->IsEmittedAtUseSite()) { |
| 5404 | // Address the length field in the array. |
| 5405 | DCHECK(array_length->IsArrayLength()); |
| 5406 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 5407 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 5408 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
| 5409 | if (index_loc.IsConstant()) { |
| 5410 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5411 | __ cmpl(array_len, Immediate(value)); |
| 5412 | } else { |
| 5413 | __ cmpl(array_len, index_loc.AsRegister<Register>()); |
| 5414 | } |
| 5415 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5416 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5417 | codegen_->GenerateIntCompare(length_loc, index_loc); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5418 | } |
| 5419 | codegen_->AddSlowPath(slow_path); |
| 5420 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5421 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5422 | } |
| 5423 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5424 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5425 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5426 | } |
| 5427 | |
| 5428 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5429 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5430 | } |
| 5431 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5432 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5433 | LocationSummary* locations = |
| 5434 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5435 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5436 | } |
| 5437 | |
| 5438 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5439 | HBasicBlock* block = instruction->GetBlock(); |
| 5440 | if (block->GetLoopInformation() != nullptr) { |
| 5441 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5442 | // The back edge will generate the suspend check. |
| 5443 | return; |
| 5444 | } |
| 5445 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5446 | // The goto will generate the suspend check. |
| 5447 | return; |
| 5448 | } |
| 5449 | GenerateSuspendCheck(instruction, nullptr); |
| 5450 | } |
| 5451 | |
| 5452 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5453 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5454 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5455 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 5456 | if (slow_path == nullptr) { |
| 5457 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); |
| 5458 | instruction->SetSlowPath(slow_path); |
| 5459 | codegen_->AddSlowPath(slow_path); |
| 5460 | if (successor != nullptr) { |
| 5461 | DCHECK(successor->IsLoopHeader()); |
| 5462 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5463 | } |
| 5464 | } else { |
| 5465 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5466 | } |
| 5467 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5468 | __ fs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86PointerSize>().Int32Value()), |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5469 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5470 | if (successor == nullptr) { |
| 5471 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5472 | __ Bind(slow_path->GetReturnLabel()); |
| 5473 | } else { |
| 5474 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5475 | __ jmp(slow_path->GetEntryLabel()); |
| 5476 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5477 | } |
| 5478 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5479 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 5480 | return codegen_->GetAssembler(); |
| 5481 | } |
| 5482 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5483 | void ParallelMoveResolverX86::MoveMemoryToMemory32(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5484 | ScratchRegisterScope ensure_scratch( |
| 5485 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5486 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5487 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5488 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5489 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5490 | } |
| 5491 | |
| 5492 | void ParallelMoveResolverX86::MoveMemoryToMemory64(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5493 | ScratchRegisterScope ensure_scratch( |
| 5494 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5495 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5496 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5497 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5498 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 5499 | __ movl(temp_reg, Address(ESP, src + stack_offset + kX86WordSize)); |
| 5500 | __ movl(Address(ESP, dst + stack_offset + kX86WordSize), temp_reg); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5501 | } |
| 5502 | |
| 5503 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5504 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5505 | Location source = move->GetSource(); |
| 5506 | Location destination = move->GetDestination(); |
| 5507 | |
| 5508 | if (source.IsRegister()) { |
| 5509 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5510 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5511 | } else if (destination.IsFpuRegister()) { |
| 5512 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5513 | } else { |
| 5514 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5515 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5516 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5517 | } else if (source.IsRegisterPair()) { |
| 5518 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 5519 | // Create stack space for 2 elements. |
| 5520 | __ subl(ESP, Immediate(2 * elem_size)); |
| 5521 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 5522 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 5523 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 5524 | // And remove the temporary stack space we allocated. |
| 5525 | __ addl(ESP, Immediate(2 * elem_size)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5526 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5527 | if (destination.IsRegister()) { |
| 5528 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
| 5529 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5530 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5531 | } else if (destination.IsRegisterPair()) { |
| 5532 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 5533 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 5534 | __ psrlq(src_reg, Immediate(32)); |
| 5535 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5536 | } else if (destination.IsStackSlot()) { |
| 5537 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5538 | } else { |
| 5539 | DCHECK(destination.IsDoubleStackSlot()); |
| 5540 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5541 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5542 | } else if (source.IsStackSlot()) { |
| 5543 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5544 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5545 | } else if (destination.IsFpuRegister()) { |
| 5546 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5547 | } else { |
| 5548 | DCHECK(destination.IsStackSlot()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5549 | MoveMemoryToMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5550 | } |
| 5551 | } else if (source.IsDoubleStackSlot()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5552 | if (destination.IsRegisterPair()) { |
| 5553 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 5554 | __ movl(destination.AsRegisterPairHigh<Register>(), |
| 5555 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 5556 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5557 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 5558 | } else { |
| 5559 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5560 | MoveMemoryToMemory64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5561 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5562 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5563 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5564 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5565 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5566 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5567 | if (value == 0) { |
| 5568 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5569 | } else { |
| 5570 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 5571 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5572 | } else { |
| 5573 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5574 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5575 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5576 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5577 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5578 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5579 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5580 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5581 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5582 | if (value == 0) { |
| 5583 | // Easy handling of 0.0. |
| 5584 | __ xorps(dest, dest); |
| 5585 | } else { |
| 5586 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5587 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5588 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5589 | __ movl(temp, Immediate(value)); |
| 5590 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5591 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5592 | } else { |
| 5593 | DCHECK(destination.IsStackSlot()) << destination; |
| 5594 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 5595 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5596 | } else if (constant->IsLongConstant()) { |
| 5597 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5598 | int32_t low_value = Low32Bits(value); |
| 5599 | int32_t high_value = High32Bits(value); |
| 5600 | Immediate low(low_value); |
| 5601 | Immediate high(high_value); |
| 5602 | if (destination.IsDoubleStackSlot()) { |
| 5603 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5604 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5605 | } else { |
| 5606 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 5607 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 5608 | } |
| 5609 | } else { |
| 5610 | DCHECK(constant->IsDoubleConstant()); |
| 5611 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5612 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5613 | int32_t low_value = Low32Bits(value); |
| 5614 | int32_t high_value = High32Bits(value); |
| 5615 | Immediate low(low_value); |
| 5616 | Immediate high(high_value); |
| 5617 | if (destination.IsFpuRegister()) { |
| 5618 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5619 | if (value == 0) { |
| 5620 | // Easy handling of 0.0. |
| 5621 | __ xorpd(dest, dest); |
| 5622 | } else { |
| 5623 | __ pushl(high); |
| 5624 | __ pushl(low); |
| 5625 | __ movsd(dest, Address(ESP, 0)); |
| 5626 | __ addl(ESP, Immediate(8)); |
| 5627 | } |
| 5628 | } else { |
| 5629 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5630 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5631 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5632 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5633 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5634 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5635 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5636 | } |
| 5637 | } |
| 5638 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 5639 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5640 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 5641 | ScratchRegisterScope ensure_scratch( |
| 5642 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 5643 | |
| 5644 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5645 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 5646 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 5647 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5648 | } |
| 5649 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5650 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5651 | ScratchRegisterScope ensure_scratch( |
| 5652 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5653 | |
| 5654 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5655 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5656 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 5657 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 5658 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5659 | } |
| 5660 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5661 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5662 | ScratchRegisterScope ensure_scratch1( |
| 5663 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5664 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5665 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 5666 | ScratchRegisterScope ensure_scratch2( |
| 5667 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5668 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5669 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 5670 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 5671 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 5672 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 5673 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 5674 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5675 | } |
| 5676 | |
| 5677 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5678 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5679 | Location source = move->GetSource(); |
| 5680 | Location destination = move->GetDestination(); |
| 5681 | |
| 5682 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 5683 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 5684 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5685 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5686 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5687 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5688 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5689 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5690 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5691 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5692 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 5693 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5694 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 5695 | // Use XOR Swap algorithm to avoid a temporary. |
| 5696 | DCHECK_NE(source.reg(), destination.reg()); |
| 5697 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5698 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5699 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5700 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 5701 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 5702 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 5703 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5704 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 5705 | // Take advantage of the 16 bytes in the XMM register. |
| 5706 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 5707 | Address stack(ESP, destination.GetStackIndex()); |
| 5708 | // Load the double into the high doubleword. |
| 5709 | __ movhpd(reg, stack); |
| 5710 | |
| 5711 | // Store the low double into the destination. |
| 5712 | __ movsd(stack, reg); |
| 5713 | |
| 5714 | // Move the high double to the low double. |
| 5715 | __ psrldq(reg, Immediate(8)); |
| 5716 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 5717 | // Take advantage of the 16 bytes in the XMM register. |
| 5718 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 5719 | Address stack(ESP, source.GetStackIndex()); |
| 5720 | // Load the double into the high doubleword. |
| 5721 | __ movhpd(reg, stack); |
| 5722 | |
| 5723 | // Store the low double into the destination. |
| 5724 | __ movsd(stack, reg); |
| 5725 | |
| 5726 | // Move the high double to the low double. |
| 5727 | __ psrldq(reg, Immediate(8)); |
| 5728 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
| 5729 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 5730 | Exchange(destination.GetHighStackIndex(kX86WordSize), source.GetHighStackIndex(kX86WordSize)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5731 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5732 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5733 | } |
| 5734 | } |
| 5735 | |
| 5736 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 5737 | __ pushl(static_cast<Register>(reg)); |
| 5738 | } |
| 5739 | |
| 5740 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 5741 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5742 | } |
| 5743 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5744 | HLoadClass::LoadKind CodeGeneratorX86::GetSupportedLoadClassKind( |
| 5745 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5746 | switch (desired_class_load_kind) { |
| 5747 | case HLoadClass::LoadKind::kReferrersClass: |
| 5748 | break; |
| 5749 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5750 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5751 | break; |
| 5752 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5753 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5754 | FALLTHROUGH_INTENDED; |
| 5755 | case HLoadClass::LoadKind::kDexCachePcRelative: |
| 5756 | DCHECK(!Runtime::Current()->UseJitCompilation()); // Note: boot image is also non-JIT. |
| 5757 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 5758 | // is incompatible with it. |
| 5759 | // TODO: Create as many X86ComputeBaseMethodAddress instructions as needed for methods |
| 5760 | // with irreducible loops. |
| 5761 | if (GetGraph()->HasIrreducibleLoops()) { |
| 5762 | return HLoadClass::LoadKind::kDexCacheViaMethod; |
| 5763 | } |
| 5764 | break; |
| 5765 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5766 | break; |
| 5767 | case HLoadClass::LoadKind::kDexCacheAddress: |
| 5768 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5769 | break; |
| 5770 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 5771 | break; |
| 5772 | } |
| 5773 | return desired_class_load_kind; |
| 5774 | } |
| 5775 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5776 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5777 | if (cls->NeedsAccessCheck()) { |
| 5778 | InvokeRuntimeCallingConvention calling_convention; |
| 5779 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5780 | cls, |
| 5781 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 5782 | Location::RegisterLocation(EAX), |
| 5783 | /* code_generator_supports_read_barrier */ true); |
| 5784 | return; |
| 5785 | } |
| 5786 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5787 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 5788 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5789 | ? LocationSummary::kCallOnSlowPath |
| 5790 | : LocationSummary::kNoCall; |
| 5791 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5792 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5793 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5794 | } |
| 5795 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5796 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 5797 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
| 5798 | load_kind == HLoadClass::LoadKind::kDexCacheViaMethod || |
| 5799 | load_kind == HLoadClass::LoadKind::kBootImageLinkTimePcRelative || |
| 5800 | load_kind == HLoadClass::LoadKind::kDexCachePcRelative) { |
| 5801 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5802 | } |
| 5803 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5804 | } |
| 5805 | |
| 5806 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5807 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5808 | if (cls->NeedsAccessCheck()) { |
| 5809 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 5810 | codegen_->InvokeRuntime(kQuickInitializeTypeAndVerifyAccess, cls, cls->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5811 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5812 | return; |
| 5813 | } |
| 5814 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5815 | Location out_loc = locations->Out(); |
| 5816 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5817 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5818 | bool generate_null_check = false; |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5819 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5820 | switch (cls->GetLoadKind()) { |
| 5821 | case HLoadClass::LoadKind::kReferrersClass: { |
| 5822 | DCHECK(!cls->CanCallRuntime()); |
| 5823 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5824 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5825 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 5826 | GenerateGcRootFieldLoad( |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5827 | cls, |
| 5828 | out_loc, |
| 5829 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), |
| 5830 | /*fixup_label*/ nullptr, |
| 5831 | requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5832 | break; |
| 5833 | } |
| 5834 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5835 | DCHECK(!requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5836 | __ movl(out, Immediate(/* placeholder */ 0)); |
| 5837 | codegen_->RecordTypePatch(cls); |
| 5838 | break; |
| 5839 | } |
| 5840 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5841 | DCHECK(!requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5842 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 5843 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
| 5844 | codegen_->RecordTypePatch(cls); |
| 5845 | break; |
| 5846 | } |
| 5847 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5848 | DCHECK(!requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5849 | DCHECK_NE(cls->GetAddress(), 0u); |
| 5850 | uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress()); |
| 5851 | __ movl(out, Immediate(address)); |
| 5852 | codegen_->RecordSimplePatch(); |
| 5853 | break; |
| 5854 | } |
| 5855 | case HLoadClass::LoadKind::kDexCacheAddress: { |
| 5856 | DCHECK_NE(cls->GetAddress(), 0u); |
| 5857 | uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress()); |
| 5858 | // /* GcRoot<mirror::Class> */ out = *address |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5859 | GenerateGcRootFieldLoad(cls, |
| 5860 | out_loc, |
| 5861 | Address::Absolute(address), |
| 5862 | /*fixup_label*/ nullptr, |
| 5863 | requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5864 | generate_null_check = !cls->IsInDexCache(); |
| 5865 | break; |
| 5866 | } |
| 5867 | case HLoadClass::LoadKind::kDexCachePcRelative: { |
| 5868 | Register base_reg = locations->InAt(0).AsRegister<Register>(); |
| 5869 | uint32_t offset = cls->GetDexCacheElementOffset(); |
| 5870 | Label* fixup_label = codegen_->NewPcRelativeDexCacheArrayPatch(cls->GetDexFile(), offset); |
| 5871 | // /* GcRoot<mirror::Class> */ out = *(base + offset) /* PC-relative */ |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5872 | GenerateGcRootFieldLoad(cls, |
| 5873 | out_loc, |
| 5874 | Address(base_reg, CodeGeneratorX86::kDummy32BitOffset), |
| 5875 | fixup_label, |
| 5876 | requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5877 | generate_null_check = !cls->IsInDexCache(); |
| 5878 | break; |
| 5879 | } |
| 5880 | case HLoadClass::LoadKind::kDexCacheViaMethod: { |
| 5881 | // /* GcRoot<mirror::Class>[] */ out = |
| 5882 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 5883 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 5884 | __ movl(out, Address(current_method, |
| 5885 | ArtMethod::DexCacheResolvedTypesOffset(kX86PointerSize).Int32Value())); |
| 5886 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5887 | GenerateGcRootFieldLoad(cls, |
| 5888 | out_loc, |
| 5889 | Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())), |
| 5890 | /*fixup_label*/ nullptr, |
| 5891 | requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5892 | generate_null_check = !cls->IsInDexCache(); |
| 5893 | break; |
| 5894 | } |
| 5895 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5896 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5897 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 5898 | DCHECK(cls->CanCallRuntime()); |
| 5899 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 5900 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5901 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5902 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5903 | if (generate_null_check) { |
| 5904 | __ testl(out, out); |
| 5905 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5906 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5907 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5908 | if (cls->MustGenerateClinitCheck()) { |
| 5909 | GenerateClassInitializationCheck(slow_path, out); |
| 5910 | } else { |
| 5911 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5912 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5913 | } |
| 5914 | } |
| 5915 | |
| 5916 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 5917 | LocationSummary* locations = |
| 5918 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5919 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5920 | if (check->HasUses()) { |
| 5921 | locations->SetOut(Location::SameAsFirstInput()); |
| 5922 | } |
| 5923 | } |
| 5924 | |
| 5925 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5926 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5927 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5928 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5929 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5930 | GenerateClassInitializationCheck(slow_path, |
| 5931 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5932 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5933 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5934 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5935 | SlowPathCode* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5936 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 5937 | Immediate(mirror::Class::kStatusInitialized)); |
| 5938 | __ j(kLess, slow_path->GetEntryLabel()); |
| 5939 | __ Bind(slow_path->GetExitLabel()); |
| 5940 | // No need for memory fence, thanks to the X86 memory model. |
| 5941 | } |
| 5942 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5943 | HLoadString::LoadKind CodeGeneratorX86::GetSupportedLoadStringKind( |
| 5944 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5945 | switch (desired_string_load_kind) { |
| 5946 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5947 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5948 | break; |
| 5949 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 5950 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5951 | FALLTHROUGH_INTENDED; |
| 5952 | case HLoadString::LoadKind::kDexCachePcRelative: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5953 | DCHECK(!Runtime::Current()->UseJitCompilation()); // Note: boot image is also non-JIT. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5954 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 5955 | // is incompatible with it. |
| 5956 | // TODO: Create as many X86ComputeBaseMethodAddress instructions as needed for methods |
| 5957 | // with irreducible loops. |
| 5958 | if (GetGraph()->HasIrreducibleLoops()) { |
| 5959 | return HLoadString::LoadKind::kDexCacheViaMethod; |
| 5960 | } |
| 5961 | break; |
| 5962 | case HLoadString::LoadKind::kBootImageAddress: |
| 5963 | break; |
| 5964 | case HLoadString::LoadKind::kDexCacheAddress: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5965 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5966 | break; |
| 5967 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 5968 | break; |
| 5969 | } |
| 5970 | return desired_string_load_kind; |
| 5971 | } |
| 5972 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5973 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5974 | LocationSummary::CallKind call_kind = (load->NeedsEnvironment() || kEmitCompilerReadBarrier) |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 5975 | ? LocationSummary::kCallOnMainOnly |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5976 | : LocationSummary::kNoCall; |
| 5977 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5978 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 5979 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod || |
| 5980 | load_kind == HLoadString::LoadKind::kBootImageLinkTimePcRelative || |
| 5981 | load_kind == HLoadString::LoadKind::kDexCachePcRelative) { |
| 5982 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5983 | } |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 5984 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod) { |
| 5985 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 5986 | } else { |
| 5987 | locations->SetOut(Location::RequiresRegister()); |
| 5988 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5989 | } |
| 5990 | |
| 5991 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5992 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5993 | Location out_loc = locations->Out(); |
| 5994 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5995 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5996 | switch (load->GetLoadKind()) { |
| 5997 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5998 | __ movl(out, Immediate(/* placeholder */ 0)); |
| 5999 | codegen_->RecordStringPatch(load); |
| 6000 | return; // No dex cache slow path. |
| 6001 | } |
| 6002 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6003 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6004 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
| 6005 | codegen_->RecordStringPatch(load); |
| 6006 | return; // No dex cache slow path. |
| 6007 | } |
| 6008 | case HLoadString::LoadKind::kBootImageAddress: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6009 | DCHECK_NE(load->GetAddress(), 0u); |
| 6010 | uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress()); |
| 6011 | __ movl(out, Immediate(address)); |
| 6012 | codegen_->RecordSimplePatch(); |
| 6013 | return; // No dex cache slow path. |
| 6014 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6015 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6016 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6017 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6018 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6019 | // TODO: Re-add the compiler code to do string dex cache lookup again. |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6020 | InvokeRuntimeCallingConvention calling_convention; |
| 6021 | __ movl(calling_convention.GetRegisterAt(0), Immediate(load->GetStringIndex())); |
| 6022 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 6023 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6024 | } |
| 6025 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6026 | static Address GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6027 | return Address::Absolute(Thread::ExceptionOffset<kX86PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6028 | } |
| 6029 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6030 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 6031 | LocationSummary* locations = |
| 6032 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 6033 | locations->SetOut(Location::RequiresRegister()); |
| 6034 | } |
| 6035 | |
| 6036 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6037 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 6038 | } |
| 6039 | |
| 6040 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
| 6041 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 6042 | } |
| 6043 | |
| 6044 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6045 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6046 | } |
| 6047 | |
| 6048 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| 6049 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6050 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6051 | InvokeRuntimeCallingConvention calling_convention; |
| 6052 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6053 | } |
| 6054 | |
| 6055 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6056 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6057 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6058 | } |
| 6059 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6060 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 6061 | return kEmitCompilerReadBarrier && |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6062 | !kUseBakerReadBarrier && |
| 6063 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6064 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6065 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 6066 | } |
| 6067 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6068 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6069 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6070 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6071 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6072 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6073 | case TypeCheckKind::kExactCheck: |
| 6074 | case TypeCheckKind::kAbstractClassCheck: |
| 6075 | case TypeCheckKind::kClassHierarchyCheck: |
| 6076 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6077 | call_kind = |
| 6078 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6079 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6080 | break; |
| 6081 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6082 | case TypeCheckKind::kUnresolvedCheck: |
| 6083 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6084 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6085 | break; |
| 6086 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6087 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6088 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6089 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6090 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6091 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6092 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6093 | locations->SetInAt(1, Location::Any()); |
| 6094 | // Note that TypeCheckSlowPathX86 uses this "out" register too. |
| 6095 | locations->SetOut(Location::RequiresRegister()); |
| 6096 | // When read barriers are enabled, we need a temporary register for |
| 6097 | // some cases. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6098 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6099 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6100 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6101 | } |
| 6102 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6103 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6104 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6105 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6106 | Location obj_loc = locations->InAt(0); |
| 6107 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6108 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6109 | Location out_loc = locations->Out(); |
| 6110 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6111 | Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6112 | locations->GetTemp(0) : |
| 6113 | Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6114 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6115 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6116 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6117 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6118 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6119 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6120 | |
| 6121 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6122 | // Avoid null check if we know obj is not null. |
| 6123 | if (instruction->MustDoNullCheck()) { |
| 6124 | __ testl(obj, obj); |
| 6125 | __ j(kEqual, &zero); |
| 6126 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6127 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6128 | // /* HeapReference<Class> */ out = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6129 | GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6130 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6131 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6132 | case TypeCheckKind::kExactCheck: { |
| 6133 | if (cls.IsRegister()) { |
| 6134 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6135 | } else { |
| 6136 | DCHECK(cls.IsStackSlot()) << cls; |
| 6137 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6138 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6139 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6140 | // Classes must be equal for the instanceof to succeed. |
| 6141 | __ j(kNotEqual, &zero); |
| 6142 | __ movl(out, Immediate(1)); |
| 6143 | __ jmp(&done); |
| 6144 | break; |
| 6145 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6146 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6147 | case TypeCheckKind::kAbstractClassCheck: { |
| 6148 | // If the class is abstract, we eagerly fetch the super class of the |
| 6149 | // object to avoid doing a comparison we know will fail. |
| 6150 | NearLabel loop; |
| 6151 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6152 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6153 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6154 | __ testl(out, out); |
| 6155 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6156 | __ j(kEqual, &done); |
| 6157 | if (cls.IsRegister()) { |
| 6158 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6159 | } else { |
| 6160 | DCHECK(cls.IsStackSlot()) << cls; |
| 6161 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6162 | } |
| 6163 | __ j(kNotEqual, &loop); |
| 6164 | __ movl(out, Immediate(1)); |
| 6165 | if (zero.IsLinked()) { |
| 6166 | __ jmp(&done); |
| 6167 | } |
| 6168 | break; |
| 6169 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6170 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6171 | case TypeCheckKind::kClassHierarchyCheck: { |
| 6172 | // Walk over the class hierarchy to find a match. |
| 6173 | NearLabel loop, success; |
| 6174 | __ Bind(&loop); |
| 6175 | if (cls.IsRegister()) { |
| 6176 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6177 | } else { |
| 6178 | DCHECK(cls.IsStackSlot()) << cls; |
| 6179 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6180 | } |
| 6181 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6182 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6183 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6184 | __ testl(out, out); |
| 6185 | __ j(kNotEqual, &loop); |
| 6186 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6187 | __ jmp(&done); |
| 6188 | __ Bind(&success); |
| 6189 | __ movl(out, Immediate(1)); |
| 6190 | if (zero.IsLinked()) { |
| 6191 | __ jmp(&done); |
| 6192 | } |
| 6193 | break; |
| 6194 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6195 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6196 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6197 | // Do an exact check. |
| 6198 | NearLabel exact_check; |
| 6199 | if (cls.IsRegister()) { |
| 6200 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6201 | } else { |
| 6202 | DCHECK(cls.IsStackSlot()) << cls; |
| 6203 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6204 | } |
| 6205 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6206 | // 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] | 6207 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6208 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6209 | __ testl(out, out); |
| 6210 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6211 | __ j(kEqual, &done); |
| 6212 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 6213 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6214 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6215 | __ movl(out, Immediate(1)); |
| 6216 | __ jmp(&done); |
| 6217 | break; |
| 6218 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6219 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6220 | case TypeCheckKind::kArrayCheck: { |
| 6221 | if (cls.IsRegister()) { |
| 6222 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6223 | } else { |
| 6224 | DCHECK(cls.IsStackSlot()) << cls; |
| 6225 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6226 | } |
| 6227 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6228 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6229 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6230 | codegen_->AddSlowPath(slow_path); |
| 6231 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6232 | __ movl(out, Immediate(1)); |
| 6233 | if (zero.IsLinked()) { |
| 6234 | __ jmp(&done); |
| 6235 | } |
| 6236 | break; |
| 6237 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6238 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6239 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6240 | case TypeCheckKind::kInterfaceCheck: { |
| 6241 | // 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] | 6242 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6243 | // cases. |
| 6244 | // |
| 6245 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6246 | // entry point without resorting to a type checking slow path |
| 6247 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6248 | // require to assign fixed registers for the inputs of this |
| 6249 | // HInstanceOf instruction (following the runtime calling |
| 6250 | // convention), which might be cluttered by the potential first |
| 6251 | // read barrier emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6252 | // |
| 6253 | // TODO: Introduce a new runtime entry point taking the object |
| 6254 | // to test (instead of its class) as argument, and let it deal |
| 6255 | // with the read barrier issues. This will let us refactor this |
| 6256 | // case of the `switch` code as it was previously (with a direct |
| 6257 | // call to the runtime not using a type checking slow path). |
| 6258 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6259 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6260 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6261 | /* is_fatal */ false); |
| 6262 | codegen_->AddSlowPath(slow_path); |
| 6263 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6264 | if (zero.IsLinked()) { |
| 6265 | __ jmp(&done); |
| 6266 | } |
| 6267 | break; |
| 6268 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6269 | } |
| 6270 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6271 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6272 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6273 | __ xorl(out, out); |
| 6274 | } |
| 6275 | |
| 6276 | if (done.IsLinked()) { |
| 6277 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6278 | } |
| 6279 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6280 | if (slow_path != nullptr) { |
| 6281 | __ Bind(slow_path->GetExitLabel()); |
| 6282 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6283 | } |
| 6284 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6285 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6286 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 6287 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6288 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6289 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6290 | case TypeCheckKind::kExactCheck: |
| 6291 | case TypeCheckKind::kAbstractClassCheck: |
| 6292 | case TypeCheckKind::kClassHierarchyCheck: |
| 6293 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6294 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 6295 | LocationSummary::kCallOnSlowPath : |
| 6296 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6297 | break; |
| 6298 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6299 | case TypeCheckKind::kUnresolvedCheck: |
| 6300 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6301 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6302 | break; |
| 6303 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6304 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6305 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6306 | locations->SetInAt(1, Location::Any()); |
| 6307 | // Note that TypeCheckSlowPathX86 uses this "temp" register too. |
| 6308 | locations->AddTemp(Location::RequiresRegister()); |
| 6309 | // When read barriers are enabled, we need an additional temporary |
| 6310 | // register for some cases. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6311 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6312 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6313 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6314 | } |
| 6315 | |
| 6316 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6317 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6318 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6319 | Location obj_loc = locations->InAt(0); |
| 6320 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6321 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6322 | Location temp_loc = locations->GetTemp(0); |
| 6323 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6324 | Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6325 | locations->GetTemp(1) : |
| 6326 | Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6327 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6328 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6329 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6330 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6331 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6332 | bool is_type_check_slow_path_fatal = |
| 6333 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 6334 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6335 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6336 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 6337 | !instruction->CanThrowIntoCatchBlock(); |
| 6338 | SlowPathCode* type_check_slow_path = |
| 6339 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6340 | is_type_check_slow_path_fatal); |
| 6341 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6342 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6343 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6344 | // Avoid null check if we know obj is not null. |
| 6345 | if (instruction->MustDoNullCheck()) { |
| 6346 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6347 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6348 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6349 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6350 | // /* HeapReference<Class> */ temp = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6351 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6352 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6353 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6354 | case TypeCheckKind::kExactCheck: |
| 6355 | case TypeCheckKind::kArrayCheck: { |
| 6356 | if (cls.IsRegister()) { |
| 6357 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6358 | } else { |
| 6359 | DCHECK(cls.IsStackSlot()) << cls; |
| 6360 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6361 | } |
| 6362 | // Jump to slow path for throwing the exception or doing a |
| 6363 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6364 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6365 | break; |
| 6366 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6367 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6368 | case TypeCheckKind::kAbstractClassCheck: { |
| 6369 | // If the class is abstract, we eagerly fetch the super class of the |
| 6370 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6371 | NearLabel loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6372 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6373 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6374 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6375 | |
| 6376 | // If the class reference currently in `temp` is not null, jump |
| 6377 | // to the `compare_classes` label to compare it with the checked |
| 6378 | // class. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6379 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6380 | __ j(kNotEqual, &compare_classes); |
| 6381 | // Otherwise, jump to the slow path to throw the exception. |
| 6382 | // |
| 6383 | // But before, move back the object's class into `temp` before |
| 6384 | // going into the slow path, as it has been overwritten in the |
| 6385 | // meantime. |
| 6386 | // /* HeapReference<Class> */ temp = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6387 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6388 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6389 | |
| 6390 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6391 | if (cls.IsRegister()) { |
| 6392 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6393 | } else { |
| 6394 | DCHECK(cls.IsStackSlot()) << cls; |
| 6395 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6396 | } |
| 6397 | __ j(kNotEqual, &loop); |
| 6398 | break; |
| 6399 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6400 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6401 | case TypeCheckKind::kClassHierarchyCheck: { |
| 6402 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6403 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6404 | __ Bind(&loop); |
| 6405 | if (cls.IsRegister()) { |
| 6406 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6407 | } else { |
| 6408 | DCHECK(cls.IsStackSlot()) << cls; |
| 6409 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6410 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6411 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6412 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6413 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6414 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6415 | |
| 6416 | // If the class reference currently in `temp` is not null, jump |
| 6417 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6418 | __ testl(temp, temp); |
| 6419 | __ j(kNotEqual, &loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6420 | // Otherwise, jump to the slow path to throw the exception. |
| 6421 | // |
| 6422 | // But before, move back the object's class into `temp` before |
| 6423 | // going into the slow path, as it has been overwritten in the |
| 6424 | // meantime. |
| 6425 | // /* HeapReference<Class> */ temp = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6426 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6427 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6428 | break; |
| 6429 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6430 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6431 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6432 | // Do an exact check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6433 | NearLabel check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6434 | if (cls.IsRegister()) { |
| 6435 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6436 | } else { |
| 6437 | DCHECK(cls.IsStackSlot()) << cls; |
| 6438 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6439 | } |
| 6440 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6441 | |
| 6442 | // 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] | 6443 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6444 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6445 | |
| 6446 | // If the component type is not null (i.e. the object is indeed |
| 6447 | // an array), jump to label `check_non_primitive_component_type` |
| 6448 | // to further check that this component type is not a primitive |
| 6449 | // type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6450 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6451 | __ j(kNotEqual, &check_non_primitive_component_type); |
| 6452 | // Otherwise, jump to the slow path to throw the exception. |
| 6453 | // |
| 6454 | // But before, move back the object's class into `temp` before |
| 6455 | // going into the slow path, as it has been overwritten in the |
| 6456 | // meantime. |
| 6457 | // /* HeapReference<Class> */ temp = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6458 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6459 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6460 | |
| 6461 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6462 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6463 | __ j(kEqual, &done); |
| 6464 | // Same comment as above regarding `temp` and the slow path. |
| 6465 | // /* HeapReference<Class> */ temp = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6466 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6467 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 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: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6472 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6473 | // We always go into the type check slow path for the unresolved |
| 6474 | // and interface check cases. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6475 | // |
| 6476 | // We cannot directly call the CheckCast runtime entry point |
| 6477 | // without resorting to a type checking slow path here (i.e. by |
| 6478 | // calling InvokeRuntime directly), as it would require to |
| 6479 | // assign fixed registers for the inputs of this HInstanceOf |
| 6480 | // instruction (following the runtime calling convention), which |
| 6481 | // might be cluttered by the potential first read barrier |
| 6482 | // emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6483 | // |
| 6484 | // TODO: Introduce a new runtime entry point taking the object |
| 6485 | // to test (instead of its class) as argument, and let it deal |
| 6486 | // with the read barrier issues. This will let us refactor this |
| 6487 | // case of the `switch` code as it was previously (with a direct |
| 6488 | // call to the runtime not using a type checking slow path). |
| 6489 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6490 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6491 | break; |
| 6492 | } |
| 6493 | __ Bind(&done); |
| 6494 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6495 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6496 | } |
| 6497 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6498 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6499 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6500 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6501 | InvokeRuntimeCallingConvention calling_convention; |
| 6502 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6503 | } |
| 6504 | |
| 6505 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6506 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject |
| 6507 | : kQuickUnlockObject, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6508 | instruction, |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6509 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6510 | if (instruction->IsEnter()) { |
| 6511 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6512 | } else { |
| 6513 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6514 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6515 | } |
| 6516 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6517 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6518 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6519 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6520 | |
| 6521 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6522 | LocationSummary* locations = |
| 6523 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6524 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6525 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6526 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6527 | locations->SetInAt(1, Location::Any()); |
| 6528 | locations->SetOut(Location::SameAsFirstInput()); |
| 6529 | } |
| 6530 | |
| 6531 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 6532 | HandleBitwiseOperation(instruction); |
| 6533 | } |
| 6534 | |
| 6535 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 6536 | HandleBitwiseOperation(instruction); |
| 6537 | } |
| 6538 | |
| 6539 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 6540 | HandleBitwiseOperation(instruction); |
| 6541 | } |
| 6542 | |
| 6543 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6544 | LocationSummary* locations = instruction->GetLocations(); |
| 6545 | Location first = locations->InAt(0); |
| 6546 | Location second = locations->InAt(1); |
| 6547 | DCHECK(first.Equals(locations->Out())); |
| 6548 | |
| 6549 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6550 | if (second.IsRegister()) { |
| 6551 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6552 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6553 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6554 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6555 | } else { |
| 6556 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6557 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6558 | } |
| 6559 | } else if (second.IsConstant()) { |
| 6560 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6561 | __ andl(first.AsRegister<Register>(), |
| 6562 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6563 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6564 | __ orl(first.AsRegister<Register>(), |
| 6565 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6566 | } else { |
| 6567 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6568 | __ xorl(first.AsRegister<Register>(), |
| 6569 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6570 | } |
| 6571 | } else { |
| 6572 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6573 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6574 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6575 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6576 | } else { |
| 6577 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6578 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6579 | } |
| 6580 | } |
| 6581 | } else { |
| 6582 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6583 | if (second.IsRegisterPair()) { |
| 6584 | if (instruction->IsAnd()) { |
| 6585 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6586 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6587 | } else if (instruction->IsOr()) { |
| 6588 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6589 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6590 | } else { |
| 6591 | DCHECK(instruction->IsXor()); |
| 6592 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6593 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6594 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6595 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6596 | if (instruction->IsAnd()) { |
| 6597 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6598 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 6599 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6600 | } else if (instruction->IsOr()) { |
| 6601 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6602 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 6603 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6604 | } else { |
| 6605 | DCHECK(instruction->IsXor()); |
| 6606 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6607 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 6608 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6609 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6610 | } else { |
| 6611 | DCHECK(second.IsConstant()) << second; |
| 6612 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6613 | int32_t low_value = Low32Bits(value); |
| 6614 | int32_t high_value = High32Bits(value); |
| 6615 | Immediate low(low_value); |
| 6616 | Immediate high(high_value); |
| 6617 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6618 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6619 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6620 | if (low_value == 0) { |
| 6621 | __ xorl(first_low, first_low); |
| 6622 | } else if (low_value != -1) { |
| 6623 | __ andl(first_low, low); |
| 6624 | } |
| 6625 | if (high_value == 0) { |
| 6626 | __ xorl(first_high, first_high); |
| 6627 | } else if (high_value != -1) { |
| 6628 | __ andl(first_high, high); |
| 6629 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6630 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6631 | if (low_value != 0) { |
| 6632 | __ orl(first_low, low); |
| 6633 | } |
| 6634 | if (high_value != 0) { |
| 6635 | __ orl(first_high, high); |
| 6636 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6637 | } else { |
| 6638 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6639 | if (low_value != 0) { |
| 6640 | __ xorl(first_low, low); |
| 6641 | } |
| 6642 | if (high_value != 0) { |
| 6643 | __ xorl(first_high, high); |
| 6644 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6645 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6646 | } |
| 6647 | } |
| 6648 | } |
| 6649 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6650 | void InstructionCodeGeneratorX86::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 6651 | Location out, |
| 6652 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6653 | Location maybe_temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6654 | Register out_reg = out.AsRegister<Register>(); |
| 6655 | if (kEmitCompilerReadBarrier) { |
| 6656 | if (kUseBakerReadBarrier) { |
| 6657 | // Load with fast path based Baker's read barrier. |
| 6658 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6659 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6660 | instruction, out, out_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6661 | } else { |
| 6662 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6663 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6664 | // in the following move operation, as we will need it for the |
| 6665 | // read barrier below. |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6666 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6667 | __ movl(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6668 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6669 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6670 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6671 | } |
| 6672 | } else { |
| 6673 | // Plain load with no read barrier. |
| 6674 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6675 | __ movl(out_reg, Address(out_reg, offset)); |
| 6676 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6677 | } |
| 6678 | } |
| 6679 | |
| 6680 | void InstructionCodeGeneratorX86::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 6681 | Location out, |
| 6682 | Location obj, |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6683 | uint32_t offset) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6684 | Register out_reg = out.AsRegister<Register>(); |
| 6685 | Register obj_reg = obj.AsRegister<Register>(); |
| 6686 | if (kEmitCompilerReadBarrier) { |
| 6687 | if (kUseBakerReadBarrier) { |
| 6688 | // Load with fast path based Baker's read barrier. |
| 6689 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6690 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6691 | instruction, out, obj_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6692 | } else { |
| 6693 | // Load with slow path based read barrier. |
| 6694 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6695 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6696 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6697 | } |
| 6698 | } else { |
| 6699 | // Plain load with no read barrier. |
| 6700 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6701 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6702 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6703 | } |
| 6704 | } |
| 6705 | |
| 6706 | void InstructionCodeGeneratorX86::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6707 | Location root, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6708 | const Address& address, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6709 | Label* fixup_label, |
| 6710 | bool requires_read_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6711 | Register root_reg = root.AsRegister<Register>(); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6712 | if (requires_read_barrier) { |
| 6713 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6714 | if (kUseBakerReadBarrier) { |
| 6715 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6716 | // Baker's read barrier are used: |
| 6717 | // |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6718 | // root = *address; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6719 | // if (Thread::Current()->GetIsGcMarking()) { |
| 6720 | // root = ReadBarrier::Mark(root) |
| 6721 | // } |
| 6722 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6723 | // /* GcRoot<mirror::Object> */ root = *address |
| 6724 | __ movl(root_reg, address); |
| 6725 | if (fixup_label != nullptr) { |
| 6726 | __ Bind(fixup_label); |
| 6727 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6728 | static_assert( |
| 6729 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6730 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6731 | "have different sizes."); |
| 6732 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6733 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6734 | "have different sizes."); |
| 6735 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6736 | // Slow path marking the GC root `root`. |
| 6737 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86( |
| 6738 | instruction, root, /* unpoison */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6739 | codegen_->AddSlowPath(slow_path); |
| 6740 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6741 | __ fs()->cmpl(Address::Absolute(Thread::IsGcMarkingOffset<kX86PointerSize>().Int32Value()), |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6742 | Immediate(0)); |
| 6743 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6744 | __ Bind(slow_path->GetExitLabel()); |
| 6745 | } else { |
| 6746 | // GC root loaded through a slow path for read barriers other |
| 6747 | // than Baker's. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6748 | // /* GcRoot<mirror::Object>* */ root = address |
| 6749 | __ leal(root_reg, address); |
| 6750 | if (fixup_label != nullptr) { |
| 6751 | __ Bind(fixup_label); |
| 6752 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6753 | // /* mirror::Object* */ root = root->Read() |
| 6754 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6755 | } |
| 6756 | } else { |
| 6757 | // Plain GC root load with no read barrier. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6758 | // /* GcRoot<mirror::Object> */ root = *address |
| 6759 | __ movl(root_reg, address); |
| 6760 | if (fixup_label != nullptr) { |
| 6761 | __ Bind(fixup_label); |
| 6762 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6763 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6764 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6765 | } |
| 6766 | } |
| 6767 | |
| 6768 | void CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6769 | Location ref, |
| 6770 | Register obj, |
| 6771 | uint32_t offset, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6772 | bool needs_null_check) { |
| 6773 | DCHECK(kEmitCompilerReadBarrier); |
| 6774 | DCHECK(kUseBakerReadBarrier); |
| 6775 | |
| 6776 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6777 | Address src(obj, offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6778 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6779 | } |
| 6780 | |
| 6781 | void CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6782 | Location ref, |
| 6783 | Register obj, |
| 6784 | uint32_t data_offset, |
| 6785 | Location index, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6786 | bool needs_null_check) { |
| 6787 | DCHECK(kEmitCompilerReadBarrier); |
| 6788 | DCHECK(kUseBakerReadBarrier); |
| 6789 | |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 6790 | static_assert( |
| 6791 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6792 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6793 | // /* HeapReference<Object> */ ref = |
| 6794 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6795 | Address src = CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6796 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6797 | } |
| 6798 | |
| 6799 | void CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6800 | Location ref, |
| 6801 | Register obj, |
| 6802 | const Address& src, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6803 | bool needs_null_check) { |
| 6804 | DCHECK(kEmitCompilerReadBarrier); |
| 6805 | DCHECK(kUseBakerReadBarrier); |
| 6806 | |
| 6807 | // In slow path based read barriers, the read barrier call is |
| 6808 | // inserted after the original load. However, in fast path based |
| 6809 | // Baker's read barriers, we need to perform the load of |
| 6810 | // mirror::Object::monitor_ *before* the original reference load. |
| 6811 | // This load-load ordering is required by the read barrier. |
| 6812 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6813 | // |
| 6814 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6815 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6816 | // HeapReference<Object> ref = *src; // Original reference load. |
| 6817 | // bool is_gray = (rb_state == ReadBarrier::gray_ptr_); |
| 6818 | // if (is_gray) { |
| 6819 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 6820 | // } |
| 6821 | // |
| 6822 | // Note: the original implementation in ReadBarrier::Barrier is |
| 6823 | // slightly more complex as: |
| 6824 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6825 | // the high-bits of rb_state, which are expected to be all zeroes |
| 6826 | // (we use CodeGeneratorX86::GenerateMemoryBarrier instead here, |
| 6827 | // which is a no-op thanks to the x86 memory model); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6828 | // - it performs additional checks that we do not do here for |
| 6829 | // performance reasons. |
| 6830 | |
| 6831 | Register ref_reg = ref.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6832 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 6833 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6834 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| 6835 | static_assert(ReadBarrier::white_ptr_ == 0, "Expecting white to have value 0"); |
| 6836 | static_assert(ReadBarrier::gray_ptr_ == 1, "Expecting gray to have value 1"); |
| 6837 | static_assert(ReadBarrier::black_ptr_ == 2, "Expecting black to have value 2"); |
| 6838 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 6839 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 6840 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 6841 | |
| 6842 | // if (rb_state == ReadBarrier::gray_ptr_) |
| 6843 | // ref = ReadBarrier::Mark(ref); |
| 6844 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 6845 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6846 | if (needs_null_check) { |
| 6847 | MaybeRecordImplicitNullCheck(instruction); |
| 6848 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6849 | |
| 6850 | // Load fence to prevent load-load reordering. |
| 6851 | // Note that this is a no-op, thanks to the x86 memory model. |
| 6852 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6853 | |
| 6854 | // The actual reference load. |
| 6855 | // /* HeapReference<Object> */ ref = *src |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6856 | __ movl(ref_reg, src); // Flags are unaffected. |
| 6857 | |
| 6858 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 6859 | // Slow path marking the object `ref` when it is gray. |
| 6860 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86( |
| 6861 | instruction, ref, /* unpoison */ true); |
| 6862 | AddSlowPath(slow_path); |
| 6863 | |
| 6864 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 6865 | __ j(kNotZero, slow_path->GetEntryLabel()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6866 | |
| 6867 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6868 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6869 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6870 | __ Bind(slow_path->GetExitLabel()); |
| 6871 | } |
| 6872 | |
| 6873 | void CodeGeneratorX86::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6874 | Location out, |
| 6875 | Location ref, |
| 6876 | Location obj, |
| 6877 | uint32_t offset, |
| 6878 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6879 | DCHECK(kEmitCompilerReadBarrier); |
| 6880 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6881 | // Insert a slow path based read barrier *after* the reference load. |
| 6882 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6883 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6884 | // reference will be carried out by the runtime within the slow |
| 6885 | // path. |
| 6886 | // |
| 6887 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6888 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6889 | // not used by the artReadBarrierSlow entry point. |
| 6890 | // |
| 6891 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6892 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 6893 | ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); |
| 6894 | AddSlowPath(slow_path); |
| 6895 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6896 | __ jmp(slow_path->GetEntryLabel()); |
| 6897 | __ Bind(slow_path->GetExitLabel()); |
| 6898 | } |
| 6899 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6900 | void CodeGeneratorX86::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6901 | Location out, |
| 6902 | Location ref, |
| 6903 | Location obj, |
| 6904 | uint32_t offset, |
| 6905 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6906 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6907 | // Baker's read barriers shall be handled by the fast path |
| 6908 | // (CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier). |
| 6909 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6910 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6911 | // by the runtime within the slow path. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6912 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6913 | } else if (kPoisonHeapReferences) { |
| 6914 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 6915 | } |
| 6916 | } |
| 6917 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6918 | void CodeGeneratorX86::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6919 | Location out, |
| 6920 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6921 | DCHECK(kEmitCompilerReadBarrier); |
| 6922 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6923 | // Insert a slow path based read barrier *after* the GC root load. |
| 6924 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6925 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6926 | // not need to do anything special for this here. |
| 6927 | SlowPathCode* slow_path = |
| 6928 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86(instruction, out, root); |
| 6929 | AddSlowPath(slow_path); |
| 6930 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6931 | __ jmp(slow_path->GetEntryLabel()); |
| 6932 | __ Bind(slow_path->GetExitLabel()); |
| 6933 | } |
| 6934 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6935 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6936 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6937 | LOG(FATAL) << "Unreachable"; |
| 6938 | } |
| 6939 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6940 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6941 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6942 | LOG(FATAL) << "Unreachable"; |
| 6943 | } |
| 6944 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6945 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6946 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6947 | LocationSummary* locations = |
| 6948 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6949 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6950 | } |
| 6951 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6952 | void InstructionCodeGeneratorX86::GenPackedSwitchWithCompares(Register value_reg, |
| 6953 | int32_t lower_bound, |
| 6954 | uint32_t num_entries, |
| 6955 | HBasicBlock* switch_block, |
| 6956 | HBasicBlock* default_block) { |
| 6957 | // Figure out the correct compare values and jump conditions. |
| 6958 | // Handle the first compare/branch as a special case because it might |
| 6959 | // jump to the default case. |
| 6960 | DCHECK_GT(num_entries, 2u); |
| 6961 | Condition first_condition; |
| 6962 | uint32_t index; |
| 6963 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 6964 | if (lower_bound != 0) { |
| 6965 | first_condition = kLess; |
| 6966 | __ cmpl(value_reg, Immediate(lower_bound)); |
| 6967 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 6968 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6969 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6970 | index = 1; |
| 6971 | } else { |
| 6972 | // Handle all the compare/jumps below. |
| 6973 | first_condition = kBelow; |
| 6974 | index = 0; |
| 6975 | } |
| 6976 | |
| 6977 | // Handle the rest of the compare/jumps. |
| 6978 | for (; index + 1 < num_entries; index += 2) { |
| 6979 | int32_t compare_to_value = lower_bound + index + 1; |
| 6980 | __ cmpl(value_reg, Immediate(compare_to_value)); |
| 6981 | // Jump to successors[index] if value < case_value[index]. |
| 6982 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 6983 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 6984 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 6985 | } |
| 6986 | |
| 6987 | if (index != num_entries) { |
| 6988 | // There are an odd number of entries. Handle the last one. |
| 6989 | DCHECK_EQ(index + 1, num_entries); |
| 6990 | __ cmpl(value_reg, Immediate(lower_bound + index)); |
| 6991 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6992 | } |
| 6993 | |
| 6994 | // And the default for any other value. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6995 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
| 6996 | __ jmp(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6997 | } |
| 6998 | } |
| 6999 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7000 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7001 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 7002 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 7003 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7004 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7005 | |
| 7006 | GenPackedSwitchWithCompares(value_reg, |
| 7007 | lower_bound, |
| 7008 | num_entries, |
| 7009 | switch_instr->GetBlock(), |
| 7010 | switch_instr->GetDefaultBlock()); |
| 7011 | } |
| 7012 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7013 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7014 | LocationSummary* locations = |
| 7015 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7016 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7017 | |
| 7018 | // Constant area pointer. |
| 7019 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7020 | |
| 7021 | // And the temporary we need. |
| 7022 | locations->AddTemp(Location::RequiresRegister()); |
| 7023 | } |
| 7024 | |
| 7025 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7026 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7027 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7028 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7029 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7030 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7031 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7032 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 7033 | GenPackedSwitchWithCompares(value_reg, |
| 7034 | lower_bound, |
| 7035 | num_entries, |
| 7036 | switch_instr->GetBlock(), |
| 7037 | default_block); |
| 7038 | return; |
| 7039 | } |
| 7040 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7041 | // Optimizing has a jump area. |
| 7042 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 7043 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 7044 | |
| 7045 | // Remove the bias, if needed. |
| 7046 | if (lower_bound != 0) { |
| 7047 | __ leal(temp_reg, Address(value_reg, -lower_bound)); |
| 7048 | value_reg = temp_reg; |
| 7049 | } |
| 7050 | |
| 7051 | // Is the value in range? |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7052 | DCHECK_GE(num_entries, 1u); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7053 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 7054 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| 7055 | |
| 7056 | // We are in the range of the table. |
| 7057 | // Load (target-constant_area) from the jump table, indexing by the value. |
| 7058 | __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); |
| 7059 | |
| 7060 | // Compute the actual target address by adding in constant_area. |
| 7061 | __ addl(temp_reg, constant_area); |
| 7062 | |
| 7063 | // And jump. |
| 7064 | __ jmp(temp_reg); |
| 7065 | } |
| 7066 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7067 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 7068 | HX86ComputeBaseMethodAddress* insn) { |
| 7069 | LocationSummary* locations = |
| 7070 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 7071 | locations->SetOut(Location::RequiresRegister()); |
| 7072 | } |
| 7073 | |
| 7074 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 7075 | HX86ComputeBaseMethodAddress* insn) { |
| 7076 | LocationSummary* locations = insn->GetLocations(); |
| 7077 | Register reg = locations->Out().AsRegister<Register>(); |
| 7078 | |
| 7079 | // Generate call to next instruction. |
| 7080 | Label next_instruction; |
| 7081 | __ call(&next_instruction); |
| 7082 | __ Bind(&next_instruction); |
| 7083 | |
| 7084 | // Remember this offset for later use with constant area. |
| 7085 | codegen_->SetMethodAddressOffset(GetAssembler()->CodeSize()); |
| 7086 | |
| 7087 | // Grab the return address off the stack. |
| 7088 | __ popl(reg); |
| 7089 | } |
| 7090 | |
| 7091 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 7092 | HX86LoadFromConstantTable* insn) { |
| 7093 | LocationSummary* locations = |
| 7094 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 7095 | |
| 7096 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7097 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 7098 | |
| 7099 | // 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] | 7100 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7101 | return; |
| 7102 | } |
| 7103 | |
| 7104 | switch (insn->GetType()) { |
| 7105 | case Primitive::kPrimFloat: |
| 7106 | case Primitive::kPrimDouble: |
| 7107 | locations->SetOut(Location::RequiresFpuRegister()); |
| 7108 | break; |
| 7109 | |
| 7110 | case Primitive::kPrimInt: |
| 7111 | locations->SetOut(Location::RequiresRegister()); |
| 7112 | break; |
| 7113 | |
| 7114 | default: |
| 7115 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7116 | } |
| 7117 | } |
| 7118 | |
| 7119 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 7120 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7121 | return; |
| 7122 | } |
| 7123 | |
| 7124 | LocationSummary* locations = insn->GetLocations(); |
| 7125 | Location out = locations->Out(); |
| 7126 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 7127 | HConstant *value = insn->GetConstant(); |
| 7128 | |
| 7129 | switch (insn->GetType()) { |
| 7130 | case Primitive::kPrimFloat: |
| 7131 | __ movss(out.AsFpuRegister<XmmRegister>(), |
| 7132 | codegen_->LiteralFloatAddress(value->AsFloatConstant()->GetValue(), const_area)); |
| 7133 | break; |
| 7134 | |
| 7135 | case Primitive::kPrimDouble: |
| 7136 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
| 7137 | codegen_->LiteralDoubleAddress(value->AsDoubleConstant()->GetValue(), const_area)); |
| 7138 | break; |
| 7139 | |
| 7140 | case Primitive::kPrimInt: |
| 7141 | __ movl(out.AsRegister<Register>(), |
| 7142 | codegen_->LiteralInt32Address(value->AsIntConstant()->GetValue(), const_area)); |
| 7143 | break; |
| 7144 | |
| 7145 | default: |
| 7146 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7147 | } |
| 7148 | } |
| 7149 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7150 | /** |
| 7151 | * Class to handle late fixup of offsets into constant area. |
| 7152 | */ |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 7153 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7154 | public: |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7155 | RIPFixup(CodeGeneratorX86& codegen, size_t offset) |
| 7156 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 7157 | |
| 7158 | protected: |
| 7159 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 7160 | |
| 7161 | CodeGeneratorX86* codegen_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7162 | |
| 7163 | private: |
| 7164 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 7165 | // Patch the correct offset for the instruction. The place to patch is the |
| 7166 | // last 4 bytes of the instruction. |
| 7167 | // The value to patch is the distance from the offset in the constant area |
| 7168 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7169 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 7170 | int32_t relative_position = constant_offset - codegen_->GetMethodAddressOffset();; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7171 | |
| 7172 | // Patch in the right value. |
| 7173 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 7174 | } |
| 7175 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7176 | // Location in constant area that the fixup refers to. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7177 | int32_t offset_into_constant_area_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7178 | }; |
| 7179 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7180 | /** |
| 7181 | * Class to handle late fixup of offsets to a jump table that will be created in the |
| 7182 | * constant area. |
| 7183 | */ |
| 7184 | class JumpTableRIPFixup : public RIPFixup { |
| 7185 | public: |
| 7186 | JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) |
| 7187 | : RIPFixup(codegen, static_cast<size_t>(-1)), switch_instr_(switch_instr) {} |
| 7188 | |
| 7189 | void CreateJumpTable() { |
| 7190 | X86Assembler* assembler = codegen_->GetAssembler(); |
| 7191 | |
| 7192 | // Ensure that the reference to the jump table has the correct offset. |
| 7193 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 7194 | SetOffset(offset_in_constant_table); |
| 7195 | |
| 7196 | // The label values in the jump table are computed relative to the |
| 7197 | // instruction addressing the constant area. |
| 7198 | const int32_t relative_offset = codegen_->GetMethodAddressOffset(); |
| 7199 | |
| 7200 | // Populate the jump table with the correct values for the jump table. |
| 7201 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 7202 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 7203 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 7204 | // The value that we want is the target offset - the position of the table. |
| 7205 | for (int32_t i = 0; i < num_entries; i++) { |
| 7206 | HBasicBlock* b = successors[i]; |
| 7207 | Label* l = codegen_->GetLabelOf(b); |
| 7208 | DCHECK(l->IsBound()); |
| 7209 | int32_t offset_to_block = l->Position() - relative_offset; |
| 7210 | assembler->AppendInt32(offset_to_block); |
| 7211 | } |
| 7212 | } |
| 7213 | |
| 7214 | private: |
| 7215 | const HX86PackedSwitch* switch_instr_; |
| 7216 | }; |
| 7217 | |
| 7218 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 7219 | // Generate the constant area if needed. |
| 7220 | X86Assembler* assembler = GetAssembler(); |
| 7221 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7222 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 7223 | // byte values. |
| 7224 | assembler->Align(4, 0); |
| 7225 | constant_area_start_ = assembler->CodeSize(); |
| 7226 | |
| 7227 | // Populate any jump tables. |
| 7228 | for (auto jump_table : fixups_to_jump_tables_) { |
| 7229 | jump_table->CreateJumpTable(); |
| 7230 | } |
| 7231 | |
| 7232 | // And now add the constant area to the generated code. |
| 7233 | assembler->AddConstantArea(); |
| 7234 | } |
| 7235 | |
| 7236 | // And finish up. |
| 7237 | CodeGenerator::Finalize(allocator); |
| 7238 | } |
| 7239 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7240 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, Register reg) { |
| 7241 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 7242 | return Address(reg, kDummy32BitOffset, fixup); |
| 7243 | } |
| 7244 | |
| 7245 | Address CodeGeneratorX86::LiteralFloatAddress(float v, Register reg) { |
| 7246 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 7247 | return Address(reg, kDummy32BitOffset, fixup); |
| 7248 | } |
| 7249 | |
| 7250 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, Register reg) { |
| 7251 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 7252 | return Address(reg, kDummy32BitOffset, fixup); |
| 7253 | } |
| 7254 | |
| 7255 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, Register reg) { |
| 7256 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 7257 | return Address(reg, kDummy32BitOffset, fixup); |
| 7258 | } |
| 7259 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 7260 | void CodeGeneratorX86::Load32BitValue(Register dest, int32_t value) { |
| 7261 | if (value == 0) { |
| 7262 | __ xorl(dest, dest); |
| 7263 | } else { |
| 7264 | __ movl(dest, Immediate(value)); |
| 7265 | } |
| 7266 | } |
| 7267 | |
| 7268 | void CodeGeneratorX86::Compare32BitValue(Register dest, int32_t value) { |
| 7269 | if (value == 0) { |
| 7270 | __ testl(dest, dest); |
| 7271 | } else { |
| 7272 | __ cmpl(dest, Immediate(value)); |
| 7273 | } |
| 7274 | } |
| 7275 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7276 | void CodeGeneratorX86::GenerateIntCompare(Location lhs, Location rhs) { |
| 7277 | Register lhs_reg = lhs.AsRegister<Register>(); |
| 7278 | if (rhs.IsConstant()) { |
| 7279 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 7280 | Compare32BitValue(lhs_reg, value); |
| 7281 | } else if (rhs.IsStackSlot()) { |
| 7282 | __ cmpl(lhs_reg, Address(ESP, rhs.GetStackIndex())); |
| 7283 | } else { |
| 7284 | __ cmpl(lhs_reg, rhs.AsRegister<Register>()); |
| 7285 | } |
| 7286 | } |
| 7287 | |
| 7288 | Address CodeGeneratorX86::ArrayAddress(Register obj, |
| 7289 | Location index, |
| 7290 | ScaleFactor scale, |
| 7291 | uint32_t data_offset) { |
| 7292 | return index.IsConstant() ? |
| 7293 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) : |
| 7294 | Address(obj, index.AsRegister<Register>(), scale, data_offset); |
| 7295 | } |
| 7296 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7297 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, |
| 7298 | Register reg, |
| 7299 | Register value) { |
| 7300 | // Create a fixup to be used to create and address the jump table. |
| 7301 | JumpTableRIPFixup* table_fixup = |
| 7302 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 7303 | |
| 7304 | // We have to populate the jump tables. |
| 7305 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7306 | |
| 7307 | // We want a scaled address, as we are extracting the correct offset from the table. |
| 7308 | return Address(reg, value, TIMES_4, kDummy32BitOffset, table_fixup); |
| 7309 | } |
| 7310 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7311 | // TODO: target as memory. |
| 7312 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, Primitive::Type type) { |
| 7313 | if (!target.IsValid()) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7314 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7315 | return; |
| 7316 | } |
| 7317 | |
| 7318 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7319 | |
| 7320 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 7321 | if (target.Equals(return_loc)) { |
| 7322 | return; |
| 7323 | } |
| 7324 | |
| 7325 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 7326 | // with the else branch. |
| 7327 | if (type == Primitive::kPrimLong) { |
| 7328 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7329 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), Primitive::kPrimInt, nullptr); |
| 7330 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), Primitive::kPrimInt, nullptr); |
| 7331 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7332 | } else { |
| 7333 | // Let the parallel move resolver take care of all of this. |
| 7334 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7335 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 7336 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7337 | } |
| 7338 | } |
| 7339 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7340 | #undef __ |
| 7341 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7342 | } // namespace x86 |
| 7343 | } // namespace art |